CoreAudio: the proper method of reading an AudioFileMarkerList?

153 Views Asked by At

Quick overview: I'm developing a Mac Swift desktop audio application. I've run into a situation that seems to require me to hit the AudioToolbox C api's in order to get an AudioFileMarkerList. There doesn't seem to be support for this in any of the newer AVStuff, so it seems you still need to work with the AudioToolbox API.

I would love to hear from someone experienced with dealing with these C structs and even better, linking them with Swift. Or, if there is another way to retrieve markers from soundfiles that I'm missing - I'd love to know that too.

1

There are 1 best solutions below

4
On BEST ANSWER

Here is the answer, in case anyone comes across this in the future.

// get size of markers property (dictionary)
UInt32          propSize;
UInt32          writable;

[EZAudioUtilities checkResult:AudioFileGetPropertyInfo( self.audioFileID,
                                                       kAudioFilePropertyMarkerList,
                                                       &propSize,
                                                       &writable)
                    operation:"Failed to get the size of the marker list"];

size_t length = NumBytesToNumAudioFileMarkers( propSize );

// allocate enough space for the markers.
AudioFileMarkerList markers[ length ];

if ( length > 0 ) {
    // pull marker list
    [EZAudioUtilities checkResult:AudioFileGetProperty( self.audioFileID,
                                                       kAudioFilePropertyMarkerList,
                                                       &propSize,
                                                       &markers)
                        operation:"Failed to get the markers list"];

} else {
    return NULL;
}

//NSLog(@"# of markers: %d\n", markers->mNumberMarkers );