SoundTouch音频处理库源码分析及算法提取(5)

变速类RateTransposer的实现

回到SoundTouch类成员函数void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)。定义一个SoundTouch类变量之后,通过简单地调用这个类函数,就可以实现音频的相关处理。分析一下他的调用形式,也很简单,第一个参数SAMPLETYPE *samples,指向一个以PCM编码的wave数据缓冲区,第二个参数uint nSamples,就是这个数据缓冲区包含的Sample个数,前面已经讨论过这个Sample的计算方法,这里就不再累述。

先看一下他的实现:

// Adds 'numSamples' pcs of samples from the 'samples' memory position into

// the input of the object.

void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)

{

    if (bSrateSet == FALSE)

    {

        throw std::runtime_error("SoundTouch : Sample rate not defined");

    }

    else if (channels == 0)

    {

        throw std::runtime_error("SoundTouch : Number of channels not defined");

    }

#ifndef PREVENT_CLICK_AT_RATE_CROSSOVER

    else if (rate <= 1.0f)

    {

        // transpose the rate down, output the transposed sound to tempo changer buffer

        assert(output == pTDStretch);

        pRateTransposer->putSamples(samples, nSamples);

        pTDStretch->moveSamples(*pRateTransposer);

    }

    else

#endif

    {

        // evaluate the tempo changer, then transpose the rate up,

        assert(output == pRateTransposer);

        pTDStretch->putSamples(samples, nSamples);

        pRateTransposer->moveSamples(*pTDStretch);

    }

}

前面大致上可以看做是判断SoundTouch类初始化过程是否顺利,重点我们看一下

#ifndef PREVENT_CLICK_AT_RATE_CROSSOVER

    else if (rate <= 1.0f)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值