Rubber Band Library  1.8.1
RubberBandStretcher.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Rubber Band Library
00005     An audio time-stretching and pitch-shifting library.
00006     Copyright 2007-2014 Particular Programs Ltd.
00007 
00008     This program is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU General Public License as
00010     published by the Free Software Foundation; either version 2 of the
00011     License, or (at your option) any later version.  See the file
00012     COPYING included with this distribution for more information.
00013 
00014     Alternatively, if you have a valid commercial licence for the
00015     Rubber Band Library obtained by agreement with the copyright
00016     holders, you may redistribute and/or modify it under the terms
00017     described in that licence.
00018 
00019     If you wish to distribute code using the Rubber Band Library
00020     under terms other than those of the GNU General Public License,
00021     you must obtain a valid commercial licence before doing so.
00022 */
00023 
00024 #ifndef _RUBBERBANDSTRETCHER_H_
00025 #define _RUBBERBANDSTRETCHER_H_
00026     
00027 #define RUBBERBAND_VERSION "1.8.1"
00028 #define RUBBERBAND_API_MAJOR_VERSION 2
00029 #define RUBBERBAND_API_MINOR_VERSION 5
00030 
00031 #include <vector>
00032 #include <map>
00033 #include <cstddef>
00034 
00060 namespace RubberBand
00061 {
00062 
00063 class RubberBandStretcher
00064 {
00065 public:
00275     enum Option {
00276 
00277         OptionProcessOffline       = 0x00000000,
00278         OptionProcessRealTime      = 0x00000001,
00279 
00280         OptionStretchElastic       = 0x00000000,
00281         OptionStretchPrecise       = 0x00000010,
00282     
00283         OptionTransientsCrisp      = 0x00000000,
00284         OptionTransientsMixed      = 0x00000100,
00285         OptionTransientsSmooth     = 0x00000200,
00286 
00287         OptionDetectorCompound     = 0x00000000,
00288         OptionDetectorPercussive   = 0x00000400,
00289         OptionDetectorSoft         = 0x00000800,
00290 
00291         OptionPhaseLaminar         = 0x00000000,
00292         OptionPhaseIndependent     = 0x00002000,
00293     
00294         OptionThreadingAuto        = 0x00000000,
00295         OptionThreadingNever       = 0x00010000,
00296         OptionThreadingAlways      = 0x00020000,
00297 
00298         OptionWindowStandard       = 0x00000000,
00299         OptionWindowShort          = 0x00100000,
00300         OptionWindowLong           = 0x00200000,
00301 
00302         OptionSmoothingOff         = 0x00000000,
00303         OptionSmoothingOn          = 0x00800000,
00304 
00305         OptionFormantShifted       = 0x00000000,
00306         OptionFormantPreserved     = 0x01000000,
00307 
00308         OptionPitchHighSpeed       = 0x00000000,
00309         OptionPitchHighQuality     = 0x02000000,
00310         OptionPitchHighConsistency = 0x04000000,
00311 
00312         OptionChannelsApart        = 0x00000000,
00313         OptionChannelsTogether     = 0x10000000,
00314 
00315         // n.b. Options is int, so we must stop before 0x80000000
00316     };
00317 
00318     typedef int Options;
00319 
00320     enum PresetOption {
00321         DefaultOptions             = 0x00000000,
00322         PercussiveOptions          = 0x00102000
00323     };
00324 
00333     RubberBandStretcher(size_t sampleRate,
00334                         size_t channels,
00335                         Options options = DefaultOptions,
00336                         double initialTimeRatio = 1.0,
00337                         double initialPitchScale = 1.0);
00338     ~RubberBandStretcher();
00339 
00345     void reset();
00346 
00368     void setTimeRatio(double ratio);
00369 
00395     void setPitchScale(double scale);
00396 
00401     double getTimeRatio() const;
00402 
00407     double getPitchScale() const;
00408 
00418     size_t getLatency() const;
00419 
00426     void setTransientsOption(Options options);
00427 
00434     void setDetectorOption(Options options);
00435 
00444     void setPhaseOption(Options options);
00445 
00454     void setFormantOption(Options options);
00455 
00462     void setPitchOption(Options options);
00463 
00471     void setExpectedInputDuration(size_t samples);
00472 
00496     void setMaxProcessSize(size_t samples);
00497 
00516      size_t getSamplesRequired() const;
00517 
00542     void setKeyFrameMap(const std::map<size_t, size_t> &);
00543     
00561     void study(const float *const *input, size_t samples, bool final);
00562 
00569     void process(const float *const *input, size_t samples, bool final);
00570 
00584     int available() const;
00585 
00593     size_t retrieve(float *const *output, size_t samples) const;
00594 
00600     float getFrequencyCutoff(int n) const;
00601 
00607     void setFrequencyCutoff(int n, float f);
00608     
00614     size_t getInputIncrement() const;
00615 
00625     std::vector<int> getOutputIncrements() const;
00626 
00636     std::vector<float> getPhaseResetCurve() const;
00637 
00646     std::vector<int> getExactTimePoints() const;
00647 
00652     size_t getChannelCount() const;
00653 
00661     void calculateStretch();
00662 
00670     void setDebugLevel(int level);
00671 
00678     static void setDefaultDebugLevel(int level);
00679 
00680 protected:
00681     class Impl;
00682     Impl *m_d;
00683 };
00684 
00685 }
00686 
00687 #endif