sox源码分析:sox_create_effect()

sox_create_effect()主要是创建一个效果器结构体sox_effect_t 并初始化,该结构体的核心处理单元是通过sox_find_effect()返回的效果器句柄。该函数源码如下

sox_effect_t * sox_create_effect(sox_effect_handler_t const * eh)
{
  sox_effect_t * effp = lsx_calloc(1, sizeof(*effp));
  effp->obuf = NULL;

  effp->global_info = sox_get_effects_globals();
  effp->handler = *eh;
  if (!effp->handler.getopts) effp->handler.getopts = default_getopts;
  if (!effp->handler.start  ) effp->handler.start   = default_function;
  if (!effp->handler.flow   ) effp->handler.flow    = lsx_flow_copy;
  if (!effp->handler.drain  ) effp->handler.drain   = default_drain;
  if (!effp->handler.stop   ) effp->handler.stop    = default_function;
  if (!effp->handler.kill   ) effp->handler.kill    = default_function;

  effp->priv = lsx_calloc(1, effp->handler.priv_size);

  return effp;
} /* sox_create_effect */

结构体sox_effect_t 贯穿整个效果器处理过程,关键核心是结构体sox_effect_handler_t 。
该结构体具体定义如下

struct sox_effect_handler_t {
  char const * name;  /**< Effect name */
  char const * usage; /**< Short explanation of parameters accepted by effect */
  unsigned int flags; /**< Combination of SOX_EFF_* flags */
  sox_effect_handler_getopts getopts; /**< Called to parse command-line arguments (called once per effect). */
  sox_effect_handler_start start;     /**< Called to initialize effect (called once per flow). */
  sox_effect_handler_flow flow;       /**< Called to process samples. */
  sox_effect_handler_drain drain;     /**< Called to finish getting output after input is complete. */
  sox_effect_handler_stop stop;       /**< Called to shut down effect (called once per flow). */
  sox_effect_handler_kill kill;       /**< Called to shut down effect (called once per effect). */
  size_t       priv_size;             /**< Size of private data SoX should pre-allocate for effect */
};

重要的参数说明
char const * name:主要用来匹配对应的效果器接口
char const * usage:帮助信息
sox_effect_handler_getopts getopts:解析命令行参数接口
sox_effect_handler_start start:初始化效果器
sox_effect_handler_flow flow:具体的处理数据操作
sox_effect_handler_drain drain:获取输出结果
sox_effect_handler_stop stop:停止处理数据
sox_effect_handler_kill kill:释放效果器
size_t priv_size:数据空间大小

每个效果器作用于一个输入流和一个输出流,处理过程大致可以划分6个处理功能,具体的调用流程图如下
在这里插入图片描述
注意:有些处理函数不是必须的,可以为NULL。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值