This project has moved and is read-only. For the latest updates, please go here.

"What you hear" feature

Aug 22, 2012 at 9:52 PM


I need a "what you hear" feature, to get the sound that the sound card is playing.
I need the sound being played from Winamp, Windows Media Player, iTunes, a Web Browser or any other software.
I will use this  data to send it over the network to another destination.

Is there a way to do with NAudio?
If not, is there a way to do it using the Win32 API's? In this case, I could contribute the code to NAudio, but I need assistance with the Windows Audio API's.

Thanks and Regards,
Fernando Pelliccioni. 

Aug 27, 2012 at 10:13 PM

This is done using "loopback recording", which can be done using WASAPI in on Windows Vista and above (see the WasapiLoopbackCapture class). If you want to do it with WaveIn, you are completely reliant on what your soundcard drivers allow, and it is a lot of work.

Aug 31, 2012 at 9:24 PM

Hi Mark,

Thanks for your answer.

Let me see if I understand.

On one hand, I can use the class "WasapiLoopbackCapture" only from Windows Vista and above.
On the other hand, I can use the class "WaveIn", but I depend on the capabilities of the soundcard drivers and it's a lot of work.
I am repeating your words, I just do not understand if you are talking about two different options.

Regarding the first option (WasapiLoopbackCapture), I used the example "WAV Recording" of "NAudio Demo" and I have a little problem.The Wav file I get has an Extensible WaveFormat. This file can not be played using the examples of NAudio, because Extensible WaveFormat.

Some questions:
    1. Can I play the WAV file captured using WasapiLoopbackCapture? (Extensible WaveFormat)   
        Can I capture a wav file with Pcm WaveFormat? (Pcm format is OK to play)

     2. Can I convert the wav file to MP3 using NAudio?, Or better, I can capture directly into MP3?   
        (The NAudio converting example requires an Pcm format)   

Finally, I'm thinking of porting the NAudio code to C++ (native C++, not managed). 
For this, my plan is to, first convert the C# code to C++/CLI (Managed C++).
Once the NAudio unit tests are executed successfully, I will change the interface to a "Modern C++" design.
Then the next step is to make the code multiplatform. I intend to minimally support Windows (thanks to NAudio), Linux and MacOSX.
I think I could contribute to NAudio making it work on other platforms than Windows, using Mono.
NAudio could wrap my library for platforms other than Windows.

I'm not a "Licence Layer", so I wonder if Ms-PL supports my intentions.

Sorry for so many questions and thank you very much in advance.

Fernando Pelliccioni.

Aug 31, 2012 at 9:49 PM

I can capture in Pcm changing


        public WasapiCapture(MMDevice captureDevice)
            this.audioClient = captureDevice.AudioClient;

            //this.waveFormat = audioClient.MixFormat;
            this.waveFormat = new WaveFormat(44100, 16, 2);


Sep 5, 2012 at 9:53 AM

yes, this is the right way to do it. WASAPI uses extensible wave format for everything but for creating WAV files it is better to just use a standard WaveFormat

Sep 5, 2012 at 2:07 PM

Thanks Mark.
I sent you a private message regarding to the convertion of NAudio to C++