Skip to content

Commit 484b17b

Browse files
committed
cleanup multiple devices faq
- line length and highlighting
1 parent 8e0b3c0 commit 484b17b

1 file changed

Lines changed: 162 additions & 147 deletions

File tree

faq/multiple_devices.md

Lines changed: 162 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,102 @@ title: "How can I use multiple soundcards with JACK?"
55

66
# How can I use multiple soundcards with JACK?
77

8-
JACK is fundamentally designed to be a component in a pro-audio/music creation
9-
environment and standard operating practice for such setups involves using
10-
only a single digital sample "clock" (something counting off the time between
11-
audio samples). This means that trying to use multiple independent soundcards
12-
is problematic, because each soundcard has its own sample clock, running
13-
independently from the others. Over time, these different clocks drift out of
14-
sync with each other, and cause glitches in the audio. You can't stop this
15-
drift, although in some cases the effects may be insignificant enough that
16-
some people might not care about them.
17-
18-
Thus in an ideal world you should not use multiple independent soundcards but
19-
instead use a single device with a single clock and all the inputs, outputs
20-
and other features that you need.
21-
22-
Of course, a lot of people don't live in an ideal world, and believe that
23-
software should make up for this. Accordingly, JACK offers several ways for
24-
you to use more than 1 device at a time.
8+
JACK is fundamentally designed to be a component in a pro-audio/music
9+
creation environment and standard operating practice for such setups
10+
involves using only a single digital sample "clock" (something counting
11+
off the time between audio samples). This means that trying to use
12+
multiple independent soundcards is problematic, because each soundcard
13+
has its own sample clock, running independently from the others. Over
14+
time, these different clocks drift out of sync with each other, and
15+
cause glitches in the audio. You can't stop this drift, although in some
16+
cases the effects may be insignificant enough that some people might not
17+
care about them.
18+
19+
Thus in an ideal world you should not use multiple independent
20+
soundcards but instead use a single device with a single clock and all
21+
the inputs, outputs and other features that you need.
22+
23+
Of course, a lot of people don't live in an ideal world, and believe
24+
that software should make up for this. Accordingly, JACK offers several
25+
ways for you to use more than 1 device at a time.
2526

2627
### 1. Use the alsa_in and alsa_out clients (Linux & ALSA only)
2728

28-
If you are using JACK on Linux and want to use additional devices that have
29-
ALSA driver support (i.e. most PCI, USB and Bluetooth devices), then this is
30-
the best option.
31-
32-
`alsa_in` and `alsa_out` are two clients written by Torben Hohn that make a
33-
single specified ALSA device appear as a set of JACK ports. They both use Erik
34-
de Castro Lopo's libsamplerate library to do any resampling required to keep
35-
the audio in sync as the clocks of each device drift over time.
36-
37-
To use them, you start JACK as normal. Then you start an instance of alsa_in
38-
or alsa_out for each additional device (and "direction") that you want to use.
39-
`alsa_out` will create a set of ports representing the playback capabilities
40-
of the device, and `alsa_in` will represent the capture/recording
41-
capabilities. These two clients must be run inside a terminal window - there
42-
is no GUI for either of them. They both take arguments very much like those of
43-
the JACK ALSA backend, with some additional controls that affect the way that
44-
resampling is done. Full details are available in the man pages for each
45-
client, which you can read in a terminal window with the command `man alsa_in`
46-
(this page covers both clients, since their arguments are identical).
47-
48-
Note that you can use these clients even if you are running JACK with a FFADO-
49-
supported device. The requirement for ALSA support only applies to the extra
50-
devices you want to use, not the one that JACK itself is using.
29+
If you are using JACK on Linux and want to use additional devices that
30+
have ALSA driver support (i.e. most PCI, USB and Bluetooth devices),
31+
then this is the best option.
32+
33+
`alsa_in` and `alsa_out` are two clients written by Torben Hohn that
34+
make a single specified ALSA device appear as a set of JACK ports. They
35+
both use Erik de Castro Lopo's libsamplerate library to do any
36+
resampling required to keep the audio in sync as the clocks of each
37+
device drift over time.
38+
39+
To use them, you start JACK as normal. Then you start an instance of
40+
`alsa_in` or alsa_out for each additional device (and "direction") that
41+
you want to use. `alsa_out` will create a set of ports representing the
42+
playback capabilities of the device, and `alsa_in` will represent the
43+
capture/recording capabilities. These two clients must be run inside a
44+
terminal window - there is no GUI for either of them. They both take
45+
arguments very much like those of the JACK ALSA backend, with some
46+
additional controls that affect the way that resampling is done. Full
47+
details are available in the man pages for each client, which you can
48+
read in a terminal window with the command `man alsa_in` (this page
49+
covers both clients, since their arguments are identical).
50+
51+
Note that you can use these clients even if you are running JACK with a
52+
FFADO- supported device. The requirement for ALSA support only applies
53+
to the extra devices you want to use, not the one that JACK itself is
54+
using.
5155

5256
### 2. Use the JACK2 audio adapter(s) (Jack2 only)
5357

5458
_More information is needed on this option_
5559

5660
### 3. Using OS facilities to merge devices into a single pseudo-device
5761

58-
Both OS X and Linux provide ways to configure your machine so that it appears
59-
to have a new audio device that is actually a combination of one or more real
60-
devices. You can use this approach to create the configuration you want to use
61-
and then start up JACK using that new "pseudo" device.
62+
Both OS X and Linux provide ways to configure your machine so that it
63+
appears to have a new audio device that is actually a combination of one
64+
or more real devices. You can use this approach to create the
65+
configuration you want to use and then start up JACK using that new
66+
"pseudo" device.
6267

6368
#### OS X
6469

65-
**You must perform these steps as a user with administrative priviledges**.
66-
The first thing to do is to open up
67-
Applications -> Utilities -> Audio/MIDI Setup.
68-
Go to the main menu bar, click on Audio and then select
69-
Open aggregate device editor. Follow the simple instructions to
70-
add each desired playback or capture device to your new aggregate device.
71-
Then pick a name for the new device. This is the name you will also use
72-
to choose the device for use with JACK.
73-
74-
Note that there are quite a few subtle bugs with Apple's "aggregate device"
75-
facilities. Various things can happen that will cause the device to lose all
76-
of its playback channels or all of its capture channels, for example. If this
77-
happens, it is generally necessary to close all applications that are using
78-
any audio devices, and quite often a reboot is required.
79-
80-
Starting with JACK2 version 1.9.6, the CoreAudio backend can now dynamically
81-
create "aggregate devices" when needed (like when the -C and -P arguments are
82-
used to specify the separated input and output devices).
70+
**You must perform these steps as a user with administrative
71+
priviledges**. The first thing to do is to open up Applications ->
72+
Utilities -> Audio/MIDI Setup. Go to the main menu bar, click on Audio
73+
and then select Open aggregate device editor. Follow the simple
74+
instructions to add each desired playback or capture device to your new
75+
aggregate device. Then pick a name for the new device. This is the name
76+
you will also use to choose the device for use with JACK.
77+
78+
Note that there are quite a few subtle bugs with Apple's "aggregate
79+
device" facilities. Various things can happen that will cause the device
80+
to lose all of its playback channels or all of its capture channels, for
81+
example. If this happens, it is generally necessary to close all
82+
applications that are using any audio devices, and quite often a reboot
83+
is required.
84+
85+
Starting with JACK2 version 1.9.6, the CoreAudio backend can now
86+
dynamically create "aggregate devices" when needed (like when the -C and
87+
-P arguments are used to specify the separated input and output
88+
devices).
8389

8490
#### Linux
8591

86-
You will need to use a text editor to create or add to your ~/.asoundrc file.
87-
This file is read by any ALSA application (including JACK, if its using the
88-
ALSA backend) and can be used to define pseudo-devices of many different
89-
kinds. The key idea here is that you're going to define a new pseudo-device
90-
composed of 2 or more other devices. In our example, we'll just focus on 2
91-
devices being merged into 1, where both devices have just 2 channels in and
92-
out. This is the text you need to make sure is in ~/.asoundrc (below, we
93-
describe what this does):
94-
95-
96-
92+
You will need to use a text editor to create or add to your
93+
`~/.asoundrc` file. This file is read by any ALSA application
94+
(including JACK, if its using the ALSA backend) and can be used to
95+
define pseudo-devices of many different kinds. The key idea here is that
96+
you're going to define a new pseudo-device composed of 2 or more other
97+
devices. In our example, we'll just focus on 2 devices being merged into
98+
1, where both devices have just 2 channels in and out. This is the text
99+
you need to make sure is in `~/.asoundrc` (below, we describe what this
100+
does):
101+
102+
103+
97104
pcm.merge {
98105
type multi;
99106
slaves.a.pcm hw:0
@@ -109,110 +116,118 @@ describe what this does):
109116
bindings.3.slave b;
110117
bindings.3.channel 1;
111118
}
112-
119+
113120

114121
Lets see what this does.
115122

116123
* It defines a new audio pseudo-device called "merge".
117-
You can use this name anywhere you might use the name of an ALSA audio device,
118-
such as "hw:0" or "hw:HDA" or "hw:DSP" or "plughw:1".
119-
* It names "hw:0" as the first component (or "slave") of this pseudo-device
120-
(slave.a.pcm) and "hw:1" as the second component (slave.b.pcm)
121-
* It states that the pseudo-device will use 2 channels from the first component
122-
and 2 channels from the 2nd component.
124+
You can use this name anywhere you might use the name of an ALSA audio
125+
device, such as "hw:0" or "hw:HDA" or "hw:DSP" or "plughw:1".
126+
* It names "hw:0" as the first component (or "slave") of this
127+
pseudo-device (slave.a.pcm) and "hw:1" as the second component
128+
(slave.b.pcm)
129+
* It states that the pseudo-device will use 2 channels from the first
130+
component and 2 channels from the 2nd component.
123131
* The lines contains `binding.` list, in order,
124-
which channel of which component will correspond to
125-
the 4 channels of the pseudo-device. In the mapping shown above,
126-
the first channel comes from the first component,
127-
then the 2nd channel from the 2nd component,
128-
the 3rd from the first component and the 4th from the second component.
132+
which channel of which component will correspond to the 4 channels of
133+
the pseudo-device. In the mapping shown above, the first channel comes
134+
from the first component, then the 2nd channel from the 2nd component,
135+
the 3rd from the first component and the 4th from the second
136+
component.
137+
138+
Note that numbering of devices and channels in ALSA starts at zero, not
139+
one.
140+
141+
The most important and complex part of the above definition is the
142+
channel mappings defined by the `bindings` lines. A full channel mapping
143+
definition consists of a pair of a lines of the following general form:
129144

130-
Note that numbering of devices and channels in ALSA starts at zero, not one.
131145

132-
The most important and complex part of the above definition is the channel
133-
mappings defined by the `bindings` lines. A full channel mapping definition
134-
consists of a pair of a lines of the following general form:
135146

136-
137-
138147
bindings.CHANNEL_OF_PSEUDO_DEVICE.slave SLAVE_DEVICE_THAT_WILL_PROVIDE_THIS_CHANNEL
139148
bindings.CHANNEL_OF_PSEUDO_DEVICE.channel CHANNEL_OF_SLAVE_DEVICE_THAT_WILL_PROVIDE_THIS_CHANNEL
140-
149+
141150

142151
So the specific pair of lines:
143152

144-
145-
153+
154+
146155
bindings.0.slave a;
147156
bindings.0.channel 0;
148-
149-
150-
mean that "channel 0 of the pseudo-device will correspond to channel 0 of the
151-
first slave device". Obviously by playing with this definition you can create
152-
all sorts of wierd and wonderful mappings from the real physical device
153-
channels to the pseudo-device channels. You probably don't want to do that,
154-
though. The example above shows the most common example: take the first N
155-
channels from the first device, and the second M channels from the second
156-
device.
157+
158+
159+
mean that "channel 0 of the pseudo-device will correspond to channel 0
160+
of the first slave device". Obviously by playing with this definition
161+
you can create all sorts of wierd and wonderful mappings from the real
162+
physical device channels to the pseudo-device channels. You probably
163+
don't want to do that, though. The example above shows the most common
164+
example: take the first N channels from the first device, and the second
165+
M channels from the second device.
157166

158167
### The Control Pseudo-device
159168

160169
In theory, the above is enough to define a new pseudo-device, but many
161-
applications, including JACK's ALSA backend, also want to open a "control
162-
device" associated with the audio playback device. This is where they can find
163-
out (and possibly control) various hardware parameters associated with the
164-
device. Unfortunately there is no way to merge these together in the same way,
165-
so we have to provide a "dummy" control device definition that will keep such
166-
applications happy. This definition looks like this:
167-
168-
169-
170+
applications, including JACK's ALSA backend, also want to open a
171+
"control device" associated with the audio playback device. This is
172+
where they can find out (and possibly control) various hardware
173+
parameters associated with the device. Unfortunately there is no way to
174+
merge these together in the same way, so we have to provide a "dummy"
175+
control device definition that will keep such applications happy. This
176+
definition looks like this:
177+
178+
179+
170180
ctl.merge {
171181
type hw
172182
card 0
173183
}
174-
175184

176-
Notice that name following the `ctl.` text **must** be the same as the name
177-
following `pcm.` in the device definition above. The control device definition
178-
we've given here effectively means "if you want to open the control device
179-
associated with "merge", open the control device associated with the first
180-
installed audio/MIDI device". This probably isn't right of course - "merge"
181-
involves two cards - but it will generally work just fine.
182185

183-
You can use this same approach to merge more than 2 devices - the resulting
184-
pcm._DEVICE-NAME_ specification will obviously include more lines. You can
185-
also use different devices than we did above, where we just used the first and
186-
second installed card.
186+
Notice that name following the `ctl.` text **must** be the same as the
187+
name following `pcm.` in the device definition above. The control device
188+
definition we've given here effectively means "if you want to open the
189+
control device associated with "merge", open the control device
190+
associated with the first installed audio/MIDI device". This probably
191+
isn't right of course - "merge" involves two cards - but it will
192+
generally work just fine.
193+
194+
You can use this same approach to merge more than 2 devices - the
195+
resulting `pcm._DEVICE-NAME_` specification will obviously include more
196+
lines. You can also use different devices than we did above, where we
197+
just used the first and second installed card.
187198

188199
### "Slave" Device naming
189200

190-
Note that you are likely better off using "hw:CARD" device names, rather than
191-
"hw:N" names, when defining a "multi" pseudo-device, as explained
192-
[here](device_naming.html). But
193-
further note that if you are using multiple instances of the same type of
194-
audio hardware (say, 4 RME Multiface devices), you will have to use "hw:N"
195-
because every card will have the same "CARD" name. In fact, with such
196-
hardware, it may be very difficult to ensure that "hw:0" always refers to the
197-
same audio interface, because there is no ALSA name that uniquely defines a
198-
particular PCI slot. This is currently an unsolved problem when using multiple
199-
identical devices. If you use PCI (or PCIe or PCIx or other derivatives of
200-
PCI) devices, the chances are that the first card will always be the same one,
201-
and so forth, so its not likely to be an issue. If you use several identical
202-
USB devices, it may be a more significant problem.
201+
Note that you are likely better off using "hw:CARD" device names, rather
202+
than "hw:N" names, when defining a "multi" pseudo-device, as explained
203+
[here](device_naming.html). But further note that if you are using
204+
multiple instances of the same type of audio hardware (say, 4 RME
205+
Multiface devices), you will have to use "hw:N" because every card will
206+
have the same "CARD" name. In fact, with such hardware, it may be very
207+
difficult to ensure that "hw:0" always refers to the same audio
208+
interface, because there is no ALSA name that uniquely defines a
209+
particular PCI slot. This is currently an unsolved problem when using
210+
multiple identical devices. If you use PCI (or PCIe or PCIx or other
211+
derivatives of PCI) devices, the chances are that the first card will
212+
always be the same one, and so forth, so its not likely to be an issue.
213+
If you use several identical USB devices, it may be a more significant
214+
problem.
203215

204216
### 4. Using the -P and -C arguments to a JACK backend
205217

206218
Several JACK backends, including the ALSA, FFADO and CoreAudio versions,
207-
support the -P and -C arguments that can be used to specify two different
208-
devices, one for playback and one for capture/recording. You cannot use this
209-
to merge multiple devices for playback or capture. This approach will not do
210-
any clock drift correction, so as the two devices drift over time, you may get
211-
glitches in the audio stream. Nevertheless, it can be an easy if unreliable
212-
way to set up JACK so that, for example, it records from a USB microphone and
213-
plays back via a builtin audio device.
214-
215-
When using -P or -C to specify different devices, do not use the -d argument
216-
(which specifies a single device) and do not use the -D argument (which tells
217-
JACK to configure a device for playback & capture).
219+
support the -P and -C arguments that can be used to specify two
220+
different devices, one for playback and one for capture/recording. You
221+
cannot use this to merge multiple devices for playback or capture. This
222+
approach will not do any clock drift correction, so as the two devices
223+
drift over time, you may get glitches in the audio stream. Nevertheless,
224+
it can be an easy if unreliable way to set up JACK so that, for example,
225+
it records from a USB microphone and plays back via a builtin audio
226+
device.
227+
228+
When using `-P` or `-C` to specify different devices, do not use the
229+
`-d`
230+
argument (which specifies a single device) and do not use the `-D`
231+
argument (which tells JACK to configure a device for playback &
232+
capture).
218233

0 commit comments

Comments
 (0)