Merge tag 'asoc-fix-v5.4-rc4' of https://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / Documentation / sound / cards / audiophile-usb.rst
CommitLineData
4e47556e
TI
1========================================================
2Guide to using M-Audio Audiophile USB with ALSA and Jack
3========================================================
e311334e 4
4e47556e
TI
5v1.5
6
7Thibault Le Meur <Thibault.LeMeur@supelec.fr>
e311334e
TLM
8
9This document is a guide to using the M-Audio Audiophile USB (tm) device with
10ALSA and JACK.
11
f8c78b82
TLM
12History
13=======
4e47556e 14
f8c78b82 15* v1.4 - Thibault Le Meur (2007-07-11)
4e47556e
TI
16
17 - Added Low Endianness nature of 16bits-modes
18 found by Hakan Lennestal <Hakan.Lennestal@brfsodrahamn.se>
19 - Modifying document structure
20
cac19c3b 21* v1.5 - Thibault Le Meur (2007-07-12)
4e47556e 22 - Added AC3/DTS passthru info
f8c78b82
TLM
23
24
4e47556e
TI
25Audiophile USB Specs and correct usage
26======================================
f8c78b82 27
e311334e
TLM
28This part is a reminder of important facts about the functions and limitations
29of the device.
30
31The device has 4 audio interfaces, and 2 MIDI ports:
4e47556e 32
e311334e 33 * Analog Stereo Input (Ai)
4e47556e 34
19739fef
TLM
35 - This port supports 2 pairs of line-level audio inputs (1/4" TS and RCA)
36 - When the 1/4" TS (jack) connectors are connected, the RCA connectors
37 are disabled
4e47556e 38
e311334e
TLM
39 * Analog Stereo Output (Ao)
40 * Digital Stereo Input (Di)
41 * Digital Stereo Output (Do)
42 * Midi In (Mi)
43 * Midi Out (Mo)
44
5732e7a2 45The internal DAC/ADC has the following characteristics:
4e47556e 46
e311334e
TLM
47* sample depth of 16 or 24 bits
48* sample rate from 8kHz to 96kHz
f8c78b82 49* Two interfaces can't use different sample depths at the same time.
4e47556e 50
f8c78b82 51Moreover, the Audiophile USB documentation gives the following Warning:
4e47556e 52 Please exit any audio application running before switching between bit depths
e311334e
TLM
53
54Due to the USB 1.1 bandwidth limitation, a limited number of interfaces can be
55activated at the same time depending on the audio mode selected:
4e47556e 56
f8c78b82 57 * 16-bit/48kHz ==> 4 channels in + 4 channels out
4e47556e 58
e311334e 59 - Ai+Ao+Di+Do
4e47556e 60
f8c78b82 61 * 24-bit/48kHz ==> 4 channels in + 2 channels out,
4e47556e
TI
62 or 2 channels in + 4 channels out
63
e311334e 64 - Ai+Ao+Do or Ai+Di+Ao or Ai+Di+Do or Di+Ao+Do
4e47556e 65
f8c78b82 66 * 24-bit/96kHz ==> 2 channels in _or_ 2 channels out (half duplex only)
4e47556e 67
e311334e
TLM
68 - Ai or Ao or Di or Do
69
70Important facts about the Digital interface:
71--------------------------------------------
4e47556e 72
5732e7a2 73 * The Do port additionally supports surround-encoded AC-3 and DTS passthrough,
4e47556e
TI
74 though I haven't tested it under Linux
75
e311334e 76 - Note that in this setup only the Do interface can be enabled
4e47556e 77
e311334e 78 * Apart from recording an audio digital stream, enabling the Di port is a way
4e47556e
TI
79 to synchronize the device to an external sample clock
80
e311334e 81 - As a consequence, the Di port must be enable only if an active Digital
4e47556e 82 source is connected
e311334e 83 - Enabling Di when no digital source is connected can result in a
4e47556e 84 synchronization error (for instance sound played at an odd sample rate)
e311334e
TLM
85
86
4e47556e
TI
87Audiophile USB MIDI support in ALSA
88===================================
e311334e 89
f8c78b82 90The Audiophile USB MIDI ports will be automatically supported once the
e311334e 91following modules have been loaded:
4e47556e 92
e311334e 93 * snd-usb-audio
e311334e
TLM
94 * snd-seq-midi
95
5732e7a2 96No additional setting is required.
e311334e 97
f8c78b82 98
4e47556e
TI
99Audiophile USB Audio support in ALSA
100====================================
e311334e
TLM
101
102Audio functions of the Audiophile USB device are handled by the snd-usb-audio
103module. This module can work in a default mode (without any device-specific
5732e7a2 104parameter), or in an "advanced" mode with the device-specific parameter called
4e47556e 105``device_setup``.
e311334e 106
4e47556e
TI
107Default Alsa driver mode
108------------------------
f8c78b82
TLM
109
110The default behavior of the snd-usb-audio driver is to list the device
111capabilities at startup and activate the required mode when required
112by the applications: for instance if the user is recording in a
11324bit-depth-mode and immediately after wants to switch to a 16bit-depth mode,
114the snd-usb-audio module will reconfigure the device on the fly.
115
116This approach has the advantage to let the driver automatically switch from sample
117rates/depths automatically according to the user's needs. However, those who
118are using the device under windows know that this is not how the device is meant to
119work: under windows applications must be closed before using the m-audio control
120panel to switch the device working mode. Thus as we'll see in next section, this
121Default Alsa driver mode can lead to device misconfigurations.
122
123Let's get back to the Default Alsa driver mode for now. In this case the
124Audiophile interfaces are mapped to alsa pcm devices in the following
125way (I suppose the device's index is 1):
4e47556e 126
e311334e
TLM
127 * hw:1,0 is Ao in playback and Di in capture
128 * hw:1,1 is Do in playback and Ai in capture
129 * hw:1,2 is Do in AC3/DTS passthrough mode
130
f8c78b82
TLM
131In this mode, the device uses Big Endian byte-encoding so that
132supported audio format are S16_BE for 16-bit depth modes and S24_3BE for
cac19c3b
TLM
13324-bits depth mode.
134
135One exception is the hw:1,2 port which was reported to be Little Endian
136compliant (supposedly supporting S16_LE) but processes in fact only S16_BE streams.
137This has been fixed in kernel 2.6.23 and above and now the hw:1,2 interface
138is reported to be big endian in this default driver mode.
e311334e
TLM
139
140Examples:
4e47556e
TI
141
142 * playing a S24_3BE encoded raw file to the Ao port::
143
e311334e 144 % aplay -D hw:1,0 -c2 -t raw -r48000 -fS24_3BE test.raw
4e47556e
TI
145
146 * recording a S24_3BE encoded raw file from the Ai port::
147
e311334e 148 % arecord -D hw:1,1 -c2 -t raw -r48000 -fS24_3BE test.raw
4e47556e
TI
149
150 * playing a S16_BE encoded raw file to the Do port::
151
e311334e 152 % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test.raw
4e47556e
TI
153
154 * playing an ac3 sample file to the Do port::
155
cac19c3b 156 % aplay -D hw:1,2 --channels=6 ac3_S16_BE_encoded_file.raw
e311334e 157
f8c78b82 158If you're happy with the default Alsa driver mode and don't experience any
e311334e
TLM
159issue with this mode, then you can skip the following chapter.
160
4e47556e
TI
161Advanced module setup
162---------------------
e311334e
TLM
163
164Due to the hardware constraints described above, the device initialization made
165by the Alsa driver in default mode may result in a corrupted state of the
166device. For instance, a particularly annoying issue is that the sound captured
f8c78b82
TLM
167from the Ai interface sounds distorted (as if boosted with an excessive high
168volume gain).
e311334e
TLM
169
170For people having this problem, the snd-usb-audio module has a new module
4e47556e 171parameter called ``device_setup`` (this parameter was introduced in kernel
f8c78b82 172release 2.6.17)
e311334e 173
4e47556e
TI
174Initializing the working mode of the Audiophile USB
175~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e311334e 176
5732e7a2 177As far as the Audiophile USB device is concerned, this value let the user
e311334e 178specify:
4e47556e 179
e311334e
TLM
180 * the sample depth
181 * the sample rate
182 * whether the Di port is used or not
183
4e47556e 184When initialized with ``device_setup=0x00``, the snd-usb-audio module has
f8c78b82
TLM
185the same behaviour as when the parameter is omitted (see paragraph "Default
186Alsa driver mode" above)
187
188Others modes are described in the following subsections.
189
4e47556e
TI
19016-bit modes
191~~~~~~~~~~~~
f8c78b82
TLM
192
193The two supported modes are:
194
4e47556e
TI
195 * ``device_setup=0x01``
196
e311334e
TLM
197 - 16bits 48kHz mode with Di disabled
198 - Ai,Ao,Do can be used at the same time
199 - hw:1,0 is not available in capture mode
200 - hw:1,2 is not available
f8c78b82 201
4e47556e
TI
202 * ``device_setup=0x11``
203
e311334e
TLM
204 - 16bits 48kHz mode with Di enabled
205 - Ai,Ao,Di,Do can be used at the same time
206 - hw:1,0 is available in capture mode
207 - hw:1,2 is not available
f8c78b82
TLM
208
209In this modes the device operates only at 16bits-modes. Before kernel 2.6.23,
210the devices where reported to be Big-Endian when in fact they were Little-Endian
211so that playing a file was a matter of using:
4e47556e
TI
212::
213
f8c78b82 214 % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test_S16_LE.raw
4e47556e 215
f8c78b82
TLM
216where "test_S16_LE.raw" was in fact a little-endian sample file.
217
218Thanks to Hakan Lennestal (who discovered the Little-Endiannes of the device in
219these modes) a fix has been committed (expected in kernel 2.6.23) and
220Alsa now reports Little-Endian interfaces. Thus playing a file now is as simple as
221using:
4e47556e
TI
222::
223
f8c78b82
TLM
224 % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_LE test_S16_LE.raw
225
4e47556e
TI
226
22724-bit modes
228~~~~~~~~~~~~
f8c78b82
TLM
229
230The three supported modes are:
231
4e47556e
TI
232 * ``device_setup=0x09``
233
e311334e
TLM
234 - 24bits 48kHz mode with Di disabled
235 - Ai,Ao,Do can be used at the same time
236 - hw:1,0 is not available in capture mode
237 - hw:1,2 is not available
f8c78b82 238
4e47556e
TI
239 * ``device_setup=0x19``
240
e311334e
TLM
241 - 24bits 48kHz mode with Di enabled
242 - 3 ports from {Ai,Ao,Di,Do} can be used at the same time
243 - hw:1,0 is available in capture mode and an active digital source must be
244 connected to Di
245 - hw:1,2 is not available
f8c78b82 246
4e47556e
TI
247 * ``device_setup=0x0D`` or ``0x10``
248
e311334e
TLM
249 - 24bits 96kHz mode
250 - Di is enabled by default for this mode but does not need to be connected
251 to an active source
252 - Only 1 port from {Ai,Ao,Di,Do} can be used at the same time
253 - hw:1,0 is available in captured mode
254 - hw:1,2 is not available
f8c78b82
TLM
255
256In these modes the device is only Big-Endian compliant (see "Default Alsa driver
257mode" above for an aplay command example)
258
4e47556e
TI
259AC3 w/ DTS passthru mode
260~~~~~~~~~~~~~~~~~~~~~~~~
f8c78b82 261
cac19c3b 262Thanks to Hakan Lennestal, I now have a report saying that this mode works.
f8c78b82 263
4e47556e
TI
264 * ``device_setup=0x03``
265
e311334e 266 - 16bits 48kHz mode with only the Do port enabled
cac19c3b 267 - AC3 with DTS passthru
e311334e
TLM
268 - Caution with this setup the Do port is mapped to the pcm device hw:1,0
269
cac19c3b 270The command line used to playback the AC3/DTS encoded .wav-files in this mode:
4e47556e
TI
271::
272
cac19c3b
TLM
273 % aplay -D hw:1,0 --channels=6 ac3_S16_LE_encoded_file.raw
274
4e47556e
TI
275How to use the ``device_setup`` parameter
276~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e311334e
TLM
277
278The parameter can be given:
f8c78b82 279
4e47556e
TI
280 * By manually probing the device (as root):::
281
e311334e
TLM
282 # modprobe -r snd-usb-audio
283 # modprobe snd-usb-audio index=1 device_setup=0x09
f8c78b82 284
e311334e 285 * Or while configuring the modules options in your modules configuration file
4e47556e
TI
286 (typically a .conf file in /etc/modprobe.d/ directory:::
287
e311334e
TLM
288 alias snd-card-1 snd-usb-audio
289 options snd-usb-audio index=1 device_setup=0x09
290
d9195881 291CAUTION when initializing the device
f8c78b82
TLM
292-------------------------------------
293
294 * Correct initialization on the device requires that device_setup is given to
295 the module BEFORE the device is turned on. So, if you use the "manual probing"
296 method described above, take care to power-on the device AFTER this initialization.
297
d9195881
ML
298 * Failing to respect this will lead to a misconfiguration of the device. In this case
299 turn off the device, unprobe the snd-usb-audio module, then probe it again with
f8c78b82
TLM
300 correct device_setup parameter and then (and only then) turn on the device again.
301
302 * If you've correctly initialized the device in a valid mode and then want to switch
303 to another mode (possibly with another sample-depth), please use also the following
304 procedure:
4e47556e 305
5732e7a2
CK
306 - first turn off the device
307 - de-register the snd-usb-audio module (modprobe -r)
308 - change the device_setup parameter by changing the device_setup
4e47556e 309 option in ``/etc/modprobe.d/*.conf``
e311334e 310 - turn on the device
4e47556e 311
f8c78b82
TLM
312 * A workaround for this last issue has been applied to kernel 2.6.23, but it may not
313 be enough to ensure the 'stability' of the device initialization.
314
4e47556e
TI
315Technical details for hackers
316-----------------------------
317
f8c78b82
TLM
318This section is for hackers, wanting to understand details about the device
319internals and how Alsa supports it.
e311334e 320
4e47556e
TI
321Audiophile USB's ``device_setup`` structure
322~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e311334e
TLM
323
324If you want to understand the device_setup magic numbers for the Audiophile
325USB, you need some very basic understanding of binary computation. However,
5732e7a2 326this is not required to use the parameter and you may skip this section.
e311334e
TLM
327
328The device_setup is one byte long and its structure is the following:
4e47556e 329::
e311334e
TLM
330
331 +---+---+---+---+---+---+---+---+
332 | b7| b6| b5| b4| b3| b2| b1| b0|
333 +---+---+---+---+---+---+---+---+
334 | 0 | 0 | 0 | Di|24B|96K|DTS|SET|
335 +---+---+---+---+---+---+---+---+
336
337Where:
4e47556e
TI
338
339 * b0 is the ``SET`` bit
340
e311334e 341 - it MUST be set if device_setup is initialized
4e47556e
TI
342
343 * b1 is the ``DTS`` bit
344
e311334e
TLM
345 - it is set only for Digital output with DTS/AC3
346 - this setup is not tested
4e47556e 347
e311334e 348 * b2 is the Rate selection flag
4e47556e
TI
349
350 - When set to ``1`` the rate range is 48.1-96kHz
e311334e 351 - Otherwise the sample rate range is 8-48kHz
4e47556e 352
e311334e 353 * b3 is the bit depth selection flag
4e47556e
TI
354
355 - When set to ``1`` samples are 24bits long
e311334e
TLM
356 - Otherwise they are 16bits long
357 - Note that b2 implies b3 as the 96kHz mode is only supported for 24 bits
358 samples
4e47556e 359
e311334e 360 * b4 is the Digital input flag
4e47556e
TI
361
362 - When set to ``1`` the device assumes that an active digital source is
e311334e
TLM
363 connected
364 - You shouldn't enable Di if no source is seen on the port (this leads to
365 synchronization issues)
366 - b4 is implied by b2 (since only one port is enabled at a time no synch
367 error can occur)
4e47556e
TI
368
369 * b5 to b7 are reserved for future uses, and must be set to ``0``
370
e311334e
TLM
371 - might become Ao, Do, Ai, for b7, b6, b4 respectively
372
373Caution:
4e47556e 374
e311334e 375 * there is no check on the value you will give to device_setup
4e47556e 376
e311334e
TLM
377 - for instance choosing 0x05 (16bits 96kHz) will fail back to 0x09 since
378 b2 implies b3. But _there_will_be_no_warning_ in /var/log/messages
4e47556e 379
e311334e 380 * Hardware constraints due to the USB bus limitation aren't checked
4e47556e 381
e311334e
TLM
382 - choosing b2 will prepare all interfaces for 24bits/96kHz but you'll
383 only be able to use one at the same time
384
4e47556e
TI
385USB implementation details for this device
386~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e311334e 387
5732e7a2 388You may safely skip this section if you're not interested in driver
f8c78b82 389hacking.
e311334e 390
f8c78b82 391This section describes some internal aspects of the device and summarizes the
5732e7a2 392data I got by usb-snooping the windows and Linux drivers.
e311334e 393
19739fef 394The M-Audio Audiophile USB has 7 USB Interfaces:
e311334e 395a "USB interface":
4e47556e 396
19739fef
TLM
397 * USB Interface nb.0
398 * USB Interface nb.1
4e47556e 399
e311334e 400 - Audio Control function
4e47556e 401
19739fef 402 * USB Interface nb.2
4e47556e 403
e311334e 404 - Analog Output
4e47556e 405
19739fef 406 * USB Interface nb.3
4e47556e 407
e311334e 408 - Digital Output
4e47556e 409
19739fef 410 * USB Interface nb.4
4e47556e 411
e311334e 412 - Analog Input
4e47556e 413
19739fef 414 * USB Interface nb.5
4e47556e 415
e311334e 416 - Digital Input
4e47556e 417
19739fef 418 * USB Interface nb.6
4e47556e 419
e311334e
TLM
420 - MIDI interface compliant with the MIDIMAN quirk
421
422Each interface has 5 altsettings (AltSet 1,2,3,4,5) except:
4e47556e 423
e311334e
TLM
424 * Interface 3 (Digital Out) has an extra Alset nb.6
425 * Interface 5 (Digital In) does not have Alset nb.3 and 5
426
427Here is a short description of the AltSettings capabilities:
4e47556e
TI
428
429* AltSettings 1 corresponds to
430
e311334e
TLM
431 - 24-bit depth, 48.1-96kHz sample mode
432 - Adaptive playback (Ao and Do), Synch capture (Ai), or Asynch capture (Di)
4e47556e
TI
433
434* AltSettings 2 corresponds to
435
e311334e
TLM
436 - 24-bit depth, 8-48kHz sample mode
437 - Asynch capture and playback (Ao,Ai,Do,Di)
4e47556e
TI
438
439* AltSettings 3 corresponds to
440
e311334e
TLM
441 - 24-bit depth, 8-48kHz sample mode
442 - Synch capture (Ai) and Adaptive playback (Ao,Do)
4e47556e
TI
443
444* AltSettings 4 corresponds to
445
e311334e
TLM
446 - 16-bit depth, 8-48kHz sample mode
447 - Asynch capture and playback (Ao,Ai,Do,Di)
4e47556e
TI
448
449* AltSettings 5 corresponds to
450
e311334e
TLM
451 - 16-bit depth, 8-48kHz sample mode
452 - Synch capture (Ai) and Adaptive playback (Ao,Do)
4e47556e
TI
453
454* AltSettings 6 corresponds to
455
e311334e
TLM
456 - 16-bit depth, 8-48kHz sample mode
457 - Synch playback (Do), audio format type III IEC1937_AC-3
458
5732e7a2 459In order to ensure a correct initialization of the device, the driver
4e47556e
TI
460*must* *know* how the device will be used:
461
5732e7a2 462 * if DTS is chosen, only Interface 2 with AltSet nb.6 must be
e311334e
TLM
463 registered
464 * if 96KHz only AltSets nb.1 of each interface must be selected
465 * if samples are using 24bits/48KHz then AltSet 2 must me used if
466 Digital input is connected, and only AltSet nb.3 if Digital input
467 is not connected
468 * if samples are using 16bits/48KHz then AltSet 4 must me used if
469 Digital input is connected, and only AltSet nb.5 if Digital input
470 is not connected
471
472When device_setup is given as a parameter to the snd-usb-audio module, the
5732e7a2 473parse_audio_endpoints function uses a quirk called
4e47556e 474``audiophile_skip_setting_quirk`` in order to prevent AltSettings not
e311334e
TLM
475corresponding to device_setup from being registered in the driver.
476
4e47556e
TI
477Audiophile USB and Jack support
478===============================
e311334e
TLM
479
480This section deals with support of the Audiophile USB device in Jack.
e311334e 481
f8c78b82 482There are 2 main potential issues when using Jackd with the device:
4e47556e 483
f8c78b82
TLM
484* support for Big-Endian devices in 24-bit modes
485* support for 4-in / 4-out channels
e311334e 486
4e47556e
TI
487Direct support in Jackd
488-----------------------
f8c78b82
TLM
489
490Jack supports big endian devices only in recent versions (thanks to
491Andreas Steinmetz for his first big-endian patch). I can't remember
d9195881 492exactly when this support was released into jackd, let's just say that
f8c78b82 493with jackd version 0.103.0 it's almost ok (just a small bug is affecting
d9195881 49416bits Big-Endian devices, but since you've read carefully the above
f8c78b82
TLM
495paragraphs, you're now using kernel >= 2.6.23 and your 16bits devices
496are now Little Endians ;-) ).
497
498You can run jackd with the following command for playback with Ao and
499record with Ai:
4e47556e
TI
500::
501
f8c78b82
TLM
502 % jackd -R -dalsa -Phw:1,0 -r48000 -p128 -n2 -D -Chw:1,1
503
4e47556e
TI
504Using Alsa plughw
505-----------------
506
f8c78b82 507If you don't have a recent Jackd installed, you can downgrade to using
4e47556e 508the Alsa ``plug`` converter.
e311334e
TLM
509
510For instance here is one way to run Jack with 2 playback channels on Ao and 2
511capture channels from Ai:
4e47556e
TI
512::
513
e311334e
TLM
514 % jackd -R -dalsa -dplughw:1 -r48000 -p256 -n2 -D -Cplughw:1,1
515
e311334e 516However you may see the following warning message:
4e47556e
TI
517 You appear to be using the ALSA software "plug" layer, probably a result of
518 using the "default" ALSA device. This is less efficient than it could be.
519 Consider using a hardware device instead rather than using the plug layer.
e311334e 520
4e47556e
TI
521Getting 2 input and/or output interfaces in Jack
522------------------------------------------------
5732e7a2
CK
523
524As you can see, starting the Jack server this way will only enable 1 stereo
525input (Di or Ai) and 1 stereo output (Ao or Do).
526
527This is due to the following restrictions:
4e47556e 528
5732e7a2
CK
529* Jack can only open one capture device and one playback device at a time
530* The Audiophile USB is seen as 2 (or three) Alsa devices: hw:1,0, hw:1,1
531 (and optionally hw:1,2)
f8c78b82 532
5732e7a2
CK
533If you want to get Ai+Di and/or Ao+Do support with Jack, you would need to
534combine the Alsa devices into one logical "complex" device.
535
536If you want to give it a try, I recommend reading the information from
537this page: http://www.sound-man.co.uk/linuxaudio/ice1712multi.html
538It is related to another device (ice1712) but can be adapted to suit
539the Audiophile USB.
540
541Enabling multiple Audiophile USB interfaces for Jackd will certainly require:
4e47556e 542
f8c78b82
TLM
543* Making sure your Jackd version has the MMAP_COMPLEX patch (see the ice1712 page)
544* (maybe) patching the alsa-lib/src/pcm/pcm_multi.c file (see the ice1712 page)
5732e7a2
CK
545* define a multi device (combination of hw:1,0 and hw:1,1) in your .asoundrc
546 file
547* start jackd with this device
548
f8c78b82
TLM
549I had no success in testing this for now, if you have any success with this kind
550of setup, please drop me an email.