捕获的音频缓冲区在Windows Phone 8上都是静音的 [英] Captured audio buffers are all silent on Windows Phone 8

查看:350
本文介绍了捕获的音频缓冲区在Windows Phone 8上都是静音的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WASAPI捕获音频.我的代码主要基于 ChatterBox VoIP示例应用 .我正在获取音频缓冲区,但是它们都保持沉默(标记为AUDCLNT_BUFFERFLAGS_SILENT).

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).

我正在将Visual Studio Express 2012用于Windows Phone.在模拟器上运行.

I'm using Visual Studio Express 2012 for Windows Phone. Running on the emulator.

推荐答案

如果我将Visual Studio设置为本机调试并且在任何时候都逐步执行了代码,则我遇到了完全相同的问题,并设法在ChatterBox示例应用程序中重现了该问题.

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.

此外,在不执行停止"过程的情况下关闭应用程序并停止AudioClient将要求您重新启动模拟器/设备,然后才能再次捕获音频数据.

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.

所以.. 1.确保不执行本机调试 2.始终调用IAudioClient-> Stop();在终止应用程序之前. 3.确保将正确的参数传递给IAudioClient-> Initialize();.

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();

我包含了一段对我来说100%可用的代码.我没有进行错误检查以保持清晰度.

I've included a piece of code that works 100% of the time for me. I've left out 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);

就是这样.在调用此代码之前,我已经启动了一个工作线程,该线程将监听m_hCaptureEvent并调用IAudioCaptureClient-> GetBuffer();.每当触发捕获事件时.

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.

当然使用Microsoft.XNA.Audio.Microphone可以很好地工作,但是引用XNA框架并非总是一种选择.:)

Of course using Microsoft.XNA.Audio.Microphone works fine to, but it's not always an option to reference the XNA framework.. :)

这篇关于捕获的音频缓冲区在Windows Phone 8上都是静音的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆