Skip to main content
2 of 4
added 198 characters in body
Florent
  • 370
  • 3
  • 18

Input/output from unsynchronized ADC/DAC

DISCLAIMER : this question is somehow related to this other question of mine, but the latter did not have any satisfying answer.

I'm working on an audio DSP project with the STM32F4xx, using 4 audio inputs and 1 audio output.

I need to

  • read each input
  • process each input's signal,
  • mix the processed signals together
  • output the result.

The input is obtained via one of the 3 STM32's internal DACs, 1 channel for each input (ie 4 channels to scan in total) and stored to a buffer using DMA.

The output is converted through a codec using an I2S bus, at 48kHz.

Everytime the codec has finished converting a buffer (or more precisely a half-buffer), it triggers a callback function in which I currently have all the DSP code. In the loop, the output samples are computed and sent to the half-buffer to be output using DMA to I2S.

Granted that I sample my input at the same rate as my output (48kHz which means that my DAC must be clocked at 4*48kHz=192kHz), how can I synchronize the ADC and the DAC conversion?

I have thought of a FIFO inbetween the input and the DSP routine, picking a sample in the queue everytime I need to process one. But I am not sure how to do that when working with chunks of data (a buffer has a depth of 64 samples).

Another solution would be to have an input buffer depth of only 1 sample, and to read this sample in the DSP routine but I am not sure weather this would work.

Does anyone knows what is the best way to do that? Or even better, how to synchronize the STM32's ADC to an external codec?

EDIT: I also thought of using the DAC in "one shot" mode ie triggering a conversion of 64 samples for all the channels everytime my codec raises its "I want samples" flag. Would that work?

Florent
  • 370
  • 3
  • 18