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