The Ill-Tempered Audiophool

iTunes, Audio MIDI Setup, and all that

One of the first things I learned when I first visited this site about a year and a half ago was the following:

iTunes (on OS 10.6.X at the time) will only play a track bit-perfectly if Audio MIDI Setup's sample frequency matches that of the track in iTunes. Otherwise it (or core audio?) up/down samples. I was told that in order to play a 96kHz track without resampling directly after playing a 44.1 kHz track, it was not enough simply to reset Audio MIDI Setup, but one had to first reset Audio MIDI Setup to 96kHz, then quit iTunes, then restart iTunes, and then play the 96kHz track.

Most of my quest with third-party software has been to make that transition more seamless. The differences in sound quality, to my ear, through my equipment (which upsamples everything), is not particularly striking.

Anyway, today Paul mentioned in another thread that more current versions of iTunes no longer necessitate the quit/restart cycle. If there was a way to automatically read the native sampling frequency of the track about to be played, match it to that of Audio MIDI, and if necessary pause the track and change it, then resume playing, you could get bit-perfect playback with iTunes with no further heroics.

I have no reason not to believe this, but I am suspicious, because it sounds almost too good to be true. Moreover, Bob Stern and I cobbled together a shell-script and iTunes plug-in to do this. I've now got versions for 10.6 and 10.7.

If someone could verify that iTunes indeed now behaves as Paul says, I would be happy to make these freely available to the community. Please let me know...

I fed it into the Proton and the sample rate LEDs changed, which is a pretty good indicator. I meant to send you a note this morning. :)

One thing, it works fine on a Macbook running Lion (32bit OS, 64bit iTunes) but did not work on the Mini, running 64bit OS/ 64 bit iTunes. It is probably user error, as I was pretty tired when I tried it last night, and it is also why I didn't send back another note.

Chris - if you could double check it on your gear, that would be great.

Sorry to hijack this thread, but I got lost reading this. Is iTunes in fact changing the sampling rate automatically or not? One person says yes, then the next person offers a script to do it...which is it?!@?@? Sorry, just not very clear reading this what the results are....

But, we are thinking that you can go into the Audio/Midi setup and change the sample rate, and it will change without exiting and restarting iTunes.

This is significant because Bill's script will automatically set the sample rate in Audio/Midi for each track.

For all intents and purposes, with Bill's script installed, that means automatic sample rate switching in iTunes.

What we have to verify is that the sample rate actually changes without the need to exit and restart iTunes. You might test it on your system, if you have a way to see the sample rate your DAC is seeing. (LEDs, Display, etc.)

4. Open iTunes, go to the Script icon in the menu bar, and select "ToggleiTunesNyquist". This allows you to turn it on or off, or uninstall the plug-in. If you select "Yes", it will prompt you to turn on assistive devices if you haven't done so (this will only happen once) and then it will prompt you to go to Audio MIDI Setup and select the appropriate output device.

If it is ok, it should all just work.

Assuming this proves to be useful, I will make a more user-friendly installer, each for 10.6 and 10.7.

Thanks Paul you cleared that up for me. I'd forgotten about all that mess you have to deal with when using iTunes. So just to clarify, this script will work better now as iTunes no longer needs to shut itself down first correct? Thanks for the tip! I may have to use iTunes just to see how it is these days.

Please play a track, and while the track is playing, open up Audio/Midi and change the sample rate. See if it changes on your DAC, without having to exit and restart iTunes. Also, please try it with no track playing. :)

The question is if you manually change the sample frequency in the Audio MIDI Setup window to match that of a non-redbook track in iTunes, and then without restarting iTunes, start to play the track, does iTunes do the right thing, or is it down-sampled and then up-sampled, or does it then output bit-perfectly?

so I can't test it now, but for me the app must change the sample rate automatically without user interfering, so changing that in MIDI setup is no solution for me. Also iTunes does not have exclusive access to the device (Hog Mod), and no integer Playback under Snow Leopard, but I must say, that iTunes 10.5 does sound better than the earlier versions, it seams to have a similar play from RAM feature, because you can see on the activity monitor, that the cpu drops after every track starts to down to 1 %, but still no comparison to AudirvanaPlus, Decibel oder BitPerfect.

In the past if the sample rate in Audio Midi is set when you start iTunes (call it sample rate A) and you then change the sample rate (to rate B) in Audio Midi while iTunes is started: iTunes outputs via resamples (if needed) the music to rate A then Core Audio resamples it to rate B...

It's now said the IF Audio Midi is changed iTunes realises this change has been made and will output or resample at rate B avoiding the potential double resampling...

Second to this Scott has created a script which changes the sample rate automatically via Audio Midi to match the sample rate of the file being played... This is only of significance if iTunes behaviour is now correct (Apple have acknowledged this was a bug previously though they said it was low priority to fix).

When I have MIDI setup at 44K when opening iTunes and played a 44K File, than everything is Bit True und fine. See the below graph, showing a 1 kHz – 3 dBFS, 24 Bit Signal, digital analyzed.

Now when I play a 48K file, without changing anything, I lost Bit True and the Mac Audio System converts the 48K signal in a 44K sample rate frame. The next measurement shows the quality of the SRC converter.

When I now stop playback and changing the sample rate in MIDI setup to 48K with leaving Itunes open and playback again the 48K signal, it looks like that I have two SRC going on. Now the output sample rate is 48K, as set in the MIDI setup, but the 48K signal looks screw up. Looks like that iTunes, that I started when MIDI setup was at 44K, converts the 48K signal into 44K and after that the Mac Audio System converts this 44K signal a second time to 48K output. See the measurement.

That looks really good. I know it sounds good, but it is nice to see why it does.

It is interesting that the 48-44-44 iTunes resampling essentially introduces what looks to my (untrained) eye, simple harmonic distortion. Maybe that is how they "get away" with doing it the way they do.

I was aware, that iTunes does sample rate convert everything that doesn't match the sample rate that was set, when starting iTunes, but the above measured (and auditioned) results also surprised me, that the sound was better, with 48 K files, played back at 44 K (sample rate, when starting iTunes), compared to the sound, when set the sample rate of the Audio / MIDI setup was set afterwards to 48 K (still playing back the 48 K source file) with leaving iTunes open. The output sample rate will then be 48 K, but the file seems to be converted internally two times.

Bill and others: I'd be very interested in playing around with the plugin (I'm on 10.6.8 so the 10.7 code above won't work for me). What you are trying to do is not impossible: there's a commercial product that does just this (Amarra HiFi). I'm also researching the possibility to do the sample rate setting directly via CoreAudio, this is supposed to be possible.