ALSA driver--PCM Interrupt handle
PCM 中断处理函数的主要作用是用来更新buffer position.
在PCM的interrupt handle里面通过snd_pcm_period_elapsed来通知alsa-core buffer position随着peroid的变化。
在声卡中可以有几种类型的中断产生方式:
1.每隔peroid就产生interupt
在这种中断模式下,可以在每次中断是调用snd_pcm_peroid_elapsed. snd_pcm_peroid_elapsed以substream作为参数,因此我们必须要能够在芯片专用数据chip中能够访问到substream,在chip中保存当前正在running的substream.可以在PCM的open 函数中将substream保存到chip(chip作为PCM的private_data)中.
典型的中断处理函数如下:
static irqreturn_t snd_mychip_interrupt(int irq, void *dev_id)
{
struct mychip *chip = dev_id;
spin_lock(&chip->lock);
....
if (pcm_irq_invoked(chip)) {
/* call updater, unlock before it */
spin_unlock(&chip->lock);
snd_pcm_period_elapsed(chip->substream);
spin_lock(&chip->lock);
/* acknowledge the interrupt if necessary */
}
....
spin_unlock(&chip->lock);
return IRQ_HANDLED;
}
2.高频率时间中断(High frequency timer interrupts)
高频率时间中断用在当硬件每隔固定的时间产生中断,而不是每隔peroid产生中断。我们必须在产生中断时检测hardware position,并计算处理的数据长度,当处理的数据长度超过peroid size时,就调用snd_pcm_peroid_elapsed。
static irqreturn_t snd_mychip_interrupt(int irq, void *dev_id)
{
struct mychip *chip = dev_id;
spin_lock(&chip->lock);
....
if (pcm_irq_invoked(chip)) {
unsigned int last_ptr, size;
/* get the current hardware pointer (in frames) */
last_ptr = get_hw_ptr(chip);
/* calculate the processed frames since the
* last update
*/
if (last_ptr < chip->last_ptr)
size = runtime->buffer_size + last_ptr
- chip->last_ptr;
else
size = last_ptr - chip->last_ptr;
/* remember the last updated point */
chip->last_ptr = last_ptr;
/* accumulate the size */
chip->size += size;
/* over the period boundary? */
if (chip->size >= runtime->period_size) {
/* reset the accumulator */
chip->size %= runtime->period_size;
/* call updater */
spin_unlock(&chip->lock);
snd_pcm_period_elapsed(substream);
spin_lock(&chip->lock);
}
/* acknowledge the interrupt if necessary */
}
....
spin_unlock(&chip->lock);
return IRQ_HANDLED;
}
在上面两种中断方式中,如果硬件已经处理了多个peroid size的数据,我们只需要调用一次snd_pcm_peroid_elapsed,alsa core就会去检查hardware position 并更新到最新状态。
ALSA driver--PCM Interrupt handle的更多相关文章
- ALSA driver --PCM 实例创建过程
前面已经写过PCM 实例的创建框架,我们现在来看看PCM 实例是如何创建的. 在调用snd_pcm_new时就会创建一个snd_pcm类型的PCM 实例. struct snd_pcm { struc ...
- Linux ALSA音频PCM播放编程
使用ALSA播放两个频率的单音,并使用GNU Radio中的Audio Source和FFT来观测声音的频谱. #include <alsa/asoundlib.h> #include & ...
- ALSA driver基本概念
https://blog.csdn.net/zyuanyun/article/details/59180272#t6 1.Card For each soundcard, a “card” recor ...
- 内核Alsa之pcm
pcm用来描述alsa中数字音频流.Alsa音频的播放/录制就是通过pcm来实现 的. 名词解释 声音是连续模拟量,计算机将它离散化之后用数字表示,就有了以下几个名词术语. Frame. 帧是音频流中 ...
- 嵌入式开发之davinci--- 8148/8168/8127 中的alsa音频pcm g711 和aac 音频格式
(1)alsa pcm (2)g711 (3)aac (4) --------------author:pkf -------------------time:2-4 ---------------- ...
- Alsa中PCM参数设置⭐⭐
1) PCM设备的句柄.2) 指定同时可供回放或截获的PCM流的方向3) 提供一些关于我们想要使用的设置选项的信息,比如缓冲区大小,采样率,PCM数据格式等4) 检查硬件是否支持设置选项. 4.1 ...
- linux alsa pcm(此pcm非硬件pcm接口)
转:https://blog.csdn.net/crycheng/article/details/7095899 CODEC :音频芯片的控制,比如静音.打开(关闭)ADC(DAC).设置ADC(DA ...
- 【转】Alsa音频编程【精华】
一.前序 这里了解一下各个参数的含义以及一些基本概念. 声音是连续模拟量,计算机将它离散化之后用数字表示,就有了以下几个名词术语. 样本长度(sample):样本是记录音频数据最基本的单位,计算机对每 ...
- Introduction to Sound Programming with ALSA
ALSA stands for the Advanced Linux Sound Architecture. It consists of a set of kernel drivers, an ap ...
随机推荐
- Yaf学习过程中遇到的问题小记
一.在多模块开发过程中,先写了后台模块,即一开始默认的Index Module,之后新增Frontend,Wap模块,想要直接把Frontend模块设置成默认模块,然而setDefaultModule ...
- 常见通用框架的理解(Redis,Zookeeper,Thrift)
redis 主要功能是内存版的Hashta zookeeper 主要功能是分布式中的全局变量. thrift 跨平台的Client和Server通信架构. taskengine用于启动定时任务和查看 ...
- Jmeter-简介及安装
一.Jmeter简介 Apache Jmeter 是Apache组织的开放源代码项目,是一个纯java桌面应用,用于压力测试和性能测量.它最初被设计用于Web应用测试但后来扩展到其它测试领域. Apa ...
- 虚拟磁盘VHD文件压缩方法
问题描述 因工作需要在Mac上跑了一个VirtualBox虚拟win7,使用对win系统友好的vhd格式作为虚拟硬盘.经过一段时间使用发现vhd占用空间远大于虚拟磁盘使用量,想办法减减肥才行. 步骤整 ...
- Pycharm操作数据库
Pymysql 用于连接mysql数据库 连接数据库 data_ip = "192.168.34.128" data_name = "lch" data_pwd ...
- orm 相关
优化
- python算术
''' 1.对每个数进行平方, 2.求和 ''' print(sum(x ** 2 for x in range(4)))
- 谷歌浏览器安装apizza
接口测试是卡发中不可缺少的一环,那么常用的postman是英文就很不方便一些小伙伴的使用,所以此工具和postman功能相同且升级并且是中文模式 安装: 链接:https://pan.baidu.co ...
- 网易云信Duilib开发实践和Windows应用界面开发框架源码开源介绍
序言 Duilib介绍 Duilib是windows平台下的一款轻量级directUI开源库(遵循BSD协议),完全免费,可用于商业软件开发,只需在软件包里附上协议文件即可.Duilib可以简单方便地 ...
- MySQL加号+ 的作用
案例:查询员工名和员工姓,连接成一个字段,并显示为: 姓名 SELECT last_name+first_name AS 姓名 FROM employees;没有报错但姓名一下全是0 Java中的 + ...