• 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: Trying to get all samples from an audio file on disk into memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to get all samples from an audio file on disk into memory


  • Subject: Re: Trying to get all samples from an audio file on disk into memory
  • From: "Patrick J. Collins" <email@hidden>
  • Date: Sat, 28 Feb 2015 19:51:43 -0800 (PST)

> either you want to use some new-fangled language and don't know how to do heap allocation or do you don't understand how to
> get the number of samples in the file?

That's correct..  I am not sure about a lot of how to properly get information like that via coreaudio's api...

This would be my code to read samples to memory:

    AudioFileID file;
    CheckError(AudioFileOpenURL((__bridge CFURLRef)self.url,
                                kAudioFileReadPermission,
                                0,
                                &file),
                                "AudioFileOpenURL failed");

    AudioStreamBasicDescription dataFormat;
    UInt32 propSize = sizeof(dataFormat);
    CheckError(AudioFileGetProperty(file,
                                    kAudioFilePropertyDataFormat,
                                    &propSize,
                                    &dataFormat),
                                    "couldn't get file's data format");


    UInt32 numBytes;
    UInt32 numPackets;
    float durationInSeconds = ???; // how do you determine the length of an audio file?

    NSUInteger samples = ceil(dataFormat.mSampleRate * durationInSeconds);
    float *buffer = (float *) malloc (sizeof (float) * samples);
    CheckError(AudioFileReadPacketData(file,
                                       false,
                                       &numBytes,
                                       NULL,
                                       0,
                                       &numPackets,
                                       buffer),
                                       "AudioFileReadData failed");

So how can I determine the durationInSeconds?

Patrick J. Collins
http://collinatorstudios.com
 _______________________________________________
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: 
 >Trying to get all samples from an audio file on disk into memory (From: "Patrick J. Collins" <email@hidden>)
 >Re: Trying to get all samples from an audio file on disk into memory (From: Paul Davis <email@hidden>)
 >Re: Trying to get all samples from an audio file on disk into memory (From: "Patrick J. Collins" <email@hidden>)
 >Re: Trying to get all samples from an audio file on disk into memory (From: Paul Davis <email@hidden>)

  • Prev by Date: Re: Trying to get all samples from an audio file on disk into memory
  • Previous by thread: Re: Trying to get all samples from an audio file on disk into memory
  • Index(es):
    • Date
    • Thread