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。