Re: writing aiff file to disk
Re: writing aiff file to disk
- Subject: Re: writing aiff file to disk
- From: Stanko Juzbasic <email@hidden>
- Date: Thu, 8 Jan 2004 17:25:05 +0100
Hi, John,
I took a look at your sample code. Does it actually mean there is no
standard system-level audio file code,
but you actually have to "re-invent" practically all the headers for
all the types of chunks for AIFF/C files,
deal with endianness and sample width issue "manually", on a per file
type basis,
then do the same thing for opening and closing and writing and reading
literally all the other audio file
standards - not to mention error detection and correction issues. In
other words, are the audio programmers
really being encouraged into writing each one's own proprietary audio
file library, rather than using a system-level one, just because there
is none, or because it's so well hidden that almost nobody believes
it's there?
Stanko
On Thursday, January 8, 2004, at 01:33 AM, john wrote:
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.
_______________________________________________
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.