PDM data to speaker

Hi,I am working with pdm mic to read data .I can able to get the audio data using dmic_read api in pcm format.I got clock of 1280000 and sampling rate of 16000 of each 16 bit sample.Now I want to play that data in tas2562 speaker amplifier.I configured pins for i2s tx i.e,clock,fclk,data out pin and I got clock frequency of 507936 of sampling rate 15873.And I got following output.I am making buffer slab free for every loop.


00> [00:00:00.001,215] <inf> dmic_sample: DMIC sample
00> [00:00:00.001,229] <inf> dmic_nrfx_pdm: PDM clock frequency: 1280000, actual PCM rate: 16000
00> [00:00:00.001,268] <inf> i2s_nrfx: I2S MCK frequency: 507936, actual PCM rate: 15873
00> Configure Stream Successful.
00> Trigger Command Successful.
00> [00:00:10.911,696] <err> dmic_nrfx_pdm: No room in RX queue
00> [00:00:11.012,512] <err> i2s_nrfx: Next buffers not supplied on time
00> [00:00:11.952,097] <err> dmic_sample: read failed: -11

  • And also to mention I can see noticeable delay in the output while listening audio in speaker.Why we are getting delay ? we are doing using threads and process is straight we read and just send in speaker.I kept AUDIO_Q_LEN + 12 memory. And if I do processing in between will delay will be increased?

  • The reason for all this is that the pdm is sampling a bit faster than the I2S is outputting. This means (as an example, not actual numbers) that if the mic records for 1 second, that results in the speaker playing 1.1 seconds (a bit of slow motion). The difference is listed in the table that you pasted earlier:

    The reason the nRF54L15 is not capable to do Audio over Bluetooth LE (like the nRF5340 is) is because it lacks a HW component, the Audio PLL, which is responsible for adjusting the clock speed to avoid these mismatches. 

    There may be better ways to do this than what I suggested. It was just an attempt to make the error that you saw go away. Perhaps you can make it work with just 2 buffers, if you handle the logic yourself. Just make sure that wherever you are trying to store your dmic buffers to are free/available.

    Best regards,

    Edvin

  • Hi Edvin,thanks for that response.I understood how its working.

    And in final I want to know reading data from PDM Mic and getting PCM data will cause more processing in time in compare with using I2S MIC  with i2s_read?.I want to confirm what mic should I use as I will be doing more processing before sending to speaker.Will both the processes will require same processing or different

    Can you clarify me this thing ?

  • That questions itself is as clear as mud. Don't expect an answer unless you completely re-write that so other people have a chance to understand it.

    As a general hint: Mess with both PDM and I²S settings until sampling frequencies match exactly and use these settings going forward.

    Re-sampling (the other way to handle the difference) is non-trivial in both code and CPU cycle usage especially if both frequencies are close to each other.

Related