LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   How to set audio input device and volume from terminal? (https://www.linuxquestions.org/questions/linux-hardware-18/how-to-set-audio-input-device-and-volume-from-terminal-4175507506/)

charlemagne-is-my-son 06-09-2014 11:03 AM

How to set audio input device and volume from terminal?
 
Ubuntu 12.04

Hi. I record with Audacity often, and I am wondering how I can avoid the hassle of opening the sound manager, selecting the mic I plug in, and setting the volume. I'd like to run an alias command which prepares all this for me.

Thx!

Pearlseattle 06-09-2014 12:19 PM

Not sure if you're referring to some specific "sound mgr" or to a frontend for the ALSA settings - if it's the second case then, concerning the volume, you can check the current volume with...
amixer -c 0 cget numid=13
...where "-c" is your soundcard number (if you have more than 1) and "numid" is the control ID that you want to check (e.g. the "Master" volume or anything else that you see in "alsamixer".
You'll get back something like...
Code:

# amixer cget numid=13
numid=13,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---R--,values=1,min=0,max=127,step=0
  : values=109
  | dBscale-min=-95.25dB,step=0.75dB,mute=1

...where "values=109" is your current volume.

To modify the volume then use...
amixer -c 0 cset numid=13 50
...which lowered it in my case from 109 to 50.

schneidz 06-09-2014 04:24 PM

Code:

amixer set Master 15

Pearlseattle 06-10-2014 12:30 PM

Quote:

Originally Posted by schneidz (Post 5185312)
Code:

amixer set Master 15

I admit that often my approach is not the simpliest one :) :) :)

charlemagne-is-my-son 06-14-2014 01:06 AM

Specificy
 
Ok. I was vague in my question. Let me restate it. First, I'm running Ubuntu 12.04. I'm not sure which sound software my computer runs. Alsa? Pulseaudio? Not sure.

I use an external microphone when I record music. After plugging in the external mic, I need to go into the Settings and Sound to select the external mic instead of the Internal Microphone which is the default.

1) How can I either make it switch to that mic automatically, or write a script which will do it automatically?

Secondly, after I select the external mic, I have to adjust the amplification of the mic each time. Unamplified, the sound it picks up is rather low and unusable in my recordings.

2) How can I set the amplification automatically? This would probably be in the same script I asked about in question 1)

Please let me know if this is nonsense.

Ubuntu

schneidz 06-14-2014 10:05 AM

2)^
Quote:

Originally Posted by schneidz (Post 5185312)
Code:

amixer set Master 15

not sure but does this not change the volume for you:
Code:

[schneidz@hyper stuff]$ amixer set Capture 90 rec
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 90 [0%] [on]
  Front Right: Capture 90 [0%] [on]

?

what does the output of amixer give you ?
also arecord -l

charlemagne-is-my-son 06-14-2014 10:13 AM

amixer output
 
Code:

matt@matt-NV57H:~/Music/my-music$ amixer
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 87 [100%] [0.00dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 46 [53%] [-30.75dB] [on]
  Front Right: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 255 [100%] [0.00dB]
  Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Mic',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Beep',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 8 [26%] [-4.50dB] [on]
  Front Right: Capture 8 [26%] [-4.50dB] [on]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Enabled'
Simple mixer control 'Digital',0
  Capabilities: cvolume penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 120
  Front Left: Capture 60 [50%] [0.00dB]
  Front Right: Capture 60 [50%] [0.00dB]
Simple mixer control 'Internal Mic',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Internal Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [36.00dB]
  Front Right: 3 [100%] [36.00dB]


charlemagne-is-my-son 06-14-2014 10:27 AM

My Microphone
 
I ran
Code:

lsusb
to find the USB microphone I plug in and got this:

Code:

Bus 002 Device 009: ID 074d:0005 Micronas GmbH
How can I order the computer to select this mic over the internal mic?

Thanks!

Edit:

Here is the other output you asked for:

Code:

matt@matt-NV57H:~/Music/my-music$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC271X Analog [ALC271X Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: Snowball [Blue Snowball], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0


schneidz 06-14-2014 10:34 AM

your soundcard/s have a lot of devices; not sure which refers to the 2nd mic.
what i would do to narrow things down is run:
amixer > audio-settings.bad
when the pc first boots up. then set everything up the way i like manually; then run again:
amixer > audio-settings.good
and:
diff audio-settings.bad audio-settings.good
to get a good idea of what changed ?

schneidz 06-14-2014 10:41 AM

oh since its usb it should be probed upon connection and take over the audio in/out (at least thats what i remember when i used a headset).

maybe someone smarter than me who knows how to set up udev rules will reply.

i would hax together some script daemon that would constantly check lsusb for the existence of the usb headset and run the requisite amixer commands.


All times are GMT -5. The time now is 10:57 PM.