• 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: sample code on how to write an AAC (was MP3) file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sample code on how to write an AAC (was MP3) file?


  • Subject: Re: sample code on how to write an AAC (was MP3) file?
  • From: Doug Wyatt <email@hidden>
  • Date: Thu, 6 Jan 2005 09:18:41 -0800

Eric,

Yes ... look at afconvert in the AudioFileTools example. Look at the information that gets moved between the AudioFile and AudioConverter (from the file to the converter when decoding, from converter to file when encoding).

To discover the file formats in which you can store encoded AAC with the AudioFile API, try afconvert with no arguments to get help, and search the output for 'aac '. With Panther/QuickTime 6.5.2 there is only ADTS .........

Doug


On Jan 6, 2005, at 7:49, Eric Hon-Anderson wrote:
Unlike David, I am in a situation where I CAN use AAC instead of MP3--is there sample code that handles that case, including the "hoops to jump through"?



The key thing to understand about how CoreAudio deals with audio files and formats -- as we stressed at WWDC last year ;-) -- is that they are utterly separate concepts.

A file is just a container and is not assumed to have any knowledge of how to encode or decode the audio data inside it.

Codecs know how to convert between PCM and encoded formats, but have no idea of how to store the data in files.


Your code looks like it's writing PCM data packets to the MP3 container.


CoreAudio's MP3 file object knows how to write a valid MP3 file -- given a series of MP3 packets. But (probably due to licensing considerations) there is no MP3 encoder in the base system.

You might be better off sending AppleEvents to iTunes or using AAC (though using the AAC encoder has its own set of hoops to jump through, and the only *currently* supported container for AAC is ADTS ...).


Doug


On Jan 3, 2005, at 21:51, David M.Cotter wrote:
i've searched the doc, i've searched google, i've searched the archives, to no avail.



i'm trying to do CD ripping.


I found this: http://www.mat.ucsb.edu:8000/CoreAudio/90


which is utterly fantastic, except it records AIFF instead of MP3


so I try to record MP3 this way:
AudioStreamBasicDescription asbd;
AudioFileTypeAndFormatID fmID;
UInt32 sizeL = sizeof(asbd);


                        fmID.mFileType  = kAudioFileMP3Type;
                        fmID.mFormatID  = kAudioFormatMPEGLayer3;

if (!err) err = AudioFileGetGlobalInfo(
kAudioFileGlobalInfo_AvailableStreamDescriptionsForFormat,
sizeof(fmID), &fmID, &sizeL, &asbd);


at this point the asbd looks nothing like i'd expect, but the following call works


if (!err) err = AudioFileInitialize(
&i_destAudioFileSpec, kAudioFileMP3Type,
&asbd, 0, &i_audioFileID);
etc etc, and I use



OSErr CSongImporter::DumpAudioSector(unsigned char *bufP) { OSErr err = noErr; UInt32 num_bytesL = kCDSectorSizeCDDA;

err = AudioFileWriteBytes(
i_audioFileID, true, i_audio_bytePos, &num_bytesL, bufP);


        if (!err) err = num_bytesL != kCDSectorSizeCDDA;
        if (!err) i_audio_bytePos += num_bytesL;
        return err;
}


the bufP is what is returned by:
dk_cd_read_t readCDParam;
UInt64 bufLen = kCDSectorSizeCDDA;



structclr(readCDParam);
readCDParam.offset = bufLen * cur_sectorL;
readCDParam.sectorArea = kCDSectorAreaUser;
readCDParam.sectorType = kCDSectorTypeCDDA;
readCDParam.bufferLength = bufLen;
readCDParam.buffer = i_buffer;



err = ioctl(i_fd, DKIOCCDREAD, (char*)&readCDParam) == -1;



so it's raw audio bytes, i suppose it's raw PCM data?

but then i end up with a 50 meg file that's NOT playable. so huh, what am I doing wrong?

is there sample code somewhere? _______________________________________________
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: 
 >Re: sample code on how to write an MP3 file? (From: Eric Hon-Anderson <email@hidden>)

  • Prev by Date: timestamps/ buffering with incoming NTSC audio frames in CoreAudio driver
  • Next by Date: Re: any MusicDevice examples?
  • Previous by thread: Re: sample code on how to write an MP3 file?
  • Next by thread: AUParametricEq Q parameter?
  • Index(es):
    • Date
    • Thread