Is NAudio the way for me to simulate vario sound?

Feb 24, 2011 at 9:00 PM
Edited Feb 24, 2011 at 9:00 PM

Having been around the traps, and ventured down many blind alleys I  ask this question before jumping into NAudio.

My application is in VB .NET built on Visual Studio 2005.

A bit of background - StarTraX (free download from replays track files that you download from your GPS in Google Earth. It's used to replay activities such as gliding, paragliding and  hanggliging as well as skiing, cycling driving etc. Any activity where you might carry a GPS.,

I would like to add a feature that replicates the audio output from a variometer (the vertical speed indicator used by the gliding fraternity to identify thermal lift). This sounds something like this . The tone rises and falls with the value of the vertical speed (VS), and the frequency of the pulse changes with the rate of change of VS.

The VS is calculated from the track file, which provides position data roughly every one to 10 seconds, depending on the GPS characteristics. 

Whilst I'm a moderate coder with a good understanding of the physics of sound, I have not previously worked with any audio applications. Over the past couple of days, using System.Media SoundPlayer I have successfully imported and replayed wave files into my app - playing them asynchronously, but I'm using pre-recorded clips whcih have a pre-determined duration which I'm not able to clip to modify the pulse frequency. Also, I'll have to generate scores of samples to get a reasonable range of pitches.

So... my question is - Is NAudio the way for me to go to achieve these objectives?

And has anyone got some helpful suggestion?


Feb 25, 2011 at 8:53 AM

yes, NAudio can do this. you create an IWaveProvider implementation (inherit from WaveProvider32) and provide the samples by your own algorithm

see this tutorial for an example of creating a sine wave


Feb 25, 2011 at 7:03 PM
Edited Mar 3, 2011 at 10:56 PM
Hi Mark,
Thanks for the reply, and for the great work you've done.
(I totally emphathise with your blog heading! "friends and family aren't interested"!)
Sorry to be a pain, but I'm a VB coder, and whilst I have been able to succesfullt migrate your wav file split code, I'm having a challenge with playback-of-sine-wave.
I'm getting a compile error in :



 and by C# just ain't up to it. Can you assist please?


I'm working on the a[pproach If I can get it to work in C#, then I can migrate to VB.
I'm working in VS2005, .NET 2.0


Feb 25, 2011 at 8:09 PM
Edited Mar 3, 2011 at 10:57 PM
Hold your horses! I've got it running
removed the get and set to

 public float Frequency;

 public float Amplitude ;

removed the WaveProvider2 class (as it's already in 1.3)
and changed var sineWaveProvider = new SineWaveProvider32();

SineWaveProvider32 sineWaveProvider = new SineWaveProvider32();

Thanks, I'm now working on the VB version.
Feb 26, 2011 at 10:40 PM

I am making progress, but have a couple of questions.

1. When I run your example in C#, I get a beautiful continuous clear tone, but when I migrated the code to VB, I get the same continuous tone but it is overlayed with a ticking at around 150 ms frequency. Any Ideas?

2. I want to generate tone pulses at around 100 ms followed by a similar length silence. I'm doing this in a loop, like

               while (true){

And am getting the required result except there is a click at the end of the pulse. Is there anything I can do to clean this up please?


Mar 2, 2011 at 10:44 AM

I would avoid Play and Stop. Instead the WaveProvider you give to WaveOut.Init should provide tone for 100ms followed by silence for 100ms,

To get rid of clicks you need to fade in and out (or at least ensure your tone generation code always stops on a zero output)


Mar 2, 2011 at 8:38 PM
Edited Mar 3, 2011 at 10:56 PM

Hi Mark,

I understand what you are suggesting, but am struggling to work out how to implement your proposals. My VS2005 won’t load your projects so I’m working a bit blind with the 1.3 NAudio.dll and my XP won’t run your examples. I have upgrades on order.

I can’t see how to manage the WaveProvider’s duration. Could you provide an example please?

And again, could you provide an example of code that controls where the tone generation code stops please?


Mar 14, 2011 at 5:53 AM

Hi Mark,

You encouraged me to use NAudio, and now I'm stuck and you've stopped talking to me. Any chance of a response to my last post? I really would appreciate it. Thanks.

Mar 14, 2011 at 10:58 AM

hi StarTraX

I'm afraid I don't have the time to answer all the support requests that come in for NAudio, so can only occasionally come on here to provide pointers in the right direction.

WaveProviders don't have a duration. To signal the end of the data, simply return 0 from the Read method. If you want a duration and to support repositioning you can use WaveStream as the base class.