Re: Simple audio file opening/reading/conversion?
Re: Simple audio file opening/reading/conversion?
- Subject: Re: Simple audio file opening/reading/conversion?
- From: "Sophia Poirier [dfx]" <email@hidden>
- Date: Wed, 13 Feb 2008 15:35:37 -0500
If you can live with a minimum system requirement of Mac OS X 10.4,
the ExtAudioFile API is simpler than using AudioFile and
AudioConverter together. Here's a little example snippet from a
project of mine (with error handling and such removed for the sake of
brevity) that reads an audio file into an AUBufferList:
ExtAudioFileRef audioFileRef = NULL;
OSStatus status = ExtAudioFileOpen(&inFileRef, &audioFileRef);
SInt64 audioFileNumFrames = 0;
UInt32 dataSize = sizeof(audioFileNumFrames);
status = ExtAudioFileGetProperty(audioFileRef,
kExtAudioFileProperty_FileLengthFrames, &dataSize, &audioFileNumFrames);
AudioStreamBasicDescription audioFileStreamFormat;
dataSize = sizeof(audioFileStreamFormat);
status = ExtAudioFileGetProperty(audioFileRef,
kExtAudioFileProperty_FileDataFormat, &dataSize,
&audioFileStreamFormat);
CAStreamBasicDescription clientStreamFormat;
clientStreamFormat.SetCanonical
(audioFileStreamFormat.mChannelsPerFrame, false);
clientStreamFormat.mSampleRate = audioFileStreamFormat.mSampleRate;
status = ExtAudioFileSetProperty(audioFileRef,
kExtAudioFileProperty_ClientDataFormat, sizeof(clientStreamFormat),
&clientStreamFormat);
AUBufferList auBufferList;
auBufferList.Allocate(clientStreamFormat, (UInt32)audioFileNumFrames);
AudioBufferList & abl = auBufferList.PrepareBuffer
(clientStreamFormat, (UInt32)audioFileNumFrames);
UInt32 audioFileNumFrames_temp = (UInt32)audioFileNumFrames;
status = ExtAudioFileRead(audioFileRef, &audioFileNumFrames_temp, &abl);
status = ExtAudioFileDispose(audioFileRef);
_______________________________________________
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