sox源码分析:sox_init()与sox_quit()

    sox是著名的音频处理开源库,号称音频界的瑞士军刀,被广泛应用于音频处理。在调用sox的API对音频进行处理时,需调用sox_init()初始化sox库的一些全局参数。

sox_init()函数调用关系

在这里插入图片描述

函数源码

init_fft_cache()源码如下,主要负责全局变量的初始化。

static int * lsx_fft_br;
static double * lsx_fft_sc;
static int fft_len = -1;
#if defined HAVE_OPENMP
static ccrw2_t fft_cache_ccrw;
#endif

void init_fft_cache(void)
{
  assert(lsx_fft_br == NULL);
  assert(lsx_fft_sc == NULL);
  assert(fft_len == -1);
  ccrw2_init(fft_cache_ccrw);
  fft_len = 0;
}

ccrw2_init()是一个宏,定义如下,主要负责对结构体fft_cache_ccrw的初始化。

#define ccrw2_init(p) do {\
  omp_init_lock(&p.mutex_1);\
  omp_init_lock(&p.mutex_2);\
  omp_init_lock(&p.mutex_3);\
  omp_init_lock(&p.w);\
  omp_init_lock(&p.r);\
} while (0)

#define omp_init_lock(omp_lock_t) (void)0

fft_cache_ccrw是结构体ccrw2_t的声明,结构体ccrw2_t定义如下,可以看出主要是读、写计数器及相关互斥锁。

typedef struct {
  int readcount, writecount; /* initial value = 0 */
  omp_lock_t mutex_1, mutex_2, mutex_3, w, r; /* initial value = 1 */
} ccrw2_t; /* Problem #2: `writers-preference' */

sox_quit()函数调用关系

在这里插入图片描述
sox_quit(),sox_init()的逆过程,主要负责清理sox库中的全局参数,需要调用sox_format_quit()对格式文件进行清理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值