Content originally posted in LPCWare by Pacman on Fri Nov 29 07:30:35 MST 2013
In your case, it might be the easiest to read one buffer ahead.
Eg. start by reading one buffer. Don't start playing.
Read another buffer, now start playing the first buffer.
You could perhaps use two pointers, a pointer to the next buffer to play, and a pointer to the next buffer to read into.
The normal way of doing this is to have a looping DMA buffer, and using a DMA interrupt to signal that all data has been buffered. When all data are buffered, more data is calculated or read from disk/sd/flash.
Note: You're not listing the most interesting part of the program. It would be more useful to see the reading routine and the routine that sends the data to the DAC. You might be able to speed the routines up a bit.