Code-Project: Virtual 5.1 Soundcard (Mac)

As far as I’m aware there very few real-time 5.1 (Dolby Digital / AC-3) encoders for the Mac that integrate into the default CoreAudio HAL (and can thus be used by any application); I’ve only stumbled upon ac3jack, which builds on the multi-platform JACK Audio Connection Kit.
I thought it’d be interesting to learn something about CoreAudio and low-latency coding and thus decided to write such a system. Currently, this is split into 3 components:

  • CoreAudio AudioCodec for transforming LPCM into encoded AC-3. I’m using libavcodec as the encoder for this.
  • Audio driver presenting a virtual sound output to the system, and forwards that data as a provided sound input. The idea is to select the virtual output as default / system output, and then encode from the virtual input into the compressed format and forward that to a physical optical output.
    In 10.8 “Mountain Lion” you can write these sorts of plug-ins as sandboxed user-space components, which is quite neat (but not well documented at the moment).
  • A normal application / menu extra that takes raw sound from the virtual sound input, passes that to the AC-3 audio encoder, and then forwards the resulting stream to a physical digital output port.

The encoder seems to work; I’m currently working on the driver and then comes the user-space connector / configuration application.

Fun times! :D

5 thoughts on “Code-Project: Virtual 5.1 Soundcard (Mac)

  1. Roberto Usai

    I had the same idea about one year ago but I figure it out immediately that I have to study too many things together in order to get something useful.
    I restarted few weeks ago because I’m not able anymore to use AC3jack on 10.7 (it seems that everything is fine, AC3jack receive the data and I’m able to save to file the resulting AC3 stream but I cannot send directly to the optical out).
    The idea now is to take a look into AC3jack and try to fix the output port addressing, but there are too many pieces involved together to compile it.
    Your idea is absolutely better but I don’t understand the need of the third piece: is it not possible to get the data from the virtual audiodriver input, convert to AC3 and send directly to the optical output?
    It is not possible to simply select which default device has to be used?

  2. [maven] Post author

    The third (user-space) piece is necessary as far as I can say. There does not seem to be a default (OS X system provided) way to forward audio from one input device, forward that to an AudioUnit (or process it internally), and pass the output of that as S/PDIF to an output device.
    This project has pretty much fallen by the wayside, although I got everything but the last part working (or so it seems). Getting the raw S/PDIF out seems to be a fair headache from looking at the VLC sources, and because AUGraph only supports a single device, I’d have to set up all the AudioUnits myself.

  3. Jonah

    Hey Maven, I’m curious how you got on with this project. Ac3jack doesn’t want to connect to Jack on my 10.8.5 installation and I’m looking for an alternative realtime AC3 encoding solution.

  4. [maven] Post author

    I saw your article linked on Hacker News, and it did look interesting. But I somehow lost interest (even though I’m still interested in getting this to work at some point). Either way, thanks for the ping!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>