This project has moved. For the latest updates, please go here.

Callback function and data accessible by the callback function

Mar 29, 2010 at 3:23 PM


First of all, I would like to thank the NAudio team for creating this software package. I tried working with DirectSound and many more of the Microsoft libraries and they are pretty god awful and don't offer some of the basics that NAudio offers. So thanks a lot.

Now to my question. I am using NAudio right now for two purposes, the first is to audio files and display them in a graph. Second, playback the file. While playing the file, I am showing in the graph via a moving line, the location of the audio that is being played back. However, this approach suffers from accuracy issues as the playback thread and the graph presentation are different threads and the synchronization is problematic. And causes the playback to sound bad because of the thread thrashing.

This has led me to believe that perhaps, it might be possible to get information for the callback function. In this fashion, I can decide to move the line every couple of calls from the call back.

My questions are:

* Is this possible?

* What sort of data is received from the call back function?

* How often is the callback function called?

* Will doing something between the two calls of callback cause audio distortion in the playback?


On another subject, are there some files with documentation on the software library. I am using NAudio 1.3.


Thanks for the help,

Oded Green



Mar 29, 2010 at 5:05 PM

can you share some of the code you are using to play back audio?

How accurate does your position cursor need to be? Remember that the callback itself is not happening at the exact moment of playback, rather it is queuing up audio that will be played later.



Apr 1, 2010 at 3:54 PM

Hi Mark,

Thanks for the prompt response.

Regarding the code that I am using, I used tutorial one for the code. I made some minor modifications to suite my own purposes.

I don't the position to be millisecond accurate(although that would be nice). Coarse grain accuracy is enough.

The question I have, is there a way for me know to know what samples(their positions in the full wave) are being played? Is there away to receive such data?

Also, I prefer not changing any of NAudio's code so that in the future when there are new updates, I will be able to change to them.

Once again, is there any documentation on the software?



Apr 1, 2010 at 4:28 PM

Hi Mark,

I would like to add the following, I am currently using a thread that sleeps for a X amount of milliseconds and then I update the graph accordingly to the sleep(because this is the only clock that I currently have). However, for long waves(40 seconds), I have noticed that there is a lag between 2-5 seconds. This is due to syncronization problems, for this reason, I would like to get the data from the playback that tells me what blocks it is playing back.

Thanks again,




Apr 6, 2010 at 5:35 PM


Pleaese!!! :-)