Вопрос

i'm trying to read a CAF-file on OSX, using AudioToolbox's Extended Audio File API.

opening the file works fine, however, i need to access the UUID chunk, and i cannot find any reference on how to do that (or how to access any header-chunk of the file)

surely there must be a way to do this without parsing the file on my own.

PS: i can already do this with libsndfile, but i want to find a way to do this with only components that come with OSX.

i already tried calling ExtAudioFileGetProperty() with the ExtAudioFilePropertyID set to 'uuid' but this doesn't seem to work.

Это было полезно?

Решение

it turned out that the trick is not to use the ExtAudio API for accessing low-level functionality like the UUID chunk. (if you need to access the file via ExtAudio API, it's possible to create an ExtAudioHandle from an AudioFileID.)

in the end i used something like this:

AudioFileID fileID;
ExtAudioFileRef extFile;

OSStatus err = AudioFileOpenURL((CFURLRef)inURL, kAudioFileReadPermission, 0, &fileID);
if(noErr!=err)return;
err = ExtAudioFileWrapAudioFileID (fileID, false, &extFile); // in case we *also* want to access the file via ExtAudio
if(noErr!=err)return;

for(index=0; ; index++) {
  UInt32 size=0;
  char*data=NULL;

  OSStatus err = AudioFileGetUserDataSize (fileID,'uuid',index,&size);
  if(noErr!=err)break;   // check whether we were able to read the chunksize
  if(0==size)continue;    // check whether there is some payload in the uuid chunk

  data=calloc(size, 1);
  if(!data)continue;
  err = AudioFileGetUserData (fileID, 'uuid', index, &size, data);
  if(noErr!=err){free(data); break;}   // check whether we were able to read the chunksize
  /* ... */
  free(data);
}
ExtAudioFileDispose(extFile);
AudioFileClose(fileID);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top