I'm trying to capture audio using WASAPI. My code is largely based on the ChatterBox VoIP sample app. I'm getting audio buffers, but they are all silent (flagged AUDCLNT_BUFFERFLAGS_SILENT).
I'm using Visual Studio Express 2012 for Windows Phone. Running on the emulator.
I had the exact same problem and managed to reproduce it in the ChatterBox sample app if I set Visual Studio to native debugging and at any point stepped through the code.
Also, closing the App without going through the "Stop" procedure and stopping the AudioClient will require you to restart the emulator/device before being able to capture audio data again.
It nearly drove me nuts before I figured out the before mentioned problems but I finally got it working.
So.. 1. Be sure to NOT do native debugging 2. Always call IAudioClient->Stop(); before terminating the App. 3. Make sure you pass the correct parameters to IAudioClient->Initialize();
I've included a piece of code that works 100% of the time for me. I've left out error checking for clarity..
And that's it.. Before calling this code I've started a worker thread that will listen to m_hCaptureEvent and call IAudioCaptureClient->GetBuffer(); whenever the capture event is triggered.
Of course using Microsoft.XNA.Audio.Microphone works fine to, but it's not always an option to reference the XNA framework.. :)
I've had the same problem. It seems like you can either use only
AudioCategory_Other
or create an instance ofVoipPhoneCall
and use onlyAudioCategory_Communications
.So the solution in my case was to use
AudioCategory_Communications
and create an outgoingVoipPhoneCall
. You should implement the background agents as in Chatterbox VoIP sample app for theVoipCallCoordinator
to work .It was a really annoying problem which waste about 2 complete days of mine.My problem was solved by setting
AudioClientProperties.eCatagory
toAudioCategory_Communications
instead ofAudioCategory_Other
.After this long try and error period I am not sure that the problem won't repeat in the future because the API doesn't act very stable and every run may return a different result.
Edit:Yeah my guess was true.Restarting the wp emulator makes the buffer silent again.But changing the
AudioClientProperties.eCatagory
back toAudioCategory_Other
again solve it.I still don't know what is wrong with it and what is the final solution.Again I encounter the same problem and this time commenting (removing) the
properties.eCategory = AudioCategory_Communications;
solve the problem.I can add my piece of advice for Windows Phone 8.1. I made the following experiment.
Then I opened capture device with AudioDeviceRole::Communications and capture device works fine all the time.
For Windows 10 capture device works all the time, no matter if you open it with AudioDeviceRole::Communications or not.