You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importarrayimporttimeimportaudiobusioimportboardimportmath# ConstantsSAMPLE_RATE=22050# Sample rate in HzDURATION=0.4# Recording duration in secondsBUFFER_SIZE=int(SAMPLE_RATE*DURATION)
# Prepare a buffer to record intobuffer=array.array("H", [0] *BUFFER_SIZE)
withaudiobusio.PDMIn(
board.GP2,
board.GP3,
sample_rate=SAMPLE_RATE,
mono=True,
oversample=64,
bit_depth=16,
startup_delay=0.2
) asmic:
# discard short period of datadump_length=int(SAMPLE_RATE*0.01)
tmp_buffer=array.array("H", [0] *dump_length)
while(dump_length>0):
samples_read=mic.record(tmp_buffer, len(tmp_buffer))
dump_length-=samples_readprint("Recording...")
offset=0whileoffset<len(buffer):
chunk_size=min(512, len(buffer) -offset)
samples_used=mic.record(memoryview(buffer)[offset:offset+chunk_size], chunk_size)
offset+=samples_usedprint("Recording complete.")
withopen(f"/audio_data{mic.sample_rate}.bin", "wb") asfile:
file.write(buffer)
file.flush()
print("Data written to file")
Behavior
When using the above code, I find that the audio data is half the expected sample rate when I inspect the data. I.e. recording a 500Hz sine tone using this code, I would expect a 22050Hz sample rate, but on inspection I see a 11025Hz sample rate because the plotted waveform from my saved data has a 1kHz frequency.
Attaching a logic analyzer to the Clock and Data pins, I see that the clock frequency is measured at 705kHz. With the args passed to the ctor to the PDMIn object, I would expect 64*22050 = 1411200 i.e. 1.41120MHz clock frequency.. I think?
Happy to dive deeper and see if I can find out what is going on and submit a PR, but just want to know first if I've misunderstood how it is meant to work! Thanks!
Description
The hardware is a Waveshare Pico Plus board, and the PDM mic is the Adafruit PDM MEMS Microphone
Additional information
No response
The text was updated successfully, but these errors were encountered:
CircuitPython version
Code/REPL
Behavior
When using the above code, I find that the audio data is half the expected sample rate when I inspect the data. I.e. recording a 500Hz sine tone using this code, I would expect a 22050Hz sample rate, but on inspection I see a 11025Hz sample rate because the plotted waveform from my saved data has a 1kHz frequency.
Attaching a logic analyzer to the Clock and Data pins, I see that the clock frequency is measured at 705kHz. With the args passed to the ctor to the PDMIn object, I would expect
64*22050 = 1411200
i.e. 1.41120MHz clock frequency.. I think?Happy to dive deeper and see if I can find out what is going on and submit a PR, but just want to know first if I've misunderstood how it is meant to work! Thanks!
Description
The hardware is a Waveshare Pico Plus board, and the PDM mic is the Adafruit PDM MEMS Microphone
Additional information
No response
The text was updated successfully, but these errors were encountered: