1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5 An audio time-stretching and pitch-shifting library.
6 Copyright 2007-2008 Chris Cannam.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
15 #ifndef _RUBBERBAND_STRETCH_CALCULATOR_H_
16 #define _RUBBERBAND_STRETCH_CALCULATOR_H_
18 #include <sys/types.h>
25 class StretchCalculator
28 StretchCalculator(size_t sampleRate, size_t inputIncrement, bool useHardPeaks);
29 virtual ~StretchCalculator();
32 * Calculate phase increments for a region of audio, given the
33 * overall target stretch ratio, input duration in audio samples,
34 * and the audio curves to use for identifying phase lock points
35 * (lockAudioCurve) and for allocating stretches to relatively
36 * less prominent points (stretchAudioCurve).
38 virtual std::vector<int> calculate(double ratio, size_t inputDuration,
39 const std::vector<float> &lockAudioCurve,
40 const std::vector<float> &stretchAudioCurve);
43 * Calculate the phase increment for a single audio block, given
44 * the overall target stretch ratio and the block's value on the
45 * phase-lock audio curve. State is retained between calls in the
46 * StretchCalculator object; call reset() to reset it. This uses
47 * a less sophisticated method than the offline calculate().
49 * If increment is non-zero, use it for the input increment for
50 * this block in preference to m_increment.
52 virtual int calculateSingle(double ratio, float curveValue,
53 size_t increment = 0);
55 void setUseHardPeaks(bool use) { m_useHardPeaks = use; }
59 void setDebugLevel(int level) { m_debugLevel = level; }
65 std::vector<Peak> getLastCalculatedPeaks() const { return m_lastPeaks; }
67 std::vector<float> smoothDF(const std::vector<float> &df);
70 std::vector<Peak> findPeaks(const std::vector<float> &audioCurve);
72 std::vector<int> distributeRegion(const std::vector<float> ®ionCurve,
73 size_t outputDuration, float ratio,
76 void calculateDisplacements(const std::vector<float> &df,
78 double &totalDisplacement,
79 double &maxDisplacement,
89 int m_transientAmnesty; // only in RT mode; handled differently offline
93 std::vector<Peak> m_lastPeaks;