• 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
AudioConverter and ExtAudioFile in AudioConverterComplexInputDataProc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AudioConverter and ExtAudioFile in AudioConverterComplexInputDataProc


  • Subject: AudioConverter and ExtAudioFile in AudioConverterComplexInputDataProc
  • From: Manu N <email@hidden>
  • Date: Sat, 25 Aug 2012 08:07:20 +0200

Hello,
I am trying to use Core Audio to do the following (sort of a lab tool) :
- read audio data from a file converted to LPCM at the file's sampling rate.
- do something with this intermediate audio data
- use an AudioConverter to oversample this audio data
- do something else with this oversampled audio data

What I have done is :
setup an ExtAudioFileRef with a LPCM client format fileOutASBD
setup an AudioConverterRef with an input format same as fileOutASBD and an output format identical to fileOutASBD excepted for the sampling frequency

I then use the ExtAudioFileRef in the AudioConverterComplexInputDataProc called by AudioConverterFillComplexBuffer to provide input data to the AudioConverterRef.

//myConverterProc
OSStatus myConverterProc(AudioConverterRef inAudioConverter,
                         UInt32 *ioNumberDataPackets,
                         AudioBufferList *ioData,
                         AudioStreamPacketDescription **outDataPacketDescription,
                         void *inUserData)
{
    OSStatus err = noErr;
   
    //setting ExtAudioFile out AudioBufferList
    UInt32 framesInFileOutBuffer = *ioNumberDataPackets;
    AudioStreamBasicDescription converterInASBD;
    UInt32 propSize = sizeof(converterInASBD);
    err = AudioConverterGetProperty(inAudioConverter,
                                    kAudioConverterCurrentInputStreamDescription,
                                    &propSize,
                                    &converterInASBD);
    assert (err == noErr);
    UInt8 *fileOutBuffer = (UInt8 *)malloc(framesInFileOutBuffer * converterInASBD.mBytesPerFrame);
    assert (fileOutBuffer != NULL);
    AudioBufferList fileOutBufferList;
    fileOutBufferList.mNumberBuffers = 1;
    fileOutBufferList.mBuffers[0].mNumberChannels = converterInASBD.mChannelsPerFrame;
    fileOutBufferList.mBuffers[0].mDataByteSize = framesInFileOutBuffer * converterInASBD.mBytesPerFrame;
    fileOutBufferList.mBuffers[0].mData = fileOutBuffer;
   
    //read audio data from file
    ExtAudioFileRef *audioFileRef = (ExtAudioFileRef *)inUserData;
   
    err = ExtAudioFileRead(*audioFileRef,
                           &framesInFileOutBuffer,
                           &fileOutBufferList);
    assert (err == noErr);
   
    doSomething(fileOutBufferList, framesInFileOutBuffer);
   
    ioNumberDataPackets = &framesInFileOutBuffer;
    ioData->mBuffers[0].mData = fileOutBuffer;
    ioData->mBuffers[0].mDataByteSize = framesInFileOutBuffer * converterInASBD.mBytesPerFrame;
    free(fileOutBuffer);   
    return err;
}

One issue I have is how to deal with end of the input file.
I call AudioConverterFillComplexBuffer with a fixed ioOutputDataPacketSize argument.
I then use the ioNumberDataPackets in the callback to read from the file.
Everything goes fine up to the moment where the ExtAudioFileRead returns less frames than requested. This means we have reached the end of the file.
It seems thet ExtAudioFileRead returns noErr in this case.
This is the return value to the AudioConverterFillComplexBuffer, but the AudioConverterFillComplexBuffer itself returns a kAudioConverterErr_InvalidInputSize, which is not surprising.


Can I assume that this kAudioConverterErr_InvalidInputSize does not damage the conversion of this last input data to the converter ?
What would be a clean way to deal with the end of the input file ?

Thanks a lot for any clue.

Side question : is there any sample code demonstrating how to deal with the AudioConverterPrimeInfo ? Should I for example stuff the last fileOutBufferList with 0's ?

Manuel
 _______________________________________________
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: AUGraph traversal during rendering
  • Next by Date: Setting volume on individual AirPlay devices?
  • Previous by thread: AUGraph traversal during rendering
  • Next by thread: Setting volume on individual AirPlay devices?
  • Index(es):
    • Date
    • Thread