Audiophile-Usb.txt 13 KB

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