首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WasapiCapture NAudio

WasapiCapture NAudio
EN

Stack Overflow用户
提问于 2013-02-14 03:29:25
回答 1查看 3.1K关注 0票数 0

我们正在使用c#编写的NAudio堆栈,并尝试以独占模式捕获音频,PCM8 8kHZ和16位/采样。

在以下函数中:

代码语言:javascript
复制
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字节的帧。

你知道那里会发生什么吗?

EN

回答 1

Stack Overflow用户

发布于 2013-02-15 15:49:48

您说您正在以独占模式捕获音频,但在示例代码中,您使用AudioClientMode.Shared调用Initialize方法。我觉得共享模式不太可能让你以8 8kHz的频率工作。不像海浪..。API,WASAPI不会为您重采样播放或捕获,因此声卡本身必须以您指定的采样率运行。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14861468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档