AudioQueue fails to start

女生的网名这么多〃 提交于 2019-12-24 08:48:06

问题


I create an AudioQueue in the following steps.

  1. Create a new output with AudioQueueNewOutput
  2. Add a property listener for the kAudioQueueProperty_IsRunning property
  3. Allocate my buffers with AudioQueueAllocateBuffer
  4. Call AudioQueuePrime
  5. Call AudioQueueStart

The problem is, when i call AudioQueuePrime it outputs following error on the console

AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)

What's wrong here?

PS:

  1. I got this error on iOS (Device & Simulator)
  2. The output callback installed when calling AudioQueueNewOutput is never called!
  3. The file is valid and the AudioStreamBasicDescription does match the format (AAC)
  4. I tested the file with Mat's AudioStreamer and it seems to work there

Sample Init Code:


// Get the stream description from the first sample buffer
OSStatus err = noErr;

EDSampleBuffer *firstBuf = [sampleBufs objectAtIndex:0];
AudioStreamBasicDescription asbd = firstBuf.streamDescription;

// TODO: remove temporary format setup, just to ensure format for now
asbd.mSampleRate = 44100.00;
asbd.mFramesPerPacket = 1024; // AAC default
asbd.mChannelsPerFrame = 2;

pfcc(asbd.mFormatID);
// -----------------------------------

// Create a new output
err = AudioQueueNewOutput(&asbd, _audioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue);
if (err) {
    [self _reportError:kASAudioQueueInitializationError];
    goto bail;
}

// Add property listener for queue state
err = AudioQueueAddPropertyListener(audioQueue, kAudioQueueProperty_IsRunning, _audioQueueIsRunningCallback, self);
if (err) {
    [self _reportError:kASAudioQueuePropertyListenerError];
    goto bail;
}

// Allocate a queue buffers
for (int i=0; i<kAQNumBufs; i++) {
    err = AudioQueueAllocateBuffer(audioQueue, kAQDefaultBufSize, &queueBuffer[i]);
    if (err) {
        [self _reportError:kASAudioQueueBufferAllocationError];
        goto bail;
    }
}

// Prime and start
err = AudioQueuePrime(audioQueue, 0, NULL);
if (err) {
    printf("failed to prime audio queue %ld\n", err);
    goto bail;
}

err = AudioQueueStart(audioQueue, NULL);
if (err) {
    printf("failed to start audio queue %ld\n", err);
    goto bail;
}

These are the format flags from the audio file stream

rate: 44100.000000
framesPerPacket: 1024
format: aac 
bitsPerChannel: 0
reserved: 0
channelsPerFrame: 2
bytesPerFrame: 0
bytesPerPacket: 0
formatFlags: 0
cookieSize 39

回答1:


AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)

What's wrong here?

You did it wrong.

No, really. That's what that error means, and that's ALL that error means.

That's why paramErr (-50) is such an annoying error code: It doesn't say a damn thing about what you (or anyone else) did wrong.

The first step to formulating guesses as to what it's complaining about is to find out what function returned that error. Change your _reportError: method to enable you to log the name of the function that returned the error. Then, log the parameters you're passing to that function and figure out why it's of the opinion that those parameters to that function don't make sense.

My own wild guess is that it's because the values you forced into the ASBD don't match the characteristics of the sample buffer. The log output you included in your question says “11025/0 frames”; 11025 is a common sample rate (but different from 44100). I assume you'd know what the 0 refers to.



来源:https://stackoverflow.com/questions/4117776/audioqueue-fails-to-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!