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