Rubber Band Library  1.8.1
RubberBandStretcher.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Rubber Band Library
5  An audio time-stretching and pitch-shifting library.
6  Copyright 2007-2014 Particular Programs Ltd.
7 
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.
13 
14  Alternatively, if you have a valid commercial licence for the
15  Rubber Band Library obtained by agreement with the copyright
16  holders, you may redistribute and/or modify it under the terms
17  described in that licence.
18 
19  If you wish to distribute code using the Rubber Band Library
20  under terms other than those of the GNU General Public License,
21  you must obtain a valid commercial licence before doing so.
22 */
23 
24 #ifndef _RUBBERBANDSTRETCHER_H_
25 #define _RUBBERBANDSTRETCHER_H_
26 
27 #define RUBBERBAND_VERSION "1.8.1"
28 #define RUBBERBAND_API_MAJOR_VERSION 2
29 #define RUBBERBAND_API_MINOR_VERSION 5
30 
31 #include <vector>
32 #include <map>
33 #include <cstddef>
34 
60 namespace RubberBand
61 {
62 
64 {
65 public:
275  enum Option {
276 
277  OptionProcessOffline = 0x00000000,
278  OptionProcessRealTime = 0x00000001,
279 
280  OptionStretchElastic = 0x00000000,
281  OptionStretchPrecise = 0x00000010,
282 
283  OptionTransientsCrisp = 0x00000000,
284  OptionTransientsMixed = 0x00000100,
286 
289  OptionDetectorSoft = 0x00000800,
290 
291  OptionPhaseLaminar = 0x00000000,
293 
294  OptionThreadingAuto = 0x00000000,
295  OptionThreadingNever = 0x00010000,
296  OptionThreadingAlways = 0x00020000,
297 
298  OptionWindowStandard = 0x00000000,
299  OptionWindowShort = 0x00100000,
300  OptionWindowLong = 0x00200000,
301 
302  OptionSmoothingOff = 0x00000000,
303  OptionSmoothingOn = 0x00800000,
304 
305  OptionFormantShifted = 0x00000000,
307 
308  OptionPitchHighSpeed = 0x00000000,
311 
312  OptionChannelsApart = 0x00000000,
314 
315  // n.b. Options is int, so we must stop before 0x80000000
316  };
317 
318  typedef int Options;
319 
321  DefaultOptions = 0x00000000,
322  PercussiveOptions = 0x00102000
323  };
324 
333  RubberBandStretcher(size_t sampleRate,
334  size_t channels,
335  Options options = DefaultOptions,
336  double initialTimeRatio = 1.0,
337  double initialPitchScale = 1.0);
339 
345  void reset();
346 
368  void setTimeRatio(double ratio);
369 
395  void setPitchScale(double scale);
396 
401  double getTimeRatio() const;
402 
407  double getPitchScale() const;
408 
418  size_t getLatency() const;
419 
426  void setTransientsOption(Options options);
427 
434  void setDetectorOption(Options options);
435 
444  void setPhaseOption(Options options);
445 
454  void setFormantOption(Options options);
455 
462  void setPitchOption(Options options);
463 
471  void setExpectedInputDuration(size_t samples);
472 
496  void setMaxProcessSize(size_t samples);
497 
516  size_t getSamplesRequired() const;
517 
542  void setKeyFrameMap(const std::map<size_t, size_t> &);
543 
561  void study(const float *const *input, size_t samples, bool final);
562 
569  void process(const float *const *input, size_t samples, bool final);
570 
584  int available() const;
585 
593  size_t retrieve(float *const *output, size_t samples) const;
594 
600  float getFrequencyCutoff(int n) const;
601 
607  void setFrequencyCutoff(int n, float f);
608 
614  size_t getInputIncrement() const;
615 
625  std::vector<int> getOutputIncrements() const;
626 
636  std::vector<float> getPhaseResetCurve() const;
637 
646  std::vector<int> getExactTimePoints() const;
647 
652  size_t getChannelCount() const;
653 
661  void calculateStretch();
662 
670  void setDebugLevel(int level);
671 
678  static void setDefaultDebugLevel(int level);
679 
680 protected:
681  class Impl;
682  Impl *m_d;
683 };
684 
685 }
686 
687 #endif
RubberBand::RubberBandStretcher::OptionProcessRealTime
@ OptionProcessRealTime
Definition: RubberBandStretcher.h:278
RubberBand::RubberBandStretcher::OptionTransientsSmooth
@ OptionTransientsSmooth
Definition: RubberBandStretcher.h:285
RubberBand
Definition: RubberBandStretcher.h:60
RubberBand::RubberBandStretcher::OptionWindowStandard
@ OptionWindowStandard
Definition: RubberBandStretcher.h:298
RubberBand::RubberBandStretcher::setPitchOption
void setPitchOption(Options options)
Change an OptionPitch configuration setting.
RubberBand::RubberBandStretcher::getFrequencyCutoff
float getFrequencyCutoff(int n) const
Return the value of internal frequency cutoff value n.
RubberBand::RubberBandStretcher::setFormantOption
void setFormantOption(Options options)
Change an OptionFormant configuration setting.
RubberBand::RubberBandStretcher::setDetectorOption
void setDetectorOption(Options options)
Change an OptionDetector configuration setting.
RubberBand::RubberBandStretcher::OptionSmoothingOff
@ OptionSmoothingOff
Definition: RubberBandStretcher.h:302
RubberBand::RubberBandStretcher::setMaxProcessSize
void setMaxProcessSize(size_t samples)
Tell the stretcher the maximum number of sample frames that you will ever be passing in to a single p...
RubberBand::RubberBandStretcher::getLatency
size_t getLatency() const
Return the processing latency of the stretcher.
RubberBand::RubberBandStretcher
Definition: RubberBandStretcher.h:63
RubberBand::RubberBandStretcher::setDefaultDebugLevel
static void setDefaultDebugLevel(int level)
Set the default level of debug output for subsequently constructed stretchers.
RubberBand::RubberBandStretcher::getSamplesRequired
size_t getSamplesRequired() const
Ask the stretcher how many audio sample frames should be provided as input in order to ensure that so...
RubberBand::RubberBandStretcher::OptionPhaseLaminar
@ OptionPhaseLaminar
Definition: RubberBandStretcher.h:291
RubberBand::RubberBandStretcher::available
int available() const
Ask the stretcher how many audio sample frames of output data are available for reading (via retrieve...
RubberBand::RubberBandStretcher::getOutputIncrements
std::vector< int > getOutputIncrements() const
In offline mode, retrieve the sequence of internal block increments for output, for the entire audio ...
RubberBand::RubberBandStretcher::OptionPitchHighConsistency
@ OptionPitchHighConsistency
Definition: RubberBandStretcher.h:310
RubberBand::RubberBandStretcher::~RubberBandStretcher
~RubberBandStretcher()
RubberBand::RubberBandStretcher::OptionThreadingAlways
@ OptionThreadingAlways
Definition: RubberBandStretcher.h:296
RubberBand::RubberBandStretcher::OptionThreadingNever
@ OptionThreadingNever
Definition: RubberBandStretcher.h:295
RubberBand::RubberBandStretcher::getExactTimePoints
std::vector< int > getExactTimePoints() const
In offline mode, retrieve the sequence of internal frames for which exact timing has been sought,...
RubberBand::RubberBandStretcher::OptionTransientsMixed
@ OptionTransientsMixed
Definition: RubberBandStretcher.h:284
RubberBand::RubberBandStretcher::OptionFormantPreserved
@ OptionFormantPreserved
Definition: RubberBandStretcher.h:306
RubberBand::RubberBandStretcher::OptionTransientsCrisp
@ OptionTransientsCrisp
Definition: RubberBandStretcher.h:283
RubberBand::RubberBandStretcher::OptionPitchHighQuality
@ OptionPitchHighQuality
Definition: RubberBandStretcher.h:309
RubberBand::RubberBandStretcher::OptionDetectorSoft
@ OptionDetectorSoft
Definition: RubberBandStretcher.h:289
RubberBand::RubberBandStretcher::OptionWindowLong
@ OptionWindowLong
Definition: RubberBandStretcher.h:300
RubberBand::RubberBandStretcher::getPhaseResetCurve
std::vector< float > getPhaseResetCurve() const
In offline mode, retrieve the sequence of internal phase reset detection function values,...
RubberBand::RubberBandStretcher::Option
Option
Processing options for the timestretcher.
Definition: RubberBandStretcher.h:275
RubberBand::RubberBandStretcher::Options
int Options
Definition: RubberBandStretcher.h:318
RubberBand::RubberBandStretcher::m_d
Impl * m_d
Definition: RubberBandStretcher.h:681
RubberBand::RubberBandStretcher::calculateStretch
void calculateStretch()
Force the stretcher to calculate a stretch profile.
RubberBand::RubberBandStretcher::OptionStretchPrecise
@ OptionStretchPrecise
Definition: RubberBandStretcher.h:281
RubberBand::RubberBandStretcher::retrieve
size_t retrieve(float *const *output, size_t samples) const
Obtain some processed output data from the stretcher.
RubberBand::RubberBandStretcher::OptionProcessOffline
@ OptionProcessOffline
Definition: RubberBandStretcher.h:277
RubberBand::RubberBandStretcher::setPitchScale
void setPitchScale(double scale)
Set the pitch scaling ratio for the stretcher.
RubberBand::RubberBandStretcher::OptionStretchElastic
@ OptionStretchElastic
Definition: RubberBandStretcher.h:280
RubberBand::RubberBandStretcher::OptionSmoothingOn
@ OptionSmoothingOn
Definition: RubberBandStretcher.h:303
RubberBand::RubberBandStretcher::getInputIncrement
size_t getInputIncrement() const
Retrieve the value of the internal input block increment value.
RubberBand::RubberBandStretcher::OptionThreadingAuto
@ OptionThreadingAuto
Definition: RubberBandStretcher.h:294
RubberBand::RubberBandStretcher::setKeyFrameMap
void setKeyFrameMap(const std::map< size_t, size_t > &)
Provide a set of mappings from "before" to "after" sample numbers so as to enforce a particular stret...
RubberBand::RubberBandStretcher::setExpectedInputDuration
void setExpectedInputDuration(size_t samples)
Tell the stretcher exactly how many input samples it will receive.
RubberBand::RubberBandStretcher::study
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...
RubberBand::RubberBandStretcher::OptionChannelsTogether
@ OptionChannelsTogether
Definition: RubberBandStretcher.h:313
RubberBand::RubberBandStretcher::OptionDetectorCompound
@ OptionDetectorCompound
Definition: RubberBandStretcher.h:287
RubberBand::RubberBandStretcher::getPitchScale
double getPitchScale() const
Return the last pitch scaling ratio value that was set (either on construction or with setPitchScale(...
RubberBand::RubberBandStretcher::OptionDetectorPercussive
@ OptionDetectorPercussive
Definition: RubberBandStretcher.h:288
RubberBand::RubberBandStretcher::OptionPitchHighSpeed
@ OptionPitchHighSpeed
Definition: RubberBandStretcher.h:308
RubberBand::RubberBandStretcher::OptionPhaseIndependent
@ OptionPhaseIndependent
Definition: RubberBandStretcher.h:292
RubberBand::RubberBandStretcher::getChannelCount
size_t getChannelCount() const
Return the number of channels this stretcher was constructed with.
RubberBand::RubberBandStretcher::getTimeRatio
double getTimeRatio() const
Return the last time ratio value that was set (either on construction or with setTimeRatio()).
RubberBand::RubberBandStretcher::setPhaseOption
void setPhaseOption(Options options)
Change an OptionPhase configuration setting.
RubberBand::RubberBandStretcher::setFrequencyCutoff
void setFrequencyCutoff(int n, float f)
Set the value of internal frequency cutoff n to f Hz.
RubberBand::RubberBandStretcher::OptionWindowShort
@ OptionWindowShort
Definition: RubberBandStretcher.h:299
RubberBand::RubberBandStretcher::setDebugLevel
void setDebugLevel(int level)
Set the level of debug output.
RubberBand::RubberBandStretcher::PresetOption
PresetOption
Definition: RubberBandStretcher.h:320
RubberBand::RubberBandStretcher::OptionChannelsApart
@ OptionChannelsApart
Definition: RubberBandStretcher.h:312
RubberBand::RubberBandStretcher::setTimeRatio
void setTimeRatio(double ratio)
Set the time ratio for the stretcher.
RubberBand::RubberBandStretcher::reset
void reset()
Reset the stretcher's internal buffers.
RubberBand::RubberBandStretcher::OptionFormantShifted
@ OptionFormantShifted
Definition: RubberBandStretcher.h:305
RubberBand::RubberBandStretcher::PercussiveOptions
@ PercussiveOptions
Definition: RubberBandStretcher.h:322
RubberBand::RubberBandStretcher::setTransientsOption
void setTransientsOption(Options options)
Change an OptionTransients configuration setting.
RubberBand::RubberBandStretcher::process
void process(const float *const *input, size_t samples, bool final)
Provide a block of "samples" sample frames for processing.
RubberBand::RubberBandStretcher::DefaultOptions
@ DefaultOptions
Definition: RubberBandStretcher.h:321
RubberBand::RubberBandStretcher::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...