Captured sound buffers are all silent on Windows Phone 8

I am trying to capture audio using WASAPI. My code is largely based on the ChatterBox VoIP sample application . I get audio buffers, but they are all silent (labeled AUDCLNT_BUFFERFLAGS_SILENT).

I am using Visual Studio Express 2012 for Windows Phone. Run on the emulator.

+3


source to share


4 answers


I had the same problem and was able to reproduce it in the ChatterBox sample example if I set Visual Studio to native debug and stepped through the code at any point.

In addition, closing the application without going through the Stop procedure and stopping the AudioClient will require a reboot of the emulator / device before you can record audio data again.

It almost upset me before I figured out the previous problems, but finally I got the job.

So .. 1. Make sure NOT to do your own debugging 2. Always call IAudioClient-> Stop (); before exiting the application. 3. Make sure you passed the correct parameters to IAudioClient-> Initialize ();



I've included a piece of code that works for me 100% of the time. I have left out the error checking for clarity.

LPCWSTR pwstrDefaultCaptureDeviceId =
  GetDefaultAudioCaptureId(AudioDeviceRole::Communications);
HRESULT hr = ActivateAudioInterface(pwstrDefaultCaptureDeviceId,
  __uuidof(IAudioClient2), (void**)&m_pAudioClient);
hr = m_pAudioClient->GetMixFormat(&m_pwfx);
m_frameSizeInBytes = (m_pwfx->wBitsPerSample / 8) * m_pwfx->nChannels;
hr = m_pAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED,
  AUDCLNT_STREAMFLAGS_NOPERSIST | AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 
  latency * 10000, 0, m_pwfx, NULL);
hr = m_pAudioClient->SetEventHandle(m_hCaptureEvent);
hr = m_pAudioClient->GetService(__uuidof(IAudioCaptureClient),
  (void**)&m_pCaptureClient);

      

What is it. Before calling this code, I started a workflow that will listen for m_hCaptureEvent and call IAudioCaptureClient-> GetBuffer (); whenever the capture event fires.

Of course using Microsoft.XNA.Audio.Microphone works fine, but it is not always possible to reference the XNA framework .. :)

+3


source


It was a really annoying problem that wasted about two full days of mine. My problem was solved by installing AudioClientProperties.eCatagory

in AudioCategory_Communications

instead of AudioCategory_Other

.

After this long attempt and a period of errors, I'm not sure if the problem won't recur in the future, because the API is not very stable and each run may return a different result.



Edit: Yes, my guess was true. Restarting wp emulator silences the buffer again. But changing AudioClientProperties.eCatagory

back to AudioCategory_Other

again will solve it. I still don't know what is wrong with it and what the final solution is.

Again I am facing the same problem, and this time commenting (deleting) properties.eCategory = AudioCategory_Communications;

 to solve the problem.

+1


source


I can add my own tip for Windows Phone 8.1. I did the following experiment.

  • Open the capture device. Buffers are not silent.
  • Open the renderer with AudioDeviceRole :: Communications. The buffers die down immediately.
  • Close the renderer. Buffers are not silent.

Then I opened the capture device with AudioDeviceRole :: The communication and the capture device are working fine all the time.

For a Windows 10 capture device, it works all the time whether you open it with AudioDeviceRole :: Communications or not.

+1


source


I had the same problem. It looks like you can only use AudioCategory_Other

or instantiate VoipPhoneCall

and only use AudioCategory_Communications

.

So the solution in my case was to use AudioCategory_Communications

and build outbound VoipPhoneCall

. You have to implement background agents like in the VoIP Chatterbox sample application for it to work VoipCallCoordinator

.

0


source







All Articles