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

TDStretch类的实现

SoundTouch类成员函数putSamples(const SAMPLETYPE *samples, uint nSamples)实现如下,根据上篇的分析rate是一个比率,大于1表示速度加快,小于1表示速度减慢,对于播放速度减慢这种情况。

……

#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);

    }

……

先通过pRateTransposer->putSamples(samples, nSamples);对声音进行了重采样,采用的是线性插值法,然后调用pTDStretch->moveSamples(*pRateTransposer);pTDStretchTDStretch类的实例。TDStretch类定义如下:

/// Class that does the time-stretch (tempo change) effect for the processed

/// sound.

class TDStretch : public FIFOProcessor

{

protected:

    int channels;

    int sampleReq;

    float tempo;

 

    SAMPLETYPE *pMidBuffer;

    SAMPLETYPE *pRefMidBuffer;

    SAMPLETYPE *pRefMidBufferUnaligned;

    int overlapLength;

    int seekLength;

    int seekWindowLength;

    int overlapDividerBits;

    int slopingDivider;

    float nominalSkip;

    float skipFract;

    FIFOSampleBuffer outputBuffer;

    FIFOSampleBuffer inputBuffer;

    BOOL bQuickSeek;

//    int outDebt;

//    BOOL bMidBufferDirty;

 

    int sampleRate;

    int sequenceMs;

    int seekWindowMs;

    int overlapMs;

    BOOL bAutoSeqSetting;

    BOOL bAutoSeekSetting;

 

    void acceptNewOverlapLength(int newOverlapLength);

 

    virtual void clearCrossCorrState();

    void calculateOverlapLength(int overlapMs);

 

    virtual LONG_SAMPLETYPE calcCrossCorrStereo(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;

    virtual LONG_SAMPLETYPE calcCrossCorrMono(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;

 

    virtual int seekBestOverlapPositionStereo(const SAMPLETYPE *refPos);

    virtual int seekBestOverlapPositionStereoQuick(const SAMPLETYPE *refPos);

    virtual int seekBestOverlapPositionMono(const SAMPLETYPE *refPos);

    virtual int seekBestOverlapPositionMonoQuick(const SAMPLETYPE *refPos);

    int seekBestOverlapPosition(const SAMPLETYPE *refPos);

 

    virtual void overlapStereo(SAMPLETYPE *output, const SAMPLETYPE *input) const;

    virtual void overlapMono(SAMPLETYPE *output, const SAMPLETYPE *input) const;

 

    void clearMidBuffer();

    void overlap(SAMPLETYPE *output, const SAMPLETYPE *input, uint ovlPos) const;

 

    void precalcCorrReferenceMono();

    void precalcCorrReferenceStereo();

 

    void calcSeqParameters();

 

    /// Changes the tempo of the given sound samples.

    /// Returns amount of samples returned in the "output" buffer.

    /// The maximum amount of samples that can be returned at a time is set by

    /// the 'set_returnBuffer_size' function.

    void processSamples();

   

public:

    TDStretch();

    virtual ~TDStretch();

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值