annotate win64-msvc/include/rubberband/RubberBandStretcher.h @ 130:1c067f014d80

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