Difference between revisions of "USB mic on Linux"

From Audacity Wiki
Jump to: navigation, search
(remove broken link to a post on old Forum)
Line 1: Line 1:
There are two different major sound-systems in Linux. One is <b>ALSA</b> (Advanced Linux Sound Architecture), the other is <b>OSS</b> (Open Sound System. ALSA is newer than OSS. The stable version of Audacity supports only OSS, but the current Linux versions out there usually come with ALSA. ALSA has an emulation-layer to support OSS applications.
+
{{Intro| This page provides some help getting a USB microphone to work with Audacity on Linux.|}}
  
<b>NOTE:</b>
 
  
The latest CVS snapshot (as of July 25 2006) of Audacity 1.3 beta + PortAudio v19-dev is able to use USB microphones as recording devices through ALSA. Have a look at [[Audacity_1.3_beta_testing]] to see how to set up a working system.
+
== OSS and ALSA==
 +
On Linux, recording with a USB microphone is best done under [http://www.alsa-project.org/ ALSA] (Advanced Linux Sound Architecture). [http://audacity.sourceforge.net/download/beta_linux Audacity Beta 1.3.x] provides native ALSA support. Stable 1.2.x versions of Audacity only support the older [http://en.wikipedia.org/wiki/Open_Sound_System OSS] (Open Sound System), but can work with ALSA using an OSS emulation layer.  
  
 
 
= USB-microphone in Open Sound System =
 
  
 +
== USB-microphone in Open Sound System ==
 
USB-microphones in OSS are usually setup as /dev/dsp1 under Linux.
 
USB-microphones in OSS are usually setup as /dev/dsp1 under Linux.
  
Line 29: Line 27:
 
which should enable audacity to use ALSA-devices natively.
 
which should enable audacity to use ALSA-devices natively.
  
= USB-microphone in ALSA =
+
 
 +
== USB-microphone in ALSA ==
  
 
Audacity 1.3.0beta has native support for ALSA devices using the Portaudio v19 library. To get the most out of trying this, download the latest version from the [http://audacity.sourceforge.net/community/developers#cvs CVS repository], and also the latest version of Portaudio from [http://www.portaudio.com/usingsvn.html http://www.portaudio.com/usingsvn.html].
 
Audacity 1.3.0beta has native support for ALSA devices using the Portaudio v19 library. To get the most out of trying this, download the latest version from the [http://audacity.sourceforge.net/community/developers#cvs CVS repository], and also the latest version of Portaudio from [http://www.portaudio.com/usingsvn.html http://www.portaudio.com/usingsvn.html].
Line 35: Line 34:
 
To compile Audacity, check out [[CompilingAudacityForBeginners]], [[Developing On Linux]] and [[Audacity_1.3_beta_testing]].
 
To compile Audacity, check out [[CompilingAudacityForBeginners]], [[Developing On Linux]] and [[Audacity_1.3_beta_testing]].
  
== Detecting the device ==
+
 
 +
=== Detecting the device ===
  
 
To see if the device is detected, do:
 
To see if the device is detected, do:
Line 133: Line 133:
 
and look for the modules <tt>usbcore, snd_usb_audio, snd_usb_lib</tt>. If they are loaded, the USB sound should work.
 
and look for the modules <tt>usbcore, snd_usb_audio, snd_usb_lib</tt>. If they are loaded, the USB sound should work.
  
== OSS emulation ==
+
 
 +
=== OSS emulation ===
  
 
To make sure that ALSA can use the USB-mic in OSS-emulation mode, do a:
 
To make sure that ALSA can use the USB-mic in OSS-emulation mode, do a:
Line 150: Line 151:
  
  
== Making sure ALSA detects the mic ==
+
=== Making sure ALSA detects the mic ===
  
 
To see if the USB-microphone is detected and installed, try:
 
To see if the USB-microphone is detected and installed, try:
Line 189: Line 190:
 
* Control interface : <tt>/dev/snd/controlC1</tt> (Control Card #1)
 
* Control interface : <tt>/dev/snd/controlC1</tt> (Control Card #1)
  
 
+
=== Tedious PCM detailed listing ===
-
 
 
 
== Tedious PCM detailed listing ==
 
  
 
To get a detailed list of all PCM's and their configuration, try:
 
To get a detailed list of all PCM's and their configuration, try:
Line 200: Line 198:
 
which will output all sound hardware on the system and its configuration. To most of us, its a heap of junk with no dicernible information, but it is good to know about how to get it on screen.
 
which will output all sound hardware on the system and its configuration. To most of us, its a heap of junk with no dicernible information, but it is good to know about how to get it on screen.
  
== Setting the stage ==
+
=== Setting the stage ===
  
 
To set the volume levels and other controls for your USB-mic, and get a nice Ncurses interface to do it in, do:
 
To set the volume levels and other controls for your USB-mic, and get a nice Ncurses interface to do it in, do:
Line 221: Line 219:
 
For the hardcore people out there, there is always the <tt>amixer</tt>, which is a text-based tool to set recording levels, muting and unmuting channels and so on. Some help may be found at [http://dsl.org/cookbook/cookbook_27.html http://dsl.org/cookbook/cookbook_27.html].
 
For the hardcore people out there, there is always the <tt>amixer</tt>, which is a text-based tool to set recording levels, muting and unmuting channels and so on. Some help may be found at [http://dsl.org/cookbook/cookbook_27.html http://dsl.org/cookbook/cookbook_27.html].
  
== Recording with ALSA ==
+
=== Recording with ALSA ===
  
 
To test the recording capabilities of your USB-mic in Linux, there is a number of neat programs to try. However, since not all programs are especially designed for PlugNPlay with USB-mics, the ALSA development people has included a rather sluggish but usable recording utility that works without any fancy GUI and effect junk that could mess things up. It is called <b><tt>arecord</tt></b> and we have used its versatility above, to display devices and PCMs. It can also be used to record, hence the name.
 
To test the recording capabilities of your USB-mic in Linux, there is a number of neat programs to try. However, since not all programs are especially designed for PlugNPlay with USB-mics, the ALSA development people has included a rather sluggish but usable recording utility that works without any fancy GUI and effect junk that could mess things up. It is called <b><tt>arecord</tt></b> and we have used its versatility above, to display devices and PCMs. It can also be used to record, hence the name.
Line 239: Line 237:
 
If it works, then you will be able to use the microphone in any setting, even if you have to dabble a lot to get things working correctly.
 
If it works, then you will be able to use the microphone in any setting, even if you have to dabble a lot to get things working correctly.
  
 
+
=== Setting default recording device ===
 
 
== Setting default recording device ==
 
  
 
Editing <tt>~/.asoundrc</tt> and putting this snippet below might work for some:
 
Editing <tt>~/.asoundrc</tt> and putting this snippet below might work for some:
Line 263: Line 259:
 
More on running two sound cards simultaneously [http://alsa.opensrc.org/TwoCardsAsOne here].
 
More on running two sound cards simultaneously [http://alsa.opensrc.org/TwoCardsAsOne here].
  
== Samson C01U USB-microphone ==
+
=== Samson C01U USB-microphone ===
  
 
The Samson C01U USB-microphone appears to be detected correctly by the Linux Kernel - however the issues specific to the Samson microphone seem to be related to setting the correct recording levels for it.
 
The Samson C01U USB-microphone appears to be detected correctly by the Linux Kernel - however the issues specific to the Samson microphone seem to be related to setting the correct recording levels for it.
Line 279: Line 275:
 
Check [http://www.music.columbia.edu/pipermail/linux-audio-user/2006-May/035739.html this] out for setting the correct recording-level for the C01U.
 
Check [http://www.music.columbia.edu/pipermail/linux-audio-user/2006-May/035739.html this] out for setting the correct recording-level for the C01U.
  
-
+
=== Samson C03U USB-microphone ===
 
 
== Samson C03U USB-microphone ==
 
  
 
The Samson C03U seems to work plug-and-play on linux, although there seems to be a lot of noise in the signal. Can anybody confirm this ? [[User:Zevv|Zevv]] 03:43, 17 December 2006 (PST)
 
The Samson C03U seems to work plug-and-play on linux, although there seems to be a lot of noise in the signal. Can anybody confirm this ? [[User:Zevv|Zevv]] 03:43, 17 December 2006 (PST)

Revision as of 00:22, 10 September 2008

This page provides some help getting a USB microphone to work with Audacity on Linux.


OSS and ALSA

On Linux, recording with a USB microphone is best done under ALSA (Advanced Linux Sound Architecture). Audacity Beta 1.3.x provides native ALSA support. Stable 1.2.x versions of Audacity only support the older OSS (Open Sound System), but can work with ALSA using an OSS emulation layer.


USB-microphone in Open Sound System

USB-microphones in OSS are usually setup as /dev/dsp1 under Linux.

The stable version of Audacity will not find /dev/dsp1 unless there is also a device called /dev/dsp0. (This is a bug in PortAudio that should be fixed in a future version.)

To work around this bug, try setting the AUDIODEV environment variable (at a terminal):

    $ AUDIODEV=/dev/dsp1 audacity

or try running

    # ln -s /dev/dsp /dev/dsp0

as root. Please let us know whether this helps or not. - this does not work. (Wez 07)

It is also possible to run Audacity through an ALSA emulation layer, with:

    $ aoss audacity

which should enable audacity to use ALSA-devices natively.


USB-microphone in ALSA

Audacity 1.3.0beta has native support for ALSA devices using the Portaudio v19 library. To get the most out of trying this, download the latest version from the CVS repository, and also the latest version of Portaudio from http://www.portaudio.com/usingsvn.html.

To compile Audacity, check out CompilingAudacityForBeginners, Developing On Linux and Audacity_1.3_beta_testing.


Detecting the device

To see if the device is detected, do:

    $ cat /proc/bus/usb/devices

And search for the name of your microphone in the output. If you see the mic detected, check for Driver= to see which USB-driver has been loaded for the mic.

Displaying a thorough list of USB-devices is done by issuing the command

    $ lsusb --verbose | less

Search for the lines which contains Audio and Control Device like in the screendump below:

    Bus 001 Device 004: ID 17a0:0001  
    Device Descriptor:
    bLength                18
    bDescriptorType         1
    bcdUSB               1.10
    bDeviceClass            0 (Defined at Interface level)
    bDeviceSubClass         0 
    bDeviceProtocol         0 
    bMaxPacketSize0         8
    idVendor           0x17a0 
    idProduct          0x0001 
    bcdDevice            0.01
    iManufacturer           1 Samson Technologies      
    iProduct                2 Samson C01U              
    iSerial                 0 
    bNumConfigurations      1
    Configuration Descriptor:
      bLength                 9
      bDescriptorType         2
      wTotalLength          177
      bNumInterfaces          2
      bConfigurationValue     1
      iConfiguration          0 
      bmAttributes         0x80
        (Bus Powered)
      MaxPower               90mA
      Interface Descriptor:
        bLength                 9
        bDescriptorType         4
        bInterfaceNumber        0
        bAlternateSetting       0
        bNumEndpoints           0
        bInterfaceClass         1 Audio
        bInterfaceSubClass      1 Control Device
        bInterfaceProtocol      0 
        iInterface              0 
        AudioControl Interface Descriptor:
          bLength                 9
          bDescriptorType        36
          bDescriptorSubtype      1 (HEADER)
          bcdADC               1.00
          wTotalLength           40
          bInCollection           1
          baInterfaceNr( 0)       1
          AudioControl Interface Descriptor:
          bLength                12
          bDescriptorType        36
          bDescriptorSubtype      2 (INPUT_TERMINAL)
          bTerminalID             1
          wTerminalType      0x0201 Microphone
          bAssocTerminal          2
          bNrChannels             2
          wChannelConfig     0x0003
            Left Front (L)
            Right Front (R)
         iChannelNames           0 
         iTerminal               0 


In the top row, (Bus 001 Device 004: ID 17a0:0001) is the USB bus number. In the listing there are many noteworthy preferences for the microphone, samplerates and the like.

To look for installed modules regarding the soundsystem, do a:

   $ lsmod | grep snd
   snd_intel8x0           33692  3
   snd_ac97_codec         92704  1 snd_intel8x0
   snd_ac97_bus            2304  1 snd_ac97_codec
   snd_usb_audio          78784  0
   snd_pcm_oss            53664  0
   snd_mixer_oss          18688  1 snd_pcm_oss
   snd_usb_lib            16640  1 snd_usb_audio
   snd_rawmidi            25504  1 snd_usb_lib
   snd_seq_device          8716  1 snd_rawmidi
   snd_hwdep               9376  1 snd_usb_audio
   snd_pcm                89864  5 snd_intel8x0,snd_ac97_codec,snd_usb_audio,snd_pcm_oss
   snd_timer              25220  2 snd_pcm
   snd                    55268  14 snd_intel8x0,snd_ac97_codec,snd_usb_audio,snd_pcm_oss,snd_mixer_oss,snd_rawmidi,snd_seq_device,snd_hwdep,snd_pcm,snd_timer
   soundcore              10208  1 snd
   snd_page_alloc         10632  2 snd_intel8x0,snd_pcm
   usbcore               130692  5 snd_usb_audio,snd_usb_lib,ehci_hcd,uhci_hcd

and look for the modules usbcore, snd_usb_audio, snd_usb_lib. If they are loaded, the USB sound should work.


OSS emulation

To make sure that ALSA can use the USB-mic in OSS-emulation mode, do a:

    $ cat /dev/sndstat
    .
    .
    Audio Devices:
    0: Intel 82801DB-ICH4 (DUPLEX)
    1: Samson C01U
    .
    .
    Mixers:
    0: Analog Devices AD1981B
    1: Samson C01U


Making sure ALSA detects the mic

To see if the USB-microphone is detected and installed, try:

    $ cat /proc/asound/cards

and

    $ cat /proc/asound/pcm
    00-00: Intel ICH : Intel 82801DB-ICH4 : playback 1 : capture 1
    00-01: Intel ICH - MIC ADC : Intel 82801DB-ICH4 - MIC ADC : capture 1
    00-02: Intel ICH - MIC2 ADC : Intel 82801DB-ICH4 - MIC2 ADC : capture 1
    00-03: Intel ICH - ADC2 : Intel 82801DB-ICH4 - ADC2 : capture 1
    00-04: Intel ICH - IEC958 : Intel 82801DB-ICH4 - IEC958 : playback 1
    01-00: Samson C01U : capture 1

or

    $ arecord --list-devices
    card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 0: Intel ICH [Intel 82801DB-ICH4]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 1: Intel ICH - MIC ADC [Intel 82801DB-ICH4 - MIC ADC]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 2: Intel ICH - MIC2 ADC [Intel 82801DB-ICH4 - MIC2 ADC]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 3: Intel ICH - ADC2 [Intel 82801DB-ICH4 - ADC2]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 1: default [Samson C01U              ], device 0: USB Audio [USB Audio]
      Subdevices: 1/1
      Subdevice #0: subdevice #0

There is also a couple of new devices in /dev/snd/, depending on the system and devices installed. An example may include:

  • PCM interface: /dev/snd/pcmC1D0c (Pulse Code Modulation - Card #1 Device #0 - capture)
  • Control interface : /dev/snd/controlC1 (Control Card #1)

Tedious PCM detailed listing

To get a detailed list of all PCM's and their configuration, try:

     $ arecord --list-pcms

which will output all sound hardware on the system and its configuration. To most of us, its a heap of junk with no dicernible information, but it is good to know about how to get it on screen.

Setting the stage

To set the volume levels and other controls for your USB-mic, and get a nice Ncurses interface to do it in, do:

     $ alsamixer -c 1 # if your mic has card number 1 in the "arecord --list-devices" listing.

Be sure to unmute the capture channel, else no sound will be recorded anywhere.

Useful Alsamixer commands:

  • To toggle mute/unmute on a channel, navigate to it using arrow-keys, and press m or M to mute/unmute on both channels.
  • To toggle mute on the right of the stereo channels, press ">".
  • To toggle mute on the left of the stereo channels, press "<".
  • To show the capture-controls only, press F4.
  • To toggle the capture facility, press [space].


Another mixer that can be used is aumix which is a more elaborate tool than the native Gnome mixer.

For the hardcore people out there, there is always the amixer, which is a text-based tool to set recording levels, muting and unmuting channels and so on. Some help may be found at http://dsl.org/cookbook/cookbook_27.html.

Recording with ALSA

To test the recording capabilities of your USB-mic in Linux, there is a number of neat programs to try. However, since not all programs are especially designed for PlugNPlay with USB-mics, the ALSA development people has included a rather sluggish but usable recording utility that works without any fancy GUI and effect junk that could mess things up. It is called arecord and we have used its versatility above, to display devices and PCMs. It can also be used to record, hence the name.

The syntax for recording is:

    arecord -f [format] -D hw:card,device -d [duration]

and if one wishes to record in cd-quality for 20 seconds using the USB microphone detected as Card #1 Device #0 as in the listing above, and save it to test.wav issue the command:

    $ arecord -f cd -D hw:1,0 -d 20 test.wav

The result can be played using the aplay utility, also available in ALSA.

    $ aplay -f cd test.wav

If it works, then you will be able to use the microphone in any setting, even if you have to dabble a lot to get things working correctly.

Setting default recording device

Editing ~/.asoundrc and putting this snippet below might work for some:

 pcm.!default {
         type asym
         playback.pcm {
                 type plug
                 slave.pcm "hw:0,0"
         }
         capture.pcm {
                 type plug
                 slave.pcm "hw:1,0"
         } 
 }

This little ALSA configuration setting uses the default sound card as playback device (hw:0,0) and sets hw:1,0 (that suppose to be your USB-mic) to become the default capture device.

More on ALSA-configuration file syntax may be found here.

More on running two sound cards simultaneously here.

Samson C01U USB-microphone

The Samson C01U USB-microphone appears to be detected correctly by the Linux Kernel - however the issues specific to the Samson microphone seem to be related to setting the correct recording levels for it.

In Ubuntu Linux - the 1.2.X Audacity package will not work with the samson C01U microphone for the reasons listed at the top of the page (ALSA vs. OSS) - however - the program called "Sound Recorder" seems to work fine (recording levels and all) for it "plug and play"

Audacity can be used however to import a flac audio file which was recorded with Sound Recorder.

There are apparently some issues with using the Samson C01U USB-microphone under Linux. There are some documents outlining the problem:

  • First post (although with not entirely correct assumptions under the "Bad news" heading)
  • Follow-up


Check this out for setting the correct recording-level for the C01U.

Samson C03U USB-microphone

The Samson C03U seems to work plug-and-play on linux, although there seems to be a lot of noise in the signal. Can anybody confirm this ? Zevv 03:43, 17 December 2006 (PST)