You are not logged in.

#1 2012-09-21 14:00:30

fpilee
Member
From: Windows 7
Registered: 2011-10-06
Posts: 104
Website

im Having trouble to do a init script.

The script must be load the usb headset card number on asound.conf.

$ ~ cat /etc/asound.conf
defaults.pcm.card 3
defaults.pcm.device 0
defaults.ctl.card 3

$ ~ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC662 rev1 Analog [ALC662 rev1 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: Headset [HP Digital Stereo Headset], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
$ ~ aplay -l | grep HP   
card 3: Headset [HP Digital Stereo Headset], device 0: USB Audio [USB Audio]
$ ~ aplay -l | grep HP | tr ":" "\n"
card 3
 Headset [HP Digital Stereo Headset], device 0
 USB Audio [USB Audio]
$ ~ aplay -l | grep HP | tr ":" "\n" | grep card 
card 3
$ ~ aplay -l | grep HP | tr ":" "\n" | grep card | tr " " "\n"
card
3

How i can select the 3.?


the idea is new to do

CARDNUMBER=`aplay -l | grep HP | tr ":" "\n" | grep card | tr " " "\n"`;
and with seed replace on asound conf

Offline

#2 2012-09-21 15:03:42

fpilee
Member
From: Windows 7
Registered: 2011-10-06
Posts: 104
Website

Re: im Having trouble to do a init script.

$ ~ cat /etc/asound.conf.base
defaults.pcm.card NUMBER
defaults.pcm.device 0
defaults.ctl.card NUMBER


$ ~ cat /etc/rc.d/usbHeadset
#!/bin/bash
CARD="`aplay -l | grep HP | tr ":" "\n" | grep card`";
CARDNUMBER="${CARD:5}";
sed s/NUMBER/"$CARDNUMBER"/g /etc/asound.conf.base > /etc/asound.conf

Script works, but the number have no changed recenty, i have to wait to stay sure.

Offline

#3 2012-09-21 16:40:28

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,837

Re: im Having trouble to do a init script.

So much wrong here....

You're mistakenly attempting to put this in /etc/rc.d/ - does that mean you want it to run every time you boot? If so, why not just hardcode the required details in your asound.conf - or better still, in your ~/.asoundrc.

If you don't want it to run every boot, when exactly do you want it to run? If it's on-demand, create the required script somewhere under $HOME, and activate it with a keybind. If it's whenever the headset is plugged in, activate it with a udev rule.

Finally, if the occasion ever arises where you need to write an initscript for inclusion in /etc/rc.d/ (and again, this is not that occasion), the very least you should do is have a look at some of the existing scripts to learn how they are structured.

Offline

#4 2012-09-21 17:04:07

fpilee
Member
From: Windows 7
Registered: 2011-10-06
Posts: 104
Website

Re: im Having trouble to do a init script.

You don't have readed how work the script... I have a usb headset but i never unplug, the card number of the "usb headset" is changed on every boot, so the last /etc/asound.conf don't  work, so i made a script to update /etc/asound.conf,   but is a good suggestion to make a udev rule.

Offline

#5 2012-09-21 17:18:14

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,837

Re: im Having trouble to do a init script.

Audio drivers usually support the 'index' option, which allows you to specify the device number. Check if the driver you're using supports it, and if it does, set your required number in /etc/modprobe.d/*.conf.

Offline

Board footer

Powered by FluxBB