由于公司蓝牙音箱的项目用到pulseaudio

出现了卡顿,google了很多资料觉得配置文件真的得好好看看

pulseaudio 官方的配置说明
arch linux 关于pulseaudio 的问题说明
其中最重要的配置是关于声音算法的配置
resample-method= The resampling algorithm to use. Use one of src-sinc-best-quality, src-sinc-medium-quality, src-sinc-fastest, src-zero-order-hold, src-linear, trivial, speex-float-N, speex-fixed-N, ffmpeg. See the documentation of libsamplerate for an explanation for the different src- methods. The method trivial is the most basic algorithm implemented. If you're tight on CPU consider using this. On the other hand it has the worst quality of them all. The Speex resamplers take an integer quality setting in the range 0..9 (bad...good). They exist in two flavours: fixed and float. The former uses fixed point numbers, the latter relies on floating point numbers. On most desktop CPUs the float point resmampler is a lot faster, and it also offers slightly better quality. See the output of dump-resample-methods for a complete list of all available resamplers. Defaults to speex-float-3. The --resample-method command line option takes precedence. Note that some modules overwrite or allow overwriting of the resampler to use.

二次采样的算法=src-sinc-best-quality 最好的声音品质,
src-sinc-medium-quality 一般pc采用的品质
当你采用嵌入式开发蓝牙音箱,那么选择 trivial 比较好,因为对CPU的压力最小.
pulseaudio 是很强大的工具.如果的CPU足够强大,很多算法可以采用.有低音炮的优化......

声音片段的设置
//=======================================================================================================================

查找您的音频设备参数(1/4)
要了解您的声卡缓冲设置是什么,请使用以下命令并滚动输出,直到找到正确的接收器条目。

$ pactl list sinks
Sink#1
状态:RUNNING
名称:alsa_output.pci-0000_00_1b.0.analog立体声
说明:内置音频模拟立体声
驱动程序:module-alsa-card.c
示例规格:s16le 2ch 44100Hz
频道映射:前左,前- 右
所有者模块:7
静音:否
音量:左前:42600/65%/ -11.22 dB,右前:42600/65%/ -11.22 dB
平衡0.00
基本音量:65536/100%/ 0.00 dB
监听源:alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
延迟:70662 usec,配置85000 usec
标志:HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
属性:
alsa.resolution_bits =“16”
device.api =“alsa”
device.class =“sound”
alsa.class =“generic”
alsa.subclass =“generic-mix”
alsa.name =“ALC283 Analog”
alsa.id =“ALC283 Analog”
alsa.subdevice = “0”
alsa.subdevice_name = “ subdevice#0”
alsa.device =“0”
alsa.card =“1”
alsa.card_name =“HDA Intel PCH”
alsa.long_card_name =“HDA Intel PCH at 0xe111c000 irq 43”
alsa。 driver_name =“snd_hda_intel”
device.bus_path =“pci-0000:00:1b.0”
sysfs.path =“/devices/pci0000 :00/0000:00:1b.0/ sound/card1”
device.bus =“pci “
device.vendor.id =“8086”
device.vendor.name =“Intel Corporation”
device.product.id =“9ca0”
device.product.name =“Wildcat Point-LP High Definition Audio Controller”
device.form_factor =“internal”
device.string =“front:1”
device.buffering.buffer_size =“352800”
device.buffering.fragment_size =“176400”
device.access_mode =“mmap + timer”
device.profile.name =“analog-stereo”
device.profile.description =“Analog Stereo”
device.description =“Built-in Audio Analog Stereo “
alsa.mixer_name =”Realtek ALC283“
alsa.components =”HDA:10ec0283,10ec0283,00100003“
module-udev-detect.discovered =”1“
设备。icon_name =“audio-card-pci”
端口:
模拟输出扬声器:扬声器(优先:10000,不可用)
模拟输出耳机:耳机(优先:9000,可用)
有效端口:模拟输出耳机
格式:
pcm
...
记下相关声卡的值buffer_size和fragment_size值。

以毫秒为单位计算碎片大小(2/4)
PulseAudio的默认采样率和位深度设置为44100Hz@ 16 bits。

使用这种配置,我们需要的比特率是44100* 16= 705600每秒的位数。那就是1411200 bps立体声。

我们来看看我们在上一步中找到的参数:

device.buffering.buffer_size =“352800”=> 352800/1411200 = 0.25 s = 250 ms
device.buffering.fragment_size =“176400”=> 176400/1411200 = 0.125 s = 125 ms
修改PulseAudio的配置文件(3/4)
/etc/pulse/daemon.conf
; default-fragments = X
; default-fragment-size-msec = Y
在上一步中,我们计算了片段大小参数。片段数是简单的buffer_size / fragment_size,在这种情况下(250/125)是2:

/etc/pulse/daemon.conf
; default-fragments = 2
; default-fragment-size-msec = 125
重新启动PulseAudio守护进程(4/4)
$ pulseaudio -k
$ pulseaudio - 启动
//=============================================================================

经过测试 是这个参数导致的卡顿
default-fragment-size-msec
The duration of a single fragment. Defaults to 25ms (i.e. the total buffer is thus 100ms long).
私人翻译如下.
单个片段的持续时间.默认是25ms,因为前面的片段设置是 4个片段,那么这个例子中的片段就是100ms.

个人认为这个就是音频流的缓冲buffer.
不知道为什么这个参数会卡.按照上面的计算方法.设置为2ms(原本是1.25ms)似乎不能设置为小数... ...
但是这样CPU的占用率提高了很多从20%一下子冲到40%.
但是不卡了... ...

posted on 2017-09-28 10:52  HDU李少帅  阅读(2714)  评论(0编辑  收藏  举报