On 22 Mar '08, at 4:58 PM, I wrote: kAudioFilePropertyBitRate is returning nonsensical values for some files. Some VBR MP3 files, such as a 124kbps one encoded by & purchased from eMusic.com, get 32 for this property.
Researched this some more. It's a more serious bug than the simple off-by-1000 one I just mentioned. It only seems to occur with VBR MP3 files, and not with all of them. I was unable to find it with any files encoded by iTunes 7.x, but I did find it in older iTunes-encoded files and with many files encoded with LAME (purchased from eMusic or downloaded as free promos.)
I just filed this as rdar://5831835, enclosing one of the problematic files. Here's the description:
The value of kAudioFilePropertyBitRate, returned from AudioFileGetProperty, is quite incorrect for many (most?) VBR MP3 files. In most cases it's about half what it should be, and I've seen some files where it's off by a factor of 4.
This makes this property totally unreliable for purposes like checking whether a file can be successfully streamed over a network connection of known bandwidth. It's actually a lot more accurate to just divide the size of the file by its duration in seconds (which is the workaround I'm using.)
[I'm already compensating for the but that MP3 files report their bitrate in kbps, not bps, so the results are a factor of 1000 smaller than for other codecs. I believe this is already a known issue.]
* STEPS TO REPRODUCE
Insert the following snippet into the sample code PlayFile.cpp (in /Developer/Applications/CoreAudio/), right before the call to AUGraphStart, which is at line 92 in my copy:
//BEGIN addition to print bit-rate --Jens Alfke
UInt32 bitRate;
propsize = sizeof(bitRate);
XThrowIfError (AudioFileGetProperty(audioFile, kAudioFilePropertyBitRate, &propsize, &bitRate), "AudioFileGetProperty");
printf("kAudioFilePropertyBitRate: %u\n", bitRate);
SInt64 byteCount;
propsize = sizeof(byteCount);
XThrowIfError (AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataByteCount, &propsize, &byteCount), "AudioFileGetProperty");
UInt32 estBitRate = round(byteCount*8 / fileDuration / 1024);
printf("Actual average bit-rate: %u\n", estBitRate);
//END addition to print bit-rate
Now build PlayFile and run it on various VBR MP3 files. I've attached one, "Inevitable Fast Access.mp3"; see results below.
* RESULTS
For some files in my iTunes library:
"Inevitable Fast Access.mp3"
Encoded by: LAME 3.89 [purchased from eMusic]
kAudioFilePropertyBitRate: 32
Actual average bit-rate: 121
According to iTunes: 124
"The Greys.mp3"
Encoded by: LAME 3.89 [downloaded free from SXSW festival website]
kAudioFilePropertyBitRate: 104
Actual average bit-rate: 210
According to iTunes: 215
"Instrumental Wish.mp3"
Encoded by: iTunes 7.0.2
kAudioFilePropertyBitRate: 240
Actual average bit-rate: 157
Reported by iTunes: 160
—Jens |