【问题标题】:Error using WASAPI with PortAudio on Win7在 Win7 上将 WASAPI 与 PortAudio 一起使用时出错
【发布时间】:2013-03-10 04:16:11
【问题描述】:

我正在尝试使用 PortAudio 和 libsndfile 在我的 Windows 7 机器上以独占模式播放 .wav 文件,但我得到了

错误号 -9984 “不兼容的主机 API 特定流信息”。

我已经填写了 PaWasapiStreamInfo 结构如下:

struct PaWasapiStreamInfo wasapiInfo ;
wasapiInfo.size = sizeof(PaWasapiStreamInfo);
wasapiInfo.hostApiType = paWASAPI;
wasapiInfo.version = 1;
wasapiInfo.flags = paWinWasapiExclusive;   
wasapiInfo.channelMask = NULL;
wasapiInfo.hostProcessorOutput = NULL;
wasapiInfo.hostProcessorInput = NULL;
wasapiInfo.threadPriority = eThreadPriorityProAudio;

然后分配hostApiSpecificStreamInfo参数,通过Pa_OpenStream打开流,如下:

/* stereo or mono */
    out_param.channelCount = sfinfo.channels;
    out_param.sampleFormat = paInt16;
    out_param.suggestedLatency = _GetDeviceInfo(out_param.device)->defaultLowOutputLatency;
    out_param.hostApiSpecificStreamInfo = (&wasapiInfo);

    err = Pa_OpenStream(&stream, NULL, &out_param, sfinfo.samplerate,
            paFramesPerBufferUnspecified, paClipOff,
            output_cb, file);

我错过了一步吗?

谢谢, 泰勒

【问题讨论】:

    标签: portaudio libsndfile wasapi


    【解决方案1】:

    您用来以独占模式运行流的技术对我有用。可能是您没有在 WASAPI 设备上打开流。根据您的系统配置,您可能还拥有 DirectSound 和 WMME 设备。以下代码将验证索引 deviceIndex 引用的设备是否为 WASAPI 设备:

    bool isWasapi = Pa_GetHostApiInfo(Pa_GetDeviceInfo(deviceIndex)->hostApi)->type == paWASAPI;
    

    您还需要在 out_param 结构中指定相同的索引:

    out_param.device = deviceIndex;
    

    你做了几件我没有做的事情。在您的示例中,您尝试设置线程优先级,但 PortAudio 文档指出以下行:

    wasapiInfo.threadPriority = eThreadPriorityProAudio;
    

    将无效,因为您没有在wasapiInfo.flags 中设置paWinWasapiThreadPriority 位。根据相同的规则,没有必要将其他变量显式设置为 null。修复这个集合wasapiInfo.flags如下:

    wasapiInfo.flags = (paWinWasapiExclusive|paWinWasapiThreadPriority)
    

    这应该启用独占模式并导致threadPriority 变量生效。

    【讨论】:

      猜你喜欢
      • 2014-01-09
      • 2023-04-10
      • 1970-01-01
      • 2011-08-28
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2016-11-05
      相关资源
      最近更新 更多