Audiophile-Usb.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. Guide to using M-Audio Audiophile USB with ALSA and Jack v1.4
  2. ========================================================
  3. Thibault Le Meur <Thibault.LeMeur@supelec.fr>
  4. This document is a guide to using the M-Audio Audiophile USB (tm) device with
  5. ALSA and JACK.
  6. History
  7. =======
  8. * v1.4 - Thibault Le Meur (2007-07-11)
  9. - Added Low Endianness nature of 16bits-modes
  10. found by Hakan Lennestal <Hakan.Lennestal@brfsodrahamn.se>
  11. - Modifying document structure
  12. 1 - Audiophile USB Specs and correct usage
  13. ==========================================
  14. This part is a reminder of important facts about the functions and limitations
  15. of the device.
  16. The device has 4 audio interfaces, and 2 MIDI ports:
  17. * Analog Stereo Input (Ai)
  18. - This port supports 2 pairs of line-level audio inputs (1/4" TS and RCA)
  19. - When the 1/4" TS (jack) connectors are connected, the RCA connectors
  20. are disabled
  21. * Analog Stereo Output (Ao)
  22. * Digital Stereo Input (Di)
  23. * Digital Stereo Output (Do)
  24. * Midi In (Mi)
  25. * Midi Out (Mo)
  26. The internal DAC/ADC has the following characteristics:
  27. * sample depth of 16 or 24 bits
  28. * sample rate from 8kHz to 96kHz
  29. * Two interfaces can't use different sample depths at the same time.
  30. Moreover, the Audiophile USB documentation gives the following Warning:
  31. "Please exit any audio application running before switching between bit depths"
  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. Important facts about the Digital interface:
  42. --------------------------------------------
  43. * The Do port additionally supports surround-encoded AC-3 and DTS passthrough,
  44. though I haven't tested it under Linux
  45. - Note that in this setup only the Do interface can be enabled
  46. * Apart from recording an audio digital stream, enabling the Di port is a way
  47. to synchronize the device to an external sample clock
  48. - As a consequence, the Di port must be enable only if an active Digital
  49. source is connected
  50. - Enabling Di when no digital source is connected can result in a
  51. synchronization error (for instance sound played at an odd sample rate)
  52. 2 - Audiophile USB MIDI support in ALSA
  53. =======================================
  54. The Audiophile USB MIDI ports will be automatically supported once the
  55. following modules have been loaded:
  56. * snd-usb-audio
  57. * snd-seq-midi
  58. No additional setting is required.
  59. 3 - Audiophile USB Audio support in ALSA
  60. ========================================
  61. Audio functions of the Audiophile USB device are handled by the snd-usb-audio
  62. module. This module can work in a default mode (without any device-specific
  63. parameter), or in an "advanced" mode with the device-specific parameter called
  64. "device_setup".
  65. 3.1 - Default Alsa driver mode
  66. ------------------------------
  67. The default behavior of the snd-usb-audio driver is to list the device
  68. capabilities at startup and activate the required mode when required
  69. by the applications: for instance if the user is recording in a
  70. 24bit-depth-mode and immediately after wants to switch to a 16bit-depth mode,
  71. the snd-usb-audio module will reconfigure the device on the fly.
  72. This approach has the advantage to let the driver automatically switch from sample
  73. rates/depths automatically according to the user's needs. However, those who
  74. are using the device under windows know that this is not how the device is meant to
  75. work: under windows applications must be closed before using the m-audio control
  76. panel to switch the device working mode. Thus as we'll see in next section, this
  77. Default Alsa driver mode can lead to device misconfigurations.
  78. Let's get back to the Default Alsa driver mode for now. In this case the
  79. Audiophile interfaces are mapped to alsa pcm devices in the following
  80. way (I suppose the device's index is 1):
  81. * hw:1,0 is Ao in playback and Di in capture
  82. * hw:1,1 is Do in playback and Ai in capture
  83. * hw:1,2 is Do in AC3/DTS passthrough mode
  84. In this mode, the device uses Big Endian byte-encoding so that
  85. supported audio format are S16_BE for 16-bit depth modes and S24_3BE for
  86. 24-bits depth mode. One exception is the hw:1,2 port which is reported
  87. to be Little Endian compliant (supposedly supporting S16_LE) but processes
  88. in fact only S16_BE streams.
  89. Examples:
  90. * playing a S24_3BE encoded raw file to the Ao port
  91. % aplay -D hw:1,0 -c2 -t raw -r48000 -fS24_3BE test.raw
  92. * recording a S24_3BE encoded raw file from the Ai port
  93. % arecord -D hw:1,1 -c2 -t raw -r48000 -fS24_3BE test.raw
  94. * playing a S16_BE encoded raw file to the Do port
  95. % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test.raw
  96. If you're happy with the default Alsa driver mode and don't experience any
  97. issue with this mode, then you can skip the following chapter.
  98. 3.2 - Advanced module setup
  99. ---------------------------
  100. Due to the hardware constraints described above, the device initialization made
  101. by the Alsa driver in default mode may result in a corrupted state of the
  102. device. For instance, a particularly annoying issue is that the sound captured
  103. from the Ai interface sounds distorted (as if boosted with an excessive high
  104. volume gain).
  105. For people having this problem, the snd-usb-audio module has a new module
  106. parameter called "device_setup" (this parameter was introduced in kernel
  107. release 2.6.17)
  108. 3.2.1 - Initializing the working mode of the Audiophile USB
  109. As far as the Audiophile USB device is concerned, this value let the user
  110. specify:
  111. * the sample depth
  112. * the sample rate
  113. * whether the Di port is used or not
  114. When initialized with "device_setup=0x00", the snd-usb-audio module has
  115. the same behaviour as when the parameter is omitted (see paragraph "Default
  116. Alsa driver mode" above)
  117. Others modes are described in the following subsections.
  118. 3.2.1.1 - 16-bit modes
  119. The two supported modes are:
  120. * device_setup=0x01
  121. - 16bits 48kHz mode with Di disabled
  122. - Ai,Ao,Do can be used at the same time
  123. - hw:1,0 is not available in capture mode
  124. - hw:1,2 is not available
  125. * device_setup=0x11
  126. - 16bits 48kHz mode with Di enabled
  127. - Ai,Ao,Di,Do can be used at the same time
  128. - hw:1,0 is available in capture mode
  129. - hw:1,2 is not available
  130. In this modes the device operates only at 16bits-modes. Before kernel 2.6.23,
  131. the devices where reported to be Big-Endian when in fact they were Little-Endian
  132. so that playing a file was a matter of using:
  133. % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test_S16_LE.raw
  134. where "test_S16_LE.raw" was in fact a little-endian sample file.
  135. Thanks to Hakan Lennestal (who discovered the Little-Endiannes of the device in
  136. these modes) a fix has been committed (expected in kernel 2.6.23) and
  137. Alsa now reports Little-Endian interfaces. Thus playing a file now is as simple as
  138. using:
  139. % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_LE test_S16_LE.raw
  140. 3.2.1.2 - 24-bit modes
  141. The three supported modes are:
  142. * device_setup=0x09
  143. - 24bits 48kHz mode with Di disabled
  144. - Ai,Ao,Do can be used at the same time
  145. - hw:1,0 is not available in capture mode
  146. - hw:1,2 is not available
  147. * device_setup=0x19
  148. - 24bits 48kHz mode with Di enabled
  149. - 3 ports from {Ai,Ao,Di,Do} can be used at the same time
  150. - hw:1,0 is available in capture mode and an active digital source must be
  151. connected to Di
  152. - hw:1,2 is not available
  153. * device_setup=0x0D or 0x10
  154. - 24bits 96kHz mode
  155. - Di is enabled by default for this mode but does not need to be connected
  156. to an active source
  157. - Only 1 port from {Ai,Ao,Di,Do} can be used at the same time
  158. - hw:1,0 is available in captured mode
  159. - hw:1,2 is not available
  160. In these modes the device is only Big-Endian compliant (see "Default Alsa driver
  161. mode" above for an aplay command example)
  162. 3.2.1.3 - AC3 w/ DTS passthru mode
  163. This mode is untested, I have no AC3 compliant device to test it. I uses:
  164. * device_setup=0x03
  165. - 16bits 48kHz mode with only the Do port enabled
  166. - AC3 with DTS passthru (not tested)
  167. - Caution with this setup the Do port is mapped to the pcm device hw:1,0
  168. 3.2.2 - How to use the device_setup parameter
  169. ----------------------------------------------
  170. The parameter can be given:
  171. * By manually probing the device (as root):
  172. # modprobe -r snd-usb-audio
  173. # modprobe snd-usb-audio index=1 device_setup=0x09
  174. * Or while configuring the modules options in your modules configuration file
  175. - For Fedora distributions, edit the /etc/modprobe.conf file:
  176. alias snd-card-1 snd-usb-audio
  177. options snd-usb-audio index=1 device_setup=0x09
  178. CAUTION when initializaing the device
  179. -------------------------------------
  180. * Correct initialization on the device requires that device_setup is given to
  181. the module BEFORE the device is turned on. So, if you use the "manual probing"
  182. method described above, take care to power-on the device AFTER this initialization.
  183. * Failing to respect this will lead in a misconfiguration of the device. In this case
  184. turn off the device, unproble the snd-usb-audio module, then probe it again with
  185. correct device_setup parameter and then (and only then) turn on the device again.
  186. * If you've correctly initialized the device in a valid mode and then want to switch
  187. to another mode (possibly with another sample-depth), please use also the following
  188. procedure:
  189. - first turn off the device
  190. - de-register the snd-usb-audio module (modprobe -r)
  191. - change the device_setup parameter by changing the device_setup
  192. option in /etc/modprobe.conf
  193. - turn on the device
  194. * A workaround for this last issue has been applied to kernel 2.6.23, but it may not
  195. be enough to ensure the 'stability' of the device initialization.
  196. 3.2.3 - Technical details for hackers
  197. -------------------------------------
  198. This section is for hackers, wanting to understand details about the device
  199. internals and how Alsa supports it.
  200. 3.2.3.1 - Audiophile USB's device_setup structure
  201. If you want to understand the device_setup magic numbers for the Audiophile
  202. USB, you need some very basic understanding of binary computation. However,
  203. this is not required to use the parameter and you may skip this section.
  204. The device_setup is one byte long and its structure is the following:
  205. +---+---+---+---+---+---+---+---+
  206. | b7| b6| b5| b4| b3| b2| b1| b0|
  207. +---+---+---+---+---+---+---+---+
  208. | 0 | 0 | 0 | Di|24B|96K|DTS|SET|
  209. +---+---+---+---+---+---+---+---+
  210. Where:
  211. * b0 is the "SET" bit
  212. - it MUST be set if device_setup is initialized
  213. * b1 is the "DTS" bit
  214. - it is set only for Digital output with DTS/AC3
  215. - this setup is not tested
  216. * b2 is the Rate selection flag
  217. - When set to "1" the rate range is 48.1-96kHz
  218. - Otherwise the sample rate range is 8-48kHz
  219. * b3 is the bit depth selection flag
  220. - When set to "1" samples are 24bits long
  221. - Otherwise they are 16bits long
  222. - Note that b2 implies b3 as the 96kHz mode is only supported for 24 bits
  223. samples
  224. * b4 is the Digital input flag
  225. - When set to "1" the device assumes that an active digital source is
  226. connected
  227. - You shouldn't enable Di if no source is seen on the port (this leads to
  228. synchronization issues)
  229. - b4 is implied by b2 (since only one port is enabled at a time no synch
  230. error can occur)
  231. * b5 to b7 are reserved for future uses, and must be set to "0"
  232. - might become Ao, Do, Ai, for b7, b6, b4 respectively
  233. Caution:
  234. * there is no check on the value you will give to device_setup
  235. - for instance choosing 0x05 (16bits 96kHz) will fail back to 0x09 since
  236. b2 implies b3. But _there_will_be_no_warning_ in /var/log/messages
  237. * Hardware constraints due to the USB bus limitation aren't checked
  238. - choosing b2 will prepare all interfaces for 24bits/96kHz but you'll
  239. only be able to use one at the same time
  240. 3.2.3.2 - USB implementation details for this device
  241. You may safely skip this section if you're not interested in driver
  242. hacking.
  243. This section describes some internal aspects of the device and summarizes the
  244. data I got by usb-snooping the windows and Linux drivers.
  245. The M-Audio Audiophile USB has 7 USB Interfaces:
  246. a "USB interface":
  247. * USB Interface nb.0
  248. * USB Interface nb.1
  249. - Audio Control function
  250. * USB Interface nb.2
  251. - Analog Output
  252. * USB Interface nb.3
  253. - Digital Output
  254. * USB Interface nb.4
  255. - Analog Input
  256. * USB Interface nb.5
  257. - Digital Input
  258. * USB Interface nb.6
  259. - MIDI interface compliant with the MIDIMAN quirk
  260. Each interface has 5 altsettings (AltSet 1,2,3,4,5) except:
  261. * Interface 3 (Digital Out) has an extra Alset nb.6
  262. * Interface 5 (Digital In) does not have Alset nb.3 and 5
  263. Here is a short description of the AltSettings capabilities:
  264. * AltSettings 1 corresponds to
  265. - 24-bit depth, 48.1-96kHz sample mode
  266. - Adaptive playback (Ao and Do), Synch capture (Ai), or Asynch capture (Di)
  267. * AltSettings 2 corresponds to
  268. - 24-bit depth, 8-48kHz sample mode
  269. - Asynch capture and playback (Ao,Ai,Do,Di)
  270. * AltSettings 3 corresponds to
  271. - 24-bit depth, 8-48kHz sample mode
  272. - Synch capture (Ai) and Adaptive playback (Ao,Do)
  273. * AltSettings 4 corresponds to
  274. - 16-bit depth, 8-48kHz sample mode
  275. - Asynch capture and playback (Ao,Ai,Do,Di)
  276. * AltSettings 5 corresponds to
  277. - 16-bit depth, 8-48kHz sample mode
  278. - Synch capture (Ai) and Adaptive playback (Ao,Do)
  279. * AltSettings 6 corresponds to
  280. - 16-bit depth, 8-48kHz sample mode
  281. - Synch playback (Do), audio format type III IEC1937_AC-3
  282. In order to ensure a correct initialization of the device, the driver
  283. _must_know_ how the device will be used:
  284. * if DTS is chosen, only Interface 2 with AltSet nb.6 must be
  285. registered
  286. * if 96KHz only AltSets nb.1 of each interface must be selected
  287. * if samples are using 24bits/48KHz then AltSet 2 must me used if
  288. Digital input is connected, and only AltSet nb.3 if Digital input
  289. is not connected
  290. * if samples are using 16bits/48KHz then AltSet 4 must me used if
  291. Digital input is connected, and only AltSet nb.5 if Digital input
  292. is not connected
  293. When device_setup is given as a parameter to the snd-usb-audio module, the
  294. parse_audio_endpoints function uses a quirk called
  295. "audiophile_skip_setting_quirk" in order to prevent AltSettings not
  296. corresponding to device_setup from being registered in the driver.
  297. 4 - Audiophile USB and Jack support
  298. ===================================
  299. This section deals with support of the Audiophile USB device in Jack.
  300. There are 2 main potential issues when using Jackd with the device:
  301. * support for Big-Endian devices in 24-bit modes
  302. * support for 4-in / 4-out channels
  303. 4.1 - Direct support in Jackd
  304. -----------------------------
  305. Jack supports big endian devices only in recent versions (thanks to
  306. Andreas Steinmetz for his first big-endian patch). I can't remember
  307. extacly when this support was released into jackd, let's just say that
  308. with jackd version 0.103.0 it's almost ok (just a small bug is affecting
  309. 16bits Big-Endian devices, but since you've read carefully the above
  310. paragraphs, you're now using kernel >= 2.6.23 and your 16bits devices
  311. are now Little Endians ;-) ).
  312. You can run jackd with the following command for playback with Ao and
  313. record with Ai:
  314. % jackd -R -dalsa -Phw:1,0 -r48000 -p128 -n2 -D -Chw:1,1
  315. 4.2 - Using Alsa plughw
  316. -----------------------
  317. If you don't have a recent Jackd installed, you can downgrade to using
  318. the Alsa "plug" converter.
  319. For instance here is one way to run Jack with 2 playback channels on Ao and 2
  320. capture channels from Ai:
  321. % jackd -R -dalsa -dplughw:1 -r48000 -p256 -n2 -D -Cplughw:1,1
  322. However you may see the following warning message:
  323. "You appear to be using the ALSA software "plug" layer, probably a result of
  324. using the "default" ALSA device. This is less efficient than it could be.
  325. Consider using a hardware device instead rather than using the plug layer."
  326. 4.3 - Getting 2 input and/or output interfaces in Jack
  327. ------------------------------------------------------
  328. As you can see, starting the Jack server this way will only enable 1 stereo
  329. input (Di or Ai) and 1 stereo output (Ao or Do).
  330. This is due to the following restrictions:
  331. * Jack can only open one capture device and one playback device at a time
  332. * The Audiophile USB is seen as 2 (or three) Alsa devices: hw:1,0, hw:1,1
  333. (and optionally hw:1,2)
  334. If you want to get Ai+Di and/or Ao+Do support with Jack, you would need to
  335. combine the Alsa devices into one logical "complex" device.
  336. If you want to give it a try, I recommend reading the information from
  337. this page: http://www.sound-man.co.uk/linuxaudio/ice1712multi.html
  338. It is related to another device (ice1712) but can be adapted to suit
  339. the Audiophile USB.
  340. Enabling multiple Audiophile USB interfaces for Jackd will certainly require:
  341. * Making sure your Jackd version has the MMAP_COMPLEX patch (see the ice1712 page)
  342. * (maybe) patching the alsa-lib/src/pcm/pcm_multi.c file (see the ice1712 page)
  343. * define a multi device (combination of hw:1,0 and hw:1,1) in your .asoundrc
  344. file
  345. * start jackd with this device
  346. I had no success in testing this for now, if you have any success with this kind
  347. of setup, please drop me an email.