Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15374746
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2009-11-17 21:37:42

int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
                   struct snd_pcm_plugin_format *src_format,
                   struct snd_pcm_plugin_format *dst_format,
                   struct snd_pcm_plugin **r_plugin)
{
    int err;
    struct mulaw_priv *data;
    struct snd_pcm_plugin *plugin;
    struct snd_pcm_plugin_format *format;
    mulaw_f func;

    if (snd_BUG_ON(!r_plugin))
        return -ENXIO;
    *r_plugin = NULL;

    if (snd_BUG_ON(src_format->rate != dst_format->rate)) // 采样率必须相同
        return -ENXIO;
    if (snd_BUG_ON(src_format->channels != dst_format->channels)) // 声音通道数目必须相同
        return -ENXIO;

    if (dst_format->format == SNDRV_PCM_FORMAT_MU_LAW) {
    // 如果dst目的format为u律, 明显snd_pcm_plug_format_plugins调用的dst为SNDRV_PCM_FORMAT_S16格式
    // 那么src源就是最终func函数需要操作的线性对象[luther.gliethttp]
        format = src_format;
        func = mulaw_encode; // 对应解码函数
    }
    else if (src_format->format == SNDRV_PCM_FORMAT_MU_LAW) {
    // 如果src源format为u律,那么dst目的就是最终func函数需要操作的线性对象[luther.gliethttp]
        format = dst_format;
        func = mulaw_decode; // 对应编码函数
    }
    else {
        snd_BUG();
        return -EINVAL;
    }
    if (snd_BUG_ON(!snd_pcm_format_linear(format->format))) // 确保format为线性
        return -ENXIO;

    err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion",
                   src_format, dst_format, 《浅析alsa声卡驱动snd_pcm_plugin_build函数》
                   sizeof(struct mulaw_priv), &plugin); // 建立并填充src_format和dst_format之间转换的plugin结构体[luther.gliethttp]
    if (err < 0)
        return err;
    data = (struct mulaw_priv *)plugin->extra_data; // 结构体plugin末尾多申请出来的struct mulaw_priv结构体存储空间
    data->func = func;  // 回调处理函数
    init_data(data, format->format);
    plugin->transfer = mulaw_transfer;  // 音频数据传输回调函数
    *r_plugin = plugin;
    return 0;
}
阅读(851) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~