ExtAudioFile Basics
ExtAudioFile Basics
- Subject: ExtAudioFile Basics
- From: Jens-Oliver Fischer <email@hidden>
- Date: Tue, 17 May 2011 14:58:17 +0200
Hi everybody,
I'm new to CA development. So here are some (probaly rather simple) questions.
The basic task is to read a file in an arbitrary format (e.g. mp3, aac, ...), which should result in a vector (or array) of float samples.
To my understanding ExtAudioFile hides all the conversion stuff, i.e. I'll just need to specify the clientformat and provide an AudioBuffer.
Everything is okay, when I provide one (large) buffer and read the audio file (or parts of it) in one run and convert short int samples to float by myself.
When doing this consecutivly with a smaller buffer in several runs, I run into problems. The audio is "chunked" up.
First question: What am I doing wrong? Is it okay to assume that ExtAudioFileRead will continue from the last read position/frame if called consecutivly?
Second question: as you can see below, I'm reading into a temporary byte/char buffer which is then converted into a float array. Is there a way to read float directly (I noticed the kAudioFormatIsFloat flag ...)?
Perhaps you guys can give me a hint on what I'm doing wrong here.
/* description is the ASBD which was read from original audioFile -- will be set as client format*/
void
AudioFile::constructClientFormat(AudioStreamBasicDescription& description)
{
description.mFormatID = kAudioFormatLinearPCM;
description.mBitsPerChannel = 16;
description.mBytesPerPacket = description.mChannelsPerFrame * (description.mBitsPerChannel / 8);
description.mFramesPerPacket = 1;
description.mBytesPerFrame = description.mBytesPerPacket;
description.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
}
unsigned int
AudioFile::read(unsigned int frames, float* buffer)
{
UInt32 numChannels = 2;
UInt32 bytesPerChannel = 2;
char* tmpBuffer = (char*) malloc(numChannels * bytesPerChannel * frames);
AudioBufferList bufList;
bufList.mNumberBuffers = 1;
bufList.mBuffers[0].mNumberChannels = numChannels;
bufList.mBuffers[0].mDataByteSize = numChannels * bytesPerChannel * frames;
bufList.mBuffers[0].mData = tmpBuffer;
UInt32 ioNumFrames = frames;
OSStatus err = ExtAudioFileRead(m_audioFile, &ioNumFrames, &bufList);
unsigned int framesRead = ioNumFrames;
convertBuffer(tmpBuffer, numChannels * bytesPerChannel * frames, buffer, frames);
free(tmpBuffer);
return framesRead;
}
Cheers,
jens _______________________________________________
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