ALSA - setting input volume for line in command line - input not recognized but available for programs - input

I cant see the input device in alsamixer on the usb board, but it is listed as I do arecord -L (also why is it listing the 2nd sound card by default ?)
arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
I can see many informations but I cant figure from man, how to change the level of the line input in command line nor in the gui
amixer info
Card default 'CODEC'/'Burr-Brown from TI USB Audio CODEC at usb-3f980000.usb-1.3, full speed'
Mixer name : 'USB Mixer'
Components : 'USB08bb:2902'
Controls : 4
Simple ctrls : 1
amixer contents
numid=3,iface=MIXER,name='PCM Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=4,iface=MIXER,name='PCM Playback Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=128,step=0
: values=128,128
| dBminmax-min=-128.00dB,max=0.00dB
numid=2,iface=PCM,name='Capture Channel Map'
; type=INTEGER,access=r----R--,values=2,min=0,max=36,step=0
: values=0,0
| container
| chmap-fixed=FL,FR
| chmap-fixed=MONO
numid=1,iface=PCM,name='Playback Channel Map'
; type=INTEGER,access=r----R--,values=2,min=0,max=36,step=0
: values=0,0
| container
| chmap-fixed=FL,FR
| chmap-fixed=MONO
I am actualy not sure about how to achieve this since many people say thousands of different thing
here I try to set the volume in a clumsy way, and it does not work :
amixer -c 1 sset numid=2 0
amixer: Unable to find simple control 'numid=2',0
amixer -c 1 cset numid=2 0
amixer: Control hw:1 element write error: Operation not permitted
sudo amixer -c 1 cset numid=2 0
amixer: Control hw:1 element write error: Operation not permitted
amixer does not list any record device although I can clearly record audio with audacity or puredata
amixer -c 1
Simple mixer control 'PCM',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 128
Mono:
Front Left: Playback 128 [100%] [0.00dB] [on]
Front Right: Playback 128 [100%] [0.00dB] [on]
amixer -c 0
Simple mixer control 'PCM',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback 0 [96%] [0.00dB] [on]
please help me out, this makes no sens at all to me
thanks guys

amixer and alsamixer shows those mixer controls that the hardware actually has.
As figure 31 in the PCM2902 datasheet shows, this device indeed has no mechanism to change the capture volume:
It might be possible to add a softvol plugin, but it would be easier to just use PulseAudio.

Related

How do I feed CD audio tracks into an ALSA-driven sound output device?

I'm using a USB CD/DVD drive without built-in sound decoder and controlling it via ALSA, which already works. The host is a Raspberry Pi 3B with the current Raspbian. Here is the corresponding config file:
pi#autoradio:/etc $ cat asound.conf
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "hw:0,0"
period_time 0
period_size 1024
buffer_size 4096
rate 192000
format S32_LE
channels 2
}
bindings {
0 0
1 1
}
}
pcm.dsnooper {
type dsnoop
ipc_key 2048
ipc_perm 0666
slave
{
pcm "hw:0,0"
period_time 0
period_size 1024
buffer_size 4096
rate 192000
format S32_LE
channels 2
}
bindings {
0 0
1 1
}
}
pcm.duplex {
type asym
playback.pcm "dmixer"
capture.pcm "dsnooper"
}
pcm.!default {
type plug
slave.pcm "duplex"
}
ctl.!default {
type hw
card 0
}
To read the music from CD-DA, I'm gonna use the CDIO++ library. Its cd-info utility recognises both the drive, and the audio CD:
pi#autoradio:/etc $ cd-info
cd-info version 2.1.0 armv7l-unknown-linux-gnueabihf
CD location : /dev/cdrom
CD driver name: GNU/Linux
access mode: IOCTL
Vendor : MATSHITA
Model : CD-RW CW-8124
Revision : DA0D
Hardware : CD-ROM or DVD
Can eject : Yes
Can close tray : Yes
Can disable manual eject : Yes
Can select juke-box disc : No
Can set drive speed : No
Can read multiple sessions (e.g. PhotoCD) : Yes
Can hard reset device : Yes
Reading....
Can read Mode 2 Form 1 : Yes
Can read Mode 2 Form 2 : Yes
Can read (S)VCD (i.e. Mode 2 Form 1/2) : Yes
Can read C2 Errors : Yes
Can read IRSC : Yes
Can read Media Channel Number (or UPC) : Yes
Can play audio : Yes
Can read CD-DA : Yes
Can read CD-R : Yes
Can read CD-RW : Yes
Can read DVD-ROM : Yes
Writing....
Can write CD-RW : Yes
Can write DVD-R : No
Can write DVD-RAM : No
Can write DVD-RW : No
Can write DVD+RW : No
__________________________________
Disc mode is listed as: CD-DA
I've already got some code to send the PCM data to the sound card and some insight regarding the (rather poorly documented) CDIO API (I know that the readSectors() method is used for reading sound data from the CD sector after sector), but not really a clue on how to hand over the data from the CD-DA input to the ALSA output routine correctly.
Please nopte that mplayer is off-limits to me as this routine will be a part of a larger solution.
Any help would be greatly appreciated.
UPDATE: Does the different block size of an audio CD (2,352 bytes) and of the sound output (910 bytes, at least in my particular case) matter?
CD audio data is just two channels of little-endian 16-bit samples at 44.1 kHz.
If you output the data to the standard output, you can pipe it into your sound-playing program, or aplay:
./my-read-cdda | ./play 44100 2 99999
./my-read-cdda | aplay --file-type raw --format cd
If you want to do everything in a single program, replace the read(0, ...) with readSectors(). (The buffer size does not need to have any relation with ALSA's period size or buffer size.)

Configuring MPD with an 5.1 external surround sound card

I've read tons of threads about this, but i cant figure it out.
So i have a MPD server running on Raspbian, with an external sound card attached to it. Music works fine trough mpd with the 2 channels, but not for 6 channels.
Also i am confused what is the task of all programs involved.
So there's alsa. I Have tried to change the /etc/asound.conf to many different configurations. Like:
pcm.!default {
type route
slave.pcm surround51
slave.channels 6
ttable.0.0 1
ttable.1.1 1
ttable.0.2 1
ttable.1.3 1
ttable.0.5 0.5
ttable.1.5 0.5
}
But it did not work. My current settings are:
pcm.!default {
type hw
card 2
device 0
}
ctl.!default {
type hw
card 2 #If you want to set HDMI as output ,turn 0 to 1.
}
Then there is pulse audio. I am not sure if the function of both programs overlap, or if you should use them together. To the pulseaudio config file /etc/pulse/daemon.conf i have edited the following line:
default-sample-channels = 6
Furthermore i have added the following line to /etc/pulse/default.pa
set-card-profile 2 output:analog-surround-51
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 # IP of l$
But i am not sure it has any effect at all.
So last there is mpd configuration which I had configure at ~/.mpd/mpd.conf
audio_output {
type "alsa"
name "My ALSA Device"
mixer_type "software"
mixer_control "PCM"
}
If i change alsa to pulse i cant hear sound. Furthermore, the command speaker-test -c 6 -t wav
IS working for 6 channels. Since mpd is configured with alsa, and speaker-test does work, i guess that it is pulseaudio that creates the surround sound. But how can i configure MPD to work with surround sound?
Does anyone have any idea? Any help is much appreciated!
Here is the ouput of aplay -l
xcb_connection_has_error() returned true
card 0: sunxicodec [sunxi-CODEC], device 0: M1 PCM [sunxi PCM]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: sunxisndhdmi [sunxi-sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Device [USB Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
and
Update:
If i play sound as the mpd user it also works with surround sound
sudo -u mpd speaker-test -c 6 -t wav
Eventually this worked for me:
pcm.ch51 {
slave sl2
#slave.channels 6
type route
ttable.0.0 1
ttable.1.1 1
ttable.0.2 1
ttable.1.3 1
ttable.0.4 0.5
ttable.1.4 0.5
ttable.0.5 0.5
ttable.1.5 0.5
}
pcm_slave.sl2 {
channels 6
pcm "hw:1,0"
}
In ~/.asoundrc. The table thing duplicates sound to other speakers so all 5+1 speakers are used. The pcm "hw:1,0" selects my external usb sound card.
Additionally in ~/.mpd/mpd.conf
audio_output {
type "alsa"
name "My ALSA Device"
channels "6"
device "ch51"
You select the device specified in asound.rc

In Bluez A2DP: how can I modify the default audio sample rate

I am using Bluez4 to sink Audio from an iphone 5 to a Raspberry pi audio output.
The default settings for BLuez 4 A2DP appear to be S16_LE, 44,1kHz Stereo.
Similar to other posts about Bluez, I can't catch Select_Configuration DBus messages in order to change the sample rate dynamically. Instead I decided to try to find the default A2DP sample rate in the BLuez Stack.
Does anyone know where the default sample rate is set? My first thought was that it was in the BLuez/audio/ folder but nothing appears to change the default 44.1kHz sample rate.
Now I'm very curious to know where it is set.
Currently using this: sudo ./a2dp-alsa --sink | aplay -c 2 -r 44100 -f S16
would like to use this sudo ./a2dp-alsa --sink | aplay -c 2 -r 16000 -f S16
I came across these lines in a2dp-alsa.c
/* Initialise connection to ALSA */
g_handle = audio_init("hw:0,0", 48000);
maybe its hard coded in a2dp-alsa - not parameterizable

Turning off a single usb device... again

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i'm running Debian.
The deal is: I bought an usb powered led lamp, which is very simple and doesn't even have an on/off switch (it works and is always on). I want to be able to turn it on/off via command line. Here's what i tried:
echo on > /sys/bus/usb/devices/usb1/power/level # turn on
echo suspend > /sys/bus/usb/devices/usb1/power/level # turn off
which is what i've found on many forums. Turning "on" works, but "suspending" yields
-su: echo: write error: Invalid argument
for every usbN. I also tried
echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"
which doesn't give an error, but also doesn't do anything (again, for every usbN)
trying
echo "usb1" > /sys/bus/usb/drivers/usb/unbind
works only for more "inteligent" devices, like the keyboard, the mouse, or the usb wifi card. What i mean is that only tyhose devices are turned off, other usbN don't give an error, but the lamp never goes off.
the contents of /sys/bus/usb/devices/ are
1-0:1.0 1-1:1.0 1-2:1.0 1-2:1.2 2-0:1.0 4-0:1.0 4-1:1.0 6-0:1.0 8-0:1.0 8-2:1.0 usb2 usb4 usb6 usb8
1-1 1-2 1-2:1.1 1-2:1.3 3-0:1.0 4-1 5-0:1.0 7-0:1.0 8-2 usb1 usb3 usb5 usb7
i tried to do
echo device_name > /sys/bus/usb/drivers/usb/unbind
with every single one of them, but only the devices usbN and N-M react, the ones of the form n-m:x.y yield
tee: /sys/bus/usb/drivers/usb/bind: No such device
(i tried putting in, for instance, "1-0:1.0", "1-0\:1.0" and "1-0\:1.0", all gave the same result).
One last thing, what is shown after executing
lsusb -t
does not change when i plug or unplug the lamp.
Any ideas?
Turn off device ID 2-1:
echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
Turn device ID 2-1 back on:
echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind
In my case, using device ID 2-1 controls power to my usb stick, and as a consequence controls the light.
TIP: If they work for you in Debian, create an alias for them to make life easier for you later.
Hope this helps,
Su
If all you want to do is reset a USB device to fix it once it gets into a broken state, then using the bind/unbind usbfs special files can be a bit of a pain (since device IDs can change, and they're a bit tricky to identify precisely if you don't want to rebind other devices). In this case I've found it much easier to use the vendor and product IDs given by lsusb with usb_modeswitch. For example, if I identify my wireless adapter using:
$ lsusb
Bus 001 Device 042: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 035: ID 0409:005a NEC Corp. HighSpeed Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I can then reset the wireless adapter using:
$ sudo usb_modeswitch -v 0x7392 -p 0x7811 --reset-usb
If you have more than one device attached with the same vendor and product IDs then usb_modeswitch provides bus and device number flags. For the wireless adapter example above I'd add -b 1 -g 42 to the flags.
Try this code it works for me (Only for rooted)
String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/unbind" };
try {
Runtime.getRuntime().exec(cmdline);
} catch (IOException e) {
Log.e("MainActivity","Failed"+e);
}
and for bind again do this
String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/bind" };
try {
Runtime.getRuntime().exec(cmdline);
} catch (IOException e) {
Log.e("MainActivity","Failed"+e);
}

remove usb node

My aim is to disable usb port usage except a specific kind of usb. Every time a usb device is inserted a udev rule is called and it runs a program to handle the work.
I can't unload usb_storage module since it is needed for usage, so how can i remove usb dev link if it doesn't meet my case?
unbind the device. Pass vendor id and product id to below script.
VENDOR=$1
PRODUCT=$2
if [ n$VENDOR = n ] || [ n$PRODUCT = n ]; then
echo "Unbinding the first non-hub device..."
ID=`grep -l "^0$" /sys/bus/usb/drivers/usb/*/maxchild | sed -e "s|/sys/bus/usb/drivers/usb/\(.*\)/maxchild|\1|" | head -n 1`
VENDOR=`cat /sys/bus/usb/drivers/usb/$ID/idVendor`
PRODUCT=`cat /sys/bus/usb/drivers/usb/$ID/idProduct`
echo $ID > /sys/bus/usb/drivers/usb/unbind
echo "Device found ($VENDOR:$PRODUCT), and unbound!"
exit 0
fi
Regards,
Barun Parichha