Code-Project: Virtual 5.1 Soundcard (Mac)

2015-12 Addendum: See SoundPusher for an update to (and new name for) this project.

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! 😀

8 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!

  5. Balandino

    Hi guys,

    any better?
    Are there any news about Virtual 5.1 Soundcard?

    I’m looking for a real time encoder to do some live music using dolby through SPDIF.
    Any advice for me?


  6. Gellis12

    Hey Maven, is there any news on this project?

    I’ve been looking for something *exactly* like this for a while now. I’ve got a 5.1 speaker system hooked up over SPDIF, and Kodi has been the only thing that’s able to make use of it so far, with its AC3 transcoding option. It’d be nice if I was able to get play 5.1 audio from other programs too.

  7. [maven] Post author

    In fact, there has been some progress. 🙂

    This is in a fairly rough state, but it seems to work for me. I haven’t put together a proper release yet, but the current state is over at GitHub for now. You should be able to compile from there.

Leave a Reply

Your email address will not be published. Required fields are marked *