• 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: Loading Audio File into Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Loading Audio File into Array


  • Subject: RE: Loading Audio File into Array
  • From: Stephen Shaw <email@hidden>
  • Date: Wed, 25 Jan 2006 12:45:21 -0800
  • Thread-topic: Loading Audio File into Array

Hey Jannik, here is a sample of how to do what you are looking to do:
-Stephen

//--------------------------------------------------------------------------
------------------------------
//--------------------------------------------------------------------------
------------------------------
OSStatus getFileInfo (AudioStreamBasicDescription *fileASBD, const char
*fileName)
{
    OSStatus err= noErr;
    UInt32 size;

    AudioFileID fileID;
    FSRef fileRef;

     FSPathMakeRef ((const UInt8 *)fileName, &fileRef, 0); //Obtain
filesystem reference to the file
     err = AudioFileOpen(&fileRef, fsRdPerm,0,&fileID);   //Obtain
AudioFileID
     checkErr (err);
     if (err != noErr)
     {
         printf ("Unable to open file for input : '%s'.\n", fileName);
         return (err);
     }
     size = sizeof(AudioStreamBasicDescription);
    memset(fileASBD, 0, size);

     //Fetch the AudioStreamBasicDescription of the audio file.
     err = AudioFileGetProperty(fileID, kAudioFilePropertyDataFormat, &size,
fileASBD);
     checkErr(err);

//    printf("File format for <%s> is:\n", fileName);
//    PrintStreamDesc(fileASBD, fileName);

    //Get total packet count, byte count, and max packet size
    //Theses values will be used later when grabbing data from the audio
file
    UInt64 totalPacketCount=0;
    UInt32 maxPacketSize =0;

    size = sizeof(totalPacketCount);
    err = AudioFileGetProperty(fileID,
kAudioFilePropertyAudioDataPacketCount, &size, &totalPacketCount);
    checkErr(err);

    size = sizeof(maxPacketSize);
    err = AudioFileGetProperty(fileID, kAudioFilePropertyMaximumPacketSize,
&size, &maxPacketSize);
    checkErr(err);

    UInt32    bytesReturned = 0;
    UInt32    ioNumPackets = totalPacketCount;
    SInt64    startAtPacket = 0;

    // create a buffer to hold ALL the sound data
    gSoundData = (void *) calloc (1, totalPacketCount * maxPacketSize);

    // read in the sound data all in one shot.
    err = AudioFileReadPackets (fileID, false, &bytesReturned, NULL,
startAtPacket, &ioNumPackets, gSoundData);
    checkErr(err);

    AudioFileClose(fileID);


    gTotalBytesCount = bytesReturned;
    gTotalPacketCount = totalPacketCount;
    gMaxPacketSize = maxPacketSize;
    printf ("Max Packet Size is: %d\n", gMaxPacketSize);

    return err;
}

 _______________________________________________
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

  • Prev by Date: surround and timePitch
  • Next by Date: Re: afinfo / ExtAudioFile relies on file extensions?
  • Previous by thread: Re: Loading Audio File into Array
  • Next by thread: [DAFx'06] CALL FOR PAPERS - Montreal, September 18-20, 2006
  • Index(es):
    • Date
    • Thread