• 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: MTCoreAudio, CAAudioFileWriter and conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MTCoreAudio, CAAudioFileWriter and conversion


  • Subject: Re: MTCoreAudio, CAAudioFileWriter and conversion
  • From: Jianhua Meng <email@hidden>
  • Date: Mon, 10 Oct 2005 21:02:24 -0700

This is a question that recurred a lot in the past. As far as I know, no one has offered an elegant solution to the list yet. I personally am struggling with the very same issue. Ideally, I would like to be able to make a few CoreAudio API calls to get the job done without resorting to complicated schemes or compromise. I ended up having to modify the C++ example code that Apple provided. It does what I want to do, but it is not as elegant as using MTCoreAudio in the context of a Cocoa app. I hope someone is kind enough to offer some help. My question would be: in minimal lines of code, how would one save a sampled sound buffer (which MTCoreAudio provides) into an AIFF file.

Thanks.
Jianhua

On Oct 10, 2005, at 8:45 PM, Olivier Destrebecq wrote:

I made progress since my last question and now have stumbled upon other road blocks.

I want to record audio to disk, so i'm using MTCoreAudio to get the data and CAAudioFileWriter to write it to disk. I'm limiting my deployment target to 10.4, so i'm using the extended API.

My code run, the file gets created, but then when i try to open it with Quicktime, it tells me it cannot open it. Also if i add code to try to convert to AAC before writing to disk i get an error. I include the code in this email for your review.


As usual, any pointers are appreciated:-) Thanks in advance Olivier http://otusweb.spymac.com/home/


//create a fileWriter from the description we get back from the mic
//
MTCoreAudioStreamDescription *audioStreamDescription = [[[[self recordingDevice] streamsForDirection: kMTCoreAudioDeviceRecordDirection] objectAtIndex: 0] streamDescriptionForSide: kMTCoreAudioStreamLogicalSide];
audioFileWriter = new CAAudioFileWriter(44100, [audioStreamDescription bytesPerFrame]); //should give us one second buffer


//create the directory reference and the filereference
FSRef parentDir;
NSString *tempRecordFileName = [@"recording" stringByAppendingString: [[NSNumber numberWithDouble: [[NSDate date] timeIntervalSince1970]] stringValue]];
NSURL *parentDirectoryURL = [NSURL fileURLWithPath: [NSTemporaryDirectory() stringByAppendingPathComponent: [[NSBundle mainBundle] bundleIdentifier]]];


//make sure the directory exists
//
[[NSFileManager defaultManager] createDirectoryAtPath: [parentDirectoryURL path]
attributes: nil];
CFURLGetFSRef((CFURLRef)parentDirectoryURL, &parentDir);


audioFileWriter->SetFile(parentDir,
(CFStringRef) tempRecordFileName,
kAudioFileCAFType, //if I set the format here i get a format error, CAF seems to be the only one working
[audioStreamDescription audioStreamBasicDescription],
NULL);


//set the converter in place for the file so that we write straight to AAC
//
// CAAudioFile theAudioFile = audioFileWriter->GetFile();
//
// MTCoreAudioStreamDescription *aacDescription = [MTCoreAudioStreamDescription streamDescriptionWithAudioStreamBasicDescription: [audioStreamDescription audioStreamBasicDescription]];
// [aacDescription setFormatID: kAudioFormatMPEG4AAC];
// theAudioFile.SetClientFormat([aacDescription audioStreamBasicDescription]);


  BOOL returnValue = [[self recordingDevice] deviceStart];
  audioFileWriter->Start();



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >MTCoreAudio, CAAudioFileWriter and conversion (From: Olivier Destrebecq <email@hidden>)

  • Prev by Date: MTCoreAudio, CAAudioFileWriter and conversion
  • Next by Date: Re: MTCoreAudio, CAAudioFileWriter and conversion
  • Previous by thread: MTCoreAudio, CAAudioFileWriter and conversion
  • Next by thread: Re: MTCoreAudio, CAAudioFileWriter and conversion
  • Index(es):
    • Date
    • Thread