Timing issue using memory stick in audio recorder applicatio

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I am developping an audio recording application.
I am sampling the audio from an external ADC WM8782 using 48KHz.
I am using double buffering: one for reading data microphone while the other is wriiten in USB memory stick.
I am using Fatfs to access (open, write,...) to USB memory stick.
When recording a sine signal (by connecting a sine wave to ADC input) I discovered some spikes.
After some debugging, it seems the issue is related to writing time consumption. In fact, write access to memory stick is lower than reading a complete buffer but sometimes (I don't know when) USB memory stick exceeds the time required to read a complete buffer.
Now I don't know what could be the root cause.
Is there somebody who could help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ensure that you have a proper buffer between the ADC and the memory device. Sometimes the memory device performs housekeeping, delaying the access. Also if you write very small blocks of data to the device, that will slow down the performance.

Do you have access to external RAM? Use 1-2 MB for buffering. The blocks you write to memory should be 4 kB or more (ideally the size of the FAT clusters on the drive).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Heihopp,

I am facing the issue with buffer size is 16KB (I have two buffers so 16*2 = 32KB of the total memory)and I don't have an external memory for buffering.

Is there another solution because I was planning to use high recording frequency 96K and 192K?
With this timing issue I think it wouldn't be posible, would be?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could try a new or formatted memory stick (to minimize file system overhead), use 16 bits instead of 24 format, or optimize in other ways to avoid the problem.

But I still think that a 32k buffer for 48 kHz stereo is a bit too small. Sometimes a flash drive may create a relatively long delay (100ms?) during "housekeeping", and the audio buffer must save all the data during that period. 100ms represents 19.2 kB at 48 kHz, stereo 16 bit. In addition there is file system and USB protocol overhead etc that the buffer must compensate for.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi bada, did you ever solve this? I'm encountering the same issue where I miss 1ms of data every couple ms; dma buffer doesn't complete so the USB buffer isn't ready to send.  Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heihopp described the problem. Write time on a usb stick or sdcard is indeterminate. You need a large buffer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Kartman,

 

Thanks for replying so quickly. In my case, I am using 40 buffers of 294 bytes (2 channels * 48 kHz * 24 bit rate) and I give it a 30ms delay (I allow at least 30 of these buffers to be full before starting my USB sends) but I'm still getting an underrun. I can't increase the number of buffers anymore because I'm running out of room on my mcu. How would you work around this?

 

Thanks!

 

EDIT: Just read the posts more thoroughly and maybe I might have to get an external for the buffering. I guess I wanted to know if OP had found a solution around getting an external since it seems like both of us didn't have enough memory for making the buffers larger. 

Last Edited: Mon. Sep 25, 2017 - 11:32 PM