Chris@13: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@13: Chris@13: /* Chris@13: Rubber Band Library Chris@13: An audio time-stretching and pitch-shifting library. Chris@13: Copyright 2007-2012 Particular Programs Ltd. Chris@13: Chris@13: This program is free software; you can redistribute it and/or Chris@13: modify it under the terms of the GNU General Public License as Chris@13: published by the Free Software Foundation; either version 2 of the Chris@13: License, or (at your option) any later version. See the file Chris@13: COPYING included with this distribution for more information. Chris@13: Chris@13: Alternatively, if you have a valid commercial licence for the Chris@13: Rubber Band Library obtained by agreement with the copyright Chris@13: holders, you may redistribute and/or modify it under the terms Chris@13: described in that licence. Chris@13: Chris@13: If you wish to distribute code using the Rubber Band Library Chris@13: under terms other than those of the GNU General Public License, Chris@13: you must obtain a valid commercial licence before doing so. Chris@13: */ Chris@13: Chris@13: #ifndef _RUBBERBANDSTRETCHER_H_ Chris@13: #define _RUBBERBANDSTRETCHER_H_ Chris@13: Chris@13: #define RUBBERBAND_VERSION "1.8.1" Chris@13: #define RUBBERBAND_API_MAJOR_VERSION 2 Chris@13: #define RUBBERBAND_API_MINOR_VERSION 5 Chris@13: Chris@13: #include Chris@13: #include Chris@13: #include Chris@13: Chris@13: /** Chris@13: * @mainpage RubberBand Chris@13: * Chris@13: * The Rubber Band API is contained in the single class Chris@13: * RubberBand::RubberBandStretcher. Chris@13: * Chris@13: * Threading notes for real-time applications: Chris@13: * Chris@13: * Multiple instances of RubberBandStretcher may be created and used Chris@13: * in separate threads concurrently. However, for any single instance Chris@13: * of RubberBandStretcher, you may not call process() more than once Chris@13: * concurrently, and you may not change the time or pitch ratio while Chris@13: * a process() call is being executed (if the stretcher was created in Chris@13: * "real-time mode"; in "offline mode" you can't change the ratios Chris@13: * during use anyway). Chris@13: * Chris@13: * So you can run process() in its own thread if you like, but if you Chris@13: * want to change ratios dynamically from a different thread, you will Chris@13: * need some form of mutex in your code. Changing the time or pitch Chris@13: * ratio is real-time safe except in extreme circumstances, so for Chris@13: * most applications that may change these dynamically it probably Chris@13: * makes most sense to do so from the same thread as calls process(), Chris@13: * even if that is a real-time thread. Chris@13: */ Chris@13: Chris@13: namespace RubberBand Chris@13: { Chris@13: Chris@13: class RubberBandStretcher Chris@13: { Chris@13: public: Chris@13: /** Chris@13: * Processing options for the timestretcher. The preferred Chris@13: * options should normally be set in the constructor, as a bitwise Chris@13: * OR of the option flags. The default value (DefaultOptions) is Chris@13: * intended to give good results in most situations. Chris@13: * Chris@13: * 1. Flags prefixed \c OptionProcess determine how the timestretcher Chris@13: * will be invoked. These options may not be changed after Chris@13: * construction. Chris@13: * Chris@13: * \li \c OptionProcessOffline - Run the stretcher in offline Chris@13: * mode. In this mode the input data needs to be provided Chris@13: * twice, once to study(), which calculates a stretch profile Chris@13: * for the audio, and once to process(), which stretches it. Chris@13: * Chris@13: * \li \c OptionProcessRealTime - Run the stretcher in real-time Chris@13: * mode. In this mode only process() should be called, and the Chris@13: * stretcher adjusts dynamically in response to the input audio. Chris@13: * Chris@13: * The Process setting is likely to depend on your architecture: Chris@13: * non-real-time operation on seekable files: Offline; real-time Chris@13: * or streaming operation: RealTime. Chris@13: * Chris@13: * 2. Flags prefixed \c OptionStretch control the profile used for Chris@13: * variable timestretching. Rubber Band always adjusts the Chris@13: * stretch profile to minimise stretching of busy broadband Chris@13: * transient sounds, but the degree to which it does so is Chris@13: * adjustable. These options may not be changed after Chris@13: * construction. Chris@13: * Chris@13: * \li \c OptionStretchElastic - Only meaningful in offline Chris@13: * mode, and the default in that mode. The audio will be Chris@13: * stretched at a variable rate, aimed at preserving the quality Chris@13: * of transient sounds as much as possible. The timings of low Chris@13: * activity regions between transients may be less exact than Chris@13: * when the precise flag is set. Chris@13: * Chris@13: * \li \c OptionStretchPrecise - Although still using a variable Chris@13: * stretch rate, the audio will be stretched so as to maintain Chris@13: * as close as possible to a linear stretch ratio throughout. Chris@13: * Timing may be better than when using \c OptionStretchElastic, at Chris@13: * slight cost to the sound quality of transients. This setting Chris@13: * is always used when running in real-time mode. Chris@13: * Chris@13: * 3. Flags prefixed \c OptionTransients control the component Chris@13: * frequency phase-reset mechanism that may be used at transient Chris@13: * points to provide clarity and realism to percussion and other Chris@13: * significant transient sounds. These options may be changed Chris@13: * after construction when running in real-time mode, but not when Chris@13: * running in offline mode. Chris@13: * Chris@13: * \li \c OptionTransientsCrisp - Reset component phases at the Chris@13: * peak of each transient (the start of a significant note or Chris@13: * percussive event). This, the default setting, usually Chris@13: * results in a clear-sounding output; but it is not always Chris@13: * consistent, and may cause interruptions in stable sounds Chris@13: * present at the same time as transient events. The Chris@13: * OptionDetector flags (below) can be used to tune this to some Chris@13: * extent. Chris@13: * Chris@13: * \li \c OptionTransientsMixed - Reset component phases at the Chris@13: * peak of each transient, outside a frequency range typical of Chris@13: * musical fundamental frequencies. The results may be more Chris@13: * regular for mixed stable and percussive notes than Chris@13: * \c OptionTransientsCrisp, but with a "phasier" sound. The Chris@13: * balance may sound very good for certain types of music and Chris@13: * fairly bad for others. Chris@13: * Chris@13: * \li \c OptionTransientsSmooth - Do not reset component phases Chris@13: * at any point. The results will be smoother and more regular Chris@13: * but may be less clear than with either of the other Chris@13: * transients flags. Chris@13: * Chris@13: * 4. Flags prefixed \c OptionDetector control the type of Chris@13: * transient detector used. These options may be changed Chris@13: * after construction when running in real-time mode, but not when Chris@13: * running in offline mode. Chris@13: * Chris@13: * \li \c OptionDetectorCompound - Use a general-purpose Chris@13: * transient detector which is likely to be good for most Chris@13: * situations. This is the default. Chris@13: * Chris@13: * \li \c OptionDetectorPercussive - Detect percussive Chris@13: * transients. Note that this was the default and only option Chris@13: * in Rubber Band versions prior to 1.5. Chris@13: * Chris@13: * \li \c OptionDetectorSoft - Use an onset detector with less Chris@13: * of a bias toward percussive transients. This may give better Chris@13: * results with certain material (e.g. relatively monophonic Chris@13: * piano music). Chris@13: * Chris@13: * 5. Flags prefixed \c OptionPhase control the adjustment of Chris@13: * component frequency phases from one analysis window to the next Chris@13: * during non-transient segments. These options may be changed at Chris@13: * any time. Chris@13: * Chris@13: * \li \c OptionPhaseLaminar - Adjust phases when stretching in Chris@13: * such a way as to try to retain the continuity of phase Chris@13: * relationships between adjacent frequency bins whose phases Chris@13: * are behaving in similar ways. This, the default setting, Chris@13: * should give good results in most situations. Chris@13: * Chris@13: * \li \c OptionPhaseIndependent - Adjust the phase in each Chris@13: * frequency bin independently from its neighbours. This Chris@13: * usually results in a slightly softer, phasier sound. Chris@13: * Chris@13: * 6. Flags prefixed \c OptionThreading control the threading Chris@13: * model of the stretcher. These options may not be changed after Chris@13: * construction. Chris@13: * Chris@13: * \li \c OptionThreadingAuto - Permit the stretcher to Chris@13: * determine its own threading model. Usually this means using Chris@13: * one processing thread per audio channel in offline mode if Chris@13: * the stretcher is able to determine that more than one CPU is Chris@13: * available, and one thread only in realtime mode. This is the Chris@13: * defafult. Chris@13: * Chris@13: * \li \c OptionThreadingNever - Never use more than one thread. Chris@13: * Chris@13: * \li \c OptionThreadingAlways - Use multiple threads in any Chris@13: * situation where \c OptionThreadingAuto would do so, except omit Chris@13: * the check for multiple CPUs and instead assume it to be true. Chris@13: * Chris@13: * 7. Flags prefixed \c OptionWindow control the window size for Chris@13: * FFT processing. The window size actually used will depend on Chris@13: * many factors, but it can be influenced. These options may not Chris@13: * be changed after construction. Chris@13: * Chris@13: * \li \c OptionWindowStandard - Use the default window size. Chris@13: * The actual size will vary depending on other parameters. Chris@13: * This option is expected to produce better results than the Chris@13: * other window options in most situations. Chris@13: * Chris@13: * \li \c OptionWindowShort - Use a shorter window. This may Chris@13: * result in crisper sound for audio that depends strongly on Chris@13: * its timing qualities. Chris@13: * Chris@13: * \li \c OptionWindowLong - Use a longer window. This is Chris@13: * likely to result in a smoother sound at the expense of Chris@13: * clarity and timing. Chris@13: * Chris@13: * 8. Flags prefixed \c OptionSmoothing control the use of Chris@13: * window-presum FFT and time-domain smoothing. These options may Chris@13: * not be changed after construction. Chris@13: * Chris@13: * \li \c OptionSmoothingOff - Do not use time-domain smoothing. Chris@13: * This is the default. Chris@13: * Chris@13: * \li \c OptionSmoothingOn - Use time-domain smoothing. This Chris@13: * will result in a softer sound with some audible artifacts Chris@13: * around sharp transients, but it may be appropriate for longer Chris@13: * stretches of some instruments and can mix well with Chris@13: * OptionWindowShort. Chris@13: * Chris@13: * 9. Flags prefixed \c OptionFormant control the handling of Chris@13: * formant shape (spectral envelope) when pitch-shifting. These Chris@13: * options may be changed at any time. Chris@13: * Chris@13: * \li \c OptionFormantShifted - Apply no special formant Chris@13: * processing. The spectral envelope will be pitch shifted as Chris@13: * normal. This is the default. Chris@13: * Chris@13: * \li \c OptionFormantPreserved - Preserve the spectral Chris@13: * envelope of the unshifted signal. This permits shifting the Chris@13: * note frequency without so substantially affecting the Chris@13: * perceived pitch profile of the voice or instrument. Chris@13: * Chris@13: * 10. Flags prefixed \c OptionPitch control the method used for Chris@13: * pitch shifting. These options may be changed at any time. Chris@13: * They are only effective in realtime mode; in offline mode, the Chris@13: * pitch-shift method is fixed. Chris@13: * Chris@13: * \li \c OptionPitchHighSpeed - Use a method with a CPU cost Chris@13: * that is relatively moderate and predictable. This may Chris@13: * sound less clear than OptionPitchHighQuality, especially Chris@13: * for large pitch shifts. This is the default. Chris@13: Chris@13: * \li \c OptionPitchHighQuality - Use the highest quality Chris@13: * method for pitch shifting. This method has a CPU cost Chris@13: * approximately proportional to the required frequency shift. Chris@13: Chris@13: * \li \c OptionPitchHighConsistency - Use the method that gives Chris@13: * greatest consistency when used to create small variations in Chris@13: * pitch around the 1.0-ratio level. Unlike the previous two Chris@13: * options, this avoids discontinuities when moving across the Chris@13: * 1.0 pitch scale in real-time; it also consumes more CPU than Chris@13: * the others in the case where the pitch scale is exactly 1.0. Chris@13: * Chris@13: * 11. Flags prefixed \c OptionChannels control the method used for Chris@13: * processing two-channel audio. These options may not be changed Chris@13: * after construction. Chris@13: * Chris@13: * \li \c OptionChannelsApart - Each channel is processed Chris@13: * individually, though timing is synchronised and phases are Chris@13: * synchronised at transients (depending on the OptionTransients Chris@13: * setting). This gives the highest quality for the individual Chris@13: * channels but a relative lack of stereo focus and unrealistic Chris@13: * increase in "width". This is the default. Chris@13: * Chris@13: * \li \c OptionChannelsTogether - The first two channels (where Chris@13: * two or more are present) are considered to be a stereo pair Chris@13: * and are processed in mid-side format; mid and side are Chris@13: * processed individually, with timing synchronised and phases Chris@13: * synchronised at transients (depending on the OptionTransients Chris@13: * setting). This usually leads to better focus in the centre Chris@13: * but a loss of stereo space and width. Any channels beyond Chris@13: * the first two are processed individually. Chris@13: */ Chris@13: Chris@13: enum Option { Chris@13: Chris@13: OptionProcessOffline = 0x00000000, Chris@13: OptionProcessRealTime = 0x00000001, Chris@13: Chris@13: OptionStretchElastic = 0x00000000, Chris@13: OptionStretchPrecise = 0x00000010, Chris@13: Chris@13: OptionTransientsCrisp = 0x00000000, Chris@13: OptionTransientsMixed = 0x00000100, Chris@13: OptionTransientsSmooth = 0x00000200, Chris@13: Chris@13: OptionDetectorCompound = 0x00000000, Chris@13: OptionDetectorPercussive = 0x00000400, Chris@13: OptionDetectorSoft = 0x00000800, Chris@13: Chris@13: OptionPhaseLaminar = 0x00000000, Chris@13: OptionPhaseIndependent = 0x00002000, Chris@13: Chris@13: OptionThreadingAuto = 0x00000000, Chris@13: OptionThreadingNever = 0x00010000, Chris@13: OptionThreadingAlways = 0x00020000, Chris@13: Chris@13: OptionWindowStandard = 0x00000000, Chris@13: OptionWindowShort = 0x00100000, Chris@13: OptionWindowLong = 0x00200000, Chris@13: Chris@13: OptionSmoothingOff = 0x00000000, Chris@13: OptionSmoothingOn = 0x00800000, Chris@13: Chris@13: OptionFormantShifted = 0x00000000, Chris@13: OptionFormantPreserved = 0x01000000, Chris@13: Chris@13: OptionPitchHighSpeed = 0x00000000, Chris@13: OptionPitchHighQuality = 0x02000000, Chris@13: OptionPitchHighConsistency = 0x04000000, Chris@13: Chris@13: OptionChannelsApart = 0x00000000, Chris@13: OptionChannelsTogether = 0x10000000, Chris@13: Chris@13: // n.b. Options is int, so we must stop before 0x80000000 Chris@13: }; Chris@13: Chris@13: typedef int Options; Chris@13: Chris@13: enum PresetOption { Chris@13: DefaultOptions = 0x00000000, Chris@13: PercussiveOptions = 0x00102000 Chris@13: }; Chris@13: Chris@13: /** Chris@13: * Construct a time and pitch stretcher object to run at the given Chris@13: * sample rate, with the given number of channels. Processing Chris@13: * options and the time and pitch scaling ratios may be provided. Chris@13: * The time and pitch ratios may be changed after construction, Chris@13: * but most of the options may not. See the option documentation Chris@13: * above for more details. Chris@13: */ Chris@13: RubberBandStretcher(size_t sampleRate, Chris@13: size_t channels, Chris@13: Options options = DefaultOptions, Chris@13: double initialTimeRatio = 1.0, Chris@13: double initialPitchScale = 1.0); Chris@13: ~RubberBandStretcher(); Chris@13: Chris@13: /** Chris@13: * Reset the stretcher's internal buffers. The stretcher should Chris@13: * subsequently behave as if it had just been constructed Chris@13: * (although retaining the current time and pitch ratio). Chris@13: */ Chris@13: void reset(); Chris@13: Chris@13: /** Chris@13: * Set the time ratio for the stretcher. This is the ratio of Chris@13: * stretched to unstretched duration -- not tempo. For example, a Chris@13: * ratio of 2.0 would make the audio twice as long (i.e. halve the Chris@13: * tempo); 0.5 would make it half as long (i.e. double the tempo); Chris@13: * 1.0 would leave the duration unaffected. Chris@13: * Chris@13: * If the stretcher was constructed in Offline mode, the time Chris@13: * ratio is fixed throughout operation; this function may be Chris@13: * called any number of times between construction (or a call to Chris@13: * reset()) and the first call to study() or process(), but may Chris@13: * not be called after study() or process() has been called. Chris@13: * Chris@13: * If the stretcher was constructed in RealTime mode, the time Chris@13: * ratio may be varied during operation; this function may be Chris@13: * called at any time, so long as it is not called concurrently Chris@13: * with process(). You should either call this function from the Chris@13: * same thread as process(), or provide your own mutex or similar Chris@13: * mechanism to ensure that setTimeRatio and process() cannot be Chris@13: * run at once (there is no internal mutex for this purpose). Chris@13: */ Chris@13: void setTimeRatio(double ratio); Chris@13: Chris@13: /** Chris@13: * Set the pitch scaling ratio for the stretcher. This is the Chris@13: * ratio of target frequency to source frequency. For example, a Chris@13: * ratio of 2.0 would shift up by one octave; 0.5 down by one Chris@13: * octave; or 1.0 leave the pitch unaffected. Chris@13: * Chris@13: * To put this in musical terms, a pitch scaling ratio Chris@13: * corresponding to a shift of S equal-tempered semitones (where S Chris@13: * is positive for an upwards shift and negative for downwards) is Chris@13: * pow(2.0, S / 12.0). Chris@13: * Chris@13: * If the stretcher was constructed in Offline mode, the pitch Chris@13: * scaling ratio is fixed throughout operation; this function may Chris@13: * be called any number of times between construction (or a call Chris@13: * to reset()) and the first call to study() or process(), but may Chris@13: * not be called after study() or process() has been called. Chris@13: * Chris@13: * If the stretcher was constructed in RealTime mode, the pitch Chris@13: * scaling ratio may be varied during operation; this function may Chris@13: * be called at any time, so long as it is not called concurrently Chris@13: * with process(). You should either call this function from the Chris@13: * same thread as process(), or provide your own mutex or similar Chris@13: * mechanism to ensure that setPitchScale and process() cannot be Chris@13: * run at once (there is no internal mutex for this purpose). Chris@13: */ Chris@13: void setPitchScale(double scale); Chris@13: Chris@13: /** Chris@13: * Return the last time ratio value that was set (either on Chris@13: * construction or with setTimeRatio()). Chris@13: */ Chris@13: double getTimeRatio() const; Chris@13: Chris@13: /** Chris@13: * Return the last pitch scaling ratio value that was set (either Chris@13: * on construction or with setPitchScale()). Chris@13: */ Chris@13: double getPitchScale() const; Chris@13: Chris@13: /** Chris@13: * Return the processing latency of the stretcher. This is the Chris@13: * number of audio samples that one would have to discard at the Chris@13: * start of the output in order to ensure that the resulting audio Chris@13: * aligned with the input audio at the start. In Offline mode, Chris@13: * latency is automatically adjusted for and the result is zero. Chris@13: * In RealTime mode, the latency may depend on the time and pitch Chris@13: * ratio and other options. Chris@13: */ Chris@13: size_t getLatency() const; Chris@13: Chris@13: /** Chris@13: * Change an OptionTransients configuration setting. This may be Chris@13: * called at any time in RealTime mode. It may not be called in Chris@13: * Offline mode (for which the transients option is fixed on Chris@13: * construction). Chris@13: */ Chris@13: void setTransientsOption(Options options); Chris@13: Chris@13: /** Chris@13: * Change an OptionDetector configuration setting. This may be Chris@13: * called at any time in RealTime mode. It may not be called in Chris@13: * Offline mode (for which the detector option is fixed on Chris@13: * construction). Chris@13: */ Chris@13: void setDetectorOption(Options options); Chris@13: Chris@13: /** Chris@13: * Change an OptionPhase configuration setting. This may be Chris@13: * called at any time in any mode. Chris@13: * Chris@13: * Note that if running multi-threaded in Offline mode, the change Chris@13: * may not take effect immediately if processing is already under Chris@13: * way when this function is called. Chris@13: */ Chris@13: void setPhaseOption(Options options); Chris@13: Chris@13: /** Chris@13: * Change an OptionFormant configuration setting. This may be Chris@13: * called at any time in any mode. Chris@13: * Chris@13: * Note that if running multi-threaded in Offline mode, the change Chris@13: * may not take effect immediately if processing is already under Chris@13: * way when this function is called. Chris@13: */ Chris@13: void setFormantOption(Options options); Chris@13: Chris@13: /** Chris@13: * Change an OptionPitch configuration setting. This may be Chris@13: * called at any time in RealTime mode. It may not be called in Chris@13: * Offline mode (for which the transients option is fixed on Chris@13: * construction). Chris@13: */ Chris@13: void setPitchOption(Options options); Chris@13: Chris@13: /** Chris@13: * Tell the stretcher exactly how many input samples it will Chris@13: * receive. This is only useful in Offline mode, when it allows Chris@13: * the stretcher to ensure that the number of output samples is Chris@13: * exactly correct. In RealTime mode no such guarantee is Chris@13: * possible and this value is ignored. Chris@13: */ Chris@13: void setExpectedInputDuration(size_t samples); Chris@13: Chris@13: /** Chris@13: * Tell the stretcher the maximum number of sample frames that you Chris@13: * will ever be passing in to a single process() call. If you Chris@13: * don't call this, the stretcher will assume that you are calling Chris@13: * getSamplesRequired() at each cycle and are never passing more Chris@13: * samples than are suggested by that function. Chris@13: * Chris@13: * If your application has some external constraint that means you Chris@13: * prefer a fixed block size, then your normal mode of operation Chris@13: * would be to provide that block size to this function; to loop Chris@13: * calling process() with that size of block; after each call to Chris@13: * process(), test whether output has been generated by calling Chris@13: * available(); and, if so, call retrieve() to obtain it. See Chris@13: * getSamplesRequired() for a more suitable operating mode for Chris@13: * applications without such external constraints. Chris@13: * Chris@13: * This function may not be called after the first call to study() Chris@13: * or process(). Chris@13: * Chris@13: * Note that this value is only relevant to process(), not to Chris@13: * study() (to which you may pass any number of samples at a time, Chris@13: * and from which there is no output). Chris@13: */ Chris@13: void setMaxProcessSize(size_t samples); Chris@13: Chris@13: /** Chris@13: * Ask the stretcher how many audio sample frames should be Chris@13: * provided as input in order to ensure that some more output Chris@13: * becomes available. Chris@13: * Chris@13: * If your application has no particular constraint on processing Chris@13: * block size and you are able to provide any block size as input Chris@13: * for each cycle, then your normal mode of operation would be to Chris@13: * loop querying this function; providing that number of samples Chris@13: * to process(); and reading the output using available() and Chris@13: * retrieve(). See setMaxProcessSize() for a more suitable Chris@13: * operating mode for applications that do have external block Chris@13: * size constraints. Chris@13: * Chris@13: * Note that this value is only relevant to process(), not to Chris@13: * study() (to which you may pass any number of samples at a time, Chris@13: * and from which there is no output). Chris@13: */ Chris@13: size_t getSamplesRequired() const; Chris@13: Chris@13: /** Chris@13: * Provide a set of mappings from "before" to "after" sample Chris@13: * numbers so as to enforce a particular stretch profile. The Chris@13: * argument is a map from audio sample frame number in the source Chris@13: * material, to the corresponding sample frame number in the Chris@13: * stretched output. The mapping should be for key frames only, Chris@13: * with a "reasonable" gap between mapped samples. Chris@13: * Chris@13: * This function cannot be used in RealTime mode. Chris@13: * Chris@13: * This function may not be called after the first call to Chris@13: * process(). It should be called after the time and pitch ratios Chris@13: * have been set; the results of changing the time and pitch Chris@13: * ratios after calling this function are undefined. Calling Chris@13: * reset() will clear this mapping. Chris@13: * Chris@13: * The key frame map only affects points within the material; it Chris@13: * does not determine the overall stretch ratio (that is, the Chris@13: * ratio between the output material's duration and the source Chris@13: * material's duration). You need to provide this ratio Chris@13: * separately to setTimeRatio(), otherwise the results may be Chris@13: * truncated or extended in unexpected ways regardless of the Chris@13: * extent of the frame numbers found in the key frame map. Chris@13: */ Chris@13: void setKeyFrameMap(const std::map &); Chris@13: Chris@13: /** Chris@13: * Provide a block of "samples" sample frames for the stretcher to Chris@13: * study and calculate a stretch profile from. Chris@13: * Chris@13: * This is only meaningful in Offline mode, and is required if Chris@13: * running in that mode. You should pass the entire input through Chris@13: * study() before any process() calls are made, as a sequence of Chris@13: * blocks in individual study() calls, or as a single large block. Chris@13: * Chris@13: * "input" should point to de-interleaved audio data with one Chris@13: * float array per channel. "samples" supplies the number of Chris@13: * audio sample frames available in "input". If "samples" is Chris@13: * zero, "input" may be NULL. Chris@13: * Chris@13: * Set "final" to true if this is the last block of data that will Chris@13: * be provided to study() before the first process() call. Chris@13: */ Chris@13: void study(const float *const *input, size_t samples, bool final); Chris@13: Chris@13: /** Chris@13: * Provide a block of "samples" sample frames for processing. Chris@13: * See also getSamplesRequired() and setMaxProcessSize(). Chris@13: * Chris@13: * Set "final" to true if this is the last block of input data. Chris@13: */ Chris@13: void process(const float *const *input, size_t samples, bool final); Chris@13: Chris@13: /** Chris@13: * Ask the stretcher how many audio sample frames of output data Chris@13: * are available for reading (via retrieve()). Chris@13: * Chris@13: * This function returns 0 if no frames are available: this Chris@13: * usually means more input data needs to be provided, but if the Chris@13: * stretcher is running in threaded mode it may just mean that not Chris@13: * enough data has yet been processed. Call getSamplesRequired() Chris@13: * to discover whether more input is needed. Chris@13: * Chris@13: * This function returns -1 if all data has been fully processed Chris@13: * and all output read, and the stretch process is now finished. Chris@13: */ Chris@13: int available() const; Chris@13: Chris@13: /** Chris@13: * Obtain some processed output data from the stretcher. Up to Chris@13: * "samples" samples will be stored in the output arrays (one per Chris@13: * channel for de-interleaved audio data) pointed to by "output". Chris@13: * The return value is the actual number of sample frames Chris@13: * retrieved. Chris@13: */ Chris@13: size_t retrieve(float *const *output, size_t samples) const; Chris@13: Chris@13: /** Chris@13: * Return the value of internal frequency cutoff value n. Chris@13: * Chris@13: * This function is not for general use. Chris@13: */ Chris@13: float getFrequencyCutoff(int n) const; Chris@13: Chris@13: /** Chris@13: * Set the value of internal frequency cutoff n to f Hz. Chris@13: * Chris@13: * This function is not for general use. Chris@13: */ Chris@13: void setFrequencyCutoff(int n, float f); Chris@13: Chris@13: /** Chris@13: * Retrieve the value of the internal input block increment value. Chris@13: * Chris@13: * This function is provided for diagnostic purposes only. Chris@13: */ Chris@13: size_t getInputIncrement() const; Chris@13: Chris@13: /** Chris@13: * In offline mode, retrieve the sequence of internal block Chris@13: * increments for output, for the entire audio data, provided the Chris@13: * stretch profile has been calculated. In realtime mode, Chris@13: * retrieve any output increments that have accumulated since the Chris@13: * last call to getOutputIncrements, to a limit of 16. Chris@13: * Chris@13: * This function is provided for diagnostic purposes only. Chris@13: */ Chris@13: std::vector getOutputIncrements() const; Chris@13: Chris@13: /** Chris@13: * In offline mode, retrieve the sequence of internal phase reset Chris@13: * detection function values, for the entire audio data, provided Chris@13: * the stretch profile has been calculated. In realtime mode, Chris@13: * retrieve any phase reset points that have accumulated since the Chris@13: * last call to getPhaseResetCurve, to a limit of 16. Chris@13: * Chris@13: * This function is provided for diagnostic purposes only. Chris@13: */ Chris@13: std::vector getPhaseResetCurve() const; Chris@13: Chris@13: /** Chris@13: * In offline mode, retrieve the sequence of internal frames for Chris@13: * which exact timing has been sought, for the entire audio data, Chris@13: * provided the stretch profile has been calculated. In realtime Chris@13: * mode, return an empty sequence. Chris@13: * Chris@13: * This function is provided for diagnostic purposes only. Chris@13: */ Chris@13: std::vector getExactTimePoints() const; Chris@13: Chris@13: /** Chris@13: * Return the number of channels this stretcher was constructed Chris@13: * with. Chris@13: */ Chris@13: size_t getChannelCount() const; Chris@13: Chris@13: /** Chris@13: * Force the stretcher to calculate a stretch profile. Normally Chris@13: * this happens automatically for the first process() call in Chris@13: * offline mode. Chris@13: * Chris@13: * This function is provided for diagnostic purposes only. Chris@13: */ Chris@13: void calculateStretch(); Chris@13: Chris@13: /** Chris@13: * Set the level of debug output. The value may be from 0 (errors Chris@13: * only) to 3 (very verbose, with audible ticks in the output at Chris@13: * phase reset points). The default is whatever has been set Chris@13: * using setDefaultDebugLevel, or 0 if that function has not been Chris@13: * called. Chris@13: */ Chris@13: void setDebugLevel(int level); Chris@13: Chris@13: /** Chris@13: * Set the default level of debug output for subsequently Chris@13: * constructed stretchers. Chris@13: * Chris@13: * @see setDebugLevel Chris@13: */ Chris@13: static void setDefaultDebugLevel(int level); Chris@13: Chris@13: protected: Chris@13: class Impl; Chris@13: Impl *m_d; Chris@13: }; Chris@13: Chris@13: } Chris@13: Chris@13: #endif