cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with saving PDM audio to SD card

Norman S
Associate II
Posted on April 01, 2018 at 20:13

I am trying to modify the SensorTile AudioLoop sample project to save the audio to an SD card, instead of sending it out to the audio DAC and USB. I have successfully managed to save some audio data to the SD card, but the quality is not great. Please see the attached .wav file oh my trying to speak 'this is a test'.

Any audio pros have any idea what is missing?

I created the attached audio file by loading the saved PDM file from SD card to Audacity. I loaded it as 'raw' format, mono, 16 bit frames, and about 30kHz sample rate.

#stm32-audio-framework #audio #mems-microphone
5 REPLIES 5
Norman S
Associate II
Posted on April 04, 2018 at 05:02

Well, it turns out that the above problematic audio clip is the results of saving off half the data.

PCM_Buffer is an array of uint16_t oflength AUDIO_IN_BUF_LEN. I was sendingAUDIO_IN_BUF_LEN number of elements of PCM_Buffer toDATALOG_SD_writeBuf(), but I casted PCM_Buffer as char first. Therefore, I was sending 8bit elements, not 16bit. Half my data was gone.

I was able to fix that and now the quality is better. However, there still is very clear interfearance. Interestingly, it's only when there is no silence.

Please listen to Audio_wav. Any suggestions are welcome.

________________

Attachments :

Audio_001.wav : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxqa&d=%2Fa%2F0X0000000b1M%2FABUsXOdYrfX2E.B_qaYmusO6cvQhT0M2s9TInq.LR64&asPdf=false
Alan Klimala
Associate II

Hi Norman,

It seems that we have exactly the same problem. Did you manage to solve it? How did you cut off the noise? What configuration for channels and filters did you use?

Norman S
Associate II

Hi!,

Initially my problem was caused by a bug in code that was simply dropping bits data. That was an easy fix.

However, in the end, I still got significant clipping sound in the audio. I played with the buffer length, which did change how the sound artifact appeared in the clip, however, it never went away.

If I was to try to solve this problem again, I would look at two things:

  1. Make sure that recording of the audio and writing to SD card occurs synchronously. If I recall, the microphone block and filter has some buffer that gets filled without the need to bother the CPU. The SD card writes need to happen while the buffer is being filled and not any longer.
  2. It might also be electrical noise cause by the SD card circuitry, but I don't know enough to confirm that theory.

Thank you for reply. I will try to play with SD card service. I'll share results if I manage to make the record to sound clean.

You were right, I was writing not enough data to SD card. It turned out that half of data was cut off. After tune the SD service up my record sound as expected. Thanks a lot Norman for pointing me out the direction of investigation. =)