audiophile-usb.rst 18 KB

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