It has been well over a year since I last released a version of NAudio, and since then there have been loads of new features and bugfixes added, so I have decided it is time for a new drop. Another reason for releasing now is that NAudio has been getting a lot more attention recently, mainly due to StackOverflow (and even got a mention on This Week on Channel 9).

What’s New?

WaveOut has a new constructor (this is breaking change), which allows three options for waveOut callbacks. This is because there is no “one size fits all” solution, but if you are creating WaveOut on the GUI thread of a WinForms or WPF application, then the default constructor should work just fine. WaveOut also allows better flexibility over controlling the number of buffers and desired latency.

Mp3FileReader and WaveFileReader can have a stream as input, and WaveFileWriter can write to a stream. These features are useful to those wanting to stream data over networks.

The new IWaveProvider interface is like a lightweight WaveStream. It doesn’t support repositioning or length and current position reporting, making the implementation of synthesizers much simpler. The IWavePlayer interface takes an IWaveProvider rather than WaveStream. WaveStream implements IWaveProvider, so existing code continues to work just fine.

Added in LoopStream, WaveProvider32 and WaveProvider16 helper classes. Expect more to be built upon these in the future.

I have also started using the WaveBuffer class. This clever idea from Alexandre Mutel allows us to trick the .NET type system into letting us cast from byte[] to float[] or short[]. This improves performance by eliminating unnecessary copying and converting of data.

There have been many bugfixes including better support for VBR MP3 file playback.

The mixer API has had a lot of bugs fixed and improvements, though differences between Vista and XP continue to prove frustrating.

The demo project (NAudioDemo) has been improved and includes audio wave-form drawing sample code.

There is now a WPF demo as well (NAudioWpfDemo), which also shows how to draw wave-forms in WPF, and even includes some preliminary FFT drawing code.

The WaveIn support has been updated and enhanced. WaveInStream is now obsolete.

WASAPI audio capture is now supported.

NAudio should now work correctly on x64 operating systems (accomplished this by setting Visual Studio to compile for x86).

As usual, I welcome any feedback on this release. Do let me know if you use NAudio to build anything cool.

hi n20 - I think you're the first person to use that function in about 6 years. I'm hoping to integrate a much better effects framework I did for the Skype Voice Changer project in the next version of NAudio

Hi Mark,Today I tried FFT function from NAudio, works fine. Seems simplier resort for my task than using BiQuadFilter.

I have another problm with selecting input device. WaveIn.DeviceCount shows only one input device however in windows Record Control panel i can pick from several(Mic, line-in etc). Maybe is any resort from selecting from own application? (running on XP)

n2o, this is where it can get a bit confusing. The number of input sources your soundcard can support is not the same as the number of devices. In other words, you have a single input device, which can provide audio from a number of sources. It is possible to use the mixer API from NAudio to select which source you actually want to record from, although this can be a frustrating process.

I am looking at your re-sampler project example and wondering if there is a simple way to use a similar set of commands to loop through a wave file's samples and tweak the volume before writing out to a new file. I would like to not just reset the volume level on the entire file, but have a minute control over the volume at any given moment in the audio so I can fade in and out throughout the file and whatnot.Thanks for any input!Jason

the core audio code was not generated using tools but simply by examining the Windows SDK header files and trial and error. It is a slow process, and after a while I discovered that Ray Molenkamp had already done a lot of the work, so much of what is used in NAudio I have taken from his work.

Mark, NAudio looks pretty cool. I'm looking for a replacement for DirectSound now that MS has deprecated it. My app uses most of the DirectSound API. Is there an API manual or programmers guide for NAudio? I didn't see a manual on CodePlex. Thanks.

Alex Kintner

November 3. 2009 16:49

Hi Alex,the only documentation is what is on this blog (also Sebastien Gray has blogged a bit about NAudio). The best way in is to look at the source code for the NAudioDemo application.

"Mp3FileReader and WaveFileReader can have a stream as input, and WaveFileWriter can write to a stream. These features are useful to those wanting to stream data over networks."

Are there any examples of how to have WaveFileWriter write to a stream? This would make NAudio the missing link in my project. Any help here would be greatly appreciated.

Paul

November 23. 2009 10:27

Hi Paul,WaveFileWriter does have a constructor that takes a stream. However, it does need to be repositionable, as Wave Files store the length of the data at the beginning, making a Wave file stream less flexible than it might otherwise be

Just want to say a big thanks for all your hard work on NAudio, have found it an incredibly useful tool. One question - now that WaveInStream is obsolete in favour of WaveIn, is it possible to change the default input device? Is there a WaveIn equivalent to WaveInStream(int deviceNumber ... ...) where deviceNumber is the mixer I wish to use?

Just to be clear, I am not asking how to change between e.g. Stereo Mix and Microphone sources (know how to do that via the Mixer API). But I have multiple WaveIn devices and want to choose between them.

Thanks in advance

CD

CD

November 25. 2009 19:10

Hi CD,glad you're finding it useful. simply set the DeviceNumber property on WaveIn before you call StartRecording

One feature I have been toying with is the use of loopback capture (basically recording directly from the speakers, thus getting round soundcards that don't have e.g. Stereo Mix or the like). Have had some success thanks to a couple of links on Codeplex (most notably http://naudio.codeplex.com/Thread/View.aspx?ThreadId=75005). However, this solution seems limited in C# because the GC seems to be unable to cope if there is any silence at all in the audio (basically it does record audio, but the recorded clip skips and jumps all the time). I saw a suggestion here of how to fix it -

but my C++ interop skills are nowhere near good enough. Wondered if you had any other ideas of how to solve this? Would love to see this feature in the future if you are looking for ways to improve an already excellent library.

Thanks once again

CD

CD

January 2. 2010 16:35

hi mark,

first of all thanks for this wonderful library, its really useful. secondly im currently working on my final year project and i need a real time live audio input so that i can save it to an array. how is the best way to implement this using the NAudio library?

i managed to do the first tutorial on sound recording and saving the file to .wav, know i dont want to save the recorded file as .wav, but i want to save the data to an array. know im using this part of the code:

hi mark,i just need to create a button which allows me to record from a line in from the pc sound card and save the contains into a buffer...any help? i already tried but im a newbie and i got no idea what im doing

Hi Mark, firstly great library! I'm planning to use it in a 'batch mode' to create individual amplitude sample sets for a large mp3 library. I notice that your demo MeteringStream class does exactly what I need, but in realtime as it intercepts the stream en route to the WavePlayer. Do you have any example code showing simple consumption of the WaveStream with creation of volume samples - I'm getting confused by the multi channel aspects and index += 4; nature of the stream's low level format.

Again, thanks for a great library!

regards

SeanR

SeanR

February 19. 2010 20:25

Hi Mark - Tom, Sarah, Dan and Jennie here. We think that the key issue is the low latency spectrum visualisation algorithm. Really what you want to do is improve your C++ interop skills to be honest. See you in the morning!

Icanusewindowspaint

February 19. 2010 21:33

Great job, but I have a question. I searched all your blog and NAudio Discussion threads but found nothing. I have a GSM file (recorded by asterisk), how can I play it with NAudio?

@dehghan NAudio can read WAV files and use ACM codecs to decompress them. Is a GSM file a custom file format, or is it inside a WAV file? If so, you may be able to use the WaveFormatConversionStream to convert it.

I have developed a sound capturing winform application using NAudio 1.3 on c#. The idea is to capture streaming songs through sound card. It isworking perfectly fine on windows xp.But On vista and windows7 machine if there is no sound driver installed it also take mic voice with itwhich is a big issue(i have checked it on dell laptop and if i mute the microphone than it does not capture any sound )i just want to capture streaming song sound .NAudio 1.3 uses WASAPI audio capture for windows vista and 7.I need to solve thisissue urgently.

yousuf hasan

September 9. 2010 13:35

Hi Mark, I have downloaded the Naudio.dll (1.3). but when i try to play .mp3 file it gives "Not a recognised mp3 Block.". Please Provide me the new version of Naudio.dll so i can play mp3 files.

Hi Mark, your work is really amazing! I would like to ask you a question ... Is there any possibility to translate the source code to vb.net 2008? I have no knowledge they in c # and I would work together to debug and optimize code, and collaborate with the project. I'm working on a radio automation software. Alejandro ([email protected])

Anonymous

October 12. 2010 19:04

hi Alejandro,I'm afraid I won't be porting NAudio to VB.NET. It is quite usable as a library from within VB.NET if you require though.

If you want to try your hand at learning C# you will find that it is not too difficult if you know VB.NET

I am trying to get the pitch of a sound using the fft function. I created an array with the intensity of each frequency and I can get the index of the pitch. Now my problem is. How can I convert this index to a frequency.

Hi Mark, I'm developing a voip application and would like to use NAudio with Wasapi for low latency. However I need to do sample rate conversion. Do you have any recommendations? Can I use the resampler in Speex for real time conversion?

Tor

December 10. 2010 14:31

hi Tor,NAudio has two options for Resampling:the DmoResamplerStreamor the WaveFormatConversionStream (uses ACM)

does anyone know a way to detect for example the highest 10 peaks? I have implemented FFT Radix2. I am using an amplitude threshold but in most cases the amplitude threshold is too high and it doesn't detect all peaks.From what I see in excel, after recording peaks, they decrease in time. Does anyone know another way to detect the highest 10, 11 peaks( or peaks)?

Need help...PLSS

detect peaks

April 20. 2011 18:11

I downloaded your library from the official site. http://naudio.codeplex.com/releases/view/34249

But I couldn`t find any BufferedWaveProvider. This is not even in the source code. Can you check please?

About Mark Heath

I'm a Microsoft MVP and software developer based in Southampton, England, currently working as a Software Architect for NICE Systems. I create courses for Pluralsight and am the author of several open source libraries. I currently specialize in architecting Azure based systems and audio programming. You can find me on: