Rubber Band Library 3.3.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-2022 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 "3.3.0"
28#define RUBBERBAND_API_MAJOR_VERSION 2
29#define RUBBERBAND_API_MINOR_VERSION 8
30
31#undef RUBBERBAND_DLLEXPORT
32#ifdef _MSC_VER
33#define RUBBERBAND_DLLEXPORT __declspec(dllexport)
34#else
35#define RUBBERBAND_DLLEXPORT
36#endif
37
38#include <vector>
39#include <map>
40#include <string>
41#include <memory>
42#include <cstddef>
43
44namespace RubberBand
45{
46
126{
127public:
385 enum Option {
386
387 OptionProcessOffline = 0x00000000,
388 OptionProcessRealTime = 0x00000001,
389
390 OptionStretchElastic = 0x00000000, // obsolete
391 OptionStretchPrecise = 0x00000010, // obsolete
392
393 OptionTransientsCrisp = 0x00000000,
394 OptionTransientsMixed = 0x00000100,
395 OptionTransientsSmooth = 0x00000200,
396
397 OptionDetectorCompound = 0x00000000,
398 OptionDetectorPercussive = 0x00000400,
399 OptionDetectorSoft = 0x00000800,
400
401 OptionPhaseLaminar = 0x00000000,
402 OptionPhaseIndependent = 0x00002000,
403
404 OptionThreadingAuto = 0x00000000,
405 OptionThreadingNever = 0x00010000,
406 OptionThreadingAlways = 0x00020000,
407
408 OptionWindowStandard = 0x00000000,
409 OptionWindowShort = 0x00100000,
410 OptionWindowLong = 0x00200000,
411
412 OptionSmoothingOff = 0x00000000,
413 OptionSmoothingOn = 0x00800000,
414
415 OptionFormantShifted = 0x00000000,
416 OptionFormantPreserved = 0x01000000,
417
418 OptionPitchHighSpeed = 0x00000000,
419 OptionPitchHighQuality = 0x02000000,
420 OptionPitchHighConsistency = 0x04000000,
421
422 OptionChannelsApart = 0x00000000,
423 OptionChannelsTogether = 0x10000000,
424
425 OptionEngineFaster = 0x00000000,
426 OptionEngineFiner = 0x20000000
427
428 // n.b. Options is int, so we must stop before 0x80000000
429 };
430
435 typedef int Options;
436
438 DefaultOptions = 0x00000000,
439 PercussiveOptions = 0x00102000
440 };
441
460 struct Logger {
462 virtual void log(const char *) = 0;
463
465 virtual void log(const char *, double) = 0;
466
468 virtual void log(const char *, double, double) = 0;
469
470 virtual ~Logger() { }
471 };
472
505 RubberBandStretcher(size_t sampleRate,
506 size_t channels,
507 Options options = DefaultOptions,
508 double initialTimeRatio = 1.0,
509 double initialPitchScale = 1.0);
510
527 RubberBandStretcher(size_t sampleRate,
528 size_t channels,
529 std::shared_ptr<Logger> logger,
530 Options options = DefaultOptions,
531 double initialTimeRatio = 1.0,
532 double initialPitchScale = 1.0);
533
535
541 void reset();
542
550 int getEngineVersion() const;
551
573 void setTimeRatio(double ratio);
574
600 void setPitchScale(double scale);
601
630 void setFormantScale(double scale);
631
636 double getTimeRatio() const;
637
642 double getPitchScale() const;
643
654 double getFormantScale() const;
655
683 size_t getPreferredStartPad() const;
684
707 size_t getStartDelay() const;
708
715 size_t getLatency() const;
716
721 size_t getChannelCount() const;
722
730
738
748 void setPhaseOption(Options options);
749
759
766 void setPitchOption(Options options);
767
781 void setExpectedInputDuration(size_t samples);
782
819 void setMaxProcessSize(size_t samples);
820
831 size_t getProcessSizeLimit() const;
832
859 size_t getSamplesRequired() const;
860
885 void setKeyFrameMap(const std::map<size_t, size_t> &);
886
911 void study(const float *const *input, size_t samples, bool final);
912
930 void process(const float *const *input, size_t samples, bool final);
931
951 int available() const;
952
969 size_t retrieve(float *const *output, size_t samples) const;
970
977 float getFrequencyCutoff(int n) const;
978
985 void setFrequencyCutoff(int n, float f);
986
993 size_t getInputIncrement() const;
994
1005 std::vector<int> getOutputIncrements() const;
1006
1017 std::vector<float> getPhaseResetCurve() const;
1018
1028 std::vector<int> getExactTimePoints() const;
1029
1039
1072 void setDebugLevel(int level);
1073
1080 static void setDefaultDebugLevel(int level);
1081
1082protected:
1083 class Impl;
1084 Impl *m_d;
1085
1088};
1089
1090}
1091
1092#endif
#define RUBBERBAND_DLLEXPORT
size_t getPreferredStartPad() const
In RealTime mode (unlike in Offline mode) the stretcher performs no automatic padding or delay/latenc...
int Options
A bitwise OR of values from the RubberBandStretcher::Option enum.
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.
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.