我正在以编程方式生成音频。 我听到缓冲区之间的沉默差距。 当我将手机连接到示波器时,我发现每个缓冲器的前几个样本都丢失了,而且它们的位置是静音。 这种沉默的长度从几乎没有变化到20毫秒。
我的第一个想法是我的原始回调函数需要太多时间。 我用尽可能短的替换它 – 它反复重新排队相同的缓冲区。 我观察到同样的行为。
AudioQueueRef aq; AudioQueueBufferRef aq_buffer; AudioStreamBasicDescription asbd; void aq_callback (void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) { OSStatus s = AudioQueueEnqueueBuffer(aq, aq_buffer, 0, NULL); } void aq_init(void) { OSStatus s; asbd.mSampleRate = AUDIO_SAMPLES_PER_S; asbd.mFormatID = kAudioFormatLinearPCM; asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; asbd.mBytesPerPacket = 1; asbd.mFramesPerPacket = 1; asbd.mBytesPerFrame = 1; asbd.mChannelsPerFrame = 1; asbd.mBitsPerChannel = 8; asbd.mReserved = 0; int PPM_PACKETS_PER_SECOND = 50; // one buffer is as long as one PPM frame int BUFFER_SIZE_BYTES = asbd.mSampleRate/PPM_PACKETS_PER_SECOND*asbd.mBytesPerFrame; s = AudioQueueNewOutput(&asbd, aq_callback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &aq); s = AudioQueueAllocateBuffer(aq, BUFFER_SIZE_BYTES, &aq_buffer); // put samples in the buffer buffer_data(my_data, aq_buffer); s = AudioQueueStart(aq, NULL); s = AudioQueueEnqueueBuffer(aq, aq_buffer, 0, NULL); }
我不熟悉iPhone音频API,但它似乎与其他通常会排队多个缓冲区的类似,这样当系统处理完第一个缓冲区时,它可以立即开始处理下一个缓冲区(因为它已经排队)正在执行第一个缓冲区上的完成回调。
就像是:
需要了解更多c/c++开发分享AudioQueue吃了我的缓冲区(前15毫秒),也可以关注C/ C++技术分享栏目—计算机技术网(www.ctvol.com)!
AudioQueueRef aq; AudioQueueBufferRef aq_buffer[2]; AudioStreamBasicDescription asbd; void aq_callback (void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) { // note that the callback tells us which buffer has been completed, so all // we have to do is queue it back up OSStatus s = AudioQueueEnqueueBuffer(aq, inBuffer, 0, NULL); } void aq_init(void) { OSStatus s; asbd.mSampleRate = AUDIO_SAMPLES_PER_S; asbd.mFormatID = kAudioFormatLinearPCM; asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; asbd.mBytesPerPacket = 1; asbd.mFramesPerPacket = 1; asbd.mBytesPerFrame = 1; asbd.mChannelsPerFrame = 1; asbd.mBitsPerChannel = 8; asbd.mReserved = 0; int PPM_PACKETS_PER_SECOND = 50; // one buffer is as long as one PPM frame int BUFFER_SIZE_BYTES = asbd.mSampleRate/PPM_PACKETS_PER_SECOND*asbd.mBytesPerFrame; s = AudioQueueNewOutput(&asbd, aq_callback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &aq); s = AudioQueueAllocateBuffer(aq, BUFFER_SIZE_BYTES, &aq_buffer[0]); s = AudioQueueAllocateBuffer(aq, BUFFER_SIZE_BYTES, &aq_buffer[1]); // put samples in the buffer - fill both buffers buffer_data(my_data, aq_buffer[0]); buffer_data(my_data, aq_buffer[1]); s = AudioQueueStart(aq, NULL); s = AudioQueueEnqueueBuffer(aq, aq_buffer[0], 0, NULL); s = AudioQueueEnqueueBuffer(aq, aq_buffer[1], 0, NULL); }
以上就是c/c++开发分享AudioQueue吃了我的缓冲区(前15毫秒)相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/980088.html