AC3Jack is a tool for creating an AC-3 (Dolby Digital) multichannel stream from its JACK input ports. Using this tool, an AC-3 stream (up to 5.1 channels) is created in real time and either written to a file or streamed to a SPDIF output.

If the SPDIF port on your audio interface for connection to a multichannel surround receiver, you can achieve full 5.1 surround mixing and monitoring of your JACK applications with a single digital cable, and no need for hardware supporting discrete outputs and inputs.

AC-3 is a compressed audio stream, so quality will suffer somewhat, but it is the price you pay for easy surround sound. The AC-3 encoder used here comes from the Aften project and although the sound quality seems good, I haven't seen any direct quality comparisons with commercial encoders.

ac3jack written by Jesse Chappell. It is licensed under the GPL and comes with NO WARRANTY of any kind.

Get the source code to the latest release and build it yourself on Linux or Mac:

GUI Usage  
The main ac3jack executable now has a GUI for easy control of the various options at runtime. There is also a command line version called ac3jack_cli. Both are capable of being controlled remotely via OSC using the messages specified in the OSC API.

ac3jack [-h] [-V] [-H <str>] [-P <num>] [-J <str>] [-S <str>]

-H <str> , --connect-host=<str>    connect to remote ac3jack on given host
-P <num> , --connect-port=<num>    connect to remote ac3jack on given port
-J <str> , --jack-name=<str>    jack client name, default is ac3jack_1
-S <str> , --jack-server-name=<str>    specify jack server name
-h , --help    this usage output
-V , --version    show version only

All other options are controlled from the GUI and can be changed at any time.

Command-line version usage  
ac3jack_cli [options...] [portname ...]


-o , --output=<str>     specify file to write output AC-3 stream, 'stdout' will write to standard output
-c <num> , --channels=<num>     number of AC-3 output channels (2-6). default is 6 (5.1)
-b <num> , --bitrate=<num>     bitrate of AC-3 stream (kbits/s). default is 448
-d <num> , --duration=<num>     duration of output stream (secs). default is 0 (forever)
-l , --lfe     enable LFE channel
-t , --jack-transport     use jack transport state (rolling/stopped) to control stream output
-R , --raw-jack-out     will write raw deinterleaved ac3 out two jack ports. careful!
-S , --spdif-out     will open a local audio device SPDIF for live AC3 output
-C <num> , --spdif-out-card     optionally specify the card # SPDIF device to use with -S option
-j <str> , --jack-name=<str>     jack client name, default is ac3jack_1
-P <num> , --osc-port=<num>     OSC server port to use (default is (12314)
-q , --quiet     do not output status to stderr
-h , --help     this usage output
-V , --version     show version only

If portname arguments are added, they are initially connected in channel order, if possible.
The allowable bitrates for AC-3 encoding are nominally variable from 32-640 kbits/s, but there are common conventions and recommendations for bitrate based on channel count. Only certain bitrates are likely to be accepted by the codec as well.
2 ch -- 192
5.1 (6 channel) -- 448

However, if doing live streaming to hardware consider using the highest quality bitrate of 640.

The sample rates allowable are 32, 44.1, and 48kHz. Note that for use as part of DVD soundtracks multiplexed with MPEG2 files, only 48kHz is allowed. Currently the sample rate is selected by the native rate of the active JACK server. I highly recommend that you use a buffer size of at least 1024 when using AC3JACK, otherwise the CPU usage will be higher than necessary due to the block processing required for AC3 frames.

The channels options will make the following input ports with each given channel count:

1 - Left
2 - Left, Right
3 - Left, Center, Right
4 - Left, Right, LeftSurround, RightSurround
5 - Left, Center, Right, LeftSurround, RightSurround
An LFE channel may be added with an additional flag enabled.

If the -t (--jack-transport) option is used, ac3jack will only write to the output when the JACK Transport state is Rolling. This is useful in order to do port connection before the streaming begins, or to synchronize AC-3 stream capture to disk. If extra arguments are added to the end of the command line, they are treated as JACK ports to connect to the inputs (in channel orders shown above).

Output to File

ac3jack_cli -o file.ac3
This will create the ac3jack client with 5 inputs, (L,R,C,LS,RS) to which you can connect with your favorite JACK patchbay (eg. qjackctl). It will create an AC-3 stream and the output will be written to the file specified. As mentioned above, the -t option can be useful here.

Real-time output to surround receiver via SPDIF

The following command line can be used to send the AC3 stream through your audio interface (sound card) SPDIF output.
ac3jack_cli -S
This will create the ac3jack client with 5 inputs, (L,R,C,LS,RS) to which you can connect with your favorite JACK patchbay (eg. qjackctl). The -S option to ac3jack_cli causes it to try to open the SPDIF portion of your sound card for raw output and send the stream through it.

Some sound cards may not allow the SPDIF to be accessed when JACK is using it. In this case, to do realtime streaming you must either have two sound cards, with JACK running on one, and the -C <card_num> option to specify the audio interface to open the SPDIF output on. Alternatively, if you have a multichannel interface that exposes the SPDIF outputs on specific channels, you can use the Raw JACK Out option to have ac3jack send the raw spdif PCM output to two JACK ports that you can connect to your SPDIF channels using a JACK patchbay.

This option is also for audio interfaces that have SPDIF but don't advertise AC3 passthrough to the OS or that don't allow its use simultaneously with JACK. You must connect the L and R ports to a pair of hardware channels that route to the SPDIF output.

WARNING! Do NOT connect these jack ports to analog channels with speakers attached, or damage might occur! It is wise to keep your target receiver muted until it locks on the AC3 stream.

All of the options for outputting encoded AC3 via SPDIF or Jack ports are available from the GUI as well.

The older 0.1.2 version of AC3Jack is now deprecated but its page and description is available here.