RubberBand::RubberBandStretcher Class Reference

#include <RubberBandStretcher.h>

Inheritance diagram for RubberBand::RubberBandStretcher:

Inheritance graph
[legend]

List of all members.


Detailed Description

Definition at line 32 of file RubberBandStretcher.h.


Public Types

typedef int Options
 Processing options for the timestretcher.

Public Member Functions

 RubberBandStretcher (size_t sampleRate, size_t channels, Options options=DefaultOptions, double initialTimeRatio=1.0, double initialPitchScale=1.0)
 Construct a time and pitch stretcher object to run at the given sample rate, with the given number of channels.
virtual ~RubberBandStretcher ()
virtual void reset ()
 Reset the stretcher's internal buffers.
virtual void setTimeRatio (double ratio)
 Set the time ratio for the stretcher.
virtual void setPitchScale (double scale)
 Set the pitch scaling ratio for the stretcher.
virtual double getTimeRatio () const
 Return the last time ratio value that was set (either on construction or with setTimeRatio()).
virtual double getPitchScale () const
 Return the last pitch scaling ratio value that was set (either on construction or with setPitchScale()).
virtual size_t getLatency () const
 Return the processing latency of the stretcher.
virtual void setTransientsOption (Options options)
 Change an OptionTransients configuration setting.
virtual void setPhaseOption (Options options)
 Change an OptionPhase configuration setting.
virtual void setExpectedInputDuration (size_t samples)
 Tell the stretcher exactly how many input samples it will receive.
virtual size_t getSamplesRequired () const
 Ask the stretcher how many audio sample frames should be provided as input in order to ensure that some more output becomes available.
virtual void setMaxProcessSize (size_t samples)
 Tell the stretcher the maximum number of sample frames that you will ever be passing in to a single process() call.
virtual void study (const float *const *input, size_t samples, bool final)
 Provide a block of "samples" sample frames for the stretcher to study and calculate a stretch profile from.
virtual void process (const float *const *input, size_t samples, bool final)
 Provide a block of "samples" sample frames for processing.
virtual int available () const
 Ask the stretcher how many audio sample frames of output data are available for reading (via retrieve()).
virtual size_t retrieve (float *const *output, size_t samples) const
 Obtain some processed output data from the stretcher.
virtual float getFrequencyCutoff (int n) const
 Return the value of internal frequency cutoff value n.
virtual void setFrequencyCutoff (int n, float f)
 Set the value of internal frequency cutoff n to f Hz.
virtual size_t getInputIncrement () const
 Retrieve the value of the internal input block increment value.
virtual std::vector
< int > 
getOutputIncrements () const
 In offline mode, retrieve the sequence of internal block increments for output, for the entire audio data, provided the stretch profile has been calculated.
virtual std::vector
< float > 
getPhaseResetCurve () const
 In offline mode, retrieve the sequence of internal phase reset detection function values, for the entire audio data, provided the stretch profile has been calculated.
virtual std::vector
< int > 
getExactTimePoints () const
 In offline mode, retrieve the sequence of internal frames for which exact timing has been sought, for the entire audio data, provided the stretch profile has been calculated.
virtual size_t getChannelCount () const
 Return the number of channels this stretcher was constructed with.
virtual void calculateStretch ()
 Force the stretcher to calculate a stretch profile.
virtual void setDebugLevel (int level)
 Set the level of debug output.

Static Public Member Functions

static void setDefaultDebugLevel (int level)
 Set the default level of debug output for subsequently constructed stretchers.

Static Public Attributes

static const int OptionProcessOffline = 0x00000000
static const int OptionProcessRealTime = 0x00000001
static const int OptionStretchElastic = 0x00000000
static const int OptionStretchPrecise = 0x00000010
static const int OptionTransientsCrisp = 0x00000000
static const int OptionTransientsMixed = 0x00000100
static const int OptionTransientsSmooth = 0x00000200
static const int OptionPhaseAdaptive = 0x00000000
static const int OptionPhasePeakLocked = 0x00001000
static const int OptionPhaseIndependent = 0x00002000
static const int OptionThreadingAuto = 0x00000000
static const int OptionThreadingNever = 0x00010000
static const int OptionThreadingAlways = 0x00020000
static const int OptionWindowStandard = 0x00000000
static const int OptionWindowShort = 0x00100000
static const int OptionWindowLong = 0x00200000
static const int DefaultOptions = 0x00000000
static const int PercussiveOptions

Protected Attributes

Impl * m_d
size_t m_sampleRate
size_t m_channels

Member Typedef Documentation

typedef int RubberBand::RubberBandStretcher::Options

Processing options for the timestretcher.

The preferred options should normally be set in the constructor, as a bitwise OR of the option flags. The default value (DefaultOptions) is intended to give good results in most situations.

1. Flags prefixed OptionProcess determine how the timestretcher will be invoked. These options may not be changed after construction.

The Process setting is likely to depend on your architecture: non-real-time operation on seekable files: Offline; real-time or streaming operation: RealTime.

2. Flags prefixed OptionStretch control the profile used for variable timestretching. Rubber Band always adjusts the stretch profile to minimise stretching of busy broadband transient sounds, but the degree to which it does so is adjustable. These options may not be changed after construction.

3. Flags prefixed OptionTransients control the component frequency phase-reset mechanism that may be used at transient points to provide clarity and realism to percussion and other significant transient sounds. These options may be changed after construction when running in real-time mode, but not when running in offline mode.

4. Flags prefixed OptionPhase control the adjustment of component frequency phases from one analysis window to the next during non-transient segments. These options may be changed at any time.

5. Flags prefixed OptionThreading control the threading model of the stretcher. These options may not be changed after construction.

6. Flags prefixed OptionWindow control the window size for FFT processing. The window size actually used will depend on many factors, but it can be influenced. These options may not be changed after construction.

Definition at line 162 of file RubberBandStretcher.h.


Constructor & Destructor Documentation

RubberBand::RubberBandStretcher::RubberBandStretcher ( size_t  sampleRate,
size_t  channels,
Options  options = DefaultOptions,
double  initialTimeRatio = 1.0,
double  initialPitchScale = 1.0 
)

Construct a time and pitch stretcher object to run at the given sample rate, with the given number of channels.

Processing options and the time and pitch scaling ratios may be provided. The time and pitch ratios may be changed after construction, but most of the options may not. See the option documentation above for more details.

virtual RubberBand::RubberBandStretcher::~RubberBandStretcher (  )  [virtual]


Member Function Documentation

virtual void RubberBand::RubberBandStretcher::reset (  )  [virtual]

Reset the stretcher's internal buffers.

The stretcher should subsequently behave as if it had just been constructed (although retaining the current time and pitch ratio).

Implements RubberBand::TimeStretcher.

virtual void RubberBand::RubberBandStretcher::setTimeRatio ( double  ratio  )  [virtual]

Set the time ratio for the stretcher.

This is the ratio of stretched to unstretched duration -- not tempo. For example, a ratio of 2.0 would make the audio twice as long (i.e. halve the tempo); 0.5 would make it half as long (i.e. double the tempo); 1.0 would leave the duration unaffected.

If the stretcher was constructed in Offline mode, the time ratio is fixed throughout operation; this function may be called any number of times between construction (or a call to reset()) and the first call to study() or process(), but may not be called after study() or process() has been called.

If the stretcher was constructed in RealTime mode, the time ratio may be varied during operation; this function may be called at any time, so long as it is not called concurrently with process(). You should either call this function from the same thread as process(), or provide your own mutex or similar mechanism to ensure that setTimeRatio and process() cannot be run at once (there is no internal mutex for this purpose).

Implements RubberBand::TimeStretcher.

virtual void RubberBand::RubberBandStretcher::setPitchScale ( double  scale  )  [virtual]

Set the pitch scaling ratio for the stretcher.

This is the ratio of target frequency to source frequency. For example, a ratio of 2.0 would shift up by one octave; 0.5 down by one octave; or 1.0 leave the pitch unaffected.

To put this in musical terms, a pitch scaling ratio corresponding to a shift of S equal-tempered semitones (where S is positive for an upwards shift and negative for downwards) is pow(2.0, S / 12.0).

If the stretcher was constructed in Offline mode, the pitch scaling ratio is fixed throughout operation; this function may be called any number of times between construction (or a call to reset()) and the first call to study() or process(), but may not be called after study() or process() has been called.

If the stretcher was constructed in RealTime mode, the pitch scaling ratio may be varied during operation; this function may be called at any time, so long as it is not called concurrently with process(). You should either call this function from the same thread as process(), or provide your own mutex or similar mechanism to ensure that setPitchScale and process() cannot be run at once (there is no internal mutex for this purpose).

Implements RubberBand::TimeStretcher.

virtual double RubberBand::RubberBandStretcher::getTimeRatio (  )  const [virtual]

Return the last time ratio value that was set (either on construction or with setTimeRatio()).

virtual double RubberBand::RubberBandStretcher::getPitchScale (  )  const [virtual]

Return the last pitch scaling ratio value that was set (either on construction or with setPitchScale()).

virtual size_t RubberBand::RubberBandStretcher::getLatency (  )  const [virtual]

Return the processing latency of the stretcher.

This is the number of audio samples that one would have to discard at the start of the output in order to ensure that the resulting audio aligned with the input audio at the start. In Offline mode, latency is automatically adjusted for and the result is zero. In RealTime mode, the latency may depend on the time and pitch ratio and other options.

Implements RubberBand::TimeStretcher.

virtual void RubberBand::RubberBandStretcher::setTransientsOption ( Options  options  )  [virtual]

Change an OptionTransients configuration setting.

This may be called at any time in RealTime mode. It may not be called in Offline mode (for which the transients option is fixed on construction).

virtual void RubberBand::RubberBandStretcher::setPhaseOption ( Options  options  )  [virtual]

Change an OptionPhase configuration setting.

This may be called at any time in any mode.

Note that if running multi-threaded in Offline mode, the change may not take effect immediately if processing is already under way when this function is called.

virtual void RubberBand::RubberBandStretcher::setExpectedInputDuration ( size_t  samples  )  [virtual]

Tell the stretcher exactly how many input samples it will receive.

This is only useful in Offline mode, when it allows the stretcher to ensure that the number of output samples is exactly correct. In RealTime mode no such guarantee is possible and this value is ignored.

virtual size_t RubberBand::RubberBandStretcher::getSamplesRequired (  )  const [virtual]

Ask the stretcher how many audio sample frames should be provided as input in order to ensure that some more output becomes available.

Normal usage consists of querying this function, providing that number of samples to process(), reading the output using available() and retrieve(), and then repeating.

Note that this value is only relevant to process(), not to study() (to which you may pass any number of samples at a time, and from which there is no output).

Implements RubberBand::TimeStretcher.

virtual void RubberBand::RubberBandStretcher::setMaxProcessSize ( size_t  samples  )  [virtual]

Tell the stretcher the maximum number of sample frames that you will ever be passing in to a single process() call.

If you don't call this function, the stretcher will assume that you never pass in more samples than getSamplesRequired() suggested you should. You should not pass in more samples than that unless you have called setMaxProcessSize first.

This function may not be called after the first call to study() or process().

Note that this value is only relevant to process(), not to study() (to which you may pass any number of samples at a time, and from which there is no output).

virtual void RubberBand::RubberBandStretcher::study ( const float *const *  input,
size_t  samples,
bool  final 
) [virtual]

Provide a block of "samples" sample frames for the stretcher to study and calculate a stretch profile from.

This is only meaningful in Offline mode, and is required if running in that mode. You should pass the entire input through study() before any process() calls are made, as a sequence of blocks in individual study() calls, or as a single large block.

"input" should point to de-interleaved audio data with one float array per channel. "samples" supplies the number of audio sample frames available in "input". If "samples" is zero, "input" may be NULL.

Set "final" to true if this is the last block of data that will be provided to study() before the first process() call.

Implements RubberBand::TimeStretcher.

virtual void RubberBand::RubberBandStretcher::process ( const float *const *  input,
size_t  samples,
bool  final 
) [virtual]

Provide a block of "samples" sample frames for processing.

See also getSamplesRequired() and setMaxProcessSize().

Set "final" to true if this is the last block of input data.

Implements RubberBand::TimeStretcher.

virtual int RubberBand::RubberBandStretcher::available (  )  const [virtual]

Ask the stretcher how many audio sample frames of output data are available for reading (via retrieve()).

This function returns 0 if no frames are available: this usually means more input data needs to be provided, but if the stretcher is running in threaded mode it may just mean that not enough data has yet been processed. Call getSamplesRequired() to discover whether more input is needed.

This function returns -1 if all data has been fully processed and all output read, and the stretch process is now finished.

Implements RubberBand::TimeStretcher.

virtual size_t RubberBand::RubberBandStretcher::retrieve ( float *const *  output,
size_t  samples 
) const [virtual]

Obtain some processed output data from the stretcher.

Up to "samples" samples will be stored in the output arrays (one per channel for de-interleaved audio data) pointed to by "output". The return value is the actual number of sample frames retrieved.

Implements RubberBand::TimeStretcher.

virtual float RubberBand::RubberBandStretcher::getFrequencyCutoff ( int  n  )  const [virtual]

Return the value of internal frequency cutoff value n.

This function is not for general use.

virtual void RubberBand::RubberBandStretcher::setFrequencyCutoff ( int  n,
float  f 
) [virtual]

Set the value of internal frequency cutoff n to f Hz.

This function is not for general use.

virtual size_t RubberBand::RubberBandStretcher::getInputIncrement (  )  const [virtual]

Retrieve the value of the internal input block increment value.

This function is provided for diagnostic purposes only.

virtual std::vector<int> RubberBand::RubberBandStretcher::getOutputIncrements (  )  const [virtual]

In offline mode, retrieve the sequence of internal block increments for output, for the entire audio data, provided the stretch profile has been calculated.

In realtime mode, retrieve any output increments that have accumulated since the last call to getOutputIncrements, to a limit of 16.

This function is provided for diagnostic purposes only.

virtual std::vector<float> RubberBand::RubberBandStretcher::getPhaseResetCurve (  )  const [virtual]

In offline mode, retrieve the sequence of internal phase reset detection function values, for the entire audio data, provided the stretch profile has been calculated.

In realtime mode, retrieve any phase reset points that have accumulated since the last call to getPhaseResetCurve, to a limit of 16.

This function is provided for diagnostic purposes only.

virtual std::vector<int> RubberBand::RubberBandStretcher::getExactTimePoints (  )  const [virtual]

In offline mode, retrieve the sequence of internal frames for which exact timing has been sought, for the entire audio data, provided the stretch profile has been calculated.

In realtime mode, return an empty sequence.

This function is provided for diagnostic purposes only.

virtual size_t RubberBand::RubberBandStretcher::getChannelCount (  )  const [virtual]

Return the number of channels this stretcher was constructed with.

virtual void RubberBand::RubberBandStretcher::calculateStretch (  )  [virtual]

Force the stretcher to calculate a stretch profile.

Normally this happens automatically for the first process() call in offline mode.

This function is provided for diagnostic purposes only.

virtual void RubberBand::RubberBandStretcher::setDebugLevel ( int  level  )  [virtual]

Set the level of debug output.

The value may be from 0 (errors only) to 3 (very verbose, with audible ticks in the output at phase reset points). The default is whatever has been set using setDefaultDebugLevel, or 0 if that function has not been called.

static void RubberBand::RubberBandStretcher::setDefaultDebugLevel ( int  level  )  [static]

Set the default level of debug output for subsequently constructed stretchers.

See also:
setDebugLevel


Member Data Documentation

const int RubberBand::RubberBandStretcher::OptionProcessOffline = 0x00000000 [static]

Definition at line 164 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionProcessRealTime = 0x00000001 [static]

Definition at line 165 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionStretchElastic = 0x00000000 [static]

Definition at line 167 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionStretchPrecise = 0x00000010 [static]

Definition at line 168 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionTransientsCrisp = 0x00000000 [static]

Definition at line 170 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionTransientsMixed = 0x00000100 [static]

Definition at line 171 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionTransientsSmooth = 0x00000200 [static]

Definition at line 172 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionPhaseAdaptive = 0x00000000 [static]

Definition at line 174 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionPhasePeakLocked = 0x00001000 [static]

Definition at line 175 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionPhaseIndependent = 0x00002000 [static]

Definition at line 176 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionThreadingAuto = 0x00000000 [static]

Definition at line 178 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionThreadingNever = 0x00010000 [static]

Definition at line 179 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionThreadingAlways = 0x00020000 [static]

Definition at line 180 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionWindowStandard = 0x00000000 [static]

Definition at line 182 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionWindowShort = 0x00100000 [static]

Definition at line 183 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::OptionWindowLong = 0x00200000 [static]

Definition at line 184 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::DefaultOptions = 0x00000000 [static]

Definition at line 186 of file RubberBandStretcher.h.

const int RubberBand::RubberBandStretcher::PercussiveOptions [static]

Initial value:

Definition at line 187 of file RubberBandStretcher.h.

Impl* RubberBand::RubberBandStretcher::m_d [protected]

Definition at line 480 of file RubberBandStretcher.h.

size_t RubberBand::TimeStretcher::m_sampleRate [protected, inherited]

Definition at line 51 of file TimeStretcher.h.

size_t RubberBand::TimeStretcher::m_channels [protected, inherited]

Definition at line 52 of file TimeStretcher.h.


The documentation for this class was generated from the following file:
Generated on Thu Dec 13 21:25:47 2007 for RubberBand by  doxygen 1.5.3