USB 音效卡驅動

    版本為 13:36, 23 Nov 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    網樂通雖然有內建 Audio 模組,不過找不到驅動的方式,所以只能使用外接 USB 音效卡方式。

    要能使用 USB 音效卡,需要的步驟如下:

    1. USB 音效裝置必須有支援 ALSA 驅動
    2. 交叉編譯 STLinux Kernel,使它支援 ALSA 音效裝置,並且編譯成模組
    3. 在網樂通裡,安裝啟動必要的 ALSA 相關驅動模組
    4. 安裝 ALSA 相關套件
      • stlinux23-sh4-alsa-lib
      • stlinux23-sh4-alsa-utils
      • stlinux23-sh4-alsaplayer
    5. 音效播放測試

    交叉編譯 Linux kernel

    編譯參數

    在原編譯檔 .config 的 General setup 上方加上 CONFIG_SOUND=m
    注意: 開始編譯後,會出現許多詢問項目,必須輸入 m 或 y

    CONFIG_SOUND=m
    #
    # General setup
    #
    ..... 
    

    Advanced Linux Sound Architecture (SND) [N/m/?] (NEW) m

     Sequencer support (SND_SEQUENCER) [N/m/?] (NEW) m
        Sequencer dummy client (SND_SEQ_DUMMY) [N/m/?] (NEW) m
      OSS Mixer API (SND_MIXER_OSS) [N/m/?] (NEW) m
      OSS PCM (digital audio) API (SND_PCM_OSS) [N/m/?] (NEW) m
      OSS PCM (digital audio) API - Include plugin system (SND_PCM_OSS_PLUGINS) [Y/n/?] (NEW) y
      OSS Sequencer API (SND_SEQUENCER_OSS) [N/y/?] (NEW) y
      Dynamic device file minor numbers (SND_DYNAMIC_MINORS) [N/y/?] (NEW) y
      Support old ALSA API (SND_SUPPORT_OLD_API) [Y/n/?] (NEW) y
      Verbose procfs contents (SND_VERBOSE_PROCFS) [Y/n/?] (NEW) y
      Verbose printk (SND_VERBOSE_PRINTK) [N/y/?] (NEW) y
     Debug (SND_DEBUG) [N/y/?] (NEW) n

      *
      * Generic devices
      *
      Dummy (/dev/null) soundcard (SND_DUMMY) [N/m/?] (NEW) m
      Virtual MIDI soundcard (SND_VIRMIDI) [N/m/?] (NEW) m
      MOTU MidiTimePiece AV multiport MIDI (SND_MTPAV) [N/m/?] (NEW) m
      UART16550 serial MIDI driver (SND_SERIAL_U16550) [N/m/?] (NEW) m
      Generic MPU-401 UART driver (SND_MPU401) [N/m/?] (NEW) m

    *
    * USB devices
    *
    USB Audio/MIDI driver (SND_USB_AUDIO) [N/m/?] (NEW) m
    Native Instruments USB audio devices (SND_USB_CAIAQ) [N/m/?] (NEW) m
      enable input device for controllers (SND_USB_CAIAQ_INPUT) [N/y/?] (NEW) y

    *
    * System on Chip audio support
    *
    ALSA for SoC audio support (SND_SOC) [N/m/?] (NEW) m
    *
    * STMicroelectronics SoCs support
    *
    STMicroelectronics SoCs support (SND_STM) [N/m/?] (NEW) m
      Name of BPA2 partition to allocate buffers from (SND_STM_BPA2_PARTITION_NAME) [audio] (NEW)
      STx7100 and STx7109 support (SND_STM_STX710X) [N/m/?] (NEW) m
      STx7105 support (SND_STM_STX7105) [M/n/?] (NEW) m
      STx7111 support (SND_STM_STX7111) [N/m/?] (NEW) m
      STx7141 support (SND_STM_STX7141) [N/m/?] (NEW) m
      STx7200 support (SND_STM_STX7200) [N/m/?] (NEW) m
      Dummy converter driver (SND_STM_CONV_DUMMY) [N/m/?] (NEW) m
      Generic GPIO-controlled converter driver (SND_STM_CONV_GPIO) [N/m/?] (NEW) m
      Generic I2C-controlled converter driver (SND_STM_CONV_I2C) [N/m/?] (NEW) m

    *
    * Open Sound System
    *
    Open Sound System (DEPRECATED) (SOUND_PRIME) [N/m/?] (NEW) n

    開始編譯

    make ARCH=sh CROSS_COMPILE=sh4-linux- vmlinux
    make ARCH=sh CROSS_COMPILE=sh4-linux- modules
    make ARCH=sh CROSS_COMPILE=sh4-linux- modules_install INSTALL_MOD_PATH=./modules_install
    

    make the vmlinux.ub

    sh4-linux-objcopy -O binary vmlinux vmlinux.bin
    gzip --best --force vmlinux.bin
    mkimage -A sh -O linux -T kernel -C gzip -a 0x80800000 -e 0x80801000 -n "Linux 2.6" -d vmlinux.bin.gz vmlinux.ub
    

    交叉編譯 ALSA-Lib 與 ALSA-Utils 套件

    套件下載: http://www.alsa-project.org/main/index.php/Download

    alsa-lib

    CC=sh4-linux-gcc \
    ./configure --host=sh4-linux
    
    make
    make install DESTDIR=/home/alang/STLinux_Cross-Compile/build_opt/alsa-lib
    

    alsa-utils

    CC=sh4-linux-gcc \
    ./configure --host=sh4-linux
    
    make
    make install DESTDIR=/home/alang/STLinux_Cross-Compile/build_opt/alsa-utils
    

    安裝 ALSA 驅動模組

    安裝模組檔至以下目錄
    /lib/modules/2.6.23.17_stm23_A18B-PDK7105-32BITS-A18B/kernel/sound
    
    啟動模組
    modprobe soundcore
    modprobe snd-usb-audio
    modprobe snd-pcm-oss
    modprobe snd_seq_midi
    modprobe snd_seq_oss 
    

    TIP:

    如果啟動失敗,必須執行 depmod -a

    檢視安裝後的模組列表

    root@localhost:/dev/snd# lsmod | grep snd
    soundcore               6468  1 snd
    snd                    49972  7 snd_usb_audio,snd_pcm,snd_timer,snd_usb_lib,snd_rawmidi,snd_seq_device,snd_hwdep
    snd_hwdep               7492  1 snd_usb_audio
    snd_seq_device          6860  1 snd_rawmidi
    snd_rawmidi            22496  1 snd_usb_lib
    snd_timer              21060  1 snd_pcm
    snd_pcm                78373  1 snd_usb_audio
    snd_page_alloc          6376  1 snd_pcm
    snd_usb_lib            15712  1 snd_usb_audio
    snd_usb_audio          80128  0
    

    新增 /etc/modprobe.conf (非必要)

    # ALSA portion
    alias char-major-116 snd
    alias snd-card-0 snd-usb-audio
    options snd-usb-audio nrpacks=1
    
    # OSS/Free portion
    alias char-major-14 soundcore
    alias sound-slot-0 snd-card-0
    
    # card #1
    alias sound-service-0-0 snd-mixer-oss
    alias sound-service-0-1 snd-seq-oss
    alias sound-service-0-3 snd-pcm-oss
    alias sound-service-0-12 snd-pcm-oss
    

    TIPs:

    加上 modprobe.conf 後,只要執行 APP 例如 aplay  -l,系統就會自動載入需要的模組。

    建立 alsa.conf
    從套件 alsa-lib 的目錄<alsa-lib>/usr/share/alsa/alsa.conf 複製到 /usr/share/alsa/alsa.conf

    以下是測試用的簡易 alsa.conf:

    pcm.!default {
       type hw
       card 0
    }
    pcm.hw {
       type hw
       card 0
       device 0
       subdevice 0
    }
    ctl.!default {
       type hw
       card 0
    }
    ctl.hw {
       type hw
       card 0
    }
    

    新增裝置檔

    新增群組 audio

    vi /etc/group
    加上這一行
    audio:*:1000:
    

    解壓附件檔案 dev_snd_all.tar.gz

    mkdir /dev/snd
    chmod 0755 /dev/snd
    tar xzf dev_snd_all.tar.gz -C /dev/snd
    

    安裝以後

    root@localhost:/dev/snd# ls -l /dev/snd
    crw-rw----    1 root     audio    116,   5 Jan  1  2000 controlC0
    crw-rw-rw-    1 root     audio    116,  32 Feb 24 16:56 controlC1
    crw-rw----    1 root     audio    116,   4 Jan  1  2000 pcmC0D0c
    crw-rw----    1 root     audio    116,   3 Jan  1  2000 pcmC0D0p
    crw-rw-rw-    1 root     audio    116,  25 Feb 24 16:56 pcmC0D1c
    crw-rw-rw-    1 root     audio    116,  17 Feb 24 16:56 pcmC0D1p
    crw-rw-rw-    1 root     audio    116,  26 Feb 24 16:56 pcmC0D2c
    crw-rw-rw-    1 root     audio    116,  18 Feb 24 16:56 pcmC0D2p
    crw-rw----    1 root     audio    116,   1 Feb 24 16:56 seq
    crw-rw----    1 root     audio    116,   2 Jan  1  2000 timer
    

    Q&A

    執行 alsamixer,發生錯誤 Error opening terminal: vt102.

    Ans:拷貝 STLinux 主機的檔案 /opt/STM/STLinux-2.3/devkit/sh4/target/usr/share/terminfo/v/vt102 至機上盒的 usr/share/terminfo/v/vt102

     

    Powered by MindTouch Core