Erik Rothoff
Erik Rothoff

Reputation: 5123

AudioUnit set property error (error code -10868)

I am trying to set a property in AudioUnit using AudioStreamBasicDescription. I am trying to set the format for the sound data. The error code returned is -10868. It only occurs on iOS 3.1.3 or less, but works on 3.2 or up. So it works in the simulator, on an iPod touch running 4.2, but not a 1st gen iPod touch.

The error occurs when I try to set the format for the AudioUnit tone unit. The code looks like this (and is from cocoawithlove.com)

// Set the format to 32 bit, single channel, floating point, linear PCM
const int four_bytes_per_float = 4;
const int eight_bits_per_byte = 8;
AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = sampleRate;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
streamFormat.mBytesPerPacket = four_bytes_per_float;
streamFormat.mFramesPerPacket = 1;  
streamFormat.mBytesPerFrame = four_bytes_per_float;     
streamFormat.mChannelsPerFrame = 1; 
streamFormat.mBitsPerChannel = four_bytes_per_float * eight_bits_per_byte;
err = AudioUnitSetProperty (toneUnit,
                            kAudioUnitProperty_StreamFormat,
                            kAudioUnitScope_Input,
                            0,
                            &streamFormat,
                            sizeof(AudioStreamBasicDescription));
// err now has error code -10868

I checked around in headers and this error code corresponds to the error "kAudioUnitErr_FormatNotSupported". So I guess the format I'm trying to set is not supported on iOS 3.1? Where can I find supported formats? Any pointers on other formats I could try out?

The render callback used:

OSStatus RenderTone(
    void *inRefCon, 
    AudioUnitRenderActionFlags *ioActionFlags, 
    const AudioTimeStamp *inTimeStamp, 
    UInt32 inBusNumber, 
    UInt32 inNumberFrames, 
    AudioBufferList *ioData)

{
    // Fixed amplitude is good enough for our purposes
    const double amplitude = 0.25;

    // Get the tone parameters out of the view controller
    ToneGeneratorViewController *viewController =
        (ToneGeneratorViewController *)inRefCon;
    double theta = viewController->theta;
    double theta_increment =
        2.0 * M_PI * viewController->frequency / viewController->sampleRate;

    // This is a mono tone generator so we only need the first buffer
    const int channel = 0;
    Float32 *buffer = (Float32 *)ioData->mBuffers[channel].mData;

    // Generate the samples
    for (UInt32 frame = 0; frame < inNumberFrames; frame++) 
    {
        buffer[frame] = sin(theta) * amplitude;

        theta += theta_increment;
        if (theta > 2.0 * M_PI)
        {
            theta -= 2.0 * M_PI;
        }
    }

    // Store the updated theta back in the view controller
    viewController->theta = theta;

    return noErr;
}

Upvotes: 3

Views: 3104

Answers (1)

Mark Pauley
Mark Pauley

Reputation: 1485

I think the main issue is that floating point audio wasn't supported on iOS prior to version 4.0. I'm not sure what the deal is with ARM float support, but I would recommend going with one of the fixed point formats for input and output.

Upvotes: 5

Related Questions