Re: writing aiff file to disk
Re: writing aiff file to disk
- Subject: Re: writing aiff file to disk
- From: Berend Schmid <email@hidden>
- Date: Thu, 8 Jan 2004 13:35:09 +0100
Hi,
I'm actually triying to use the AudioFile header for reading/writing my
audio file.
The part where I'm stuck is, how do I get the data from my input device
to be written to disk.
I turned the whole thing around, reading an audio file to play it back
through my output device, to an idea of how things work. But, what a
surprise, I'm again stuck with getting the data from my file to being
played by the output device. I'd like to use the HAL-api for the whole
process.
I also looked at a sample code at
http://www.mat.ucsb.edu:8000/CoreAudio/90, where exactly the part I
don't get isn't covered.
thanks for the replay (the last and hopefully the next one),
Berend
Am 08.01.2004 um 01:33 schrieb john:
>
Hi Berend,
>
>
Here's a snippet of ObjC sample code for writing a basic stereo 16bit
>
44100 AIFF header. The audio data can come right after the header.
>
>
>
- (void)writeAIFFHeader: (unsigned long)audioLength
>
{
>
NSMutableData *theAiffFormat = [NSMutableData data];
>
UInt8 theRate[10] = {0x40, 0x0E,
>
0xAC, 0x44, 0, 0, 0, 0, 0, 0};
>
unsigned long fileLength = (audioLength + 42);
>
unsigned long chunkSize = 0;
>
unsigned short channels = 2;
>
unsigned long frames = (audioLength / 4);
>
unsigned short bits = 16;
>
unsigned long offset = 0;
>
unsigned long blockSize = 0;
>
>
// seek to the beginning
>
[myFileHandle seekToFileOffset: 0];
>
>
// set up the FORM part
>
[theAiffFormat appendBytes: "FORM" length: 4];
>
[theAiffFormat appendBytes: &fileLength length: 4];
>
// set up the AIFF part
>
[theAiffFormat appendBytes: "AIFF" length: 4];
>
// update the chunk size for the next part
>
chunkSize = 18;
>
// now setup the COMM part
>
[theAiffFormat appendBytes: "COMM" length: 4];
>
[theAiffFormat appendBytes: &chunkSize length: 4];
>
[theAiffFormat appendBytes: &channels length: 2];
>
[theAiffFormat appendBytes: &frames length: 4];
>
[theAiffFormat appendBytes: &bits length: 2];
>
[theAiffFormat appendBytes: theRate length: 10];
>
// update the chunk size for the next part
>
chunkSize = (8 + audioLength);
>
// now do the SSND part
>
[theAiffFormat appendBytes: "SSND" length: 4];
>
[theAiffFormat appendBytes: &chunkSize length: 4];
>
[theAiffFormat appendBytes: &offset length: 4];
>
[theAiffFormat appendBytes: &blockSize length: 4];
>
// write the data
>
[myFileHandle writeData: theAiffFormat];
>
}
>
>
Hope this helps.
>
>
-- John
>
>
>
> Hi, everyone!
>
>
>
> I'm trying to write an AIFF file to disk. I'm getting more and more
>
> confused because there seem to be a lot of different ways you can
>
> actually do this. Anyway, everything I tried didn't work.
>
>
>
> Also the sample projects are more confusing than helpful.
>
> Can anyone help me out giving me some code snippets on how to do it?
>
> The audio coming from my input device should be recorded.
>
>
>
> thanks,
>
> Berend
_______________________________________________
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.