Back when I was first getting audio output to work with the media center on OS X, I decided to use the PortAudio library. It’s portable, powerful, and I was already familiar with it, having used it on a previous job.
The downside to PortAudio turned out to be its lack of support for doing passthrough of encoded digital audio streams like AC3 and DTS. I always figured that a digital audio stream was just bits, and if the stream was set to the right bit-width and sample rate, encoded audio would work fine. It turns out I was only partially right; most receivers will accept this stream and lock onto the encoded audio. However, they’re only doing that because they’re being liberal about what they accept. The bitstream is actually lacking lower-level S/PDIF bits (meaning that they can’t be set at the application level) making it an official encoded audio stream. This meant that some receivers, acting by the letter of the law (like the one owned by poor fatez) refused to interpret the stream as encoded digital audio.
We first knew this was a problem around 8 months ago, which makes it the longest running Plex bug in history. The first person to tackle the problem was Brandon Golm. He worked extremely hard over several months on enhancing Portaudio with support for passthrough. However, the CoreAudio code in PortAudio isn’t the easiest to modify, and this approach (which I suggested and accept full blame for) didn’t end up coming to fruition.
Enter our resident Plex audio expert Ryan (who, incidentally, was one of the very first people to contribute code to the OSXBMC project!). Ryan took an interest in the problem and decided to approach it by porting VLC’s CoreAudio output module to Plex. After a enormous amount of hard work, the day finally arrived when he could claim victory:
- Auto-detection of whether devices support encoded digital output. This is extremely useful for not getting your ears blasted with static, since when you switch from your Built-in Digital Output to your Logitech Headset, it will switch automatically to analog mode.
- Increased flexibility: Interestingly enough, there are some audio devices (e.g. some external USB or Firewire devices) which don’t show up under CoreAudio as supporting encoded digital audio (S/PDIF). In this case, you can switch the digital output support to “Force Digital” and it will send audio to the device encoded “unofficially”. This means it likely won’t work with fatez’s receiver, but it is useful in some scenarios.
- Improved lip-sync: the new code monitors the hardware latency reported by CoreAudio, so Plex is able to provide better synchronization between video and audio.
The new output module, coupled with the AC3 transcoding ability Ryan added back in Plex/Five (which allows converting 5.1 AAC and DTS stream to AC3), means that Plex now has — hands down — the absolute finest audio output features of any media center on the Mac, if not across all platforms.