Search code examples
naudio

Event when N bytes have been played in a playback


I want to play an audio file and compare if the buffer with size N just played has the same main frequency as the buffer with size N just capture in the mic. Looking at the SpectrumVisualization sample seems like I have to implement my own ISampleProvider to be able to fire event when N bytes have been played from my file. Is that correct? Can I use any of the existing providers to do that?

thanks


Solution

  • yes, this is the general technique. In the demo it batches up 1024 samples before passing them to an FFT. If your algorithm can cope with arbitrary batch sizes then it might be easier just to pass the audio received in each call to Read into it, which will align with the buffer size being used by the playback device.