gpt4 book ai didi

c++ - PortAudio 回调不连续?

转载 作者:太空宇宙 更新时间:2023-11-04 12:48:49 25 4
gpt4 key购买 nike

我在使用 PortAudio 时遇到问题,我不确定是我不太了解回调的工作原理,还是我做错了什么。我的假设是回调应该连续“on tick”触发,包含当前样本,但似乎我在打开和启动流时只收到一些回调,然后我不会再收到回调。我的代码:

PaStreamParameters inputP, outputP;
inputP.device = DeviceIndex;
inputP.channelCount = CardInfo->maxInputChannels;
inputP.sampleFormat = paFloat32;
inputP.suggestedLatency = CardInfo->defaultLowInputLatency;
inputP.hostApiSpecificStreamInfo = NULL;

outputP.device = DeviceIndex;
outputP.channelCount = CardInfo->maxOutputChannels;
outputP.sampleFormat = paFloat32;
outputP.suggestedLatency = CardInfo->defaultLowOutputLatency;
outputP.hostApiSpecificStreamInfo = NULL;

PaError err = Pa_OpenStream(
&AudioStream,
&inputP,
&outputP,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff,
&CAudio::AudioCallback,
this
);

err = Pa_StartStream(AudioStream);

我使用了以下常量

#define SAMPLE_RATE 44100
#define FRAMES_PER_BUFFER 64

回调:

int CAudio::AudioCallback(const void* pInputBuffer, void* pOutputBuffer, unsigned long iFramesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* userData)
{
CAudio* AudioInterface = (CAudio*)userData;

const float* buffer = (const float*)pInputBuffer;

printf("Callback: %d frames per buffer %d t %f\n", AudioInterface->CallbackIndex, iFramesPerBuffer, Pa_GetStreamTime(AudioInterface->AudioStream));
AudioInterface->CallbackIndex++;

return paContinue;
}

现在,如果我打开并启动流会发生什么,我会得到六个回调,以下日志输出

Opening audio stream on 'USB PnP Sound Device: Audio (hw:1,0)'
Opened audio stream, starting it...
Callback: 0 frames per buffer 64 t 21812.485122
Callback: 1 frames per buffer 64 t 21812.497681
Callback: 2 frames per buffer 64 t 21812.514483
Callback: 3 frames per buffer 64 t 21812.525110
Callback: 4 frames per buffer 64 t 21812.626489
Callback: 5 frames per buffer 64 t 21812.635590

是我做错了什么,还是我对回调发生的事情的理解有误?

最佳答案

好吧,现在我通过使用阻塞 API 解决了这个问题,抓取流并将其写入在另一个 std::thread 中运行的 while 循环中的缓冲区,这工作得很好。

关于c++ - PortAudio 回调不连续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50051654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com