Unable to AUGraphStart a simple Voice-Processing I/O with 2 render callbacks

255 views Asked by At

I currently have an audio graph set up with just one Voice-Processing I/O. There are render callbacks for both the input and output bus and their appropriate AudioStreamBasicDescription applied to both the inward facing sides of the bus.

So my audio graph is setup like so

Input

  • User's voice-->Mic-->send pcm frame over network in input callback.

Output

  • network-->TPCircularBuffer.... which is then pulled to the output side of the ioUnit through the callback.

Now whenever I try and start the graph I get kAudioFormatUnsupportedDataFormatError. From searching around, this error pops up because I am trying to write an invalid file format. But as you can see above, I am not writing any files?? So what gives? I'm guessing from the error description, there is something wrong with the AudioStreamBasicDescription, but wouldn't it give me an error when I was setting it up?

This is how my stream is being setup. Both functions return noErr.

- (BOOL)setUpStreamFormat:(NSError **)error
{
    UInt32 bytesPerSample = sizeof(SInt16);
    double sampleRate = [AVAudioSession sharedInstance].sampleRate;

    self.currentAudioSampleRate = sampleRate;

    AudioStreamBasicDescription asbd = {0};
    asbd.mSampleRate = sampleRate;
    asbd.mFormatID = kAudioFormatLinearPCM;
    asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
    asbd.mChannelsPerFrame = 2;
    asbd.mBytesPerFrame = bytesPerSample;
    asbd.mBitsPerChannel = 8 * bytesPerSample;
    asbd.mFramesPerPacket = 1;
    asbd.mBytesPerPacket = bytesPerSample;

    OSStatus status = AudioUnitSetProperty(self.ioUnit,
                                            kAudioUnitProperty_StreamFormat,
                                            kAudioUnitScope_Output,
                                            kInputBus,
                                            &asbd,
                                            sizeof(asbd));
    if (status != noErr) {
        [self fillError:error
               withCode:status
            description:@"Stream Format"
          failureReason:@"Failed to setup input stream format"];
        return NO;
    }

    status = AudioUnitSetProperty(self.ioUnit,
                                            kAudioUnitProperty_StreamFormat,
                                            kAudioUnitScope_Input,
                                            kOutputBus,
                                            &asbd,
                                            sizeof(asbd));
    if (status != noErr) {
        [self fillError:error
               withCode:status
            description:@"Stream Format"
          failureReason:@"Failed to setup output stream format"];
        return NO;
    }
    return YES;
}
1

There are 1 answers

0
cvu On

I figured out the answer to my problem. Apparently the ABSD that I had setup was incorrect.The format should of been below:

AudioStreamBasicDescription asbd = {0};
asbd.mSampleRate = self.currentAudioSampleRate;
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
asbd.mChannelsPerFrame = 2;
asbd.mBytesPerFrame = bytesPerSample * 2;
asbd.mBitsPerChannel = 8 * bytesPerSample;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerPacket = bytesPerSample * 2;