LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1597|回复: 4

关于声卡问题的简易解决方案

[复制链接]
发表于 2007-2-28 21:03:34 | 显示全部楼层 |阅读模式
本人安装FC5,FC6时声卡总是有问题。所以写下点东西,希望对有同样问题的兄弟有帮助。
我的声卡是Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio Controller,用的是alsa的驱动snd_intel8x0
系统能正确认出,声卡检测不能发声。

后来猜测可能是内核加载时的问题,所以就想写个服务,开机时自动卸载、加载模块,命名为alsa

#!/bin/bash
#
# alsa: Alsaconfigure
#
# chkconfig: 2345 88 10
# description: Alsaconfigure,so Alsa module can be used while starting the computer!
#
#


start()
{
echo "ALSA is starting."
rmmod snd_intel8x0
modprobe snd_intel8x0
}

stop()
{
echo "ALSA is stoping."
rmmod snd_intel8x0
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload}"
exit 1
esac

exit 0

没有经过严格测试,基本有用。赋予可执行属性,放入/etc/init.d
然后,打开 系统--管理--服务器设置--服务 里,“行动”里添加alsa,下次开机就能运行了
发表于 2007-3-1 21:17:07 | 显示全部楼层
lz 的脚本还不错,就是少了一些功能, 比如模块配置放在 /etc/modprobe.conf 里, 启动时恢复音量, 退出时保存音量.
看看 alsa 自带的脚本吧(我相信 fc6 也会有类似的功能完全的脚本的)

  1. #!/bin/bash
  2. #
  3. # alsasound     This shell script takes care of starting and stopping
  4. #               the ALSA sound driver.
  5. #
  6. # This script requires /usr/sbin/alsactl and /usr/bin/aconnect
  7. # programs from the alsa-utils package.
  8. #
  9. # Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  10. #
  11. #
  12. #  This program is free software; you can redistribute it and/or modify
  13. #  it under the terms of the GNU General Public License as published by
  14. #  the Free Software Foundation; either version 2 of the License, or
  15. #  (at your option) any later version.
  16. #
  17. #  This program is distributed in the hope that it will be useful,
  18. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. #  GNU General Public License for more details.
  21. #
  22. #  You should have received a copy of the GNU General Public License
  23. #  along with this program; if not, write to the Free Software
  24. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  25. #
  26. #
  27. # For RedHat 5.0+:
  28. # chkconfig: 2345 87 14
  29. # description: ALSA driver
  30. #
  31. # modified to visually fit into SuSE 6.0+ by Philipp Thomas <pthomas@suse.de>
  32. # further improvements by Bernd Kaindl, Olaf Hering and Takashi Iwai.
  33. #
  34. ### BEGIN INIT INFO
  35. # Provides:       alsasound
  36. # Required-Start: $remote_fs
  37. # Required-Stop: $remote_fs
  38. # Default-Start:  2 3 5
  39. # Default-Stop:
  40. # Description:    Loading ALSA drivers and store/restore the current setting
  41. ### END INIT INFO

  42. if [ -r /etc/rc.config ]; then
  43.   . /etc/rc.config
  44.   rc_warning="\033[33m\033[1m"
  45. else
  46.   rc_done="done"
  47.   rc_warning=""
  48.   rc_reset=""
  49. fi

  50. if [ x$START_ALSA != xno ]; then
  51.   START_ALSA=yes
  52. fi
  53. if [ x$START_ALSA_SEQ != xno ]; then
  54.   START_ALSA_SEQ=yes
  55. fi

  56. # Determine the base and follow a runlevel link name.
  57. base=${0##*/}
  58. link=${base#*[SK][0-9][0-9]}

  59. # Force execution if not called by a runlevel directory.
  60. test $link = $base && START_ALSA=yes
  61. test "$START_ALSA" = yes || exit 0

  62. alsactl=/usr/sbin/alsactl
  63. asoundcfg=/etc/asound.state
  64. aconnect=/usr/bin/aconnect
  65. alsascrdir=/etc/alsa.d
  66. if [ -x /sbin/lsmod ]; then
  67.   lsmod=/sbin/lsmod
  68. else
  69.   lsmod=lsmod
  70. fi

  71. # modprobe returns 255 when failed..
  72. function probe_module () {
  73.    /sbin/modprobe $*
  74.    test $? = 0 && return 0
  75.    return 1
  76. }

  77. function start() {
  78.   #
  79.   # insert all sound modules
  80.   #

  81.   module_loaded=0
  82.   drivers=`/sbin/modprobe -c | \
  83.     grep -E "^[[:space:]]*alias[[:space:]]+snd-card-[[:digit:]]" | \
  84.     awk '{print $3}'`
  85.   for i in $drivers; do
  86.     if [ "$i" != off ]; then
  87.       echo -n "Starting sound driver: $i "
  88.       probe_module $i && module_loaded=1
  89.       echo -e "$rc_done"
  90.     fi
  91.   done
  92.   test $module_loaded -eq 0 && return
  93.   #
  94.   # insert sequencer modules
  95.   #
  96.   if [ x"$START_ALSA_SEQ" = xyes -a -r /proc/asound/seq/drivers ]; then
  97.     cut -d , -f 1 /proc/asound/seq/drivers | \
  98.     while read t ; do
  99.       test -z $t || /sbin/modprobe $t
  100.     done
  101.   fi
  102.   #
  103.   # restore driver settings
  104.   #
  105.   if [ -d /proc/asound ]; then
  106.     if [ ! -r $asoundcfg ]; then
  107.       echo "No mixer config in $asoundcfg, you have to unmute your card!"
  108.     else
  109.       if [ -x $alsactl ]; then
  110.         $alsactl -F -f $asoundcfg restore
  111.       else
  112.         echo -e "${rc_warning}ERROR: alsactl not found${rc_reset}"
  113.       fi
  114.     fi
  115.   fi
  116.   #
  117.   # run card-dependent scripts
  118.   for i in $drivers; do
  119.     t=${i##snd-}
  120.     if [ -x $alsascrdir/$t ]; then
  121.       $alsascrdir/$t
  122.     fi
  123.   done

  124.   #
  125.   # touch lockfile if lockdir exists
  126.   #
  127.   if [ -d /var/lock/subsys ] ; then
  128.     touch /var/lock/subsys/alsasound
  129.   fi
  130. }

  131. function terminate() {
  132.   #
  133.   # Kill processes holding open sound devices
  134.   #
  135.   # DEVS=`find /dev/ -follow -type c -maxdepth 1 -print 2>/dev/null | xargs ls -dils | grep "1*1[46]," | cut -d: -f2 | cut -d" " -f2; echo /proc/asound/dev/*`
  136.   fuser -k /dev/admmidi? /dev/adsp? /dev/amidi? /dev/audio* /dev/dmfm* \
  137.      /dev/dmmidi? /dev/dsp* /dev/dspW* /dev/midi0? /dev/mixer? /dev/music \
  138.      /dev/patmgr? /dev/sequencer* /dev/sndstat >/dev/null 2>&1
  139.   if [ -d /proc/asound/dev ]; then
  140.     fuser -k /proc/asound/dev/* >/dev/null 2>&1
  141.   fi
  142.   if [ -d /dev/snd ]; then
  143.     fuser -k /dev/snd/* >/dev/null 2>&1
  144.   fi
  145.   #
  146.   # remove all sequencer connections if any
  147.   #
  148.   if [ -f /proc/asound/seq/clients -a -x $aconnect ]; then
  149.     $aconnect --removeall
  150.   fi
  151. }

  152. function stop() {
  153.   #
  154.   # store driver settings
  155.   #
  156.   if [ -x $alsactl ]; then
  157.     $alsactl -f $asoundcfg store
  158.   else
  159.     echo -n -e "${rc_warning}!!!alsactl not found!!!${rc_reset} "
  160.   fi
  161.   #
  162.   # mute master to avoid clicks at unload
  163.   #
  164.   /usr/bin/amixer set Master mute >/dev/null 2>&1
  165.   #
  166.   # remove all sound modules
  167.   #
  168.   $lsmod | grep -E "^snd" | grep -Ev "(snd-page-alloc|snd_page_alloc)" | while read line; do \
  169.      /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
  170.   done
  171.   # remove the 2.2 soundcore module (if possible)
  172.   /sbin/rmmod soundcore 2> /dev/null
  173.   /sbin/rmmod gameport 2> /dev/null

  174.   #
  175.   # remove lockfile if lockdir exists
  176.   #
  177.   if [ -d /var/lock/subsys ] ; then
  178.     rm -f /var/lock/subsys/alsasound
  179.   fi
  180. }

  181. # See how we were called.
  182. case "$1" in
  183.   start)
  184.         # Start driver if it isn't already up.
  185.         if [ ! -d /proc/asound ]; then
  186.           start
  187.         else
  188.           echo "ALSA driver is already running."
  189.         fi
  190.         ;;
  191.   stop)
  192.         # Stop daemons.
  193.         if [ -d /proc/asound ]; then
  194.           echo -n "Shutting down sound driver: "
  195.           terminate
  196.           stop
  197.           echo -e "$rc_done"
  198.         fi
  199.         ;;
  200.   restart|reload)
  201.         $0 stop
  202.         $0 start
  203.         ;;
  204.   status)
  205.         if [ -d /proc/asound ]; then
  206.           echo -n "ALSA sound driver loaded."
  207.         else
  208.           echo -n "ALSA sound driver not loaded."
  209.         fi
  210.         echo
  211.         ;;
  212.   *)
  213.         echo "Usage: alsasound {start|stop|restart|status}"
  214.         exit 1
  215. esac

  216. exit 0
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-3 22:47:15 | 显示全部楼层
我不大懂这些,只要求简单能用就行,见笑了。
回复 支持 反对

使用道具 举报

发表于 2008-2-9 12:32:43 | 显示全部楼层
不行啊,我的FC8还是没有声音啊
添加服务alsa后在服务列表里没有这一项服务,不知怎么回事?
谢谢!!!
回复 支持 反对

使用道具 举报

发表于 2008-2-10 15:12:05 | 显示全部楼层

just have a try

Post by panwei;1815003
不行啊,我的FC8还是没有声音啊
添加服务alsa后在服务列表里没有这一项服务,不知怎么回事?
谢谢!!!



You can try to add "options snd-hda-intel model=laptop-eapd" to the buttom of
/etc/modprobe.d/alsa-base,but you must install alsa first.

这个是针对fc6 的,我用的fc8,开始跟你一样的情况.然后我加了这一句话,笔记本扬声器和耳机就都能正常了.

但是,有以下两个问题需要注意:

1, FC8中的modprobe位置跟上面的不一样,但是大概都在那里,找不到可以搜索一下就出来了.

2,我是笔记本用户,添加了后的确有声音了,但是,你插上耳机后电脑自带的喇叭还是有声音.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表