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. blob - 二进制文件流下载

    /** * 返回值文件类型为 blob 二进制流文件 * responseType: 'blob' * params 接口所需参数 * 命名文件名:依据时间戳命名文件名 * (导出时需要延迟,否则导出 ...

  2. AcWing 1016. 最大上升子序列和

    #include<iostream> using namespace std ; ; int f[N]; int a[N]; int main() { int n; cin>> ...

  3. 2019牛客多校第五场 G subsequence 1 dp+组合数学

    subsequence 1 题意 给出两个数字串s,t,求s的子序列中在数值上大于t串的数量 分析 数字大于另一个数字,要么位数多,要么位数相同,字典序大,位数多可以很方便地用组合数学来解决,所以只剩 ...

  4. 数据库 oracle 函数

    static OracleConnection mQracleConnecting = null; public static OracleConnection QracleConnecting { ...

  5. js 时间延迟

    dojosetTimeout(dojo.hitch(this, function(){ this.onClickCount(); }), 3000); 普通应用在js中,延迟执行函数有两种,setTi ...

  6. Oracle允许IP访问配置

    http://www.linuxidc.com/Linux/2014-10/108650.htm 1.oracle服务器下/opt/app/oracle/product/11.2.0/network/ ...

  7. Unity中常用的数据结构总结

    本篇博文对U3D经常用到的数据结构和各种数据结构的应用场景总结下. 1.几种常见的数据结构 这里主要总结下在工作中常碰到的几种数据结构:Array,ArrayList,List<T>,Li ...

  8. 消息中间件之ActiveMQ

    一.什么是消息中间件(MQ) 1.1 为什么会需要消息队列(MQ)? 主要原因是由于在高并发环境下,由于来不及同步处理,请求往往会发生堵塞,比如说,大量的insert,update之类的请求同时到达M ...

  9. 面试题:HashSet、TreeSet 和HashMap 的实现与原理

    说下 TreeSet 和 HashSet 什么区别呢? 它们的区别点主要在他们的底层数据结构不同,HashSet 使用的是 HashMap 来实现,而 TreeSet 使用的是 TreeMap 来实现 ...

  10. vue插槽(slot)的模板与JSX写法

    vue官网API: 插槽:https://cn.vuejs.org/v2/guide/components-slots.html JSX:https://cn.vuejs.org/v2/guide/r ...