Simple example playing buffer data?

Oct 6, 2009 at 2:20 AM

Hello all,

 

I was very happy to stumble across this class library, it looks great! I've downloaded the examples but I'm having a tough time figuring out where to get started. I'd really like to see an example...just a few lines...showing how to continuously loop wave data in a buffer. For example, let's assume I've precomputed a sine wave of frequency 500 Hz and stored the samples in a short[]. How then do I play this audio in a continuous loop? Thanks so much.

 

-L

Coordinator
Oct 8, 2009 at 3:13 PM

Hi,

have a look at these recent posts on my blog:

http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html

http://mark-dot-net.blogspot.com/2009/10/looped-playback-in-net-with-naudio.html

Mark

Oct 8, 2009 at 8:55 PM

Mark,

I've looked at the October 10 post and this looks exactly like what I'm after, even the real-time wave modification part. Great stuff! Just to clarify: this seamlessly loops the sinewave until the user hits the button (StartStopSineWave), correct?

-L

Oct 8, 2009 at 9:13 PM

Sorry, one more question in addition to the one posted above. Can someone point me to the instructions on how to acquire/build the latest NAudio from the source control so I can try this out? Thanks!

 

-L

Coordinator
Oct 9, 2009 at 7:31 AM

Hi,

it should be a continuous loop, although bear in mind that if you make sudden rather than gradual changes to the Frequency or Amplitude, then you could get a discontinuity in the output, which would possibly be audible as a click

secondly, I am hoping to release a new NAudio real soon. However, to build from source, go to the Source Code tab above and in the top right corner, click Download under Latest Version. You should find NAudio.sln which you can open in visual studio and press build. You'll find the NAudio.dll in the bin/Debug folder under the NAudio project folder

 

Mark

Oct 9, 2009 at 8:53 PM

Mark,

 

I'm a little confused over the usage of the "Read" methods in your Sine Wave example.  I don't see anywhere in your code where they are explicitly being called...are these methods being called from within the WaveOut.Play() method? Is there documentation describing the IWaveProvider interface and the other classes that make up NAudio? Thanks so much.

 

-L

Coordinator
Oct 10, 2009 at 2:57 PM

yes, when you call Play on an IWavePlayer, it will call the Read method repeatedly whenever it needs to fill up a buffer. To find more documentation on NAudio, take a look at the NAudio category on my blog:

http://mark-dot-net.blogspot.com/search/label/NAudio

Mark

Oct 12, 2009 at 5:03 PM

Hi Mark,

 

I've implemented this and it's working perfectly...almost. I'm getting some pretty loud clicks whenever I change frequency "on the fly". I'm using a trackbar that sets the new frequency every time I drag it around. I've tried changing the trackbar's Min/Max properties so that every scroll event causes a smaller jump in frequency, but it has no effect on the clicking noise. Is there some way to defeat or lessen this? I'm tantalizingly close to a perfect solution. Thanks in advance!

 

-L