Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[pandora-kernel.git] / Documentation / sound / alsa / Audiophile-Usb.txt
1         Guide to using M-Audio Audiophile USB with ALSA and Jack        v1.2
2         ========================================================
3
4             Thibault Le Meur <Thibault.LeMeur@supelec.fr>
5
6 This document is a guide to using the M-Audio Audiophile USB (tm) device with 
7 ALSA and JACK.
8
9 1 - Audiophile USB Specs and correct usage
10 ==========================================
11 This part is a reminder of important facts about the functions and limitations 
12 of the device.
13
14 The device has 4 audio interfaces, and 2 MIDI ports:
15  * Analog Stereo Input (Ai)
16    - This port supports 2 pairs of line-level audio inputs (1/4" TS and RCA) 
17    - When the 1/4" TS (jack) connectors are connected, the RCA connectors
18      are disabled
19  * Analog Stereo Output (Ao)
20  * Digital Stereo Input (Di)
21  * Digital Stereo Output (Do)
22  * Midi In (Mi)
23  * Midi Out (Mo)
24
25 The internal DAC/ADC has the following caracteristics:
26 * sample depth of 16 or 24 bits
27 * sample rate from 8kHz to 96kHz
28 * Two ports can't use different sample depths at the same time.Moreover, the 
29 Audiophile USB documentation gives the following Warning: "Please exit any 
30 audio application running before switching between bit depths"
31
32 Due to the USB 1.1 bandwidth limitation, a limited number of interfaces can be 
33 activated at the same time depending on the audio mode selected:
34  * 16-bit/48kHz ==> 4 channels in/ 4 channels out
35    - Ai+Ao+Di+Do
36  * 24-bit/48kHz ==> 4 channels in/2 channels out, 
37                     or 2 channels in/4 channels out
38    - Ai+Ao+Do or Ai+Di+Ao or Ai+Di+Do or Di+Ao+Do
39  * 24-bit/96kHz ==> 2 channels in, or 2 channels out (half duplex only)
40    - Ai or Ao or Di or Do
41
42 Important facts about the Digital interface:
43 --------------------------------------------
44  * The Do port additionnaly supports surround-encoded AC-3 and DTS passthrough, 
45 though I haven't tested it under linux
46    - Note that in this setup only the Do interface can be enabled
47  * Apart from recording an audio digital stream, enabling the Di port is a way 
48 to synchronize the device to an external sample clock
49    - As a consequence, the Di port must be enable only if an active Digital 
50 source is connected
51    - Enabling Di when no digital source is connected can result in a 
52 synchronization error (for instance sound played at an odd sample rate)
53
54
55 2 - Audiophile USB support in ALSA
56 ==================================
57
58 2.1 - MIDI ports
59 ----------------
60 The Audiophile USB MIDI ports will be automatically supported once the 
61 following modules have been loaded:
62  * snd-usb-audio
63  * snd-seq
64  * snd-seq-midi
65
66 No additionnal setting is required.
67
68 2.2 - Audio ports
69 -----------------
70
71 Audio functions of the Audiophile USB device are handled by the snd-usb-audio 
72 module. This module can work in a default mode (without any device-specific 
73 parameter), or in an advanced mode with the device-specific parameter called 
74 "device_setup".
75
76 2.2.1 - Default Alsa driver mode
77
78 The default behaviour of the snd-usb-audio driver is to parse the device 
79 capabilities at startup and enable all functions inside the device (including 
80 all ports at any sample rates and any sample depths supported). This approach 
81 has the advantage to let the driver easily switch from sample rates/depths 
82 automatically according to the need of the application claiming the device.
83
84 In this case the Audiophile ports are mapped to alsa pcm devices in the 
85 following way (I suppose the device's index is 1):
86  * hw:1,0 is Ao in playback and Di in capture
87  * hw:1,1 is Do in playback and Ai in capture
88  * hw:1,2 is Do in AC3/DTS passthrough mode
89
90 You must note as well that the device uses Big Endian byte encoding so that 
91 supported audio format are S16_BE  for 16-bit depth modes and S24_3BE for 
92 24-bits depth mode. One exception is the hw:1,2 port which is Little Endian 
93 compliant and thus uses S16_LE.
94
95 Examples:
96  * playing a S24_3BE encoded raw file to the Ao port
97    % aplay -D hw:1,0 -c2 -t raw -r48000 -fS24_3BE test.raw
98  * recording a  S24_3BE encoded raw file from the Ai port
99    % arecord -D hw:1,1 -c2  -t raw -r48000 -fS24_3BE test.raw
100  * playing a S16_BE encoded raw file to the Do port
101    % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test.raw
102
103 If you're happy with the default Alsa driver setup and don't experience any 
104 issue with this mode, then you can skip the following chapter.
105
106 2.2.2 - Advanced module setup
107
108 Due to the hardware constraints described above, the device initialization made 
109 by the Alsa driver in default mode may result in a corrupted state of the 
110 device. For instance, a particularly annoying issue is that the sound captured 
111 from the Ai port sounds distorted (as if boosted with an excessive high volume 
112 gain).
113
114 For people having this problem, the snd-usb-audio module has a new module 
115 parameter called "device_setup".
116
117 2.2.2.1 - Initializing the working mode of the Audiohile USB
118
119 As far as the Audiohile USB device is concerned, this value let the user 
120 specify:
121  * the sample depth
122  * the sample rate
123  * whether the Di port is used or not 
124
125 Here is a list of supported device_setup values for this device:
126  * device_setup=0x00 (or omitted)
127    - Alsa driver default mode
128    - maintains backward compatibility with setups that do not use this 
129      parameter by not introducing any change
130    - results sometimes in corrupted sound as decribed earlier
131  * device_setup=0x01
132    - 16bits 48kHz mode with Di disabled
133    - Ai,Ao,Do can be used at the same time
134    - hw:1,0 is not available in capture mode
135    - hw:1,2 is not available
136  * device_setup=0x11
137    - 16bits 48kHz mode with Di enabled
138    - Ai,Ao,Di,Do can be used at the same time
139    - hw:1,0 is available in capture mode
140    - hw:1,2 is not available
141  * device_setup=0x09
142    - 24bits 48kHz mode with Di disabled
143    - Ai,Ao,Do can be used at the same time
144    - hw:1,0 is not available in capture mode
145    - hw:1,2 is not available
146  * device_setup=0x19
147    - 24bits 48kHz mode with Di enabled
148    - 3 ports from {Ai,Ao,Di,Do} can be used at the same time
149    - hw:1,0 is available in capture mode and an active digital source must be 
150      connected to Di
151    - hw:1,2 is not available
152  * device_setup=0x0D or 0x10
153    - 24bits 96kHz mode
154    - Di is enabled by default for this mode but does not need to be connected 
155      to an active source
156    - Only 1 port from {Ai,Ao,Di,Do} can be used at the same time
157    - hw:1,0 is available in captured mode
158    - hw:1,2 is not available
159  * device_setup=0x03
160    - 16bits 48kHz mode with only the Do port enabled 
161    - AC3 with DTS passthru (not tested)
162    - Caution with this setup the Do port is mapped to the pcm device hw:1,0
163
164 2.2.2.2 - Setting and switching configurations with the device_setup parameter
165
166 The parameter can be given:
167  * By manually probing the device (as root):
168    # modprobe -r snd-usb-audio
169    # modprobe snd-usb-audio index=1 device_setup=0x09
170  * Or while configuring the modules options in your modules configuration file
171    - For Fedora distributions, edit the /etc/modprobe.conf file:
172        alias snd-card-1 snd-usb-audio
173        options snd-usb-audio index=1 device_setup=0x09
174
175 IMPORTANT NOTE WHEN SWITCHING CONFIGURATION:
176 -------------------------------------------
177  * You may need to _first_ intialize the module with the correct device_setup 
178    parameter and _only_after_ turn on the Audiophile USB device
179  * This is especially true when switching the sample depth:
180    - first trun off the device
181    - de-register the snd-usb-audio module
182    - change the device_setup parameter (by either manually reprobing the module 
183      or changing modprobe.conf)
184    - turn on the device
185
186 2.2.2.3 - Audiophile USB's device_setup structure
187
188 If you want to understand the device_setup magic numbers for the Audiophile 
189 USB, you need some very basic understanding of binary computation. However, 
190 this is not required to use the parameter and you may skip thi section.
191
192 The device_setup is one byte long and its structure is the following:
193
194        +---+---+---+---+---+---+---+---+
195        | b7| b6| b5| b4| b3| b2| b1| b0|
196        +---+---+---+---+---+---+---+---+
197        | 0 | 0 | 0 | Di|24B|96K|DTS|SET|
198        +---+---+---+---+---+---+---+---+
199
200 Where:
201  * b0 is the "SET" bit
202    - it MUST be set if device_setup is initialized 
203  * b1 is the "DTS" bit
204    - it is set only for Digital output with DTS/AC3
205    - this setup is not tested
206  * b2 is the Rate selection flag
207    - When set to "1" the rate range is 48.1-96kHz
208    - Otherwise the sample rate range is 8-48kHz
209  * b3 is the bit depth selection flag
210    - When set to "1" samples are 24bits long
211    - Otherwise they are 16bits long
212    - Note that b2 implies b3 as the 96kHz mode is only supported for 24 bits 
213      samples
214  * b4 is the Digital input flag
215    - When set to "1" the device assumes that an active digital source is 
216      connected 
217    - You shouldn't enable Di if no source is seen on the port (this leads to 
218      synchronization issues)
219    - b4 is implied by b2 (since only one port is enabled at a time no synch 
220      error can occur) 
221  * b5 to b7 are reserved for future uses, and must be set to "0"
222    - might become Ao, Do, Ai, for b7, b6, b4 respectively
223
224 Caution:
225  * there is no check on the value you will give to device_setup
226    - for instance choosing 0x05 (16bits 96kHz) will fail back to 0x09 since 
227      b2 implies b3. But _there_will_be_no_warning_ in /var/log/messages
228  * Hardware constraints due to the USB bus limitation aren't checked
229    - choosing b2 will prepare all interfaces for 24bits/96kHz but you'll
230      only be able to use one at the same time
231
232 2.2.3 -  USB implementation details for this device
233
234 You may safely skip this section if you're not interrested in driver 
235 development.
236
237 This section describes some internals aspect of the device and summarize the 
238 data I got by usb-snooping the windows and linux drivers.
239
240 The M-Audio Audiophile USB has 7 USB Interfaces:
241 a "USB interface":
242  * USB Interface nb.0
243  * USB Interface nb.1
244    - Audio Control function
245  * USB Interface nb.2
246    - Analog Output
247  * USB Interface nb.3
248    - Digital Output
249  * USB Interface nb.4
250    - Analog Input
251  * USB Interface nb.5
252    - Digital Input
253  * USB Interface nb.6
254    - MIDI interface compliant with the MIDIMAN quirk 
255
256 Each interface has 5 altsettings (AltSet 1,2,3,4,5) except:
257  * Interface 3 (Digital Out) has an extra Alset nb.6 
258  * Interface 5 (Digital In) does not have Alset nb.3 and 5 
259
260 Here is a short description of the AltSettings capabilities:
261  * AltSettings 1 corresponds to
262   - 24-bit depth, 48.1-96kHz sample mode
263   - Adaptive playback (Ao and Do), Synch capture (Ai), or Asynch capture (Di)
264  * AltSettings 2 corresponds to
265   - 24-bit depth, 8-48kHz sample mode
266   - Asynch capture and playback  (Ao,Ai,Do,Di)
267  * AltSettings 3 corresponds to
268   - 24-bit depth, 8-48kHz sample mode
269   - Synch capture (Ai) and Adaptive playback (Ao,Do)
270  * AltSettings 4 corresponds to
271   - 16-bit depth, 8-48kHz sample mode
272   - Asynch capture and playback  (Ao,Ai,Do,Di)
273  * AltSettings 5 corresponds to
274   - 16-bit depth, 8-48kHz sample mode
275   - Synch capture (Ai) and Adaptive playback (Ao,Do)
276  * AltSettings 6 corresponds to
277   - 16-bit depth, 8-48kHz sample mode
278   - Synch playback (Do), audio format type III IEC1937_AC-3
279
280 In order to ensure a correct intialization of the device, the driver 
281 _must_know_ how the device will be used:
282  * if DTS is choosen, only Interface 2 with AltSet nb.6 must be
283    registered
284  * if 96KHz only AltSets nb.1 of each interface must be selected
285  * if samples are using 24bits/48KHz then AltSet 2 must me used if
286    Digital input is connected, and only AltSet nb.3 if Digital input
287    is not connected
288  * if samples are using 16bits/48KHz then AltSet 4 must me used if
289    Digital input is connected, and only AltSet nb.5 if Digital input
290    is not connected
291
292 When device_setup is given as a parameter to the snd-usb-audio module, the 
293 parse_audio_enpoint function uses a quirk called 
294 "audiophile_skip_setting_quirk" in order to prevent AltSettings not 
295 corresponding to device_setup from being registered in the driver.
296
297 3 - Audiophile USB and Jack support
298 ===================================
299
300 This section deals with support of the Audiophile USB device in Jack.
301 The main issue regarding this support is that the device is Big Endian 
302 compliant.
303
304 3.1 - Using the plug alsa plugin
305 --------------------------------
306
307 Jack doesn't directly support big endian devices. Thus, one way to have support 
308 for this device with Alsa is to use the Alsa "plug" converter.
309
310 For instance here is one way to run Jack with 2 playback channels on Ao and 2 
311 capture channels from Ai:
312   % jackd -R -dalsa -dplughw:1 -r48000 -p256 -n2 -D -Cplughw:1,1
313
314
315 However you may see the following warning message:
316 "You appear to be using the ALSA software "plug" layer, probably a result of 
317 using the "default" ALSA device. This is less efficient than it could be. 
318 Consider using a hardware device instead rather than using the plug layer."
319
320
321 3.2 - Patching alsa to use direct pcm device
322 -------------------------------------------
323 A patch for Jack by Andreas Steinmetz adds support for Big Endian devices. 
324 However it has not been included in the CVS tree.
325
326 You can find it at the following URL:
327 http://sourceforge.net/tracker/index.php?func=detail&aid=1289682&group_id=39687&
328 atid=425939
329
330 After having applied the patch you can run jackd with the following command 
331 line:
332   % jackd -R -dalsa -Phw:1,0 -r48000 -p128 -n2 -D -Chw:1,1
333