Audiophile-Usb.txt 13 KB

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