annotate win32-mingw/include/rubberband/RubberBandStretcher.h @ 44:9894b839b0cb

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