軟硬件平台:ARM9(S3C2410A),UDA1341, 2.6.33.1內核,arm-none-linux-gnueabi-gcc-4.3.2
ASoC:
ALSA為嵌入式系統提供的SOC級驅動,支持PCM,I2S和AC97。
詳細內容可查閱:http://www.alsa-project.org/main/index.php/ASoC
(1)驅動移植
2.6.33.1已經為提供了UDA134X的ALSA驅動,只需要稍微配置即可。
在arch/arm/mach-s3c2410/mach-smdk2410.c中添加:
static struct s3c24xx_uda134x_platform_data s3c24xx_uda134x_data = {
.l3_clk = S3C2410_GPB(4),
.l3_data = S3C2410_GPB(3),
.l3_mode = S3C2410_GPB(2),
.model = UDA134X_UDA1341,
};
static struct platform_device s3c24xx_uda134x = {
.name = "s3c24xx_uda134x",
.dev = {
.platform_data = &s3c24xx_uda134x_data,
}
};
在smdk2410_devices[]添加一項:&s3c24xx_uda134x
配置內核選項,選中ALSA支持。
更新內核,啟動顯示
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
usbcore: registered new interface driver snd-usb-audio
usbcore: registered new interface driver snd-usb-caiaq
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: UDA134X <-> s3c24xx-i2s mapping ok
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
ALSA device list:
#0: S3C24XX_UDA134X (UDA134X)
驅動移植成功。可以支持板子的UDA1341,可支持我的usb聲卡了。
(此處也可以直接使用alsa-driver提供驅動程序,具體我沒有做)
(2)alsa-lib移植
版本alsa-lib-1.0.22
./configure --host=arm-linux --target=arm-linux --prefix=/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr --enable-static --enable-shared --disable-python --with-configdir=/usr/local/share --with-plugindir=/usr/local/lib/alsa_lib
編譯安裝,將庫文件、配置文件和插件文件轉移到嵌入式文件系統的對應目錄上。
(3)alsa-utils移植
版本alsa-utils-1.0.23
PKG_CONFIG_PATH="/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/lib/pkgconfig" LDFLAGS="-L/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib -lpthread -lc -lgcc" CFLAGS="-I/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/include" ./configure --host=arm-linux --target=arm-linux --prefix=/home/gyh/mybook/alsa-utils-prefix --disable-alsamixer --with-alsa-prefix=/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/lib/ --with-alsa-inc-prefix=/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/
將/home/gyh/mybook/alsa-utils-prefix目錄拷貝到嵌入式文件系統的對應目錄上。
(4)alsa配置
在啟動腳本中添加:(可能您的不需要)
/bin/mkdir /dev/snd
/bin/ln -s /dev/pcmC0D0c /dev/snd/pcmC0D0c
/bin/ln -s /dev/pcmC0D0p /dev/snd/pcmC0D0p
/bin/ln -s /dev/controlC0 /dev/snd/controlC0
/bin/ln -s /dev/pcmC1D0c /dev/snd/pcmC1D0c
/bin/ln -s /dev/pcmC1D0p /dev/snd/pcmC1D0p
/bin/ln -s /dev/controlC1 /dev/snd/controlC1
/bin/ln -s /dev/seq /dev/snd/seq
/bin/ln -s /dev/timer /dev/snd/timer
modprobe.conf文件內容為
#for ALSA
alias char-major-116 snd
options snd cards_limit=2
alias snd-card-0 snd-soc-uda134x #換成您自己的
alias snd-card-1 snd-usb-audio
#for OSS
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0
#OSS Emulation by ALSA
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-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss
alias sound-slot-1 snd-card-1
alias sound-service-1-0 snd-mixer-oss
alias sound-service-1-1 snd-seq-oss
alias sound-service-1-3 snd-pcm-oss
alias sound-service-1-8 snd-seq-oss
alias sound-service-1-12 snd-pcm-oss
options snd-soc-uda134x index=0
options snd-usb-audio index=1
asound.conf裡內容為
# asoc:uda134x
pcm.!dmix {
type dmix
ipc_key 5678293
ipc_key_add_uid yes
slave {
pcm "hw:0,0"
period_time 0
period_size 2048
buffer_size 16384
format S16_LE
rate 48000
}
}
pcm.!dsnoop {
type dsnoop
ipc_key 5778293
ipc_key_add_uid yes
slave {
pcm "hw:0,0"
period_time 0
period_size 2048
buffer_size 16384
format S16_LE
rate 48000
}
}
pcm.asymed {
type asym
playback.pcm "dmix"
capture.pcm "dsnoop"
}
pcm.!default {
type plug
slave.pcm "asymed"
}
pcm.dsp0 {
type plug
slave.pcm "asymed"
}
ctl.mixer0 {
type hw
card 0
}
(5)測試放音和錄音
./aplay try.wav &
顯示Playing WAVE 'try.wav' : Signed 16 bit Little .....
聽到音樂了。
./arecord -t wav -f dat myrecord.wav
顯示mapped channel 9 to 1
Recording WAVE 'myrecord.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Steo
對著麥克風說話,ctrl+C停止
./aplay myrecord.wav聽到剛才說的話。
設置音量
./amixer set Master 50%
./amixer set Capture 50%
./alsactl store -f asound.state
在開機啟動腳本中增加腳本使每次開機恢復設置,我增加的腳本如下:
/home/gyh/mybook/alsa-utils-prefix/sbin/alsactl restore -f /home/gyh/mybook/alsa-utils-prefix/sbin/asound.state