做linux音频编程对alsa应该不陌生。
但是对于刚接触这块技术的同学来说是一件困难的事情。原因在于:网上关于alsa的资料太少了,特别国内的资料更是大部分重复。对于初学者来说特别苦恼。
由于笔者经历过一步步摸索的痛苦过程,现在回想起来有些问题当初可以避免的。因此把问题解决方法和经验教训写出来,引以为戒。
写一系列的技术贴与网友们分享。
录音
arecord -D hw:2,0 -f S16_LE -r 44100 -c 2 /root/record.wav
查看音频设备命令
arecord:加-l参数列出当前数字音频设备,加-L列出当前PCM设备。
arecord -D 设备名 xxx.wav可录音。
alsaconf用来配置声卡的
alsamixer用来设置声音
aplay播放wav
Example:
aplay -c 1 -t raw -r 22050 -f mu_law foobar
will play the raw file "foobar" as a 22050-Hz, mono, 8-bit, Mu-Law .au file.
arecord -d 10 -f cd -t wav -D copy foobar.wav
will record foobar.wav as a 10-second, CD-quality wave file, using the PCM "copy" (which might be defined in the user's .asoundrc file as:
arecord
命令行的声音记录器和播放器的ALSA声卡驱动
[ package | 手册 1 | 用法 | 首页 ]
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 available 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)
原文出处:http://www.cnblogs.com/zhuojun/
扫我吧!!!