ios - iPhone播放AudioQueue在调试过程中断点暂停后停止/无法继续

标签 ios xcode debugging playback audioqueue

出于某种原因,似乎在调试期间停在断点处会终止我的音频队列播放。

  1. AudioQueue 将播放音频 输出。
  2. 触发断点 暂停我的 iPhone 应用程序。
  3. 后续 恢复,不再播放音频。
  4. ( 但是,AudioQueue 回调 函数仍在被调用。)
  5. ( 没有 AudioSession 或 AudioQueue 发现错误。)

由于调试器暂停应用程序(而不是来电,例如),这不是典型的 iPhone 中断,所以 AudioSession interruption callbacks do not get triggered like in this solution .

我正在使用 three AudioQueue buffers在 22kHz 的 4096 个样本处并以循环方式填充它们。

多线程和单线程模式都会出现问题。

  • 在调试 session 期间是否存在无法暂停和恢复 AudioSession 或 AudioQueues 的已知问题?
  • 它是否用完了“队列缓冲区”并且它正在破坏/杀死 AudioQueue 对象(但我的 AQ 回调不应触发)。

有人了解 iPhone AudioQueues 的内部工作原理吗?

最佳答案

在过去几天反复研究之后,在发布到 StackOverflow 之前,我今天才找到答案。去图吧!

只需调用我的“准备函数”再次重新创建 AudioQueue

SetupNewQueue(mDataFormat.mSampleRate, mDataFormat.mChannelsPerFrame);
StartQueue(true);

因此,请检测您的 AudioQueue 何时“死亡”。在我的例子中,我会将数据写入输入缓冲区,以供 AudioQueue 回调“拉取”。如果它在特定时间内没有发生,或者在输入缓冲区的 X 个字节已被填充后,我将重新创建 AudioQueue。

这似乎解决了遇到调试断点时“停止/失败”音频的问题。

这些函数的简化版本如下:

void AQPlayer::SetupNewQueue(double inSampleRate, UInt32 inChannelsPerFrame)
{
    //Prep AudioStreamBasicDescription
    mDataFormat.mSampleRate = inSampleRate;
    mDataFormat.SetCanonical(inChannelsPerFrame, YES);

    XThrowIfError(AudioQueueNewOutput(&mDataFormat, AQPlayer::AQBufferCallback, this, 
                                    NULL, kCFRunLoopCommonModes, 0, &mQueue), "AudioQueueNew failed");

    // adjust buffer size to represent about a half second of audio based on this format
    CalculateBytesForTime(mDataFormat, kBufferDurationSeconds, &mBufferByteSize, &mNumPacketsToRead);
    ctl->cmsg(CMSG_INFO, VERB_NOISY, "AQPlayer Buffer Byte Size: %d, Num Packets to Read: %d\n", (int)mBufferByteSize, (int)mNumPacketsToRead);

    mBufferWaitTime = mNumPacketsToRead / mDataFormat.mSampleRate * 0.9;

    XThrowIfError(AudioQueueAddPropertyListener(mQueue, kAudioQueueProperty_IsRunning, isRunningProc, this), "adding property listener");

    //Allocate AQ buffers (assume we are using CBR (constant bitrate)
    for (int i = 0; i < kNumberBuffers; ++i) {
        XThrowIfError(AudioQueueAllocateBuffer(mQueue, mBufferByteSize, &mBuffers[i]), "AudioQueueAllocateBuffer failed");
    }
...
}

OSStatus AQPlayer::StartQueue(BOOL inResume)
{   
// if we are not resuming, we also should restart the file read index
    if (!inResume)
        mCurrentPacket = 0; 

    // prime the queue with some data before starting
    for (int i = 0; i < kNumberBuffers; ++i) {
        mBuffers[i]->mAudioDataByteSize = mBuffers[i]->mAudioDataBytesCapacity;
        memset( mBuffers[i]->mAudioData, 0, mBuffers[i]->mAudioDataByteSize );

        XThrowIfError(AudioQueueEnqueueBuffer( mQueue,
                                mBuffers[i],
                                0,
                                NULL ),"AudioQueueEnqueueBuffer failed");
    }

    OSStatus status;
    status = AudioSessionSetActive( true );
    XThrowIfError(status, "\n\n*** AudioSession failed to become active *** \n\n");

    status = AudioQueueStart(mQueue, NULL);
    XThrowIfError(status, "\n\n*** AudioQueue failed to start *** \n\n");

    return status;
}

关于ios - iPhone播放AudioQueue在调试过程中断点暂停后停止/无法继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3771979/

相关文章:

ios - 是否可以在透明部分标题后面 "hide"UITableViewCell?

.net - Process Monitor 中的托管堆栈

调试中的 C 函数崩溃(未给出错误)

ios - Swift:根据提供的用户信息读取字符串

ios - 在范围内找不到类型 'SKAdImpression'

iphone - 选择时 Xcode UITableView 行未突出显示

php - PHP 中的命令相当于 javascript 中的警报

ios - 64 位 iOS 设备中的 realloc()

ios - ActivityIndi​​cator 边界图形错误

xcode - 关于 macOS 编程的弹出消息