Re: converting aiff sound data into AudioBuffer.mData format
Re: converting aiff sound data into AudioBuffer.mData format
- Subject: Re: converting aiff sound data into AudioBuffer.mData format
- From: Bill Stewart <email@hidden>
- Date: Mon, 3 Sep 2001 01:44:12 -0700
In 10.1 there will be an AudioConverter API that will allow you to
specify a source and destination format and the converter will do
this work for you (though not to discourage your exploration and
understanding of the issues you're dealing with)
You can get the output format of the device (an
AudioStreamBasicDescription) from either the OutputUnit or an
AudioDevice. You can construct the source format from the
information you extract from the AIF file itself. The converter
will then do all the work for you. There will also be examples in
both C and Java in the Examples/CoreAudio directory in the
developer tools about how to use the AudioConverter.
Bill
On Sunday, September 2, 2001, at 11:48 PM, email@hidden wrote:
Hello,
While being offlist I wrote a message with some similar concerns; I
don't know if it will post (moderator can ignore it, I suppose)
but this
isn't completely redundant. Anyway...
For practice I wrote an AIFF/AIFC parser and am at the point of
trying
to figure out how to properly format the data before putting it
into the
mData field in the AudioBuffer. I know the bit-depth of the sound
data but
I don't know how to configure it to play correctly in the
audiobuffer. I
don't want to embarrass myself too much by going into the details of my
current attempt, so here are a few things I think may work:
-divide the DefaultAudioDevice's sampleRate by the file's sample
rate and
use that as the marker for repition of the file's samples in comparison
with the device's. I realize that even if this works, it only
works when
the device's rate is a multiple of the file's rate.
- I'm assuming that if the aiff has multiple channels, you use the
first
set of bytes for the first channel, the second set for the 2nd
channel and
so on. As far as the above mentioned repetition of samples for
meeting the
device's sample rate, I'm not certain how to do this.
From everything I've read, the bit depth of the file is how the
sound
data in the file should be treated, with a rounding up according
to byte
divisions (e.g. 12 bit formatted as 16 bit). One thing I'm
confused about
is how to properly segment the data on the fly according to bit depth,
e.g.
for (i=startingSamplePos; i<(startingSamplePos+(numSamples/2));
++curSamplesFrameCount)
{
if (i >= (sampleLength-1)) // > tempbd
{
return 0;
}
//an attempt at handling 16 bit sound data when stored in a 32 bit
type, aka float
*mData++ = sampleHolder->samples[i];//first 16 bit value
*mData++ = 65536*sampleHolder->samples[i] ; //second 16
bit value?
if (curSamplesFrameCount != 0 &&
(curSamplesFrameCount%numFramesPerSoundSample == 0))
{//repeated this set of samples enough to compensate for file's
//slower sampling rate, move to next set of samples
i += 1;
curSamplePos = i;
}
}
where samples is a float pointer. What I really need to know is
how to do
something similar to the above code, but correct for different bit
depths/sample rates and number of channels. I've seen old Aiff
specification sheets that refer to the sound data as a char array but
I don't know how to combine multiple members in the char array (e.g. 2
chars into 1 16 bit depth item) properly bit-wise. I'm also confused by
the fact that I've only seen mData treated as a float array but yet my
current, incorrect code which gives NaN and -Inf oftentimes when
printing
as a float still loosely resembles the actual file's timbre. Any help
appreciated.
Thanks,
Ben D.
_______________________________________________
coreaudio-api mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
mailto:email@hidden
tel: +1 408 974 4056
__________________________________________________________________________
Cat: "Leave me alone, I'm trying to nap... Ah, What's that clicking
noise?"
__________________________________________________________________________