ArmDeveloperEcosystem / microphone-library-for-pico

Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. 🎤
Apache License 2.0
231 stars 47 forks source link

Sample rate lower than 16000 may cause some PDM microphone to stop outputting data #17

Open rxing365 opened 2 years ago

rxing365 commented 2 years ago

The output frequency of the clk pin is calculated by the sample rate, and some PDM microphone has a limited frequency range for clock speed (Like MP34Dxxx has a clock rate limit from1 to 3.25 MHz), which causes the sample rate below 16000(Corresponding to the clk frequency of 1.024MHz) to sometimes fail to make the microphone work.

sandeepmistry commented 2 years ago

Hi @rxing365,

How do you suggest this be addressed? Would you like to see a new API added?

Would changing the PDM_DECIMATION macro to 128 work for your use case?

rxing365 commented 2 years ago

Really appreciate your reply. I tested it on my adafruit board and it works. I'm trying to run some voice recognition algorithms on pi pico, it doesn't need much sound quality, the high sample rate is a big challenge for memory. A sample rate of 8000Hz is a reasonable value for my audio buffer, but it would be more convenient to have an API that would allow me to set a lower value. The PDM to PCM conversion seems to be implemented with a lookup table, does that mean it would be hard to implement functions for arbitrary decimation values? It would be a cool feature if the library could automatically adjust the decimation settings to a range acceptable to the sensor, or manually set arbitrary decimation values.