• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: writing aiff file to disk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: writing aiff file to disk


  • Subject: Re: writing aiff file to disk
  • From: john <email@hidden>
  • Date: Wed, 7 Jan 2004 19:33:51 -0500

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.

References: 
 >writing aiff file to disk (From: Berend Schmid <email@hidden>)

  • Prev by Date: Re: [OT] Mail hangs real-time processes
  • Next by Date: Re: Speaking of HALLab telemetry
  • Previous by thread: writing aiff file to disk
  • Next by thread: Re: writing aiff file to disk
  • Index(es):
    • Date
    • Thread