Audiophile-Usb.txt 14 KB

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