annotate osx/include/rubberband/RubberBandStretcher.h @ 54:5f67a29f0fc7

Rebuild MAD with 64-bit FPM
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 30 Nov 2016 20:59:17 +0000
parents fffb975dc0b1
children
rev   line source
matthiasm@27 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
matthiasm@27 2
matthiasm@27 3 /*
matthiasm@27 4 Rubber Band Library
matthiasm@27 5 An audio time-stretching and pitch-shifting library.
matthiasm@27 6 Copyright 2007-2012 Particular Programs Ltd.
matthiasm@27 7
matthiasm@27 8 This program is free software; you can redistribute it and/or
matthiasm@27 9 modify it under the terms of the GNU General Public License as
matthiasm@27 10 published by the Free Software Foundation; either version 2 of the
matthiasm@27 11 License, or (at your option) any later version. See the file
matthiasm@27 12 COPYING included with this distribution for more information.
matthiasm@27 13
matthiasm@27 14 Alternatively, if you have a valid commercial licence for the
matthiasm@27 15 Rubber Band Library obtained by agreement with the copyright
matthiasm@27 16 holders, you may redistribute and/or modify it under the terms
matthiasm@27 17 described in that licence.
matthiasm@27 18
matthiasm@27 19 If you wish to distribute code using the Rubber Band Library
matthiasm@27 20 under terms other than those of the GNU General Public License,
matthiasm@27 21 you must obtain a valid commercial licence before doing so.
matthiasm@27 22 */
matthiasm@27 23
matthiasm@27 24 #ifndef _RUBBERBANDSTRETCHER_H_
matthiasm@27 25 #define _RUBBERBANDSTRETCHER_H_
matthiasm@27 26
matthiasm@27 27 #define RUBBERBAND_VERSION "1.8.1"
matthiasm@27 28 #define RUBBERBAND_API_MAJOR_VERSION 2
matthiasm@27 29 #define RUBBERBAND_API_MINOR_VERSION 5
matthiasm@27 30
matthiasm@27 31 #include <vector>
matthiasm@27 32 #include <map>
matthiasm@27 33 #include <cstddef>
matthiasm@27 34
matthiasm@27 35 /**
matthiasm@27 36 * @mainpage RubberBand
matthiasm@27 37 *
matthiasm@27 38 * The Rubber Band API is contained in the single class
matthiasm@27 39 * RubberBand::RubberBandStretcher.
matthiasm@27 40 *
matthiasm@27 41 * Threading notes for real-time applications:
matthiasm@27 42 *
matthiasm@27 43 * Multiple instances of RubberBandStretcher may be created and used
matthiasm@27 44 * in separate threads concurrently. However, for any single instance
matthiasm@27 45 * of RubberBandStretcher, you may not call process() more than once
matthiasm@27 46 * concurrently, and you may not change the time or pitch ratio while
matthiasm@27 47 * a process() call is being executed (if the stretcher was created in
matthiasm@27 48 * "real-time mode"; in "offline mode" you can't change the ratios
matthiasm@27 49 * during use anyway).
matthiasm@27 50 *
matthiasm@27 51 * So you can run process() in its own thread if you like, but if you
matthiasm@27 52 * want to change ratios dynamically from a different thread, you will
matthiasm@27 53 * need some form of mutex in your code. Changing the time or pitch
matthiasm@27 54 * ratio is real-time safe except in extreme circumstances, so for
matthiasm@27 55 * most applications that may change these dynamically it probably
matthiasm@27 56 * makes most sense to do so from the same thread as calls process(),
matthiasm@27 57 * even if that is a real-time thread.
matthiasm@27 58 */
matthiasm@27 59
matthiasm@27 60 namespace RubberBand
matthiasm@27 61 {
matthiasm@27 62
matthiasm@27 63 class RubberBandStretcher
matthiasm@27 64 {
matthiasm@27 65 public:
matthiasm@27 66 /**
matthiasm@27 67 * Processing options for the timestretcher. The preferred
matthiasm@27 68 * options should normally be set in the constructor, as a bitwise
matthiasm@27 69 * OR of the option flags. The default value (DefaultOptions) is
matthiasm@27 70 * intended to give good results in most situations.
matthiasm@27 71 *
matthiasm@27 72 * 1. Flags prefixed \c OptionProcess determine how the timestretcher
matthiasm@27 73 * will be invoked. These options may not be changed after
matthiasm@27 74 * construction.
matthiasm@27 75 *
matthiasm@27 76 * \li \c OptionProcessOffline - Run the stretcher in offline
matthiasm@27 77 * mode. In this mode the input data needs to be provided
matthiasm@27 78 * twice, once to study(), which calculates a stretch profile
matthiasm@27 79 * for the audio, and once to process(), which stretches it.
matthiasm@27 80 *
matthiasm@27 81 * \li \c OptionProcessRealTime - Run the stretcher in real-time
matthiasm@27 82 * mode. In this mode only process() should be called, and the
matthiasm@27 83 * stretcher adjusts dynamically in response to the input audio.
matthiasm@27 84 *
matthiasm@27 85 * The Process setting is likely to depend on your architecture:
matthiasm@27 86 * non-real-time operation on seekable files: Offline; real-time
matthiasm@27 87 * or streaming operation: RealTime.
matthiasm@27 88 *
matthiasm@27 89 * 2. Flags prefixed \c OptionStretch control the profile used for
matthiasm@27 90 * variable timestretching. Rubber Band always adjusts the
matthiasm@27 91 * stretch profile to minimise stretching of busy broadband
matthiasm@27 92 * transient sounds, but the degree to which it does so is
matthiasm@27 93 * adjustable. These options may not be changed after
matthiasm@27 94 * construction.
matthiasm@27 95 *
matthiasm@27 96 * \li \c OptionStretchElastic - Only meaningful in offline
matthiasm@27 97 * mode, and the default in that mode. The audio will be
matthiasm@27 98 * stretched at a variable rate, aimed at preserving the quality
matthiasm@27 99 * of transient sounds as much as possible. The timings of low
matthiasm@27 100 * activity regions between transients may be less exact than
matthiasm@27 101 * when the precise flag is set.
matthiasm@27 102 *
matthiasm@27 103 * \li \c OptionStretchPrecise - Although still using a variable
matthiasm@27 104 * stretch rate, the audio will be stretched so as to maintain
matthiasm@27 105 * as close as possible to a linear stretch ratio throughout.
matthiasm@27 106 * Timing may be better than when using \c OptionStretchElastic, at
matthiasm@27 107 * slight cost to the sound quality of transients. This setting
matthiasm@27 108 * is always used when running in real-time mode.
matthiasm@27 109 *
matthiasm@27 110 * 3. Flags prefixed \c OptionTransients control the component
matthiasm@27 111 * frequency phase-reset mechanism that may be used at transient
matthiasm@27 112 * points to provide clarity and realism to percussion and other
matthiasm@27 113 * significant transient sounds. These options may be changed
matthiasm@27 114 * after construction when running in real-time mode, but not when
matthiasm@27 115 * running in offline mode.
matthiasm@27 116 *
matthiasm@27 117 * \li \c OptionTransientsCrisp - Reset component phases at the
matthiasm@27 118 * peak of each transient (the start of a significant note or
matthiasm@27 119 * percussive event). This, the default setting, usually
matthiasm@27 120 * results in a clear-sounding output; but it is not always
matthiasm@27 121 * consistent, and may cause interruptions in stable sounds
matthiasm@27 122 * present at the same time as transient events. The
matthiasm@27 123 * OptionDetector flags (below) can be used to tune this to some
matthiasm@27 124 * extent.
matthiasm@27 125 *
matthiasm@27 126 * \li \c OptionTransientsMixed - Reset component phases at the
matthiasm@27 127 * peak of each transient, outside a frequency range typical of
matthiasm@27 128 * musical fundamental frequencies. The results may be more
matthiasm@27 129 * regular for mixed stable and percussive notes than
matthiasm@27 130 * \c OptionTransientsCrisp, but with a "phasier" sound. The
matthiasm@27 131 * balance may sound very good for certain types of music and
matthiasm@27 132 * fairly bad for others.
matthiasm@27 133 *
matthiasm@27 134 * \li \c OptionTransientsSmooth - Do not reset component phases
matthiasm@27 135 * at any point. The results will be smoother and more regular
matthiasm@27 136 * but may be less clear than with either of the other
matthiasm@27 137 * transients flags.
matthiasm@27 138 *
matthiasm@27 139 * 4. Flags prefixed \c OptionDetector control the type of
matthiasm@27 140 * transient detector used. These options may be changed
matthiasm@27 141 * after construction when running in real-time mode, but not when
matthiasm@27 142 * running in offline mode.
matthiasm@27 143 *
matthiasm@27 144 * \li \c OptionDetectorCompound - Use a general-purpose
matthiasm@27 145 * transient detector which is likely to be good for most
matthiasm@27 146 * situations. This is the default.
matthiasm@27 147 *
matthiasm@27 148 * \li \c OptionDetectorPercussive - Detect percussive
matthiasm@27 149 * transients. Note that this was the default and only option
matthiasm@27 150 * in Rubber Band versions prior to 1.5.
matthiasm@27 151 *
matthiasm@27 152 * \li \c OptionDetectorSoft - Use an onset detector with less
matthiasm@27 153 * of a bias toward percussive transients. This may give better
matthiasm@27 154 * results with certain material (e.g. relatively monophonic
matthiasm@27 155 * piano music).
matthiasm@27 156 *
matthiasm@27 157 * 5. Flags prefixed \c OptionPhase control the adjustment of
matthiasm@27 158 * component frequency phases from one analysis window to the next
matthiasm@27 159 * during non-transient segments. These options may be changed at
matthiasm@27 160 * any time.
matthiasm@27 161 *
matthiasm@27 162 * \li \c OptionPhaseLaminar - Adjust phases when stretching in
matthiasm@27 163 * such a way as to try to retain the continuity of phase
matthiasm@27 164 * relationships between adjacent frequency bins whose phases
matthiasm@27 165 * are behaving in similar ways. This, the default setting,
matthiasm@27 166 * should give good results in most situations.
matthiasm@27 167 *
matthiasm@27 168 * \li \c OptionPhaseIndependent - Adjust the phase in each
matthiasm@27 169 * frequency bin independently from its neighbours. This
matthiasm@27 170 * usually results in a slightly softer, phasier sound.
matthiasm@27 171 *
matthiasm@27 172 * 6. Flags prefixed \c OptionThreading control the threading
matthiasm@27 173 * model of the stretcher. These options may not be changed after
matthiasm@27 174 * construction.
matthiasm@27 175 *
matthiasm@27 176 * \li \c OptionThreadingAuto - Permit the stretcher to
matthiasm@27 177 * determine its own threading model. Usually this means using
matthiasm@27 178 * one processing thread per audio channel in offline mode if
matthiasm@27 179 * the stretcher is able to determine that more than one CPU is
matthiasm@27 180 * available, and one thread only in realtime mode. This is the
matthiasm@27 181 * defafult.
matthiasm@27 182 *
matthiasm@27 183 * \li \c OptionThreadingNever - Never use more than one thread.
matthiasm@27 184 *
matthiasm@27 185 * \li \c OptionThreadingAlways - Use multiple threads in any
matthiasm@27 186 * situation where \c OptionThreadingAuto would do so, except omit
matthiasm@27 187 * the check for multiple CPUs and instead assume it to be true.
matthiasm@27 188 *
matthiasm@27 189 * 7. Flags prefixed \c OptionWindow control the window size for
matthiasm@27 190 * FFT processing. The window size actually used will depend on
matthiasm@27 191 * many factors, but it can be influenced. These options may not
matthiasm@27 192 * be changed after construction.
matthiasm@27 193 *
matthiasm@27 194 * \li \c OptionWindowStandard - Use the default window size.
matthiasm@27 195 * The actual size will vary depending on other parameters.
matthiasm@27 196 * This option is expected to produce better results than the
matthiasm@27 197 * other window options in most situations.
matthiasm@27 198 *
matthiasm@27 199 * \li \c OptionWindowShort - Use a shorter window. This may
matthiasm@27 200 * result in crisper sound for audio that depends strongly on
matthiasm@27 201 * its timing qualities.
matthiasm@27 202 *
matthiasm@27 203 * \li \c OptionWindowLong - Use a longer window. This is
matthiasm@27 204 * likely to result in a smoother sound at the expense of
matthiasm@27 205 * clarity and timing.
matthiasm@27 206 *
matthiasm@27 207 * 8. Flags prefixed \c OptionSmoothing control the use of
matthiasm@27 208 * window-presum FFT and time-domain smoothing. These options may
matthiasm@27 209 * not be changed after construction.
matthiasm@27 210 *
matthiasm@27 211 * \li \c OptionSmoothingOff - Do not use time-domain smoothing.
matthiasm@27 212 * This is the default.
matthiasm@27 213 *
matthiasm@27 214 * \li \c OptionSmoothingOn - Use time-domain smoothing. This
matthiasm@27 215 * will result in a softer sound with some audible artifacts
matthiasm@27 216 * around sharp transients, but it may be appropriate for longer
matthiasm@27 217 * stretches of some instruments and can mix well with
matthiasm@27 218 * OptionWindowShort.
matthiasm@27 219 *
matthiasm@27 220 * 9. Flags prefixed \c OptionFormant control the handling of
matthiasm@27 221 * formant shape (spectral envelope) when pitch-shifting. These
matthiasm@27 222 * options may be changed at any time.
matthiasm@27 223 *
matthiasm@27 224 * \li \c OptionFormantShifted - Apply no special formant
matthiasm@27 225 * processing. The spectral envelope will be pitch shifted as
matthiasm@27 226 * normal. This is the default.
matthiasm@27 227 *
matthiasm@27 228 * \li \c OptionFormantPreserved - Preserve the spectral
matthiasm@27 229 * envelope of the unshifted signal. This permits shifting the
matthiasm@27 230 * note frequency without so substantially affecting the
matthiasm@27 231 * perceived pitch profile of the voice or instrument.
matthiasm@27 232 *
matthiasm@27 233 * 10. Flags prefixed \c OptionPitch control the method used for
matthiasm@27 234 * pitch shifting. These options may be changed at any time.
matthiasm@27 235 * They are only effective in realtime mode; in offline mode, the
matthiasm@27 236 * pitch-shift method is fixed.
matthiasm@27 237 *
matthiasm@27 238 * \li \c OptionPitchHighSpeed - Use a method with a CPU cost
matthiasm@27 239 * that is relatively moderate and predictable. This may
matthiasm@27 240 * sound less clear than OptionPitchHighQuality, especially
matthiasm@27 241 * for large pitch shifts. This is the default.
matthiasm@27 242
matthiasm@27 243 * \li \c OptionPitchHighQuality - Use the highest quality
matthiasm@27 244 * method for pitch shifting. This method has a CPU cost
matthiasm@27 245 * approximately proportional to the required frequency shift.
matthiasm@27 246
matthiasm@27 247 * \li \c OptionPitchHighConsistency - Use the method that gives
matthiasm@27 248 * greatest consistency when used to create small variations in
matthiasm@27 249 * pitch around the 1.0-ratio level. Unlike the previous two
matthiasm@27 250 * options, this avoids discontinuities when moving across the
matthiasm@27 251 * 1.0 pitch scale in real-time; it also consumes more CPU than
matthiasm@27 252 * the others in the case where the pitch scale is exactly 1.0.
matthiasm@27 253 *
matthiasm@27 254 * 11. Flags prefixed \c OptionChannels control the method used for
matthiasm@27 255 * processing two-channel audio. These options may not be changed
matthiasm@27 256 * after construction.
matthiasm@27 257 *
matthiasm@27 258 * \li \c OptionChannelsApart - Each channel is processed
matthiasm@27 259 * individually, though timing is synchronised and phases are
matthiasm@27 260 * synchronised at transients (depending on the OptionTransients
matthiasm@27 261 * setting). This gives the highest quality for the individual
matthiasm@27 262 * channels but a relative lack of stereo focus and unrealistic
matthiasm@27 263 * increase in "width". This is the default.
matthiasm@27 264 *
matthiasm@27 265 * \li \c OptionChannelsTogether - The first two channels (where
matthiasm@27 266 * two or more are present) are considered to be a stereo pair
matthiasm@27 267 * and are processed in mid-side format; mid and side are
matthiasm@27 268 * processed individually, with timing synchronised and phases
matthiasm@27 269 * synchronised at transients (depending on the OptionTransients
matthiasm@27 270 * setting). This usually leads to better focus in the centre
matthiasm@27 271 * but a loss of stereo space and width. Any channels beyond
matthiasm@27 272 * the first two are processed individually.
matthiasm@27 273 */
matthiasm@27 274
matthiasm@27 275 enum Option {
matthiasm@27 276
matthiasm@27 277 OptionProcessOffline = 0x00000000,
matthiasm@27 278 OptionProcessRealTime = 0x00000001,
matthiasm@27 279
matthiasm@27 280 OptionStretchElastic = 0x00000000,
matthiasm@27 281 OptionStretchPrecise = 0x00000010,
matthiasm@27 282
matthiasm@27 283 OptionTransientsCrisp = 0x00000000,
matthiasm@27 284 OptionTransientsMixed = 0x00000100,
matthiasm@27 285 OptionTransientsSmooth = 0x00000200,
matthiasm@27 286
matthiasm@27 287 OptionDetectorCompound = 0x00000000,
matthiasm@27 288 OptionDetectorPercussive = 0x00000400,
matthiasm@27 289 OptionDetectorSoft = 0x00000800,
matthiasm@27 290
matthiasm@27 291 OptionPhaseLaminar = 0x00000000,
matthiasm@27 292 OptionPhaseIndependent = 0x00002000,
matthiasm@27 293
matthiasm@27 294 OptionThreadingAuto = 0x00000000,
matthiasm@27 295 OptionThreadingNever = 0x00010000,
matthiasm@27 296 OptionThreadingAlways = 0x00020000,
matthiasm@27 297
matthiasm@27 298 OptionWindowStandard = 0x00000000,
matthiasm@27 299 OptionWindowShort = 0x00100000,
matthiasm@27 300 OptionWindowLong = 0x00200000,
matthiasm@27 301
matthiasm@27 302 OptionSmoothingOff = 0x00000000,
matthiasm@27 303 OptionSmoothingOn = 0x00800000,
matthiasm@27 304
matthiasm@27 305 OptionFormantShifted = 0x00000000,
matthiasm@27 306 OptionFormantPreserved = 0x01000000,
matthiasm@27 307
matthiasm@27 308 OptionPitchHighSpeed = 0x00000000,
matthiasm@27 309 OptionPitchHighQuality = 0x02000000,
matthiasm@27 310 OptionPitchHighConsistency = 0x04000000,
matthiasm@27 311
matthiasm@27 312 OptionChannelsApart = 0x00000000,
matthiasm@27 313 OptionChannelsTogether = 0x10000000,
matthiasm@27 314
matthiasm@27 315 // n.b. Options is int, so we must stop before 0x80000000
matthiasm@27 316 };
matthiasm@27 317
matthiasm@27 318 typedef int Options;
matthiasm@27 319
matthiasm@27 320 enum PresetOption {
matthiasm@27 321 DefaultOptions = 0x00000000,
matthiasm@27 322 PercussiveOptions = 0x00102000
matthiasm@27 323 };
matthiasm@27 324
matthiasm@27 325 /**
matthiasm@27 326 * Construct a time and pitch stretcher object to run at the given
matthiasm@27 327 * sample rate, with the given number of channels. Processing
matthiasm@27 328 * options and the time and pitch scaling ratios may be provided.
matthiasm@27 329 * The time and pitch ratios may be changed after construction,
matthiasm@27 330 * but most of the options may not. See the option documentation
matthiasm@27 331 * above for more details.
matthiasm@27 332 */
matthiasm@27 333 RubberBandStretcher(size_t sampleRate,
matthiasm@27 334 size_t channels,
matthiasm@27 335 Options options = DefaultOptions,
matthiasm@27 336 double initialTimeRatio = 1.0,
matthiasm@27 337 double initialPitchScale = 1.0);
matthiasm@27 338 ~RubberBandStretcher();
matthiasm@27 339
matthiasm@27 340 /**
matthiasm@27 341 * Reset the stretcher's internal buffers. The stretcher should
matthiasm@27 342 * subsequently behave as if it had just been constructed
matthiasm@27 343 * (although retaining the current time and pitch ratio).
matthiasm@27 344 */
matthiasm@27 345 void reset();
matthiasm@27 346
matthiasm@27 347 /**
matthiasm@27 348 * Set the time ratio for the stretcher. This is the ratio of
matthiasm@27 349 * stretched to unstretched duration -- not tempo. For example, a
matthiasm@27 350 * ratio of 2.0 would make the audio twice as long (i.e. halve the
matthiasm@27 351 * tempo); 0.5 would make it half as long (i.e. double the tempo);
matthiasm@27 352 * 1.0 would leave the duration unaffected.
matthiasm@27 353 *
matthiasm@27 354 * If the stretcher was constructed in Offline mode, the time
matthiasm@27 355 * ratio is fixed throughout operation; this function may be
matthiasm@27 356 * called any number of times between construction (or a call to
matthiasm@27 357 * reset()) and the first call to study() or process(), but may
matthiasm@27 358 * not be called after study() or process() has been called.
matthiasm@27 359 *
matthiasm@27 360 * If the stretcher was constructed in RealTime mode, the time
matthiasm@27 361 * ratio may be varied during operation; this function may be
matthiasm@27 362 * called at any time, so long as it is not called concurrently
matthiasm@27 363 * with process(). You should either call this function from the
matthiasm@27 364 * same thread as process(), or provide your own mutex or similar
matthiasm@27 365 * mechanism to ensure that setTimeRatio and process() cannot be
matthiasm@27 366 * run at once (there is no internal mutex for this purpose).
matthiasm@27 367 */
matthiasm@27 368 void setTimeRatio(double ratio);
matthiasm@27 369
matthiasm@27 370 /**
matthiasm@27 371 * Set the pitch scaling ratio for the stretcher. This is the
matthiasm@27 372 * ratio of target frequency to source frequency. For example, a
matthiasm@27 373 * ratio of 2.0 would shift up by one octave; 0.5 down by one
matthiasm@27 374 * octave; or 1.0 leave the pitch unaffected.
matthiasm@27 375 *
matthiasm@27 376 * To put this in musical terms, a pitch scaling ratio
matthiasm@27 377 * corresponding to a shift of S equal-tempered semitones (where S
matthiasm@27 378 * is positive for an upwards shift and negative for downwards) is
matthiasm@27 379 * pow(2.0, S / 12.0).
matthiasm@27 380 *
matthiasm@27 381 * If the stretcher was constructed in Offline mode, the pitch
matthiasm@27 382 * scaling ratio is fixed throughout operation; this function may
matthiasm@27 383 * be called any number of times between construction (or a call
matthiasm@27 384 * to reset()) and the first call to study() or process(), but may
matthiasm@27 385 * not be called after study() or process() has been called.
matthiasm@27 386 *
matthiasm@27 387 * If the stretcher was constructed in RealTime mode, the pitch
matthiasm@27 388 * scaling ratio may be varied during operation; this function may
matthiasm@27 389 * be called at any time, so long as it is not called concurrently
matthiasm@27 390 * with process(). You should either call this function from the
matthiasm@27 391 * same thread as process(), or provide your own mutex or similar
matthiasm@27 392 * mechanism to ensure that setPitchScale and process() cannot be
matthiasm@27 393 * run at once (there is no internal mutex for this purpose).
matthiasm@27 394 */
matthiasm@27 395 void setPitchScale(double scale);
matthiasm@27 396
matthiasm@27 397 /**
matthiasm@27 398 * Return the last time ratio value that was set (either on
matthiasm@27 399 * construction or with setTimeRatio()).
matthiasm@27 400 */
matthiasm@27 401 double getTimeRatio() const;
matthiasm@27 402
matthiasm@27 403 /**
matthiasm@27 404 * Return the last pitch scaling ratio value that was set (either
matthiasm@27 405 * on construction or with setPitchScale()).
matthiasm@27 406 */
matthiasm@27 407 double getPitchScale() const;
matthiasm@27 408
matthiasm@27 409 /**
matthiasm@27 410 * Return the processing latency of the stretcher. This is the
matthiasm@27 411 * number of audio samples that one would have to discard at the
matthiasm@27 412 * start of the output in order to ensure that the resulting audio
matthiasm@27 413 * aligned with the input audio at the start. In Offline mode,
matthiasm@27 414 * latency is automatically adjusted for and the result is zero.
matthiasm@27 415 * In RealTime mode, the latency may depend on the time and pitch
matthiasm@27 416 * ratio and other options.
matthiasm@27 417 */
matthiasm@27 418 size_t getLatency() const;
matthiasm@27 419
matthiasm@27 420 /**
matthiasm@27 421 * Change an OptionTransients configuration setting. This may be
matthiasm@27 422 * called at any time in RealTime mode. It may not be called in
matthiasm@27 423 * Offline mode (for which the transients option is fixed on
matthiasm@27 424 * construction).
matthiasm@27 425 */
matthiasm@27 426 void setTransientsOption(Options options);
matthiasm@27 427
matthiasm@27 428 /**
matthiasm@27 429 * Change an OptionDetector configuration setting. This may be
matthiasm@27 430 * called at any time in RealTime mode. It may not be called in
matthiasm@27 431 * Offline mode (for which the detector option is fixed on
matthiasm@27 432 * construction).
matthiasm@27 433 */
matthiasm@27 434 void setDetectorOption(Options options);
matthiasm@27 435
matthiasm@27 436 /**
matthiasm@27 437 * Change an OptionPhase configuration setting. This may be
matthiasm@27 438 * called at any time in any mode.
matthiasm@27 439 *
matthiasm@27 440 * Note that if running multi-threaded in Offline mode, the change
matthiasm@27 441 * may not take effect immediately if processing is already under
matthiasm@27 442 * way when this function is called.
matthiasm@27 443 */
matthiasm@27 444 void setPhaseOption(Options options);
matthiasm@27 445
matthiasm@27 446 /**
matthiasm@27 447 * Change an OptionFormant configuration setting. This may be
matthiasm@27 448 * called at any time in any mode.
matthiasm@27 449 *
matthiasm@27 450 * Note that if running multi-threaded in Offline mode, the change
matthiasm@27 451 * may not take effect immediately if processing is already under
matthiasm@27 452 * way when this function is called.
matthiasm@27 453 */
matthiasm@27 454 void setFormantOption(Options options);
matthiasm@27 455
matthiasm@27 456 /**
matthiasm@27 457 * Change an OptionPitch configuration setting. This may be
matthiasm@27 458 * called at any time in RealTime mode. It may not be called in
matthiasm@27 459 * Offline mode (for which the transients option is fixed on
matthiasm@27 460 * construction).
matthiasm@27 461 */
matthiasm@27 462 void setPitchOption(Options options);
matthiasm@27 463
matthiasm@27 464 /**
matthiasm@27 465 * Tell the stretcher exactly how many input samples it will
matthiasm@27 466 * receive. This is only useful in Offline mode, when it allows
matthiasm@27 467 * the stretcher to ensure that the number of output samples is
matthiasm@27 468 * exactly correct. In RealTime mode no such guarantee is
matthiasm@27 469 * possible and this value is ignored.
matthiasm@27 470 */
matthiasm@27 471 void setExpectedInputDuration(size_t samples);
matthiasm@27 472
matthiasm@27 473 /**
matthiasm@27 474 * Tell the stretcher the maximum number of sample frames that you
matthiasm@27 475 * will ever be passing in to a single process() call. If you
matthiasm@27 476 * don't call this, the stretcher will assume that you are calling
matthiasm@27 477 * getSamplesRequired() at each cycle and are never passing more
matthiasm@27 478 * samples than are suggested by that function.
matthiasm@27 479 *
matthiasm@27 480 * If your application has some external constraint that means you
matthiasm@27 481 * prefer a fixed block size, then your normal mode of operation
matthiasm@27 482 * would be to provide that block size to this function; to loop
matthiasm@27 483 * calling process() with that size of block; after each call to
matthiasm@27 484 * process(), test whether output has been generated by calling
matthiasm@27 485 * available(); and, if so, call retrieve() to obtain it. See
matthiasm@27 486 * getSamplesRequired() for a more suitable operating mode for
matthiasm@27 487 * applications without such external constraints.
matthiasm@27 488 *
matthiasm@27 489 * This function may not be called after the first call to study()
matthiasm@27 490 * or process().
matthiasm@27 491 *
matthiasm@27 492 * Note that this value is only relevant to process(), not to
matthiasm@27 493 * study() (to which you may pass any number of samples at a time,
matthiasm@27 494 * and from which there is no output).
matthiasm@27 495 */
matthiasm@27 496 void setMaxProcessSize(size_t samples);
matthiasm@27 497
matthiasm@27 498 /**
matthiasm@27 499 * Ask the stretcher how many audio sample frames should be
matthiasm@27 500 * provided as input in order to ensure that some more output
matthiasm@27 501 * becomes available.
matthiasm@27 502 *
matthiasm@27 503 * If your application has no particular constraint on processing
matthiasm@27 504 * block size and you are able to provide any block size as input
matthiasm@27 505 * for each cycle, then your normal mode of operation would be to
matthiasm@27 506 * loop querying this function; providing that number of samples
matthiasm@27 507 * to process(); and reading the output using available() and
matthiasm@27 508 * retrieve(). See setMaxProcessSize() for a more suitable
matthiasm@27 509 * operating mode for applications that do have external block
matthiasm@27 510 * size constraints.
matthiasm@27 511 *
matthiasm@27 512 * Note that this value is only relevant to process(), not to
matthiasm@27 513 * study() (to which you may pass any number of samples at a time,
matthiasm@27 514 * and from which there is no output).
matthiasm@27 515 */
matthiasm@27 516 size_t getSamplesRequired() const;
matthiasm@27 517
matthiasm@27 518 /**
matthiasm@27 519 * Provide a set of mappings from "before" to "after" sample
matthiasm@27 520 * numbers so as to enforce a particular stretch profile. The
matthiasm@27 521 * argument is a map from audio sample frame number in the source
matthiasm@27 522 * material, to the corresponding sample frame number in the
matthiasm@27 523 * stretched output. The mapping should be for key frames only,
matthiasm@27 524 * with a "reasonable" gap between mapped samples.
matthiasm@27 525 *
matthiasm@27 526 * This function cannot be used in RealTime mode.
matthiasm@27 527 *
matthiasm@27 528 * This function may not be called after the first call to
matthiasm@27 529 * process(). It should be called after the time and pitch ratios
matthiasm@27 530 * have been set; the results of changing the time and pitch
matthiasm@27 531 * ratios after calling this function are undefined. Calling
matthiasm@27 532 * reset() will clear this mapping.
matthiasm@27 533 *
matthiasm@27 534 * The key frame map only affects points within the material; it
matthiasm@27 535 * does not determine the overall stretch ratio (that is, the
matthiasm@27 536 * ratio between the output material's duration and the source
matthiasm@27 537 * material's duration). You need to provide this ratio
matthiasm@27 538 * separately to setTimeRatio(), otherwise the results may be
matthiasm@27 539 * truncated or extended in unexpected ways regardless of the
matthiasm@27 540 * extent of the frame numbers found in the key frame map.
matthiasm@27 541 */
matthiasm@27 542 void setKeyFrameMap(const std::map<size_t, size_t> &);
matthiasm@27 543
matthiasm@27 544 /**
matthiasm@27 545 * Provide a block of "samples" sample frames for the stretcher to
matthiasm@27 546 * study and calculate a stretch profile from.
matthiasm@27 547 *
matthiasm@27 548 * This is only meaningful in Offline mode, and is required if
matthiasm@27 549 * running in that mode. You should pass the entire input through
matthiasm@27 550 * study() before any process() calls are made, as a sequence of
matthiasm@27 551 * blocks in individual study() calls, or as a single large block.
matthiasm@27 552 *
matthiasm@27 553 * "input" should point to de-interleaved audio data with one
matthiasm@27 554 * float array per channel. "samples" supplies the number of
matthiasm@27 555 * audio sample frames available in "input". If "samples" is
matthiasm@27 556 * zero, "input" may be NULL.
matthiasm@27 557 *
matthiasm@27 558 * Set "final" to true if this is the last block of data that will
matthiasm@27 559 * be provided to study() before the first process() call.
matthiasm@27 560 */
matthiasm@27 561 void study(const float *const *input, size_t samples, bool final);
matthiasm@27 562
matthiasm@27 563 /**
matthiasm@27 564 * Provide a block of "samples" sample frames for processing.
matthiasm@27 565 * See also getSamplesRequired() and setMaxProcessSize().
matthiasm@27 566 *
matthiasm@27 567 * Set "final" to true if this is the last block of input data.
matthiasm@27 568 */
matthiasm@27 569 void process(const float *const *input, size_t samples, bool final);
matthiasm@27 570
matthiasm@27 571 /**
matthiasm@27 572 * Ask the stretcher how many audio sample frames of output data
matthiasm@27 573 * are available for reading (via retrieve()).
matthiasm@27 574 *
matthiasm@27 575 * This function returns 0 if no frames are available: this
matthiasm@27 576 * usually means more input data needs to be provided, but if the
matthiasm@27 577 * stretcher is running in threaded mode it may just mean that not
matthiasm@27 578 * enough data has yet been processed. Call getSamplesRequired()
matthiasm@27 579 * to discover whether more input is needed.
matthiasm@27 580 *
matthiasm@27 581 * This function returns -1 if all data has been fully processed
matthiasm@27 582 * and all output read, and the stretch process is now finished.
matthiasm@27 583 */
matthiasm@27 584 int available() const;
matthiasm@27 585
matthiasm@27 586 /**
matthiasm@27 587 * Obtain some processed output data from the stretcher. Up to
matthiasm@27 588 * "samples" samples will be stored in the output arrays (one per
matthiasm@27 589 * channel for de-interleaved audio data) pointed to by "output".
matthiasm@27 590 * The return value is the actual number of sample frames
matthiasm@27 591 * retrieved.
matthiasm@27 592 */
matthiasm@27 593 size_t retrieve(float *const *output, size_t samples) const;
matthiasm@27 594
matthiasm@27 595 /**
matthiasm@27 596 * Return the value of internal frequency cutoff value n.
matthiasm@27 597 *
matthiasm@27 598 * This function is not for general use.
matthiasm@27 599 */
matthiasm@27 600 float getFrequencyCutoff(int n) const;
matthiasm@27 601
matthiasm@27 602 /**
matthiasm@27 603 * Set the value of internal frequency cutoff n to f Hz.
matthiasm@27 604 *
matthiasm@27 605 * This function is not for general use.
matthiasm@27 606 */
matthiasm@27 607 void setFrequencyCutoff(int n, float f);
matthiasm@27 608
matthiasm@27 609 /**
matthiasm@27 610 * Retrieve the value of the internal input block increment value.
matthiasm@27 611 *
matthiasm@27 612 * This function is provided for diagnostic purposes only.
matthiasm@27 613 */
matthiasm@27 614 size_t getInputIncrement() const;
matthiasm@27 615
matthiasm@27 616 /**
matthiasm@27 617 * In offline mode, retrieve the sequence of internal block
matthiasm@27 618 * increments for output, for the entire audio data, provided the
matthiasm@27 619 * stretch profile has been calculated. In realtime mode,
matthiasm@27 620 * retrieve any output increments that have accumulated since the
matthiasm@27 621 * last call to getOutputIncrements, to a limit of 16.
matthiasm@27 622 *
matthiasm@27 623 * This function is provided for diagnostic purposes only.
matthiasm@27 624 */
matthiasm@27 625 std::vector<int> getOutputIncrements() const;
matthiasm@27 626
matthiasm@27 627 /**
matthiasm@27 628 * In offline mode, retrieve the sequence of internal phase reset
matthiasm@27 629 * detection function values, for the entire audio data, provided
matthiasm@27 630 * the stretch profile has been calculated. In realtime mode,
matthiasm@27 631 * retrieve any phase reset points that have accumulated since the
matthiasm@27 632 * last call to getPhaseResetCurve, to a limit of 16.
matthiasm@27 633 *
matthiasm@27 634 * This function is provided for diagnostic purposes only.
matthiasm@27 635 */
matthiasm@27 636 std::vector<float> getPhaseResetCurve() const;
matthiasm@27 637
matthiasm@27 638 /**
matthiasm@27 639 * In offline mode, retrieve the sequence of internal frames for
matthiasm@27 640 * which exact timing has been sought, for the entire audio data,
matthiasm@27 641 * provided the stretch profile has been calculated. In realtime
matthiasm@27 642 * mode, return an empty sequence.
matthiasm@27 643 *
matthiasm@27 644 * This function is provided for diagnostic purposes only.
matthiasm@27 645 */
matthiasm@27 646 std::vector<int> getExactTimePoints() const;
matthiasm@27 647
matthiasm@27 648 /**
matthiasm@27 649 * Return the number of channels this stretcher was constructed
matthiasm@27 650 * with.
matthiasm@27 651 */
matthiasm@27 652 size_t getChannelCount() const;
matthiasm@27 653
matthiasm@27 654 /**
matthiasm@27 655 * Force the stretcher to calculate a stretch profile. Normally
matthiasm@27 656 * this happens automatically for the first process() call in
matthiasm@27 657 * offline mode.
matthiasm@27 658 *
matthiasm@27 659 * This function is provided for diagnostic purposes only.
matthiasm@27 660 */
matthiasm@27 661 void calculateStretch();
matthiasm@27 662
matthiasm@27 663 /**
matthiasm@27 664 * Set the level of debug output. The value may be from 0 (errors
matthiasm@27 665 * only) to 3 (very verbose, with audible ticks in the output at
matthiasm@27 666 * phase reset points). The default is whatever has been set
matthiasm@27 667 * using setDefaultDebugLevel, or 0 if that function has not been
matthiasm@27 668 * called.
matthiasm@27 669 */
matthiasm@27 670 void setDebugLevel(int level);
matthiasm@27 671
matthiasm@27 672 /**
matthiasm@27 673 * Set the default level of debug output for subsequently
matthiasm@27 674 * constructed stretchers.
matthiasm@27 675 *
matthiasm@27 676 * @see setDebugLevel
matthiasm@27 677 */
matthiasm@27 678 static void setDefaultDebugLevel(int level);
matthiasm@27 679
matthiasm@27 680 protected:
matthiasm@27 681 class Impl;
matthiasm@27 682 Impl *m_d;
matthiasm@27 683 };
matthiasm@27 684
matthiasm@27 685 }
matthiasm@27 686
matthiasm@27 687 #endif