I also noticed that it looks like I can do what I want with
ExtAudioFile.  I tried that out but I was just getting garbage audio.

  ExtAudioFileRef inputFile;

  CheckResult(ExtAudioFileOpenURL((__bridge CFURLRef)self.url,
                                  &inputFile),
              "ExtAudioFileOpenURL failed");

  UInt32 numberOfFrames = 0;
  UInt32 propSize = sizeof(SInt64);
  CheckResult(ExtAudioFileGetProperty(inputFile, 
kExtAudioFileProperty_FileLengthFrames, &propSize, &numberOfFrames), 
"GetProperty failed");

  AudioBufferList *ioData;
  ioData = (AudioBufferList *)malloc(sizeof(AudioBufferList) + 
sizeof(AudioBuffer));
  ioData->mBuffers[0].mNumberChannels = 1;
  ioData->mBuffers[0].mDataByteSize = numberOfFrames * sizeof(SInt16);
  ExtAudioFileRead(inputFile, &numberOfFrames, ioData);

  // do stuff with samples...

  free(ioData);
  ExtAudioFileDispose(inputFile);

...

When I play back the samples, it just sounds like harsh white noise...

Patrick J. Collins
http://collinatorstudios.com


On Sun, 1 Mar 2015, Yuriy Romanchenko wrote:

> Hi,
>
> Assuming AIFF format you have got uncompressed lpcm samples there.
> You can simply determine how much packets in that file by calling 
> AudioFileGetProperty
> with kAudioFilePropertyAudioDataPacketCount property id.
> To determine length of audio file you should do the following:
>
> packets_per_second = sample_rate  / frames_per_packet;
> seconds = total_packet / packets_per_second
>
> For constant bit rate formats frames_per_packet will be equal to 1.
>
> Best regards,
> Yuri.
>
> On Mar 1, 2015, at 5:51, Patrick J. Collins <[email protected]> 
> wrote:
>
>             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 protected])
>       Help/Unsubscribe/Update your Subscription:
>       https://lists.apple.com/mailman/options/coreaudio-api/solomidsf%40bk.ru
>
>       This email sent to [email protected]
>
>
>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to