ALSA 简介
ALSA 音频工具编译安装
2、创建 alsa 安装目录(如 /home/rudy/alsa 目录),并在该目录下创建 install 目录,接着把压缩包拷到 alsa 目录下。
3、编译 alsa-lib 用户空间库。
# tar -xvf alsa-lib-1.0.27.2.tar.bz2 # cd alsa-lib-1.0.27.2 # CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/home/rudy/alsa/install/ # make # make install
# tar -xvf alsa-utils-1.0.27.2.tar.bz2 # cd alsa-utils-1.0.27.2 # CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/home/rudy/alsa/install/ --host=arm-linux --with-alsa-inc-prefix=/home/rudy/alsa/install/include --with-alsa-prefix=/home/rudy/alsa/install/lib --disable-alsamixer --disable-xmlto --disable-nls # make
音频录制——arecord
# arecord -h Usage: arecord [OPTION]... [FILE]... -h, --help help --version print current version -l, --list-devices list all soundcards and digital audio devices -L, --list-pcms list device names -D, --device=NAME select PCM by name -q, --quiet quiet mode -t, --file-type TYPE file type (voc, wav, raw or au) -c, --channels=# channels -f, --format=FORMAT sample format (case insensitive) -r, --rate=# sample rate -d, --duration=# interrupt after # seconds -M, --mmap mmap stream -N, --nonblock nonblocking mode -F, --period-time=# distance between interrupts is # microseconds -B, --buffer-time=# buffer duration is # microseconds --period-size=# distance between interrupts is # frames --buffer-size=# buffer duration is # frames -A, --avail-min=# min available space for wakeup is # microseconds -R, --start-delay=# delay for automatic PCM start is # microseconds (relative to buffer size if <= 0) -T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun -v, --verbose show PCM structure and setup (accumulative) -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo) -I, --separate-channels one file for each channel --disable-resample disable automatic rate resample --disable-channels disable automatic channel conversions --disable-format disable automatic format conversions --disable-softvol disable software volume control (softvol) --test-position test ring buffer position --test-coef=# test coeficient for ring buffer position (default 8) expression for validation is: coef * (buffer_size / 2) --test-nowait do not wait for ring buffer - eats whole CPU --max-file-time=# start another output file when the old file has recorded for this many seconds --process-id-file write the process ID here --use-strftime apply the strftime facility to the output file name Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Some of these may not be available on selected hardware The availabled format shortcuts are: -f cd (16 bit little endian, 44100, stereo) -f cdr (16 bit big endian, 44100, stereo) -f dat (16 bit little endian, 48000, stereo)
用 # arecord -l 命令可以列出声卡和数字音频设备,如:
card 0: SOUND0 [TI81XX SOUND0], device 0: TVP-PCM tvp5158-hifi-0 [] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: SOUND0 [TI81XX SOUND0], device 1: AIC3X tlv320aic3x-hifi-1 [] Subdevices: 1/1 Subdevice #0: subdevice #0
-D 参数用于指定音频设备 PCM,以 hwx,x 开头(前 x 表示声卡号,后 x 表示设备号)。根据上面 # arecord -l 列出的设备,如果选择 tvp5158 来录制声音的话,那么 pcm 设备就为 hw0,0,如果选择 tlv320aic3x,则 pcm 设备为 hw0,1。
-r 指定采样频率:5512/8000/11025/16000/22050/32000/44100/48000/64000/88200/96000//。
-f 指定采样格式:cd/cdr/dat。
用 arecord 录制音频的例子如下(录制完后在 /a 目录下可以找到 1.wmv 文件):
# arecord -Dhw:0,1 -r8000 -f cd /a/1.wmv
音频播放——aplay
# aplay -h Usage: aplay [OPTION]... [FILE]... -h, --help help --version print current version -l, --list-devices list all soundcards and digital audio devices -L, --list-pcms list device names -D, --device=NAME select PCM by name -q, --quiet quiet mode -t, --file-type TYPE file type (voc, wav, raw or au) -c, --channels=# channels -f, --format=FORMAT sample format (case insensitive) -r, --rate=# sample rate -d, --duration=# interrupt after # seconds -M, --mmap mmap stream -N, --nonblock nonblocking mode -F, --period-time=# distance between interrupts is # microseconds -B, --buffer-time=# buffer duration is # microseconds --period-size=# distance between interrupts is # frames --buffer-size=# buffer duration is # frames -A, --avail-min=# min available space for wakeup is # microseconds -R, --start-delay=# delay for automatic PCM start is # microseconds (relative to buffer size if <= 0) -T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun -v, --verbose show PCM structure and setup (accumulative) -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo) -I, --separate-channels one file for each channel --disable-resample disable automatic rate resample --disable-channels disable automatic channel conversions --disable-format disable automatic format conversions --disable-softvol disable software volume control (softvol) --test-position test ring buffer position --test-coef=# test coeficient for ring buffer position (default 8) expression for validation is: coef * (buffer_size / 2) --test-nowait do not wait for ring buffer - eats whole CPU --max-file-time=# start another output file when the old file has recorded for this many seconds --process-id-file write the process ID here --use-strftime apply the strftime facility to the output file name Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Some of these may not be available on selected hardware The availabled format shortcuts are: -f cd (16 bit little endian, 44100, stereo) -f cdr (16 bit big endian, 44100, stereo) -f dat (16 bit little endian, 48000, stereo)
与 arecord 命令类似,用 # aplay -l 可以列出声卡和数字音频设备。
一个简单的播放例子如下:
# aplay -Dhw:0,1 -r8000 -f cd /a/1.wmv
如果想要一边播放一边收听可以用下面利用管道的命令:
# arecord -Dhw:0,1 -r -f cd|aplay -Dhw:0,1 -r
音频配置——amixer
amixer 用法说明:
# amixer -h Usage: amixer
[
command] Available options: -h,
--help this help -c,
--card N select the card -D,
--device N select the device, default 'default' -d,
--debug debug mode -n,
--nocheck do not perform range checking -v,
--version print version of this program -q,
--quiet be quiet -i,
--inactive show also inactive controls -
a,
--abstract L select abstraction level (none or basic) -s,
--stdin Read and execute commands from stdin sequentially Available commands: scontrols show all mixer simple controls scontents show contents
of all mixer simple controls (default
command) sset
sID P
set contents
for
one mixer simple control sget
sID
get contents
for
one mixer simple control controls show all controls
for given card contents show contents
of all controls
for given card cset cID P
set control contents
for
one control cget cID
get control contents
for
one control
# amixer cget numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' ; type=BOOLEAN,access=rw------,values=1 : values=off
4、根据控制参数类型设置控制参数使用 # amixer cset + 控制参数 + 设置参数 命令。如:
# amixer cset numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' on numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' ; type=BOOLEAN,access=rw------,values=1 : values=on
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208535.html原文链接:https://javaforall.net
