gpt4 book ai didi

ios - AudioQueueDispose延迟

转载 作者:IT王子 更新时间:2023-10-29 07:54:28 30 4
gpt4 key购买 nike

根据此处的文档 https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/AudioQueueReference/#//apple_ref/c/func/AudioQueueDispose

err = AudioQueueDispose(queue, true);

我使用 true 所以处理 AudioQueue 会立即发生,尽管它有时会立即处理队列,其他时候它会延迟 3-4 秒,最多延迟 13 秒设备。 err = AudioQueueStop(queue, true) 也有同样的问题。

我的理解是,这两个函数都尝试刷新释放缓冲区已经和即将入队...
因此,如果要调用 AudioQueueDispose,我什至会帮助我的回调函数刷新缓冲区。

static void MyAQOutputCallBack(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer)
{
if (player.shouldDispose) {
printf("player shouldDispose !!!!!!!!!!!\n\n\n\n\n\n");
OSStatus dispose = AudioQueueFlush (inAQ);
return;
}
}

由于我要在播放轨道后使用 AudioQueues 录制内容,因此我需要立即返回此函数。几百毫秒没问题,但 3-4 秒?这是 Not Acceptable 。

其他 AudioQueue 函数也在同一个线程上被调用,它们似乎工作正常。

我也试过在主线程上调用它来确定它是否会改变任何东西

[self performSelectorOnMainThread:@selector(tryOnMain) withObject:nil waitUntilDone:NO];

dispatch_sync(dispatch_get_main_queue(),^{ 没有任何区别

知道会发生什么吗?

最佳答案

我成功地立即停止了我的音频播放:

-(void)stopAudio
{
@synchronized(audioLock) {
audioLock=[NSNumber numberWithBool:false];
OSStatus err;
err=AudioQueueReset (_audioQueue);
if (err != noErr)
{
NSLog(@"AudioQueueReset() error: %d", (int)err);
}
err=AudioQueueStop (_audioQueue, YES);
if (err != noErr)
{
NSLog(@"AudioQueueStop() error: %d", (int)err);
}
err=AudioQueueDispose (_audioQueue, YES);
if (err != noErr)
{
NSLog(@"AudioQueueDispose() error: %d", (int)err);
}
}
}

在我的:

void audioCallback(void *custom_data, AudioQueueRef queue, AudioQueueBufferRef buffer)

只有在以下情况下,我才会在队列中放入更多东西:

myObject *weakSelf = (__bridge myObject *)custom_data;
@synchronized(weakSelf -> audioLock) {
if ([weakSelf -> audioLock boolValue]) {
Put_more_stuff_on_queue
}

在我的特殊情况下,我播放 AAC-LC 音频。

关于ios - AudioQueueDispose延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31477520/

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