Rubber Band Library 4.0.0
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-2024 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 RUBBERBAND_STRETCHER_H
25#define RUBBERBAND_STRETCHER_H
26
27#define RUBBERBAND_VERSION "4.0.0"
28#define RUBBERBAND_API_MAJOR_VERSION 3
29#define RUBBERBAND_API_MINOR_VERSION 0
30
31#undef RUBBERBAND_DLLEXPORT
32#ifdef _MSC_VER
33#ifndef RUBBERBAND_STATIC
34#define RUBBERBAND_DLLEXPORT __declspec(dllexport)
35#else
36#define RUBBERBAND_DLLEXPORT
37#endif
38#else
39#define RUBBERBAND_DLLEXPORT
40#endif
41
42#include <vector>
43#include <map>
44#include <string>
45#include <memory>
46#include <cstddef>
47
48namespace RubberBand
49{
50
133{
134public:
392 enum Option {
393
394 OptionProcessOffline = 0x00000000,
395 OptionProcessRealTime = 0x00000001,
396
397 OptionStretchElastic = 0x00000000, // obsolete
398 OptionStretchPrecise = 0x00000010, // obsolete
399
400 OptionTransientsCrisp = 0x00000000,
401 OptionTransientsMixed = 0x00000100,
402 OptionTransientsSmooth = 0x00000200,
403
404 OptionDetectorCompound = 0x00000000,
405 OptionDetectorPercussive = 0x00000400,
406 OptionDetectorSoft = 0x00000800,
407
408 OptionPhaseLaminar = 0x00000000,
409 OptionPhaseIndependent = 0x00002000,
410
411 OptionThreadingAuto = 0x00000000,
412 OptionThreadingNever = 0x00010000,
413 OptionThreadingAlways = 0x00020000,
414
415 OptionWindowStandard = 0x00000000,
416 OptionWindowShort = 0x00100000,
417 OptionWindowLong = 0x00200000,
418
419 OptionSmoothingOff = 0x00000000,
420 OptionSmoothingOn = 0x00800000,
421
422 OptionFormantShifted = 0x00000000,
423 OptionFormantPreserved = 0x01000000,
424
425 OptionPitchHighSpeed = 0x00000000,
426 OptionPitchHighQuality = 0x02000000,
427 OptionPitchHighConsistency = 0x04000000,
428
429 OptionChannelsApart = 0x00000000,
430 OptionChannelsTogether = 0x10000000,
431
432 OptionEngineFaster = 0x00000000,
433 OptionEngineFiner = 0x20000000
434
435 // n.b. Options is int, so we must stop before 0x80000000
436 };
437
442 typedef int Options;
443
445 DefaultOptions = 0x00000000,
446 PercussiveOptions = 0x00102000
447 };
448
467 struct Logger {
469 virtual void log(const char *) = 0;
470
472 virtual void log(const char *, double) = 0;
473
475 virtual void log(const char *, double, double) = 0;
476
477 virtual ~Logger() { }
478 };
479
512 RubberBandStretcher(size_t sampleRate,
513 size_t channels,
514 Options options = DefaultOptions,
515 double initialTimeRatio = 1.0,
516 double initialPitchScale = 1.0);
517
534 RubberBandStretcher(size_t sampleRate,
535 size_t channels,
536 std::shared_ptr<Logger> logger,
537 Options options = DefaultOptions,
538 double initialTimeRatio = 1.0,
539 double initialPitchScale = 1.0);
540
542
548 void reset();
549
557 int getEngineVersion() const;
558
580 void setTimeRatio(double ratio);
581
607 void setPitchScale(double scale);
608
637 void setFormantScale(double scale);
638
643 double getTimeRatio() const;
644
649 double getPitchScale() const;
650
661 double getFormantScale() const;
662
690 size_t getPreferredStartPad() const;
691
714 size_t getStartDelay() const;
715
722 size_t getLatency() const;
723
728 size_t getChannelCount() const;
729
737
745
755 void setPhaseOption(Options options);
756
766
773 void setPitchOption(Options options);
774
788 void setExpectedInputDuration(size_t samples);
789
826 void setMaxProcessSize(size_t samples);
827
838 size_t getProcessSizeLimit() const;
839
866 size_t getSamplesRequired() const;
867
892 void setKeyFrameMap(const std::map<size_t, size_t> &);
893
918 void study(const float *const *input, size_t samples, bool final);
919
937 void process(const float *const *input, size_t samples, bool final);
938
958 int available() const;
959
976 size_t retrieve(float *const *output, size_t samples) const;
977
984 float getFrequencyCutoff(int n) const;
985
992 void setFrequencyCutoff(int n, float f);
993
1000 size_t getInputIncrement() const;
1001
1012 std::vector<int> getOutputIncrements() const;
1013
1024 std::vector<float> getPhaseResetCurve() const;
1025
1035 std::vector<int> getExactTimePoints() const;
1036
1046
1079 void setDebugLevel(int level);
1080
1087 static void setDefaultDebugLevel(int level);
1088
1089protected:
1090 class Impl;
1091 Impl *m_d;
1092
1095};
1096
1097}
1098
1099#endif
#define RUBBERBAND_DLLEXPORT
size_t getPreferredStartPad() const
In RealTime mode (unlike in Offline mode) the stretcher performs no automatic padding or delay/latenc...
void process(const float *const *input, size_t samples, bool final)
Provide a block of "samples" sample frames for processing.
size_t getInputIncrement() const
Retrieve the value of the internal input block increment value.
void setFrequencyCutoff(int n, float f)
Set the value of internal frequency cutoff n to f Hz.
void calculateStretch()
Force the stretcher to calculate a stretch profile.
std::vector< int > getExactTimePoints() const
In offline mode, retrieve the sequence of internal frames for which exact timing has been sought,...
std::vector< float > getPhaseResetCurve() const
In offline mode, retrieve the sequence of internal phase reset detection function values,...
void setDebugLevel(int level)
Set the level of debug output.
float getFrequencyCutoff(int n) const
Return the value of internal frequency cutoff value n.
void reset()
Reset the stretcher's internal buffers.
void setExpectedInputDuration(size_t samples)
Tell the stretcher exactly how many input sample frames it will receive.
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...
RubberBandStretcher(size_t sampleRate, size_t channels, std::shared_ptr< Logger > logger, Options options=DefaultOptions, double initialTimeRatio=1.0, double initialPitchScale=1.0)
Construct a time and pitch stretcher object with a custom debug logger.
void setFormantScale(double scale)
Set a pitch scale for the vocal formant envelope separately from the overall pitch scale.
double getTimeRatio() const
Return the last time ratio value that was set (either on construction or with setTimeRatio()).
int available() const
Ask the stretcher how many audio sample frames of output data are available for reading (via retrieve...
double getFormantScale() const
Return the last formant scaling ratio that was set with setFormantScale, or 0.0 if the default automa...
size_t getStartDelay() const
Return the output delay of the stretcher.
int Options
A bitwise OR of values from the RubberBandStretcher::Option enum.
static void setDefaultDebugLevel(int level)
Set the default level of debug output for subsequently constructed stretchers.
size_t getProcessSizeLimit() const
Obtain the overall maximum supported process buffer size in sample frames, which is also the maximum ...
Option
Processing options for the timestretcher.
void setPitchOption(Options options)
Change an OptionPitch configuration setting.
void setFormantOption(Options options)
Change an OptionFormant configuration setting.
size_t getLatency() const
Return the start delay of the stretcher.
std::vector< int > getOutputIncrements() const
In offline mode, retrieve the sequence of internal block increments for output, for the entire audio ...
void setDetectorOption(Options options)
Change an OptionDetector configuration setting.
void setPhaseOption(Options options)
Change an OptionPhase configuration setting.
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...
void setTimeRatio(double ratio)
Set the time ratio for the stretcher.
RubberBandStretcher(const RubberBandStretcher &)=delete
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...
RubberBandStretcher & operator=(const RubberBandStretcher &)=delete
size_t getChannelCount() const
Return the number of channels this stretcher was constructed with.
size_t retrieve(float *const *output, size_t samples) const
Obtain some processed output data from the stretcher.
size_t getSamplesRequired() const
Ask the stretcher how many audio sample frames should be provided as input in order to ensure that so...
int getEngineVersion() const
Return the active internal engine version, according to the OptionEngine flag supplied on constructio...
void setPitchScale(double scale)
Set the pitch scaling ratio for the stretcher.
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...
void setTransientsOption(Options options)
Change an OptionTransients configuration setting.
double getPitchScale() const
Return the last pitch scaling ratio value that was set (either on construction or with setPitchScale(...
Interface for log callbacks that may optionally be provided to the stretcher on construction.
virtual void log(const char *, double)=0
Receive a log message and one accompanying numeric value.
virtual void log(const char *)=0
Receive a log message with no numeric values.
virtual void log(const char *, double, double)=0
Receive a log message and two accompanying numeric values.