1 前言

2 下载编译

具体构建过程参照官方文档:https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/PulseAudioFromGit/

2.1 下载代码

git clone git://anongit.freedesktop.org/pulseaudio/pulseaudio

2.2 编译

编译过程遇到太多错误了,见问题集,主要是依赖没有安装

meson build
ninja -C build
sudo ninja -C build install
sudo ldconfig

3 demo实践

PulseAudio对外api非常简单,基本就是和io操作一样:read,write,open…
pa_simple_new:创建到服务器的新连接。
pa_simple_read:从服务器读取一些数据。(阻塞)
pa_simple_write:向服务器写入一些数据。
pa_simple_free:关闭并释放与服务器的连接。
pa_simple_drain:等待守护进程播放所有已写入的数据。
pa_simple_flush:刷新播放或记录缓冲区。
pa_simple_get_latency:返回播放或记录延迟。
下面是官方demo:

/***This file is part of PulseAudio.PulseAudio is free software; you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License as publishedby the Free Software Foundation; either version 2.1 of the License,or (at your option) any later version.PulseAudio is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU Lesser General Public Licensealong with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/#ifdef HAVE_CONFIG_H
#include <config.h>
#endif#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>#include <pulse/simple.h>
#include <pulse/error.h>#define BUFSIZE 1024int main(int argc, char*argv[]) {/* The Sample format to use */static const pa_sample_spec ss = {.format = PA_SAMPLE_S16LE,.rate = 44100,.channels = 2};pa_simple *s = NULL;int ret = 1;int error;/* replace STDIN with the specified file if needed */if (argc > 1) {int fd;if ((fd = open(argv[1], O_RDONLY)) < 0) {fprintf(stderr, __FILE__": open() failed: %s\n", strerror(errno));goto finish;}if (dup2(fd, STDIN_FILENO) < 0) {fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno));goto finish;}close(fd);}/* Create a new playback stream */if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));goto finish;}for (;;) {uint8_t buf[BUFSIZE];ssize_t r;#if 0pa_usec_t latency;if ((latency = pa_simple_get_latency(s, &error)) == (pa_usec_t) -1) {fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error));goto finish;}fprintf(stderr, "%0.0f usec    \r", (float)latency);
#endif/* Read some data ... */if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {if (r == 0) /* EOF */break;fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno));goto finish;}/* ... and play it */if (pa_simple_write(s, buf, (size_t) r, &error) < 0) {fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error));goto finish;}}/* Make sure that every single sample was played */if (pa_simple_drain(s, &error) < 0) {fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error));goto finish;}ret = 0;finish:if (s)pa_simple_free(s);return ret;
}

4 问题集

4.1 tdb库缺失

问题描述

meson.build:595:2: ERROR: Dependency “tdb” not found, tried pkgconfig and cmake

解决方案:
下载最新版本tdb编译安装。
下载地址:https://www.samba.org/ftp/tdb/

tar -xvf tdb-1.4.5.tar.gz
cd tdb-1.4.5
./configure && make && make install

4.2 sndfile库缺失

meson.build:653:0: ERROR: Dependency “sndfile” not found, tried pkgconfig and cmake

解决方案:
下载最新版本tdb编译安装。
下载地址:http://www.mega-nerd.com/libsndfile/

tar -xvf libsndfile-1.0.28.tar.gz
cd libsndfile-1.0.28
./configure && make && make install

4.3 xtst库缺失

meson.build:686:2: ERROR: Dependency “xtst” not found, tried pkgconfig and cmake

解决方案:

sudo apt-get install libxtst-dev

4.4 check库缺失

meson.build:792:0: ERROR: Dependency “check” not found, tried pkgconfig and cmake

解决方案:

apt-get install check

Ubuntu18.04 PulseAudio实战相关推荐

  1. Ubuntu18.04.1实战安装百度网盘以及遇到的问题解决方案

    Ubuntu18.04.1实战安装百度网盘以及遇到的问题解决方案 Ubuntu版本:18.04.1 英文版 系统配置: 64位 进入百度网盘下载中心 百度网盘下载中心地址:https://pan.ba ...

  2. ubuntu18.04 PulseAudio蓝牙耳机开启mic的解决办法

    一.背景 基于Linux音频服务子系统PulseAudio(Linux默认声音服务器)进行音频开发,包括采集(record)和播放(playback); 测试中发现笔记本(ubuntu 18.04)连 ...

  3. 【CV实战】Ubuntu18.04源码编译安装opencv-3.4.X+测试demo

    之前在Windows上借助VS编译opencv,很轻松就能搞定,到Linux下踩了坑,Ubuntu下编译.卸掉重编.搞了几次,还把系统库给卸载掉了(sudo apt-get remove python ...

  4. Linux实战001:VMware下安装Ubuntu18.04(服务器版)

    要想做好一个程序员,基本的服务器构架的能力还是需要有的.除了在本地开发,我们还要学会如何去部署我们开发好的系统.由于Linux的开源免费且功能强大,性能卓越.很多企业都会选择将服务部署在Linux系统 ...

  5. docker ubuntu-18.04 实战系列一

    linux 环境 ubuntu-18.04.1-desktop-amd64 一.docker 安装 oly@ubuntu-desktop-amd64:~$ sudo apt-get updateoly ...

  6. K8S实战部署系列-K3S v1.22.5+k3s1(Ubuntu18.04)

    使用初始化完成系统 root@master01:~# cat /proc/version Linux version 5.4.0-92-generic (buildd@lcy01-amd64-026) ...

  7. 1.EdgeX实战 Ubuntu18.04搭建运行环境

    文章目录 前言: 1.搭建Ubuntu18.04服务器平台 2.安装docker和docker-compose 3.运行EdgeX 4.使用浏览器访问EdgeX 前言: 想着把之前arduino和树莓 ...

  8. 解决Ubuntu18.04没有声音(简便且终极方法)

    安装完Ubuntu18.04系统之后发现没有声音输出,网上百度了好久都没有找到解决方法,最后终于解决这个问题了.解决方法如下: 1. 首先下载PulseAudio Volum Control . Pu ...

  9. 树莓派输出pwm波c语言,树莓派Ubuntu18.04使用pigpio库产生PWM波实现舵机控制

    树莓派Ubuntu18.04使用pigpio库产生PWM波实现舵机控制 树莓派Ubuntu18.04使用pigpio库产生PWM波实现舵机控制 一:pigpio库简介 pigpio是一个用于树莓派的库 ...

  10. 【Ubuntu18.04】移动固态硬盘安装ubuntu18.04、NIVDIA、CUDA、CUDNN——01

    [Ubuntu18.04安装及配置唠叨版]"轻轻松松"拿下ubuntu18.04.NIVDIA.CUDA.CUDNN--01 心路简要:建议直接找到有用的部分操作hhh 为什么要装 ...

最新文章

  1. mysql 二十条记录_记 MySQL优化 20条
  2. smbus使用 树莓派_树莓派学习笔记——I2C使用 PCF8574 Python SMBUS
  3. Android开发各类常见错误解决方案
  4. 在leopard下用textmate开发rails项目
  5. Linux云服务器安装JDK详细步骤
  6. 【C++基础】异常匹配与内建异常类
  7. Remote Desktop 访问设置
  8. 9102年,曝光这几个高质量的公众号,年薪7位数!
  9. wgan 不理解 损失函数_GAN损失函数||WGAN
  10. CAD2014安装一整套流程
  11. matlab批量处理excel(CSV)文件数据
  12. STM32 USART串口发送软件调试
  13. xshell进入桌面_xshell中启动linux图形界面
  14. 字节跳动确认将自研芯片;美国国土安全部被曝大量购买和使用手机定位数据;谷歌被俄罗斯罚款3.6亿美元 | 每日大事件...
  15. html 气泡上升效果,css气泡效果
  16. ug安装lmtools显示未连接服务器,服务器(LMTOOLS)设置教程
  17. Verilog/@符号什么意思
  18. 【观察】华为云连续四年蝉联政务云第一,背后是“长跑选手”实力的印证
  19. Flink之窗口 (Window) 下篇
  20. 子查询 navicat可视化,pymysql用法

热门文章

  1. 了解LabVIEW编程
  2. 一篇文章了解光学器件的各种参数含义
  3. 校园网如何使用IPv6
  4. excel2010设置列宽为像素_如何以厘米为单位精确设置Excel表格的行高列宽?
  5. excel表格中怎样让某一行数据一直显示
  6. 怎么提高,芝麻信用分到750
  7. DataGridView控件绑定数据源时:用户sa登录失败
  8. Activity生命周期
  9. Android 接入穿山甲广告
  10. MySql 常用命令集