Spurious 'device in use' error from waveInOpen and IAudioClient::Initialize

I have discovered what appears to be a Windows Vista bug.

If I change the default recording device in the Sound applet (mmsys.cpl) while an application is recording, all future calls to waveInOpen (WAVE_MAPPER, ...) or IAudioClient::Initialize for the default audio endpoint fail with error code MMSYSERR_ALLOCATED or AUDCLNT_E_DEVICE_IN_USE respectively.

To demonstrate the problem, proceed as follows:

  1. Start SoundRecorder
  2. Start recording
  3. While recording, go to the Sound applet and change the default recording device
  4. Stop recording (and save the file)
  5. Try to start recording again
  6. SoundRecorder then reports 'An audio device cannot be found'
  7. Restarting SoundRecorder does not help

The situation can be resolved by changing the default recording device while no applications are recording.

[935 byte] By [PaulSanders] at [2008-2-4]
# 1

Stop press: this problem only arises when the Sound applet is open. Probably explains how it got through testing.

How do I bring this to the attention of Microsoft?

PaulSanders at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 2

You have :)

When you have the sound control panel applet open, it is actively capturing from the audio device (that's how it is able to display the meter information - you don't get that unless you're capturing). I suspect that has something to do with the problem.

LarryOsterman at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 3

I thought you used IAudioMeterInformation for that.

Anyway, just to be clear, the problem only arises if you change the default recording device while an application is capturing from it. When you do this, the green tick mark moves to the newly selected default but the little 'VU meter' stays where it is (which is fair enough). But, and this is the problem, when the application finishes capturing, the VU meter does not move to the newly selected default device, which, IMO, it clearly should, and any subsequent attempt to capture from the (new) default audio endpoint fails until you either close the Sound applet or change the default recording device again.

PaulSanders at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 4

You do. But if the capture device doesn't support a hardware meter control, the IAudioMeterInformation interface relies on a meter APO inserted in the capture graph. If you're not capturing, there is no capture graph, if there is no capture graph, there is no meter APO, with no meter APO, you don't get valid information.

Unfortunately most existing audio hardware doesn't support a hardware meter control (we only have one device in-house with this support), so mmsys.cpl captures data and throws it away.

Either way, I've asked our test team to look into the problem.

LarryOsterman at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 5

Thank you; naughty mmsys.cpl!

I see from your Weblog (which I found very helpful) that APO = Audio Processing Object, i.e. a link in the chain of software entities processing the capture stream. I guess we're wandering off the point a bit, but presumably this implies that an attempt to get an IAudioMeterInformation interface might fail with error AUDCLNT_E_DEVICE_IN_USE. I guess that makes sense, once you understand the bigger picture.

PaulSanders at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 6

Nope, you shouldn't ever get a device in use error from the meter information.

I'm not sure where the device in use error is coming from, we're digging into it today.

LarryOsterman at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 7

Paul, the test lead for our group just stopped by, his team was unable to reproduce this problem with several different devices.

What exactly are the devices you're using in your reproduction?

LarryOsterman at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 8

It reports itself as a 'Create Audio PCI (ES1371, ES1373) (WDM)'. Driver provider is Creative Technology Ltd, date 18/06/2002, version 5.2.3633.0.

I just tried it again and I can reliably reproduce the problem (unfortunately, I don't have another Vista installation to try it on). Just to recap, the steps are:

  1. Open the Sound applet; default recording device at this time was Line In
  2. Open Sound Recorder and start recording
  3. While recording, change the default recording device to Microphone; the Sound applet now shows the default recording device as Microphone (green tick) and the active device as Line In (VU meter) (see screenshot)
  4. Stop recording and close Sound Recorder; the Sound applet display remains unchanged (which is the bug, of course)
  5. Open Sound Recorder and try to record - Sound Recorder reports 'An audio recording device cannot be found'.
  6. Close the Sound applet and try again; Sound Recorder now starts recording (from the Microphone)
  7. Open the Sound applet; it now shows Microphone as both the default and active Recording device, and peace and harmony are restored

Hope this helps.

PaulSanders at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 9

Thanks Paul, I've passed it onto the test team.

LarryOsterman at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...
# 10

This is an old thread but I was searching the net as I have the exact same problem in Vista which has had me going around the bend for the last week.

I'm using the old Wave API for my audio app. WaveInOpen can fail if the Sound control panel (mmsys.cpl) is open. Here are the steps to reproduce it.

1. With the Sound control panel closed, start a recording session with a specific recording device selected such as "Microphone (Your Soundcard Name)".

2. Open the Sound control panel displaying the Recording Devices tab.

3. Stop recording and select a different input device eg. "Line In (Your Soundcard Name)".

4. Try to start recording, but it fails at WaveInOpen with the error MMSYSERR_ALLOCATED.

Only the original recording device can be selected before recording works as it should.

If the Sound control panel is closed, there are no problems at all.

Perhaps this is only related to some soundcards. Mine is a SoundMax Integrated Digital Audio.

Hopefully you can fix this in a Windows Update patch.

Regards,

Ross.

RossLevis at 2007-9-4 > top of Msdn Tech,Software Development for Windows Vista,Vista Pro-Audio Application Development...

Software Development for Windows Vista

Site Classified