Friday, April 29, 2005

The Proof is in the Bi-Phase Coding

Well, I figured it might be helpful to figure out what my speakers expected to see if they were ever to play AC-3 files over S/PDIF. So back to Google. Ah, some company called Audio Precision puts out a series of technotes on audio electronics. Technote 26 is on "The Digital Interface," and it lays out what my speakers expect to see. (You need to register to get the full technote.)

Of non-practical interest to me, the signal sent over the TOS-Link uses Bi-Phase Coding which is a clever encoding scheme which insures that regardless of the data (all binary 1's, all binary 0's or any mixture) the receiver gets a constant stream of regularly spaced signal transitions with which to sync itself.

Of practical import is a little history. The S/P DIF standard did indeed only expect to transport PCM encoded, uncompressed, two channel data, and then at some point, someone asked whether it would be possible to transport multi-channel compressed audio over the same connection, using the same protocol. Would the wires, encoders circuitry, decoder circuitry, etc. care if instead of PCM style data, there were the bytes from a compressed audio stream? Well no, especially if a bit was set in every data frame saying that it was "invalid" audio, and if periodically a channel status block was sent out saying that the channel was sending out "non-audio". Bytes is bytes. A receiver which didn't know about compressed formats would see such a stream and go into mute mode awaiting valid audio. A receiver designed to play raw AC-3 files, would know to see if the stream being sent appeared to be an AC-3 stream. Newer receivers might even look for Microsoft audio streams, and future receivers might know to look for some futuristic format. The only requirement being that the compressed audio fit in a bandwidth adequate for uncompressed stereo, and that your receiver know about it. This extension (hack) to S/P DIF is called IEC61937.

So the question still remains, how do you set the invalid audio bit of the PCM frame, and the channel status packet?

It's in the Chips

As I mentioned in my previous post, the Turtle Beach Audio Advantage Micro uses a USB interface by some company called C-Media Electronics, Inc. A quick Google search finds them in Taiwan. This is the present and future of electronics manufacturing, Taiwanese companies both designing and manufacturing items branded by American companies. It's why PowerBooks ship direct to you from factories on Taipei.

C-Media is quite happy, I'm sure, to sell anyone with enough cash the exact same chip set they sold Turtle Beach, the CM102 USB Audio Controlller. And the provided technical documentation is quite interesting. It looks like almost all the needed functionality you would need to implement a AAM like device is on this single integrated circuit. All that would be needed would be a USB connector, circuit board, a variety of capacitors and resistors and a TOS-Link emitter package; it'd be fun to slap these things together if I did that sort of thing.

But not a lot of help towards knowing what the driver should send the device to get my goal of AC-3 playthrough. It does mention something called "Xear 3DTM Sound Technology," but that is probably something proprietary and useless to me, so I will ignore it for now.

My answers are elsewhere.

Thursday, April 28, 2005

Investigating the Audio Advantage Micro

If you've installed Developer tools on your Mac you will find a useful little application called USB Prober.
/Developer/Applications/Utilities/USB Prober.app

If you have a AAM plugged in, and you run USB Prober, you find out what the Apple driver has to work with in configuring and sending it data.
Full Speed device @ 3 (0x19110000): ............................................. Composite device: "USB Audio"
Device Descriptor
Descriptor Version Number: 0x0110
Device Class: 0 (Composite)
Device Subclass: 0
Device Protocol: 0
Device MaxPacketSize: 8
Device VendorID/ProductID: 0x0D8C/0x0001 (C-MEDIA ELECTRONICS INC.)
Device Version Number: 0x0010
Number of Configurations: 1
Manufacturer String: 1 "C-Media INC."
Product String: 2 "USB Audio"
Serial Number String: 0 (none)

It's been a while since I did driver development, but let's break this down: it's a composite device which means it can be treated as two or more types of devices. For instance, it might be a outlet for audio data, and also be a volume control. The actual manufacturer of the USB interface chip was not Turtle Beach, but instead is somebody called C-Media Electronics, who've been issued a VendorID of 0x0D8C by the maintainer of a list of unique vendor IDs. and this is their first product using this ID.

Below this we have 2 interfaces. These are alternate pathways towards controlling the device. A driver will follow a very standardized series of calls over the USB bus to set up a communication pathway, these public interfaces lets the driver what format the device expects on the other side.

The first interface is given as Interface #0 - Audio/Audio Control
and a perusal indicates it is a standard USB protocol for controlling audio playback by giving a standard way to support muting, volume, etc. (I guess)

The second interface is given by Interface #1 - Audio/Audio Streaming
and basically says that this interface will accept a stream of PCM formatted audio data in an isochronous stream. The PCM is 2 channel stereo with a sampling rate of 48Khz. Very similar to what you get off of an audio CD except an audio CD is natively 44.1kHz. It's an isochronous stream which basically means the USB bus will try hard to allocate the stream a constant bandwidth, it's better for your mouse movement to be choppy than your audio playback.

But nothing about S/P-DIF. How does the PC driver send AC-3 to the receiver if it only supports PCM? Well there must be a way.

Necessity is the Mother of Drivers

I've been doing some online research on digital audio.

It all started when I purchased the device pictured below, a Turtle Beach Audio Advantage Micro, at a CompUSA store for $30.

What interests me about this product is I have a set of Logitech Z-5500 digital, 5.1, speakers, which have an unused optical input. The Audio Advantage has an optical output. So I can plug the AAM into my Powerbook 12" and get beautifully clean sound avoiding the auditory ugliness of a ⅛" mini-jack. And it works! iTunes sounds clearer than ever.

But there is something else I would like.

As of Mac OS X 10.3, the DVD Player application has an interesting option. If you have a S/P DIF output (which for all intents and purposes, the TOS-Link on the AAM is), and the driver for that output supports what is called bypass mode, the DVD Player can be set to not decode the AC-3 soundtrack on your DVD, it can be lazy and not convert the beautiful 5.1 soundtrack into old school stereo. Instead, the raw AC-3 file will get spit out the S/P DIF and into your stereo receiver, and if your receiver can handle it (which the Z-5500 most certainly can), you will get surround sound of the highest quality instead of lame stereo with a Pro-Logic II effect to make it sound sort of like surround sound.

So, the DVD Player supports it, the AAM supports it, my speaker system supports it. What doesn't support it? The Apple provided driver does not know about the AAM, and therefore cannot tell the DVD Player to send AC-3 streams through. The AAM supports this bypass mode on the PC, my desktop Dell sounds great, because Turtle Beach has written a driver for Windows XP. They rely on Apple's generic audio driver for the basic stereo support we Mac users get. If someone in the know were to write a Mac driver for the AAM, you could get surround sound out of a Powerbook, Mac Mini, eMac, iMac or iBook for $30+. PowerMac G5's already have an optical output.

As it happens, I have written a handful of USB drivers in my professional life, but never for OS X, and never involving audio. So I am investigating how I would go about writing a driver, and I will test out using the blog form to publish my finds here, if I abandon the effort someone might find my entries useful.

Of course, I'll get my copy of Mac OS 10.4 (Tiger) in a few days, and it's USB audio driver might support the AAM, and I'll say forget it.

Monday, April 11, 2005

On 5.1 sound

Well, it's quite late, and I spent the last 4 days not getting much work done. We are late in the development cycle at my day job and I am in desperate need of two weeks off. My problem with contract work is I have to pay for my own vacations. So I haven't gotten proper R&R in over a year. All those weeks of problem solving and design, of never turning my brain off, have caught up with me. Anyway, I have a new toy to distract me.

Dell had a low price on Logitech Z-5500 desktop speakers. My primary interest was the number of inputs: six. Four analog and two digital which means no more unplugging my PC to give an input for my Powerbook, etc. And it's my first foray into the wonderful world of Dolby Digital 5.1 sound. My Sony DVD player is more than happy to output 96/24 (whatever that means) over the coaxial digital line, so I can watch movies on my widescreen 20.1" LCD monitor while being immersed in sound waves. I watched the Two Towers tonight and I am just amazed how much proper sound adds to the effect. Sonically, it is more real than real. Amazing.

And this is with the subwoofer set to 1 on an 11 point loudness scale, and the satellites at 3. I wouldn't want to keep the downstairs neighbors up.

I also bought a cheap Turtle Beach Audio Advantage Micro USB to optical adaptor, which does not give my Powerbook 5.1 output unfortunately, but does give it beautiful, hum-free, stereo output. iTunes sounds better than I've ever heard it. What a bargain.

Sunday, April 10, 2005

Welcome to My Soon to be Abandoned Blog

I wanted to post a comment on Anne Althouse's blog, which required me to setup this blog account. I doubt I will ever make use of this, but I might use it to run a diary of a Cocoa based multimedia application I have been considering writing. If I do the project, I'll be back. You can see my homepage at http://genhelp.com