我们正在使用c#编写的NAudio堆栈,并尝试以独占模式捕获音频,PCM8 8kHZ和16位/采样。
在以下函数中:
private void InitializeCaptureDevice()
{
if (initialized)
return;
long requestedDuration = REFTIMES_PER_MILLISEC * 100;
if (!audioClient.IsFormatSupported(AudioClientShareMode.Shared, WaveFormat) &&
(!audioClient.IsFormatSupported(AudioClientShareMode.Exclusive, WaveFormat)))
{
throw new ArgumentException("Unsupported Wave Format");
}
var streamFlags = GetAudioClientStreamFlags();
audioClient.Initialize(AudioClientShareMode.Shared,
streamFlags,
requestedDuration,
requestedDuration,
this.waveFormat,
Guid.Empty);
int bufferFrameCount = audioClient.BufferSize;
this.bytesPerFrame = this.waveFormat.Channels * this.waveFormat.BitsPerSample / 8;
this.recordBuffer = new byte[bufferFrameCount * bytesPerFrame];
Debug.WriteLine(string.Format("record buffer size = {0}", this.recordBuffer.Length));
initialized = true;
}在调用此函数之前,我们将WaveFormat配置为(8000,1),并且周期为100ms。我们期望系统根据请求分配1600字节的缓冲区和100毫秒的间隔。
但我们注意到发生了以下情况: 1.系统分配的audioClient.BufferSize是4800,"this.recordBuffer“是一个9600字节的数组(这意味着一个600ms的缓冲区,而不是100ms)。2.线程将要休眠,然后获取2400个样本(4800字节),而不是预期的1600字节的帧。
你知道那里会发生什么吗?
发布于 2013-02-15 15:49:48
您说您正在以独占模式捕获音频,但在示例代码中,您使用AudioClientMode.Shared调用Initialize方法。我觉得共享模式不太可能让你以8 8kHz的频率工作。不像海浪..。API,WASAPI不会为您重采样播放或捕获,因此声卡本身必须以您指定的采样率运行。
https://stackoverflow.com/questions/14861468
复制相似问题