• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
AudioConverterFillComplexBuffer returning paramErr on ALAC conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AudioConverterFillComplexBuffer returning paramErr on ALAC conversion


  • Subject: AudioConverterFillComplexBuffer returning paramErr on ALAC conversion
  • From: Jason Perkins <email@hidden>
  • Date: Wed, 12 Oct 2011 10:24:31 -0400

Hello all,

I'm trying to convert a PCM 32-bit float audio stream to ALAC. I found some working examples to build from, but my own code keeps getting a -50 (paramErr) from AudioConverterFillComplexBuffer. My eyes are crossing from looking at this code; I can't see what's different from the examples.

I set up my input and output formats and create the converter:

    UInt32 numChannels = 2;

    // Describe the input stream
    AudioStreamBasicDescription inputFormat;
    memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
    inputFormat.mSampleRate = 44100;
    inputFormat.mFormatID = kAudioFormatLinearPCM;
    inputFormat.mFramesPerPacket = 1;
    inputFormat.mChannelsPerFrame = numChannels;
    inputFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked;
    inputFormat.mBitsPerChannel = sizeof(Float32) * 8;
    inputFormat.mBytesPerPacket = numChannels * (inputFormat.mBitsPerChannel / 8);
    inputFormat.mBytesPerFrame = inputFormat.mBytesPerPacket * inputFormat.mFramesPerPacket;

    // Describe the output stream
    AudioStreamBasicDescription outputFormat;
    memset(&outputFormat, 0, sizeof(AudioStreamBasicDescription));
    outputFormat.mSampleRate = 44100;
    outputFormat.mFormatID = kAudioFormatAppleLossless;
    outputFormat.mFramesPerPacket = 4096;

    OSStatus err = AudioConverterNew(&inputFormat, &outputFormat, &_alacConverter);

CAShow(_alacConverter) shows this:

    AudioConverter 0xa8404e (0x101c449f0):
      PCMConverter2 0x101c34370
        Input:   2 ch,  44100 Hz, 'lpcm' (0x00000009) 32-bit little-endian float
        Output:  2 ch,  44100 Hz, 'lpcm' (0x0000000C) 32-bit little-endian signed integer
      CodecConverter 0x101c44b90
        Input:   2 ch,  44100 Hz, 'lpcm' (0x0000000C) 32-bit little-endian signed integer
        Output:  2 ch,  44100 Hz, 'alac' (0x00000004) from 32-bit source, 4096 frames/packet
        codec: 'aenc'/'alac'/'appl'
        Input layout tag: 0x650002
        Output layout tag: 0x650002

Then I get the maximum output packet size (which returns 32776) and allocate a buffer to hold the converted data:

    size = sizeof(UInt32);
    UInt32 maxOutputSize;
    AudioConverterGetProperty(_alacConverter,
                              kAudioConverterPropertyMaximumOutputPacketSize,
                              &size,
                              &maxOutputSize);

    _outputBuffer = [[NSMutableData dataWithCapacity:maxOutputSize] retain];

Finally, I call AudioConverterFillComplexBuffer to get some data:

    AudioBufferList bufferList;
    memset(&bufferList, 0, sizeof(AudioBufferList));
    memset(&bufferList.mBuffers[0], 0, sizeof(AudioBuffer));

    bufferList.mNumberBuffers = 1;
    bufferList.mBuffers[0].mNumberChannels = numChannels;
    bufferList.mBuffers[0].mDataByteSize = [_outputBuffer length];
    bufferList.mBuffers[0].mData = [_outputBuffer mutableBytes];

    AudioStreamPacketDescription streamDesc = {0};

    UInt32 numPackets = 1;

    err = AudioConverterFillComplexBuffer(_alacConverter,
                                          _encoderDataProc,
                                          self,
                                          &numPackets,
                                          &bufferList,
                                          &streamDesc);

...where I always get the -50 error. Can anyone give me a clue where I'm going wrong? Many (many) thanks!

Jason

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Calling MIDIPacketListAdd from NSTimer
  • Next by Date: Big problems with Core Audio and OSX Lion : SynthNote does not work
  • Previous by thread: Re: AU notify host that state is dirty
  • Next by thread: Big problems with Core Audio and OSX Lion : SynthNote does not work
  • Index(es):
    • Date
    • Thread