ALSA lib基本概念
1.channel
通道,即我们熟知的声道数。左/右声道,5.1channel等等
2.sample
A sample is a single value that describes the amplitude of the audio signal at a single point in time, on a single channel.
sample即一次采样,通常的sample bit指的是一个channnel上,一次采样的bit数(常见的sample bit 8/16/24/32bits)
3.frame
When we talk about working with digital audio, we often want to talk about the data that represents all channels at a single point in time. This is a collection of samples, one per channel, and is generally called a "frame". When we talk about the passage of time in terms of frames, its roughly equivalent to what people when they measure in terms of samples, but is more accurate; more importantly, when we're talking about the amount of data needed to represent all the channels at a point in time, its the only unit that makes sense.
一个frame是一次采样时所有channel上的sample bit.即frame = channels * (sample bit).
4.peroid
A period is the number of frames in between each hardware interrupt.
每当hardware buffer 中有peroid size个frame的空间时,硬件就产生中断,来通知alsa driver来往硬件写数据。
5.buffer size
This determines how large the hardware buffer is.
hardware buffer size 是由多个peroid组成。buffer size = peroid size * peroids。
6.Data access and layout
interleaveda: data layout arrangement where the samples of each channel that will be played at the same time follow each other sequentially. See "non-interleaved"
non-interleaveda: data layout where the samples for a single channel follow each other sequentially; samples for another channel are either in another buffer or another part of this buffer. Contrast with "interleaved"
在一个period以内(interleaved和non-interleaved是在一个period里面排),数据是按照channel1排完了再排channel2呢,还是一个frame一个frame的来排(frame在alsa里指的是一次采样时间内,两个channel的数据放一块儿就是一个frame)上图是interleaved。
7.Hardware parameter
These are parameters that directly affect the hardware of the audio interface.
Hardware parameter是作用于声卡硬件的,包括sample rate, sample format, interupt intervals, data access and layout, buffer size.
8.Software parameter
These are parameters that control the operation of the device driver rather than the hardware itself. Most programs that use the ALSA Audio API will not need to set any of these; a few will need set a subset of them.
software parameter 是作用于alsa core的。通常用来控制When to start the device, what to do about xruns, Available minimum space/data for wakeup,Transfer chunk size.
8.1 When to start the device
When you open the audio interface, ALSA ensures that it is not active - no data is being moved to or from its external connectors. Presumably, at some point you want this data transfer to begin. There are several options for how to make this happen.
The control point here the start threshold, which defines the number of frames of space/data necessary to start the device automatically. If set to some value other than zero for playback, it is necessary to prefill the playback buffer before the device will start. If set to zero, the first data written to the device (or first attempt to read from a capture stream) will start the device.
You can also start the device explicitly using snd_pcm_start
, but this requires buffer prefilling in the case of the playback stream. If you attempt to start the stream without doing this, you will get -EPIPE as a return code, indicating that there is no data waiting to deliver to the playback hardware buffer.
我们可以通过API snd_pcm_sw_params_set_start_threshold来设置什么时候开始启动声卡。对于playback,假设第设置start threshold 为320,那么就是说,当用户调用writei,写入的数据,将暂时存在alsa驱动空间里,当这个数据量达到 320帧时,alsa驱动才开始将数据写入hardware buffer,并启动DA转换。
8.2What to do about xruns
If an xrun occurs, the device driver may, if requested, take certain steps to handle it. Options include stopping the device, or silencing all or part of the hardware buffer used for playback.
the stop threshold
if the number of frames of data/space available meets or exceeds this value, the driver will stop the interface.
the silence threshold
if the number of frames of space available for a playback stream meets or exceeds this value, the driver will fill part of the playback hardware buffer with silence.
silence size
when the silence threshold level is met, this determines how many frames of silence are written into the playback hardware buffer
xrun指的是,声卡period一到,引发一个中断,告诉alsa驱动,要填入数据,或读走数据,但是,问题在于alsa的读取和写入操作必须用户调用writei和readi才会发生的,它不会去缓存数据。如果上层没有用户调用writei和readi,那么就会产生 overrun(录制时,数据都满了,还没被alsa驱动读走)和underrun(需要数据来播放,alsa驱动却不写入数据),统称为xrun。
当xrun发生时,可以在空余空间超过stop threshold时,stop audio interface.
也可以通过设置silence threshold,当空余空间超过silence threshold时,就hardware buffer 写入silence.
8.3 Available minimum space/data for wakeup
Programs that use poll(2)
or select(2)
to determine when audio data may be transferred to/from the interface may set this to control at what point relative to the state of the hardware buffer, they wish to be woken up.
这个software parameters仅用在interrupt-driven模式。这个模式是alsa驱动层的,不是硬件interrupt。它的意思是,用户使用 snd_pcm_wait()时,这个实际封装的是系统的poll调用,表示用户在等待,那么在等待什么呢?对于playback来讲,就是等待下面的声卡的hardware buffer里有一定数量的空间,可以放入新的数据了,对于record来讲,就是等待下面声卡新采集的数据达到了一定数量了。这个一定数量,就是用 snd_pcm_sw_params_set_avail_min来设置,单位是frame。
8.4 Transfer chunk size
this determines the number of frames used when transferring data to/from the device hardware buffer.
ALSA lib cross compile:
http://blog.sina.com.cn/s/blog_7d7e9d0f0101lqlp.html
ALSA lib基本概念的更多相关文章
- ALSA lib编译
http://blog.sina.com.cn/s/blog_7d7e9d0f0101lqlp.html alsa lib: #!bin/sh rm -rf ./output/* mkdir -p ...
- ALSA lib调用实例
1. Display Some PCM Types and Formats 2. Opening PCM Device and Setting Parameters /* This example o ...
- ALSA driver基本概念
https://blog.csdn.net/zyuanyun/article/details/59180272#t6 1.Card For each soundcard, a “card” recor ...
- ALSA 学习小记
对于playback snd_pcm_begin snd_pcm_commit, 貌似 commit给的frame才会使得alsa去把数据填充 转自 http://magodo.github.io/ ...
- linux alsa pcm(此pcm非硬件pcm接口)
转:https://blog.csdn.net/crycheng/article/details/7095899 CODEC :音频芯片的控制,比如静音.打开(关闭)ADC(DAC).设置ADC(DA ...
- 基于ALSA的WAV播放和录音程序
http://blog.csdn.net/azloong/article/details/6140824 这段时间在探索ALSA架构,从ALSA Core到ALSA Lib,再到Android Aud ...
- 关于vs的lib文件和dll文件
一.LIB文件概念 一个lib文件是obj文件的集合.当然,其中还夹杂着其他一些辅助信息,目的是为了让编译器能够准确找到对应的obj文件 二.与DLL的区别 (1)lib是编译时需要的,dll是运行时 ...
- 36、ALSA声卡驱动和应用
(注意:内核上电的时候会把一些没运行的控制器模块的时钟都关掉,所有在写驱动的时候需要在使用的使用使用clk_get和clk_enable使能时钟) (说明:与ALSA声卡对应的是OSS架构,第二期视频 ...
- ALSA driver --PCM 实例创建过程
前面已经写过PCM 实例的创建框架,我们现在来看看PCM 实例是如何创建的. 在调用snd_pcm_new时就会创建一个snd_pcm类型的PCM 实例. struct snd_pcm { struc ...
随机推荐
- 安装python3.7.4时报错:Service Pack 1 is required to continue installation
python3.7.4安装失败:Service Pack 1 is required to continue installation 解决办法: 点击报错页面中的“log file”,日志最后一行显 ...
- 复选框与bitmap算法实践
bitmap(位图)算法 bitmap算法是利用数据二进制的每一位的值来表示数据的算法,可用来压缩保存数据集. 如何保存 如 5(int)的二进制表示为 101b,第一位和第三位的值是1就可以表示数据 ...
- 巨杉Tech | 使用 SequoiaDB + Docker + Nodejs 搭建 Web 服务器
容器化技术的出现大大简化了应用开发人员在构建底层基础设施的工作.SequoiaDB 巨杉数据库于3.2.1版本正式推出了 Docker 容器化部署方案,本文将会基于 SequoiaDB 巨杉数据库与N ...
- jdk8-》lambda
lambda表达式 使⽤场景(前提):⼀个接⼝中只包含⼀个⽅法,则可以使⽤Lambda表达式,这样的接⼝称之为“函数接⼝” 语法: (params) -> expression 第⼀部分为括 ...
- 牛客CSP-S提高组赛前集训营2 赛后总结
比赛链接 A.服务器需求 维护每天需要的服务器数量的全局最大值(记为\(Max\))和总和(记为\(sum\)),那么答案为: \[max(Max,\lceil\dfrac{sum}{m}\rceil ...
- 读书笔记 (.NET企业级应用架构设计)
建议你自己和别人多沟通(学会沟通会使你在公司更好的发展,有意见就提,有问题就问,有困难就说)加油lxp 1.架构师是用来干嘛的: 架构师分析需求,分析系统要去做什么,架构怎么去做 2.架构师的职责是: ...
- Mybatis-对数据库的关联查询
由于MyBatis逆向工程生成的代码只能进行对单表的操作(功能已经很强大了),但是远远不能满足开发的需要,下面就简单讲解下MyBatis进行关联查询的简单案例. 一.一对一关联查询 1 ...
- spring项目中 通过自定义applicationContext工具类获取到applicationContext上下文对象
spring项目在服务器启动的时候 spring容器中就已经被创建好了各种对象,在我们需要使用的时候可以进行调用. 工具类代码如下 import org.springframework.beans.B ...
- 题解 P1203 【[USACO1.1]坏掉的项链Broken Necklace】
[USACO1.1]坏掉的项链Broken Necklace 22892 破碎的项链 方法一:很容易想到枚举断点,再分别两头找,但是要注意很多细节 #include<iostream> # ...
- SpringBoot整合WEB开发--(二)静态资源访问
1.默认策略: 静态资源的位置一共5个,开发者可以将静态资源放到其中任意一个,分别是: "classpath:/META-INF/resources/", "classp ...