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

Creating metronome track to play along with my ASIO input

Sep 24, 2013 at 4:42 AM
Hello,

I am trying to implement a click track (metronome) that will play simultaneously with the asio input. The click track will be 120 beats per minute, so I need to play a certain wav file twice every second. I'm trying to figure out the best way to go about this.

Would I create a separate parallel task to run on a new thread that calls the C# Timer method? This would fire off the BufferedWaveProvider.AddSamples twice every second to play the wav file?

Or would I want both the click track & Asio output to run through the MixingSampleProvider? That way I can easily adjust the volume & panning before output?

Any guidance is greatly appreciated!
Coordinator
Sep 25, 2013 at 9:43 AM
Probably the best place to look is in the source code for the NAudio WPF demo app which has a drum machine sample. It doesn't require any timers so you can get sample accuracy in your timing.
Sep 28, 2013 at 3:56 AM
Great, looking into this now. It looks like ASIO Out implements IWavePlayer. Would I convert this to ISampleProvider in order to use inside a MixingSampleProvider? My goal is to be able to use the ASIO output & Metronome output inside a mixer.
Coordinator
Sep 29, 2013 at 7:02 AM
IWavePlayer is the base interface for everything that can play audio. In the init method it takes an IWaveProvider
It's a little complicated to set up with ASIO, but you can use a BufferedWaveProvider, copy the ASIO samples into that, convert to a SampleProvider, do your mixing, and then convert back to IWaveProvider for the IWavePlayer to play from
Oct 1, 2013 at 5:34 AM
Edited Oct 2, 2013 at 4:48 AM
Thanks Mark - I think I have this working now.