annotate win64-msvc/include/rubberband/RubberBandStretcher.h @ 53:e1712f7d74a4

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