Re: Converting Split AIFF to Interleaved
Re: Converting Split AIFF to Interleaved
- Subject: Re: Converting Split AIFF to Interleaved
- From: Doug Wyatt <email@hidden>
- Date: Thu, 29 Apr 2004 18:42:10 -0700
You could use the afinterleave tool in the latest SDK -- it's in the
AudioFileTools project.
Doug
On Apr 28, 2004, at 20:58, Joey Coyle wrote:
Hi,
I have been on a quest to discover the Rosetta Stone to translate Core
Audio into understandable code. Still a dream. I think one of the
vendors threw it into a volcano. ;-}
I will be going from Two Mono AIFF Files to One Stereo AIFF Interleaved
File. I know how to get the AudioFileBasicStreamInformation from the
Mono Files, and Create one for the output format.
In the Swiki example, they create an AudioConverterRef, would I do
this?? Would I put the Mono AudioFileBasicStreamInformation in the
from format, and the Stereo AudioFileBasicStreamInformation in the to
format.
AudioConverterRef converter;
status = AudioConverterNew( &floatFormat, // from format
&aiffFormat, // to format
&converter); // if successful
refereces
the newly created converter.
Or do I need to create two converters, and convert each mono file into
some internal format. And then make another convertor from this
internal format to the output format???
clueless,
joey
HINT... someone could make a fortune if they wrote the first book for
dummies. Or I mean professional programmers, but I do feel pretty
dumb. Maybe I have just never tried to learn something so
undocumented.
On Sep 27, 2003, at 5:33 PM, daniel oberhoff wrote:
hi folks!
i am having trouble with the audio converter api (also due to lack of
documentation...).
i want to convert sampledata (so far always loaded thru audiofile api)
into a noninterleaved, 32bit float format so i can easily render it to
my custom gl sampledata view. now whenever i encounter an interleaved
2
channel format my conversion method will just run forever. it seems as
though the proc i hand over to AudioConverterFillBuffer doesnt ever
get
called in this case, because neither does the read pointer get
increased nor do printf's or NSLog's come out of it. when i first
convert it to a mono format i have no problem (i also get messages out
of my input proc then!). only when i tell the converter to
deinterleave
channels. i would not like to move to complex buffers, as there seems
to be a lot of information wanted to be handled in the imput proc that
i dont know what to do with. if that would be the only solution i
would
rather deinterleave by hand...
heres the relevant code, its from inside an NSObject called SampleData
which basically keeps the data and the format (an
AudioStreamBasicDescription) and supplies a bunch of useful methods.
everything from outside this code snippet should be self explamatory.
please cc any answers to me!
thanx
daniel
OSStatus SDACInputDataProc( AudioConverterRef inAudioConverter,
UInt32* ioDataSize,
void** outData,
void* inUserData) {
SDACprocessBuffer* buf = (SDACprocessBuffer*)inUserData;
*outData = &buf->data[buf->position];
if (buf->length - buf->position < 0)
return noErr + 1;
if (*ioDataSize > buf->length - buf->position)
*ioDataSize = buf->length - buf->position;
NSLog(@"[SDACInputDataProc] handed over %d bytes, buffer: %d/%d",
*ioDataSize, buf->position, buf->length);
buf->position += *ioDataSize;
return noErr;
}
static unsigned int _SDACstepsize = 1024; //conversion based on pull
model, pull buffers of this size!
+ (void) convertData:(NSData*)src inRange:(NSRange)sRange
format:(const
AudioStreamBasicDescription*)srcFormat
toData:(NSMutableData*)dst toFormat:(const
AudioStreamBasicDescription*)dstFormat {
AudioConverterRef converter;
OSErr error;
SDACprocessBuffer inbuf, outbuf;
UInt32 ioDataSize;
unsigned inSize = sRange.length;
double estGrow = (double)dstFormat->mBytesPerFrame /
(double)srcFormat->mBytesPerFrame * (double)dstFormat->mSampleRate /
(double)srcFormat->mSampleRate;
unsigned estSize = inSize * (unsigned) ceil(estGrow);
error = AudioConverterNew(srcFormat, dstFormat, &converter);
if (error != noErr)
[NSException raise:@"SampleData conversion failure"
format:@"failed to allocate converter"];
[dst setLength:estSize];
inbuf.length = inSize;
inbuf.data = (Byte*)([src bytes] + (size_t)sRange.location);
inbuf.position = 0;
outbuf.length = estSize;
outbuf.data = [dst mutableBytes];
outbuf.position = 0;
while(inbuf.position < inbuf.length) {
ioDataSize = _SDACstepsize;
//resize if needed
if (outbuf.position + ioDataSize > outbuf.length) {
outbuf.length += MAX(outbuf.length >> 2, ioDataSize);
[dst setLength:outbuf.length];
}
AudioConverterFillBuffer(converter, SDACInputDataProc,
&inbuf,
&ioDataSize, &outbuf.data[outbuf.position]);
outbuf.position += ioDataSize;
#if debug
NSLog(@"conv[%d/%d]: got %d bytes, total %d bytes, outbuf %d
bytes", inbuf.position, inbuf.length, ioDataSize, outbuf.position,
outbuf.length);
#endif
}
[dst setLength:outbuf.position];
AudioConverterDispose(converter);
}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.