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

Unsupported wave format

Mar 18, 2014 at 4:00 AM
I am using nAudio for wasapi loopback capture in a c# application (my first!), so a big thank you for Naudio!

I have handed the application to a few friends, to test and it seems to run fine for them all - everyone is win 7 .net4.5, one however is getting the following error and I am unable to recreate it and since he is in another country I don't have access to the comp directly to debug easily.

Has anyone seen this issue before/have an idea what the cause could be off hand, or can give me a pointer as to how to get a better idea of what's causing it?
System.ArgumentException: Unsupported Wave Format
   at NAudio.CoreAudioApi.WasapiCapture.InitializeCaptureDevice()
   at NAudio.CoreAudioApi.WasapiCapture.StartRecording()
I am initialising similar to the demo:
waveIn = new WasapiLoopbackCapture();
writer = new WaveFileWriter(Path.Combine(outputFolder, outputFilename), waveIn.WaveFormat);
Many Thanks in advance,
Mar 18, 2014 at 9:21 AM
do you get the error recording, or trying to replay the file?
Mar 18, 2014 at 11:25 AM
Thanks for the reply, the error comes when trying to record, interestingly the only difference in setup I have found so far is that he is running win 7 professional.
Mar 18, 2014 at 12:22 PM
I've experienced this when the format listed on the advanced tab of the microphone properties doesn't match the wave format in the code
Mar 18, 2014 at 12:28 PM
WasapiLoopbackCapture will usually be 44.1kHz or 48kHz, stereo, and 32 bit floating point. What might be catching you out is that WASAPI likes to use WAVEFORMATEXTENSIBLE in preference to a regular PCM/IEEE float WAVEFORMATEX

What actually is the contents of waveIn.WaveFormat?
Mar 18, 2014 at 3:09 PM
Edited Mar 18, 2014 at 3:27 PM
@erminh Will double check that when I can tonight, thank you.

@Mark I am not actually setting it directly, would make sense that this is the issue - am curious as to why it would work for others in this case though. Checking the contents on my machine it is: IeeeFloat, so looks as though I do need to change that to WAVEFORMATEXTENSIBLE. Sorry for my super noobieness, how and when should I set that in the above code?
Mar 18, 2014 at 3:11 PM
normally you should not be setting it at all, which is why I am interested in finding out what it actually is
Mar 18, 2014 at 3:41 PM
Edited Mar 18, 2014 at 4:01 PM
Sorry edited before I had refreshed to check answers,

Checking the contents on my machine it is: IeeeFloat, so looks as though I do need to change that to WAVEFORMATEXTENSIBLE. Will try and find out from my friend what it contains on his machine and post back.
Mar 19, 2014 at 3:17 PM
Just to update, in case anyone else has this problem. The issue was an out dated Realtek Audio Driver. Updating it has fixed the issue.

Big thanks for the help though!
Mar 19, 2014 at 3:19 PM
great, thanks for sharing what the problem is. I've had issues with Realtek drivers in the past
Jan 6, 2015 at 6:35 PM
Edited Jan 6, 2015 at 6:39 PM
i have to resume this post, because i have the same problem in the object only when using the latest version of naudio 1.7.2 in my application.

if i use an old version that i used to use in my application all works fine: old version of naudio is the
if i use the version 1.7.0 i obtain the "Unsupported wave format" error.

i use win 7 x64 with a sound blaster Z with the latest drivers available (1.00.28).

for the moment i stick to the old version, but i would like to upgrade to the latest.

Thank you very much

Jan 9, 2015 at 10:20 PM
Hi, I think this is an unfortunate side-effect of a change I made to fix another issue. In WasapiCapture's constructor, I convert the device's MixFormat to a "standard waveformat". In other words, I prefer a WAVEFORMATEX to a WAVEFORMATEXTENSIBLE. THis is so that anyone who is creating a WAV file can just use WasapiCapture.WaveFormat directly and not get a weird wave format that not all players can play. However, it appears some soundcard drivers require WAVEFORMATEXTENSIBLE. You can fix this either by modifying your own copy of WasapiCapture to not include the offending lines below, or by resetting the WaveFormat property to a WaveFormatExtensible again before you start recording.
        /// <summary>
        /// Initialises a new instance of the WASAPI capture class
        /// </summary>
        /// <param name="captureDevice">Capture device to use</param>
        public WasapiCapture(MMDevice captureDevice)
            syncContext = SynchronizationContext.Current;
            audioClient = captureDevice.AudioClient;
            ShareMode = AudioClientShareMode.Shared;

            waveFormat = audioClient.MixFormat;
            var wfe = waveFormat as WaveFormatExtensible;
            if (wfe != null)
                    waveFormat = wfe.ToStandardWaveFormat();
                catch (InvalidOperationException)
                    // couldn't convert to a standard format
Hope this makes sense, and it's definitely on my list of things to sort out for the future.

Jan 10, 2015 at 1:02 AM
by resetting the WaveFormat property to a WaveFormatExtensible again before you start recording
this sounds interestings.

my application is a sound visualizer

this is the simple code
            wasapi = new NAudio.Wave.WasapiLoopbackCapture();
            wasapi.DataAvailable += new EventHandler<WaveInEventArgs>(OnDataAvailable);
then in OnDataAvailable i pass the bytes to the visualizer.

if it's possible to convert my wasapi to a standard format or resetting as you say would be awesome.