• 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: ExtAudioFileRead() + mp3 + 10.5 Crash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ExtAudioFileRead() + mp3 + 10.5 Crash


  • Subject: Re: ExtAudioFileRead() + mp3 + 10.5 Crash
  • From: patrick machielse <email@hidden>
  • Date: Mon, 29 Oct 2007 00:08:45 +0100

To follow up on my earlier message:

On Leopard I'm experiencing a crash when
reading mp3 files. All other file formats my program supports (aac
aiff wav) seem to work fine.

I just found this list message:

<http://lists.apple.com/archives/coreaudio-api/2007/May/msg00154.html>

On Leopard I'm seeing the same behavior: the read buffer must be at least 4608 frames long (not 4607!), otherwise a crash occurs in ExtAudioFileRead() when reading mp3 files. On 10.4.x systems I've tried (I think 10.4.9 when I first started used this function) there is no such limitation. This only happens with mp3 files.

Below is a test program that exposes this behavior:

/*
    readfile.c

compile:
cc main.c -o readfile -framework CoreServices -framework AudioToolbox
*/


#include <AudioToolbox/AudioToolbox.h>


// number of frames to read at once, must not be 1 frame less on 10.5.0!
#define FRAMES 9*512


int main (int argc, const char * argv[])
{
    if ( argc != 2 ) {
        fprintf(stderr, "usage: readmp3 file-path\n");
        exit(EXIT_FAILURE);
    }

// open the input file
OSStatus error;
FSRef fileRef;
if ( error = FSPathMakeRef((UInt8 *)argv[1], &fileRef, NULL) ) {
fprintf(stderr, "can't make FSRef for file \'%s\' (%d)\n", argv[1], error);
exit(EXIT_FAILURE);
}


ExtAudioFileRef mp3File = NULL;
if ( error = ExtAudioFileOpen(&fileRef, &mp3File) ) {
fprintf(stderr, "can't open the input audio file (%d)\n", error);
exit(EXIT_FAILURE);
}


    //  set client format
    UInt32 nChannels = 2;

    AudioStreamBasicDescription asbd;
    asbd.mSampleRate       = 44100;
    asbd.mFormatID         = kAudioFormatLinearPCM;
    asbd.mFormatFlags      = kAudioFormatFlagsNativeFloatPacked;
    asbd.mBytesPerPacket   = nChannels * sizeof (float);
    asbd.mFramesPerPacket  = 1;
    asbd.mBytesPerFrame    = nChannels * sizeof (float);
    asbd.mChannelsPerFrame = nChannels;
    asbd.mBitsPerChannel   = 8 * sizeof (float);

error = ExtAudioFileSetProperty(mp3File,
kExtAudioFileProperty_ClientDataFormat,
sizeof asbd,
&asbd);
if ( error ) {
fprintf(stderr, "setting client stream format failed (%ld) \n", error);
exit(EXIT_FAILURE);
}


// prepare buffer
AudioBufferList list;
list.mNumberBuffers = 1;
list.mBuffers[0].mNumberChannels = asbd.mChannelsPerFrame;
list.mBuffers[0].mDataByteSize = FRAMES * asbd.mBytesPerFrame;
list.mBuffers[0].mData = alloca(FRAMES * asbd.mBytesPerFrame);


// read all data
UInt32 framesRead, totalFrames = 0;
do {
framesRead = FRAMES;
error = ExtAudioFileRead(mp3File, &framesRead, &list);
if ( error ) {
fprintf(stderr, "ExtAudioFileRead returned error: %d", error);
exit(EXIT_FAILURE);
}
totalFrames += framesRead;
printf("read frames: %d\n", totalFrames);
fflush(stdout);


    } while ( framesRead != 0 );

    printf("SUCCESS\n");
    ExtAudioFileDispose(mp3File);
    return EXIT_SUCCESS;
}

patrick machielse
Hieper Software

_______________________________________________
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


  • Follow-Ups:
    • Re: ExtAudioFileRead() + mp3 + 10.5 Crash
      • From: William Stewart <email@hidden>
  • Prev by Date: Having AudioConverter recognise custom AudioCodec components
  • Next by Date: ExtAudioFileWrapAudioFileID crashing in Leopard
  • Previous by thread: ExtAudioFileRead() + mp3 + 10.5 Crash
  • Next by thread: Re: ExtAudioFileRead() + mp3 + 10.5 Crash
  • Index(es):
    • Date
    • Thread