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