alsaloop 简述
Alsaloop for PCM loopback. 它可以构建A声卡录音 B声卡播放。Alsaloop 支持任意声卡,自适应时钟同步,自适应重采样;还支持 mixer controls重定向。同时支持任意声卡间的路由,可实现边录边播功能。
1 alsaloop 简单应用
1.1 alsaloop 边录边播
- 声卡1录音,声卡0播放
alsaloop -C hw:1,0 -P hw:0,0 -t 10000 -A 3 -S 1 -b -v
2)声卡rockchiprk809co的设备1录音,设备0播放
arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: rockchiprk809co [rockchip,rk809-codec], device 0: fe410000.i2s-rk817-hifi rk817-hifi-0 [fe410000.i2s-rk817-hifi rk817-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: rockchiprk809co [rockchip,rk809-codec], device 1: fe420000.i2s-bt-sco-pcm bt-sco-pcm-1 [fe420000.i2s-bt-sco-pcm bt-sco-pcm-1]
Subdevices: 1/1
Subdevice #0: subdevice #0
录音命令如下
alsaloop -C hw:0,1 -P hw:0,0 -t 10000 -A 3 -S 1 -b -v
Scheduler set to Round Robin with priority 99
Hardware PCM card 0 'rockchip,rk809-codec' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 1920
period_size : 240
period_time : 5000
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1444
period_event : 0
start_threshold : 2147483647
stop_threshold : 1920
silence_threshold: 0
silence_size : 0
boundary : 2013265920
appl_ptr : 0
hw_ptr : 0
Hardware PCM card 0 'rockchip,rk809-codec' device 1 subdevice 0
Its setup is:
stream : CAPTURE
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 8000
exact rate : 8000 (8000/1)
msbits : 16
buffer_size : 320
period_size : 40
period_time : 5000
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 40
period_event : 0
start_threshold : 2147483647
stop_threshold : 320
silence_threshold: 0
silence_size : 0
boundary : 1342177280
appl_ptr : 0
hw_ptr : 0
Latency 480 frames, 10000.000us, 10.000000ms (100.0000Hz)
playback hw:0,0/capture hw:0,1 sync type: SIMPLE
New pitch for playback hw:0,0/capture hw:0,1: 1.00000000 (min/max samples = 0/0)
- arecord+aplay实现边录边播
arecord -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f s16_le
-t raw | aplay -D hw:1,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f
s16_le -t raw
1.2 alsaloop 命令
Usage: alsaloop [OPTION]...
-h,--help help
-g,--config configuration file (one line = one job specified)
-d,--daemonize daemonize the main process and use syslog for errors
-P,--pdevice playback device
-C,--cdevice capture device
-X,--pctl playback ctl device
-Y,--cctl capture ctl device
-l,--latency requested latency in frames
-t,--tlatency requested latency in usec (1/1000000sec)
-f,--format sample format
-c,--channels channels
-r,--rate rate
-n,--resample resample in alsa-lib
-A,--samplerate use converter (0=sincbest,1=sincmedium,2=sincfastest,
3=zerohold,4=linear)
-B,--buffer buffer size in frames
-E,--period period size in frames
-s,--seconds duration of loop in seconds
-b,--nblock non-block mode (very early process wakeup)
-S,--sync sync mode(0=none,1=simple,2=captshift,3=playshift,4=samplerate,
5=auto)
-a,--slave stream parameters slave mode (0=auto, 1=on, 2=off)
-T,--thread thread number (-1 = create unique)
-m,--mixer redirect mixer, argument is:
SRC_SLAVE_ID(PLAYBACK)[@DST_SLAVE_ID(CAPTURE)]
-O,--ossmixer rescan and redirect oss mixer, argument is:
ALSA_ID@OSS_ID (for example: "Master@VOLUME")
-e,--effect apply an effect (bandpass filter sweep)
-v,--verbose verbose mode (more -v means more verbose)
-w,--workaround use workaround (serialopen)
-U,--xrun xrun profiling
-W,--wake process wake timeout in ms
-z,--syslog use syslog for errors
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_LAE
Tip #1 (usable 500ms latency, good CPU usage, superb xrun prevention):
alsaloop -t 500000
Tip #2 (superb 1ms latency, but heavy CPU usage):
alsaloop -t 1000
总结
知识要分享,做个合格的搬运工。