Back to home page

OSCL-LXR

 
 

    


0001 ========================================================
0002 Guide to using M-Audio Audiophile USB with ALSA and Jack
0003 ========================================================
0004 
0005 v1.5
0006 
0007 Thibault Le Meur <Thibault.LeMeur@supelec.fr>
0008 
0009 This document is a guide to using the M-Audio Audiophile USB (tm) device with 
0010 ALSA and JACK.
0011 
0012 History
0013 =======
0014 
0015 * v1.4 - Thibault Le Meur (2007-07-11)
0016 
0017   - Added Low Endianness nature of 16bits-modes
0018     found by Hakan Lennestal <Hakan.Lennestal@brfsodrahamn.se>
0019   - Modifying document structure
0020 
0021 * v1.5 - Thibault Le Meur (2007-07-12)
0022   - Added AC3/DTS passthru info
0023 
0024 
0025 Audiophile USB Specs and correct usage
0026 ======================================
0027 
0028 This part is a reminder of important facts about the functions and limitations 
0029 of the device.
0030 
0031 The device has 4 audio interfaces, and 2 MIDI ports:
0032 
0033  * Analog Stereo Input (Ai)
0034 
0035    - This port supports 2 pairs of line-level audio inputs (1/4" TS and RCA) 
0036    - When the 1/4" TS (jack) connectors are connected, the RCA connectors
0037      are disabled
0038 
0039  * Analog Stereo Output (Ao)
0040  * Digital Stereo Input (Di)
0041  * Digital Stereo Output (Do)
0042  * Midi In (Mi)
0043  * Midi Out (Mo)
0044 
0045 The internal DAC/ADC has the following characteristics:
0046 
0047 * sample depth of 16 or 24 bits
0048 * sample rate from 8kHz to 96kHz
0049 * Two interfaces can't use different sample depths at the same time.
0050 
0051 Moreover, the Audiophile USB documentation gives the following Warning:
0052   Please exit any audio application running before switching between bit depths
0053 
0054 Due to the USB 1.1 bandwidth limitation, a limited number of interfaces can be 
0055 activated at the same time depending on the audio mode selected:
0056 
0057  * 16-bit/48kHz ==> 4 channels in + 4 channels out
0058 
0059    - Ai+Ao+Di+Do
0060 
0061  * 24-bit/48kHz ==> 4 channels in + 2 channels out, 
0062    or 2 channels in + 4 channels out
0063 
0064    - Ai+Ao+Do or Ai+Di+Ao or Ai+Di+Do or Di+Ao+Do
0065 
0066  * 24-bit/96kHz ==> 2 channels in _or_ 2 channels out (half duplex only)
0067 
0068    - Ai or Ao or Di or Do
0069 
0070 Important facts about the Digital interface:
0071 --------------------------------------------
0072 
0073  * The Do port additionally supports surround-encoded AC-3 and DTS passthrough, 
0074    though I haven't tested it under Linux
0075 
0076    - Note that in this setup only the Do interface can be enabled
0077 
0078  * Apart from recording an audio digital stream, enabling the Di port is a way 
0079    to synchronize the device to an external sample clock
0080 
0081    - As a consequence, the Di port must be enable only if an active Digital 
0082      source is connected
0083    - Enabling Di when no digital source is connected can result in a 
0084      synchronization error (for instance sound played at an odd sample rate)
0085 
0086 
0087 Audiophile USB MIDI support in ALSA
0088 ===================================
0089 
0090 The Audiophile USB MIDI ports will be automatically supported once the
0091 following modules have been loaded:
0092 
0093  * snd-usb-audio
0094  * snd-seq-midi
0095 
0096 No additional setting is required.
0097 
0098 
0099 Audiophile USB Audio support in ALSA
0100 ====================================
0101 
0102 Audio functions of the Audiophile USB device are handled by the snd-usb-audio 
0103 module. This module can work in a default mode (without any device-specific 
0104 parameter), or in an "advanced" mode with the device-specific parameter called 
0105 ``device_setup``.
0106 
0107 Default Alsa driver mode
0108 ------------------------
0109 
0110 The default behavior of the snd-usb-audio driver is to list the device 
0111 capabilities at startup and activate the required mode when required 
0112 by the applications: for instance if the user is recording in a 
0113 24bit-depth-mode and immediately after wants to switch to a 16bit-depth mode,
0114 the snd-usb-audio module will reconfigure the device on the fly.
0115 
0116 This approach has the advantage to let the driver automatically switch from sample 
0117 rates/depths automatically according to the user's needs. However, those who 
0118 are using the device under windows know that this is not how the device is meant to
0119 work: under windows applications must be closed before using the m-audio control
0120 panel to switch the device working mode. Thus as we'll see in next section, this 
0121 Default Alsa driver mode can lead to device misconfigurations.
0122 
0123 Let's get back to the Default Alsa driver mode for now.  In this case the 
0124 Audiophile interfaces are mapped to alsa pcm devices in the following 
0125 way (I suppose the device's index is 1):
0126 
0127  * hw:1,0 is Ao in playback and Di in capture
0128  * hw:1,1 is Do in playback and Ai in capture
0129  * hw:1,2 is Do in AC3/DTS passthrough mode
0130 
0131 In this mode, the device uses Big Endian byte-encoding so that 
0132 supported audio format are S16_BE for 16-bit depth modes and S24_3BE for 
0133 24-bits depth mode.
0134 
0135 One exception is the hw:1,2 port which was reported to be Little Endian 
0136 compliant (supposedly supporting S16_LE) but processes in fact only S16_BE streams.
0137 This has been fixed in kernel 2.6.23 and above and now the hw:1,2 interface 
0138 is reported to be big endian in this default driver mode.
0139 
0140 Examples:
0141 
0142  * playing a S24_3BE encoded raw file to the Ao port::
0143 
0144    % aplay -D hw:1,0 -c2 -t raw -r48000 -fS24_3BE test.raw
0145 
0146  * recording a  S24_3BE encoded raw file from the Ai port::
0147 
0148    % arecord -D hw:1,1 -c2  -t raw -r48000 -fS24_3BE test.raw
0149 
0150  * playing a S16_BE encoded raw file to the Do port::
0151 
0152    % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test.raw
0153 
0154  * playing an ac3 sample file to the Do port::
0155 
0156    % aplay -D hw:1,2 --channels=6 ac3_S16_BE_encoded_file.raw
0157 
0158 If you're happy with the default Alsa driver mode and don't experience any 
0159 issue with this mode, then you can skip the following chapter.
0160 
0161 Advanced module setup
0162 ---------------------
0163 
0164 Due to the hardware constraints described above, the device initialization made 
0165 by the Alsa driver in default mode may result in a corrupted state of the 
0166 device. For instance, a particularly annoying issue is that the sound captured 
0167 from the Ai interface sounds distorted (as if boosted with an excessive high
0168 volume gain).
0169 
0170 For people having this problem, the snd-usb-audio module has a new module 
0171 parameter called ``device_setup`` (this parameter was introduced in kernel
0172 release 2.6.17)
0173 
0174 Initializing the working mode of the Audiophile USB
0175 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0176 
0177 As far as the Audiophile USB device is concerned, this value let the user 
0178 specify:
0179 
0180  * the sample depth
0181  * the sample rate
0182  * whether the Di port is used or not 
0183 
0184 When initialized with ``device_setup=0x00``, the snd-usb-audio module has
0185 the same behaviour as when the parameter is omitted (see paragraph "Default 
0186 Alsa driver mode" above)
0187 
0188 Others modes are described in the following subsections.
0189 
0190 16-bit modes
0191 ~~~~~~~~~~~~
0192 
0193 The two supported modes are:
0194 
0195  * ``device_setup=0x01``
0196 
0197    - 16bits 48kHz mode with Di disabled
0198    - Ai,Ao,Do can be used at the same time
0199    - hw:1,0 is not available in capture mode
0200    - hw:1,2 is not available
0201 
0202  * ``device_setup=0x11``
0203 
0204    - 16bits 48kHz mode with Di enabled
0205    - Ai,Ao,Di,Do can be used at the same time
0206    - hw:1,0 is available in capture mode
0207    - hw:1,2 is not available
0208 
0209 In this modes the device operates only at 16bits-modes. Before kernel 2.6.23,
0210 the devices where reported to be Big-Endian when in fact they were Little-Endian
0211 so that playing a file was a matter of using:
0212 ::
0213 
0214    % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_BE test_S16_LE.raw
0215 
0216 where "test_S16_LE.raw" was in fact a little-endian sample file.
0217 
0218 Thanks to Hakan Lennestal (who discovered the Little-Endiannes of the device in
0219 these modes) a fix has been committed (expected in kernel 2.6.23) and
0220 Alsa now reports Little-Endian interfaces. Thus playing a file now is as simple as
0221 using:
0222 ::
0223 
0224    % aplay -D hw:1,1 -c2 -t raw -r48000 -fS16_LE test_S16_LE.raw
0225 
0226 
0227 24-bit modes
0228 ~~~~~~~~~~~~
0229 
0230 The three supported modes are:
0231 
0232  * ``device_setup=0x09``
0233 
0234    - 24bits 48kHz mode with Di disabled
0235    - Ai,Ao,Do can be used at the same time
0236    - hw:1,0 is not available in capture mode
0237    - hw:1,2 is not available
0238 
0239  * ``device_setup=0x19``
0240 
0241    - 24bits 48kHz mode with Di enabled
0242    - 3 ports from {Ai,Ao,Di,Do} can be used at the same time
0243    - hw:1,0 is available in capture mode and an active digital source must be 
0244      connected to Di
0245    - hw:1,2 is not available
0246 
0247  * ``device_setup=0x0D`` or ``0x10``
0248 
0249    - 24bits 96kHz mode
0250    - Di is enabled by default for this mode but does not need to be connected 
0251      to an active source
0252    - Only 1 port from {Ai,Ao,Di,Do} can be used at the same time
0253    - hw:1,0 is available in captured mode
0254    - hw:1,2 is not available
0255 
0256 In these modes the device is only Big-Endian compliant (see "Default Alsa driver 
0257 mode" above for an aplay command example)
0258 
0259 AC3 w/ DTS passthru mode
0260 ~~~~~~~~~~~~~~~~~~~~~~~~
0261 
0262 Thanks to Hakan Lennestal, I now have a report saying that this mode works.
0263 
0264  * ``device_setup=0x03``
0265 
0266    - 16bits 48kHz mode with only the Do port enabled 
0267    - AC3 with DTS passthru
0268    - Caution with this setup the Do port is mapped to the pcm device hw:1,0
0269 
0270 The command line used to playback the AC3/DTS encoded .wav-files in this mode:
0271 ::
0272 
0273    % aplay -D hw:1,0 --channels=6 ac3_S16_LE_encoded_file.raw
0274 
0275 How to use the ``device_setup`` parameter
0276 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0277 
0278 The parameter can be given:
0279 
0280  * By manually probing the device (as root):::
0281 
0282    # modprobe -r snd-usb-audio
0283    # modprobe snd-usb-audio index=1 device_setup=0x09
0284 
0285  * Or while configuring the modules options in your modules configuration file
0286    (typically a .conf file in /etc/modprobe.d/ directory:::
0287 
0288        alias snd-card-1 snd-usb-audio
0289        options snd-usb-audio index=1 device_setup=0x09
0290 
0291 CAUTION when initializing the device
0292 -------------------------------------
0293 
0294  * Correct initialization on the device requires that device_setup is given to
0295    the module BEFORE the device is turned on. So, if you use the "manual probing"
0296    method described above, take care to power-on the device AFTER this initialization.
0297 
0298  * Failing to respect this will lead to a misconfiguration of the device. In this case
0299    turn off the device, unprobe the snd-usb-audio module, then probe it again with
0300    correct device_setup parameter and then (and only then) turn on the device again.
0301 
0302  * If you've correctly initialized the device in a valid mode and then want to switch
0303    to  another mode (possibly with another sample-depth), please use also the following 
0304    procedure:
0305 
0306    - first turn off the device
0307    - de-register the snd-usb-audio module (modprobe -r)
0308    - change the device_setup parameter by changing the device_setup
0309      option in ``/etc/modprobe.d/*.conf``
0310    - turn on the device
0311 
0312  * A workaround for this last issue has been applied to kernel 2.6.23, but it may not
0313    be enough to ensure the 'stability' of the device initialization.
0314 
0315 Technical details for hackers
0316 -----------------------------
0317 
0318 This section is for hackers, wanting to understand details about the device
0319 internals and how Alsa supports it.
0320 
0321 Audiophile USB's ``device_setup`` structure
0322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0323 
0324 If you want to understand the device_setup magic numbers for the Audiophile 
0325 USB, you need some very basic understanding of binary computation. However, 
0326 this is not required to use the parameter and you may skip this section.
0327 
0328 The device_setup is one byte long and its structure is the following:
0329 ::
0330 
0331        +---+---+---+---+---+---+---+---+
0332        | b7| b6| b5| b4| b3| b2| b1| b0|
0333        +---+---+---+---+---+---+---+---+
0334        | 0 | 0 | 0 | Di|24B|96K|DTS|SET|
0335        +---+---+---+---+---+---+---+---+
0336 
0337 Where:
0338 
0339  * b0 is the ``SET`` bit
0340 
0341    - it MUST be set if device_setup is initialized 
0342 
0343  * b1 is the ``DTS`` bit
0344 
0345    - it is set only for Digital output with DTS/AC3
0346    - this setup is not tested
0347 
0348  * b2 is the Rate selection flag
0349 
0350    - When set to ``1`` the rate range is 48.1-96kHz
0351    - Otherwise the sample rate range is 8-48kHz
0352 
0353  * b3 is the bit depth selection flag
0354 
0355    - When set to ``1`` samples are 24bits long
0356    - Otherwise they are 16bits long
0357    - Note that b2 implies b3 as the 96kHz mode is only supported for 24 bits 
0358      samples
0359 
0360  * b4 is the Digital input flag
0361 
0362    - When set to ``1`` the device assumes that an active digital source is 
0363      connected 
0364    - You shouldn't enable Di if no source is seen on the port (this leads to 
0365      synchronization issues)
0366    - b4 is implied by b2 (since only one port is enabled at a time no synch 
0367      error can occur) 
0368 
0369  * b5 to b7 are reserved for future uses, and must be set to ``0``
0370 
0371    - might become Ao, Do, Ai, for b7, b6, b4 respectively
0372 
0373 Caution:
0374 
0375  * there is no check on the value you will give to device_setup
0376 
0377    - for instance choosing 0x05 (16bits 96kHz) will fail back to 0x09 since 
0378      b2 implies b3. But _there_will_be_no_warning_ in /var/log/messages
0379 
0380  * Hardware constraints due to the USB bus limitation aren't checked
0381 
0382    - choosing b2 will prepare all interfaces for 24bits/96kHz but you'll
0383      only be able to use one at the same time
0384 
0385 USB implementation details for this device
0386 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0387 
0388 You may safely skip this section if you're not interested in driver 
0389 hacking.
0390 
0391 This section describes some internal aspects of the device and summarizes the 
0392 data I got by usb-snooping the windows and Linux drivers.
0393 
0394 The M-Audio Audiophile USB has 7 USB Interfaces:
0395 a "USB interface":
0396 
0397  * USB Interface nb.0
0398  * USB Interface nb.1
0399 
0400    - Audio Control function
0401 
0402  * USB Interface nb.2
0403 
0404    - Analog Output
0405 
0406  * USB Interface nb.3
0407 
0408    - Digital Output
0409 
0410  * USB Interface nb.4
0411 
0412    - Analog Input
0413 
0414  * USB Interface nb.5
0415 
0416    - Digital Input
0417 
0418  * USB Interface nb.6
0419 
0420    - MIDI interface compliant with the MIDIMAN quirk 
0421 
0422 Each interface has 5 altsettings (AltSet 1,2,3,4,5) except:
0423 
0424  * Interface 3 (Digital Out) has an extra Alset nb.6 
0425  * Interface 5 (Digital In) does not have Alset nb.3 and 5 
0426 
0427 Here is a short description of the AltSettings capabilities:
0428 
0429 * AltSettings 1 corresponds to
0430 
0431   - 24-bit depth, 48.1-96kHz sample mode
0432   - Adaptive playback (Ao and Do), Synch capture (Ai), or Asynch capture (Di)
0433 
0434 * AltSettings 2 corresponds to
0435 
0436   - 24-bit depth, 8-48kHz sample mode
0437   - Asynch capture and playback  (Ao,Ai,Do,Di)
0438 
0439 * AltSettings 3 corresponds to
0440 
0441   - 24-bit depth, 8-48kHz sample mode
0442   - Synch capture (Ai) and Adaptive playback (Ao,Do)
0443 
0444 * AltSettings 4 corresponds to
0445 
0446   - 16-bit depth, 8-48kHz sample mode
0447   - Asynch capture and playback  (Ao,Ai,Do,Di)
0448 
0449 * AltSettings 5 corresponds to
0450 
0451   - 16-bit depth, 8-48kHz sample mode
0452   - Synch capture (Ai) and Adaptive playback (Ao,Do)
0453 
0454 * AltSettings 6 corresponds to
0455 
0456   - 16-bit depth, 8-48kHz sample mode
0457   - Synch playback (Do), audio format type III IEC1937_AC-3
0458 
0459 In order to ensure a correct initialization of the device, the driver 
0460 *must* *know* how the device will be used:
0461 
0462  * if DTS is chosen, only Interface 2 with AltSet nb.6 must be
0463    registered
0464  * if 96KHz only AltSets nb.1 of each interface must be selected
0465  * if samples are using 24bits/48KHz then AltSet 2 must me used if
0466    Digital input is connected, and only AltSet nb.3 if Digital input
0467    is not connected
0468  * if samples are using 16bits/48KHz then AltSet 4 must me used if
0469    Digital input is connected, and only AltSet nb.5 if Digital input
0470    is not connected
0471 
0472 When device_setup is given as a parameter to the snd-usb-audio module, the 
0473 parse_audio_endpoints function uses a quirk called 
0474 ``audiophile_skip_setting_quirk`` in order to prevent AltSettings not 
0475 corresponding to device_setup from being registered in the driver.
0476 
0477 Audiophile USB and Jack support
0478 ===============================
0479 
0480 This section deals with support of the Audiophile USB device in Jack.
0481 
0482 There are 2 main potential issues when using Jackd with the device:
0483 
0484 * support for Big-Endian devices in 24-bit modes
0485 * support for 4-in / 4-out channels
0486 
0487 Direct support in Jackd
0488 -----------------------
0489 
0490 Jack supports big endian devices only in recent versions (thanks to
0491 Andreas Steinmetz for his first big-endian patch). I can't remember 
0492 exactly when this support was released into jackd, let's just say that
0493 with jackd version 0.103.0 it's almost ok (just a small bug is affecting 
0494 16bits Big-Endian devices, but since you've read carefully the above
0495 paragraphs, you're now using kernel >= 2.6.23 and your 16bits devices 
0496 are now Little Endians ;-) ).
0497 
0498 You can run jackd with the following command for playback with Ao and
0499 record with Ai:
0500 ::
0501 
0502   % jackd -R -dalsa -Phw:1,0 -r48000 -p128 -n2 -D -Chw:1,1
0503 
0504 Using Alsa plughw
0505 -----------------
0506 
0507 If you don't have a recent Jackd installed, you can downgrade to using
0508 the Alsa ``plug`` converter.
0509 
0510 For instance here is one way to run Jack with 2 playback channels on Ao and 2 
0511 capture channels from Ai:
0512 ::
0513 
0514   % jackd -R -dalsa -dplughw:1 -r48000 -p256 -n2 -D -Cplughw:1,1
0515 
0516 However you may see the following warning message:
0517   You appear to be using the ALSA software "plug" layer, probably a result of 
0518   using the "default" ALSA device. This is less efficient than it could be. 
0519   Consider using a hardware device instead rather than using the plug layer.
0520 
0521 Getting 2 input and/or output interfaces in Jack
0522 ------------------------------------------------
0523 
0524 As you can see, starting the Jack server this way will only enable 1 stereo
0525 input (Di or Ai) and 1 stereo output (Ao or Do).
0526 
0527 This is due to the following restrictions:
0528 
0529 * Jack can only open one capture device and one playback device at a time
0530 * The Audiophile USB is seen as 2 (or three) Alsa devices: hw:1,0, hw:1,1
0531   (and optionally hw:1,2)
0532 
0533 If you want to get Ai+Di and/or Ao+Do support with Jack, you would need to
0534 combine the Alsa devices into one logical "complex" device.
0535 
0536 If you want to give it a try, I recommend reading the information from
0537 this page: http://www.sound-man.co.uk/linuxaudio/ice1712multi.html
0538 It is related to another device (ice1712) but can be adapted to suit
0539 the Audiophile USB.
0540 
0541 Enabling multiple Audiophile USB interfaces for Jackd will certainly require:
0542 
0543 * Making sure your Jackd version has the MMAP_COMPLEX patch (see the ice1712 page)
0544 * (maybe) patching the alsa-lib/src/pcm/pcm_multi.c file (see the ice1712 page)
0545 * define a multi device (combination of hw:1,0 and hw:1,1) in your .asoundrc
0546   file 
0547 * start jackd with this device
0548 
0549 I had no success in testing this for now, if you have any success with this kind 
0550 of setup, please drop me an email.