I'm trying to determine whether an audio file uses VBR or not in a Cocoa app (OS X 10.8+).
AVFoundation doesn't seem to be able to answer the question at all, and AudioToolbox is lying to me.
The code below adamantly claims that any mp3 file I throw at it is VBR; even for files where I know that isn't the case (cross-checked with MediaInfo)
OSStatus result = noErr;
UInt32 size;
AudioFileID audioFile;
AudioStreamBasicDescription audioFormat;
AudioFormatPropertyID vbrInfo;
// Open audio file.
result = AudioFileOpenURL( (__bridge CFURLRef)originalURL, kAudioFileReadPermission, 0, &audioFile );
if( result != noErr )
{
NSLog( @"Error in AudioFileOpenURL: %d", (int)result );
return;
}
// Get data format
size = sizeof( audioFormat );
result = AudioFileGetProperty( audioFile, kAudioFilePropertyDataFormat, &size, &audioFormat );
if( result != noErr )
{
NSLog( @"Error in AudioFileGetProperty: %d", (int)result );
return;
}
// Get vbr info
size = sizeof( vbrInfo );
result = AudioFormatGetProperty( kAudioFormatProperty_FormatIsVBR, sizeof(audioFormat), &audioFormat, &size, &vbrInfo);
if( result != noErr )
{
NSLog( @"Error getting vbr info: %d", (int)result );
return;
}
NSLog(@"%@ is VBR: %d", originalURL.lastPathComponent, vbrInfo);
Why is it lying? What am I doing wrong?
How can I realiably determine the VBR-iness of an audio file in a Cocoa Application?
VBR and CBR sample files can be obtained here (not my page).