Resampling in Mac OS part 2 :)

After a few snarky messages from Mac owners, I thought I had better post a follow-up. I experimented a little at the weekend and found the following:

If I leave my soundcard (Audiophile Firewire) permanently on 96kHz, then:

iTunes will resample to 96kHz internally, with quality that sounds just fine.

VLC will output at whatever the sample rate of the media is, and get resampled to 96k by AUHAL on its default quality setting, which sounds a bit sketchy.

But, VLC can be set to always output at a particular rate, resampling internally. There’s an option called “Frequency” in the advanced audio preferences. According to VLC’s debug stream, it uses a module called “bandlimited_resampler”, and that’s encouraging, because it suggests that the guy who coded it knows the word “bandlimited”. It uses about 6% CPU time, and again, sounds fine. Thanks to the wonders of open source, we can see bandlimited.h here! Ooo, a 1536 point sinc kernel with linear interpolation and single-precision floating point arithmetic.

I got VLC’s “Media Library” to work too, so it can store a playlist, remembering what FLAC stuff I have and the track order of it.

I’ve not tried to play DVDs yet, but hopefully the computer won’t catch fire.

So in conclusion, I’m upgrading this from “:(” to “:)”

Resampling in Mac OS :(

Recently I’ve been experimenting with higher definition music downloads. For example, the Studio Masters recordings from Linn Records, or the material from B&W Society Of Sound. Everything went nicely until I got my new Mac.

First of all, the only lossless format supported by iTunes is Apple Lossless. It won’t play FLAC (the open source Free Lossless Audio Codec) properly, even with the xiph.org extensions, Fluke, or whatever. A bummer, as I already had a fair amount of music in FLAC format. Sure, VLC will play it, but VLC can’t understand iTunes playlists.

Second, Linn don’t support Apple Lossless. They supply their music in FLAC and WMA formats only. I guess they’d rather you bought their own stupid, overpriced DS network media players, even if you have a Mac already.

Third, Mac OS resamples! Windows was smart enough (or dumb enough?) to set your audio hardware to the actual sample rate and bit depth of the track that was currently playing. Or at least the setup I used, Winamp Classic with the ASIO driver, would do that, guaranteeing bit-accurate output under all conditions.

The Mac doesn’t. You set the sample rate and bit depth once and for all in the audio control panel, and all the sound gets resampled to that. You can play 96kHz material till you’re blue in the face, using any player application you like, but if the system sample rate is set to 44.1, it’ll get downsampled. Watch a DVD, and the sound is getting resampled from 48 to 44.1.

I don’t know about you, but I wouldn’t trust any resampling algorithm I hadn’t written or at least tested myself. They’re notoriously hard to get right. And a “right” one consumes so much CPU power that there’s a real incentive to downgrade the performance deliberately.

Here’s the official line from the Coreaudio mailing list, found here

This was a comment posed to the list (which was replayed verbatim from Benchmark’s Elias Gwinn)
> […] If the user changes CoreAudio’s sample-rate in AudioMIDI Setup to something different than what iTunes is locked to, CoreAudio will convert the sample rate of the audio that it is receiving from iTunes. In this case, the audio may be undergoing two levels of sample-rate conversion (once by iTunes and once by CoreAudio). (The SRC in iTunes is of very high quality (virtually inaudible), but the SRC in CoreAudio is horrible and will cause significant distortion.) If the user wants to change the sample rate of CoreAudio, iTunes should be restarted so that it can lock to the correct sample rate.

This is the response from an Apple employee:
iTunes uses the AudioConverter API internally but we set the quality to “max” and AUHAL probably uses the default (I don’t know). One SRC at max quality followed by one at the default quality is not so great when analyzing sine tone playback.

So the bottom line seems to be, that if you have material recorded at a higher sample rate than 44.1, then you need to turn your system’s sample rate up to appreciate it. And if you do that, then all of your other stuff will get upsampled, though at least it uses Coreaudio’s best quality algorithm. Or does it? Leopard introduced a new “Mastering grade” algorithm, and it’s not obvious whether that one is used.

One step forward, two back. Come on Apple, twiddle those nose rings and come up with a sexy solution.