经过之前一系列复杂的配置,我搭建好了交叉编译pulseaudio的环境,现在我们可以调用相应的api去进行录音.

使用

我这里使用的例程为parec-simple.c

当配置好交叉编译环境之后直接执行arm-linux-gnueabihf-gcc parec-simple.c -lpulse -lpulse-simple -o record即可.

在树莓派中执行,并通过ctrl+c退出录制,接着开始播放~:

pi@raspberrypi:~ $ ./record > test
^C
pi@raspberrypi:~ $ pacat -pv test --format=s16le
Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
Connection established.
Stream successfully created.
Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528
Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'.
Connected to device bluez_sink.E8_07_BF_E1_1B_02.headset_head_unit (index: 5, suspended: no).
Got EOF.
Stream started.
Playback stream drained.: 55360 usec.
Draining connection to server.

解析

程序的基本结构如下:

  1. 创建一个新的采样流(pa_simple_new)

  2. 读取音频流(pa_simple_read)

  3. 写出输出(write)

  4. 释放流资源(pa_simple_free)