[Hint] How to play DTS surround audio over iTunes

Posted:
in iPod + iTunes + AppleTV

How to play DTS surround audio over iTunes


It is well known that iTunes limits its choice of audio files (on Mac) to MP3, AAC, ALAC, AIFF and WAV and only plays them in stereo. In general, owners of a surround system are not able to play back surround content via iTunes. However, it is possible with a trick to get iTunes to play surround content. To do this, you "disguise" a DTS stream as a stereo WAV file. This procedure is known from so-called DTS Music Discs. How to do this (using iTunes) I would like to briefly explain here. Initially it's a little handicraft work, but afterwards you can manage your surround music via iTunes. I was searching for such a method for a long time, so I hope it will be interesting for some other people here too.


You need:

- iTunes
- FFmpeg (try to get the most recent release version)
- An Airplay-enabled AirPort Express
- One Toslink to 3.5mm Mini Digital Toslink Audio Cable
- A surround receiver with optical (Toslink) audio input
- Delicious biscuits (optional)


1. Set up iTunes

For everything to work smoothly, the audio signal must be transmitted bit-perfect from iTunes to the receiver. This means that all "sound modifiers" must first be turned off in iTunes. To do this, go to the playback preferences and deactivate everything there (sound enhancers, crossfading, auto volume adjustment).
Next, set the iTunes volume control to Maximum (see picture below).

2. Connect AirPort

It also only becomes bit-perfect if the signal is transmitted optically digital and not analogue from the AirPort Express to the surround receiver. The AirPort Express has to be connected to the Toslink socket of the receiver to the AirPort Express 3.5 mm jack port via the optical cable. Then you can configure it on your Mac with the AirPort utility for AirPlay operation and connect it to the WLAN network. Now you should be able to select the AirPort station to the right of the volume control in iTunes, when you have a WLAN connection. With your existing stereo music, you can now test whether the configuration works up to here.



3. The audio material

So far so simple, now it's getting a little more elaborate. It's about creating the audio material. The first thing needed for this is the command line program FFmpeg, which is operated via the Terminal application. Because it is Open Source, it is free of charge.

3a. Install FFmpeg

FFmpeg can be downloaded here: https://www.ffmpeg.org/download.html#build-mac
Here you can find packages ready compiled for macOS. If you want to build it by your own, you can compile it yourself from the source code, but I only recommend this for really tinkering enthusiasts. Once FFmpeg is installed, open the Terminal application and type:
$ ffmpeg -h

If you get a long list now, the installation was successful and we can go on to the next step (or strengthen ourselves with some cookies for the next step).

3b. Get the audio file

Now we need the surround encoded music that we would like to have in iTunes. Best, you already have a multichannel audio file. If not, you can create one. Multichannel music DVDs or BluRays are suitable for this. From these we first have to get the movie as a file, but I'm not going to explain how that works here, that should be known (or can be found in the web). The format doesn't matter at all, because we're only interested in the audio stream. For the audio part we should try to get the best quality as possible. Next we need to extract the audio stream from the encoded movie. Now we will use FFmpeg. We start the Terminal application. Now we enter into the Terminal (don't hit enter now):
$ ffmpeg -i
and then we drag the movie from the Finder into the terminal window. The whole thing should look e.g. like this:

$ ffmpeg -i /Movies/Test.mkv

Now we press enter. Then a whole series of text appears. Somewhere at the bottom is the coding of the video and audio stream. That looks like this:
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2713 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
Metadata: handler_name : VideoHandler
Stream #0:2(eng): Audio: dts (DTS-HD MA), 96000 Hz, 5.1(side), s32p (24 bit)

Important is the part with "Audio", there we remember the stream identifier, in this case #0:2. Next we extract the audio stream and convert it into the lossless format FLAC. The command for FFmpeg in our example should look like this:

$ ffmpeg -i /Movies/Test.mkv -map 0:2 -vn -acodec flac /Movies/Test.flac

The path to the movie has to be adjusted accordingly. Then it takes a while and at the end you have a multichannel FLAC file. Here the sampling rate and the bit value do not matter, this is converted later in a slip. If you like, you can now divide them into the respective titles with an audio program and save them individually. But then save everything as multichannel FLAC again. Now you are almost finished. Only the "magic trick" is missing.

3c. Packing the multichannel audio as DTS in WAV

To convert the multichannel FLAC file to DTS and convert it to WAV you need FFmpeg again. First we convert the FLAC file into a SPDIF coded DTS file. In the Terminal as follows:
$ ffmpeg -i /Movies/Test.flac -strict -2 -acodec dts -ar 44100 -f spdif /Movies/Test.spdif

If you have a lot of files you want to convert in batch, you can also use "cd" to go to this folder and enter:
$ for file in *.flac; do ffmpeg -i "$file" -strict -2 -acodec dts -ar 44100 -f spdif "${file%.flac}".spdif; done
You can eat a cookie here, it takes a while.

Next we wrap this DTS file into a stereo WAV file with 44.1 kHz. In the Terminal as follows:
$ ffmpeg -f s16le -ac 2 -ar 44100 -i /Movies/Test.spdif -acodec copy /Movies/Test.wav
Or batch again:
$ for file in *.spdif; do ffmpeg -f s16le -ac 2 -ar 44100 -i "$file" -acodec copy "${file%.spdif}".wav; done
Note the "-ac 2" no matter if the input is stereo or not! This is important.
(For the code with the spdif and the WAV encapsulation, thanks to Carl Eugen Hoyos from the FFmpeg-user mailing list)

4. Importing

Now we're nearly done. Now the WAV file(s) can be imported into iTunes and labeled. One limitation is that WAV files cannot be provided with a cover.
If you play the file normally in iTunes like this, you will only hear digital noise and chirping. Therefore we now switch the audio output of iTunes to AirPort Express and switch on the surround receiver. Now the DTS signal is transmitted to the AirPort Express and transferred via the optical cable to the receiver for decoding. The music should now be heard in DTS Surround.



Notes: 

- Since the AirPort Express is limited to 44.1 kHz and 16-bit, the WAV file should also be encoded in 44.1 kHz. In addition, the DTS stream must also have 44.1 kHz. If it has 48 kHz, the music playback is about 8% slower than the original.
- I couldn't make it work with AppleTV.
- Some surround receivers do have an integrated AirPlay support. But it does not work if iTunes is connected with the surround receiver via AirPlay directly.
- If you have just noise on your receiver instead of music, switch the receivers surround modus to DTS, so it recognizes the DTS stream correctly. Then you can change the surround modus, if you want.
- For some surround receivers (not for all) it also works if AIFF is used instead of WAV, sometimes it even works to compress the WAV/AIFF as ALAC inside iTunes after importing. Than you also can give the files a cover. WAV always seems to work.
$ ffmpeg -f s16le -ac 2 -ar 44100 -i /Movies/Test.spdif -acodec copy /Movies/Test.aiff
- This also works if the files are stored on a NAS (in my case a Synology one) which is connected to the surround receiver via Ethernet. Also here WAV always seems to work.
- The DTS encoder in FFmpeg is still in experimental status (hence -strict -2), which means that the sound quality might not satisfy high audio quality standards

Sign In or Register to comment.