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的更多相关文章

  1. ALSA driver --PCM 实例创建过程

    前面已经写过PCM 实例的创建框架,我们现在来看看PCM 实例是如何创建的. 在调用snd_pcm_new时就会创建一个snd_pcm类型的PCM 实例. struct snd_pcm { struc ...

  2. Linux ALSA音频PCM播放编程

    使用ALSA播放两个频率的单音,并使用GNU Radio中的Audio Source和FFT来观测声音的频谱. #include <alsa/asoundlib.h> #include & ...

  3. ALSA driver基本概念

    https://blog.csdn.net/zyuanyun/article/details/59180272#t6 1.Card For each soundcard, a “card” recor ...

  4. 内核Alsa之pcm

    pcm用来描述alsa中数字音频流.Alsa音频的播放/录制就是通过pcm来实现 的. 名词解释 声音是连续模拟量,计算机将它离散化之后用数字表示,就有了以下几个名词术语. Frame. 帧是音频流中 ...

  5. 嵌入式开发之davinci--- 8148/8168/8127 中的alsa音频pcm g711 和aac 音频格式

    (1)alsa pcm (2)g711 (3)aac (4) --------------author:pkf -------------------time:2-4 ---------------- ...

  6. Alsa中PCM参数设置⭐⭐

    1) PCM设备的句柄.2) 指定同时可供回放或截获的PCM流的方向3) 提供一些关于我们想要使用的设置选项的信息,比如缓冲区大小,采样率,PCM数据格式等4) 检查硬件是否支持设置选项.   4.1 ...

  7. linux alsa pcm(此pcm非硬件pcm接口)

    转:https://blog.csdn.net/crycheng/article/details/7095899 CODEC :音频芯片的控制,比如静音.打开(关闭)ADC(DAC).设置ADC(DA ...

  8. 【转】Alsa音频编程【精华】

    一.前序 这里了解一下各个参数的含义以及一些基本概念. 声音是连续模拟量,计算机将它离散化之后用数字表示,就有了以下几个名词术语. 样本长度(sample):样本是记录音频数据最基本的单位,计算机对每 ...

  9. Introduction to Sound Programming with ALSA

    ALSA stands for the Advanced Linux Sound Architecture. It consists of a set of kernel drivers, an ap ...

随机推荐

  1. [HNOI2003] 消防局的设立 - 树形dp

    仍然是点覆盖集问题,但覆盖半径变成了\(2\) 延续上一题的思路,只是式子更加复杂了 想体验一下min_element大法于是不想优化了 #include <bits/stdc++.h> ...

  2. CTF——代码审计之变量覆盖漏洞writeup【2】

    题目: 基础: 所需基础知识见变量覆盖漏洞[1]  分析: 现在的$a=’hi’,而下面的函数需满足$a=’jaivy’才可以输出flag,那么需要做的事就是想办法覆盖掉$a原来的值. 那么出现的提示 ...

  3. P3391 【模板】文艺平衡树

    模板题 link Splay 区间翻转,存个代码 旋转时,要注意goal是引用 , 并记得修改 , 有标记的一定记得标记下放 , 还有清空 #include<iostream> #incl ...

  4. 7.Springboot之web开发

    自用 要解决的问题: 1.导入静态资源(html之类的(webapp)) 2.首页 3.没有写Jsp的地方-------->所以要学模板引擎Thymeleaf 4.装配扩展springmvc 5 ...

  5. 广度优先搜索(Breadth First Search, BFS)

    广度优先搜索(Breadth First Search, BFS) BFS算法实现的一般思路为: // BFS void BFS(int s){ queue<int> q; // 定义一个 ...

  6. Jarvis OJ - 栈系列部分pwn - Writeup

    最近做了Jarvis OJ的一部分pwn题,收获颇丰,现在这里简单记录一下exp,分析过程和思路以后再补上 Tell Me Something 此题与level0类似,请参考level0的writeu ...

  7. 神舟战神笔记本使用U盘重装系统

    今天我的神舟战神笔记本电脑系统故障了,在这里记录一下使用U盘重装系统的方法: 1.插入装机U盘. 2.按开机键,然后马上按Esc键. 3.选择Boot Manager进入. 4.选择EFI USB D ...

  8. MonoBehaviour单例的另外一种省事的写法

    using UnityEngine; public class CommSystem: SingletonGeneric<CommSystem> { public static strin ...

  9. IDEA常用操作链接

    idea中svn的提交.更新等操作 https://jingyan.baidu.com/article/375c8e19e3c47a25f3a22955.html Idea 部署SVN详细步骤以及上传 ...

  10. AcWing 790. 数的三次方根

    #include<bits/stdc++.h> using namespace std ; int main(){ double x; cin>>x; ,r=; ) { ; i ...