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-2012 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