AudioQueue不输出任何声音
我在 iPhone 实验中无法获得声音输出,而且我已经没有主意了。
这是我填充音频队列缓冲区的回调
void AudioOutputCallback(void *user, AudioQueueRef refQueue, AudioQueueBufferRef inBuffer)
{
NSLog(@"callback called");
inBuffer->mAudioDataByteSize = 1024;
gme_play((Music_Emu*)user, 1024, (short *)inBuffer->mAudioData);
AudioQueueEnqueueBuffer(refQueue, inBuffer, 0, NULL);
}
我使用以下代码片段设置音频队列
// Create stream description
AudioStreamBasicDescription streamDescription;
streamDescription.mSampleRate = 44100;
streamDescription.mFormatID = kAudioFormatLinearPCM;
streamDescription.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
streamDescription.mBytesPerPacket = 1024;
streamDescription.mFramesPerPacket = 1024 / 4;
streamDescription.mBytesPerFrame = 2 * sizeof(short);
streamDescription.mChannelsPerFrame = 2;
streamDescription.mBitsPerChannel = 16;
AudioQueueNewOutput(&streamDescription, AudioOutputCallback, theEmu, NULL, NULL, 0, &theAudioQueue);
OSStatus errorCode = AudioQueueAllocateBuffer(theAudioQueue, 1024, &someBuffer);
if( errorCode )
{
NSLog(@"Cannot allocate buffer");
}
AudioOutputCallback(theEmu, theAudioQueue, someBuffer);
AudioQueueSetParameter(theAudioQueue, kAudioQueueParam_Volume, 1.0);
AudioQueueStart(theAudioQueue, NULL);
我使用的库正在输出线性 PCM 16 位 44hz。
I have trouble getting sound output on my iPhone experiment and I'm out of ideas.
Here is my callback to fill the Audio Queue buffer
void AudioOutputCallback(void *user, AudioQueueRef refQueue, AudioQueueBufferRef inBuffer)
{
NSLog(@"callback called");
inBuffer->mAudioDataByteSize = 1024;
gme_play((Music_Emu*)user, 1024, (short *)inBuffer->mAudioData);
AudioQueueEnqueueBuffer(refQueue, inBuffer, 0, NULL);
}
I setup the audio queue using the following snippet
// Create stream description
AudioStreamBasicDescription streamDescription;
streamDescription.mSampleRate = 44100;
streamDescription.mFormatID = kAudioFormatLinearPCM;
streamDescription.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
streamDescription.mBytesPerPacket = 1024;
streamDescription.mFramesPerPacket = 1024 / 4;
streamDescription.mBytesPerFrame = 2 * sizeof(short);
streamDescription.mChannelsPerFrame = 2;
streamDescription.mBitsPerChannel = 16;
AudioQueueNewOutput(&streamDescription, AudioOutputCallback, theEmu, NULL, NULL, 0, &theAudioQueue);
OSStatus errorCode = AudioQueueAllocateBuffer(theAudioQueue, 1024, &someBuffer);
if( errorCode )
{
NSLog(@"Cannot allocate buffer");
}
AudioOutputCallback(theEmu, theAudioQueue, someBuffer);
AudioQueueSetParameter(theAudioQueue, kAudioQueueParam_Volume, 1.0);
AudioQueueStart(theAudioQueue, NULL);
The library I'm using is outputting linear PCM 16bit 44hz.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常使用 3 个缓冲区。您至少需要 2 个,因为当其中一个开始播放时,另一个就会被您的代码填充。如果只有一个,则没有足够的时间来填充相同的缓冲区并将其重新排队并实现无缝播放。所以它可能只是停止你的队列,因为它耗尽了缓冲区。
I usually use 3 buffers. You need at least 2 because as one gets played, the other one is filled by your code. If you have only one, there's not enough time to fill the same buffer and re-enqueue it and have playback be seamless. So it probably just stops your queue because it ran out of buffers.