Mercurial > hg > sv-dependency-builds
comparison win32-mingw/include/rubberband/RubberBandStretcher.h @ 13:e66e9011ec93
Add Rubber Band build
author | Chris Cannam |
---|---|
date | Wed, 20 Mar 2013 15:58:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:b7bda433d832 | 13:e66e9011ec93 |
---|---|
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-2012 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.1" | |
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 samples 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 void setExpectedInputDuration(size_t samples); | |
472 | |
473 /** | |
474 * Tell the stretcher the maximum number of sample frames that you | |
475 * will ever be passing in to a single process() call. If you | |
476 * don't call this, the stretcher will assume that you are calling | |
477 * getSamplesRequired() at each cycle and are never passing more | |
478 * samples than are suggested by that function. | |
479 * | |
480 * If your application has some external constraint that means you | |
481 * prefer a fixed block size, then your normal mode of operation | |
482 * would be to provide that block size to this function; to loop | |
483 * calling process() with that size of block; after each call to | |
484 * process(), test whether output has been generated by calling | |
485 * available(); and, if so, call retrieve() to obtain it. See | |
486 * getSamplesRequired() for a more suitable operating mode for | |
487 * applications without such external constraints. | |
488 * | |
489 * This function may not be called after the first call to study() | |
490 * or process(). | |
491 * | |
492 * Note that this value is only relevant to process(), not to | |
493 * study() (to which you may pass any number of samples at a time, | |
494 * and from which there is no output). | |
495 */ | |
496 void setMaxProcessSize(size_t samples); | |
497 | |
498 /** | |
499 * Ask the stretcher how many audio sample frames should be | |
500 * provided as input in order to ensure that some more output | |
501 * becomes available. | |
502 * | |
503 * If your application has no particular constraint on processing | |
504 * block size and you are able to provide any block size as input | |
505 * for each cycle, then your normal mode of operation would be to | |
506 * loop querying this function; providing that number of samples | |
507 * to process(); and reading the output using available() and | |
508 * retrieve(). See setMaxProcessSize() for a more suitable | |
509 * operating mode for applications that do have external block | |
510 * size constraints. | |
511 * | |
512 * Note that this value is only relevant to process(), not to | |
513 * study() (to which you may pass any number of samples at a time, | |
514 * and from which there is no output). | |
515 */ | |
516 size_t getSamplesRequired() const; | |
517 | |
518 /** | |
519 * Provide a set of mappings from "before" to "after" sample | |
520 * numbers so as to enforce a particular stretch profile. The | |
521 * argument is a map from audio sample frame number in the source | |
522 * material, to the corresponding sample frame number in the | |
523 * stretched output. The mapping should be for key frames only, | |
524 * with a "reasonable" gap between mapped samples. | |
525 * | |
526 * This function cannot be used in RealTime mode. | |
527 * | |
528 * This function may not be called after the first call to | |
529 * process(). It should be called after the time and pitch ratios | |
530 * have been set; the results of changing the time and pitch | |
531 * ratios after calling this function are undefined. Calling | |
532 * reset() will clear this mapping. | |
533 * | |
534 * The key frame map only affects points within the material; it | |
535 * does not determine the overall stretch ratio (that is, the | |
536 * ratio between the output material's duration and the source | |
537 * material's duration). You need to provide this ratio | |
538 * separately to setTimeRatio(), otherwise the results may be | |
539 * truncated or extended in unexpected ways regardless of the | |
540 * extent of the frame numbers found in the key frame map. | |
541 */ | |
542 void setKeyFrameMap(const std::map<size_t, size_t> &); | |
543 | |
544 /** | |
545 * Provide a block of "samples" sample frames for the stretcher to | |
546 * study and calculate a stretch profile from. | |
547 * | |
548 * This is only meaningful in Offline mode, and is required if | |
549 * running in that mode. You should pass the entire input through | |
550 * study() before any process() calls are made, as a sequence of | |
551 * blocks in individual study() calls, or as a single large block. | |
552 * | |
553 * "input" should point to de-interleaved audio data with one | |
554 * float array per channel. "samples" supplies the number of | |
555 * audio sample frames available in "input". If "samples" is | |
556 * zero, "input" may be NULL. | |
557 * | |
558 * Set "final" to true if this is the last block of data that will | |
559 * be provided to study() before the first process() call. | |
560 */ | |
561 void study(const float *const *input, size_t samples, bool final); | |
562 | |
563 /** | |
564 * Provide a block of "samples" sample frames for processing. | |
565 * See also getSamplesRequired() and setMaxProcessSize(). | |
566 * | |
567 * Set "final" to true if this is the last block of input data. | |
568 */ | |
569 void process(const float *const *input, size_t samples, bool final); | |
570 | |
571 /** | |
572 * Ask the stretcher how many audio sample frames of output data | |
573 * are available for reading (via retrieve()). | |
574 * | |
575 * This function returns 0 if no frames are available: this | |
576 * usually means more input data needs to be provided, but if the | |
577 * stretcher is running in threaded mode it may just mean that not | |
578 * enough data has yet been processed. Call getSamplesRequired() | |
579 * to discover whether more input is needed. | |
580 * | |
581 * This function returns -1 if all data has been fully processed | |
582 * and all output read, and the stretch process is now finished. | |
583 */ | |
584 int available() const; | |
585 | |
586 /** | |
587 * Obtain some processed output data from the stretcher. Up to | |
588 * "samples" samples will be stored in the output arrays (one per | |
589 * channel for de-interleaved audio data) pointed to by "output". | |
590 * The return value is the actual number of sample frames | |
591 * retrieved. | |
592 */ | |
593 size_t retrieve(float *const *output, size_t samples) const; | |
594 | |
595 /** | |
596 * Return the value of internal frequency cutoff value n. | |
597 * | |
598 * This function is not for general use. | |
599 */ | |
600 float getFrequencyCutoff(int n) const; | |
601 | |
602 /** | |
603 * Set the value of internal frequency cutoff n to f Hz. | |
604 * | |
605 * This function is not for general use. | |
606 */ | |
607 void setFrequencyCutoff(int n, float f); | |
608 | |
609 /** | |
610 * Retrieve the value of the internal input block increment value. | |
611 * | |
612 * This function is provided for diagnostic purposes only. | |
613 */ | |
614 size_t getInputIncrement() const; | |
615 | |
616 /** | |
617 * In offline mode, retrieve the sequence of internal block | |
618 * increments for output, for the entire audio data, provided the | |
619 * stretch profile has been calculated. In realtime mode, | |
620 * retrieve any output increments that have accumulated since the | |
621 * last call to getOutputIncrements, to a limit of 16. | |
622 * | |
623 * This function is provided for diagnostic purposes only. | |
624 */ | |
625 std::vector<int> getOutputIncrements() const; | |
626 | |
627 /** | |
628 * In offline mode, retrieve the sequence of internal phase reset | |
629 * detection function values, for the entire audio data, provided | |
630 * the stretch profile has been calculated. In realtime mode, | |
631 * retrieve any phase reset points that have accumulated since the | |
632 * last call to getPhaseResetCurve, to a limit of 16. | |
633 * | |
634 * This function is provided for diagnostic purposes only. | |
635 */ | |
636 std::vector<float> getPhaseResetCurve() const; | |
637 | |
638 /** | |
639 * In offline mode, retrieve the sequence of internal frames for | |
640 * which exact timing has been sought, for the entire audio data, | |
641 * provided the stretch profile has been calculated. In realtime | |
642 * mode, return an empty sequence. | |
643 * | |
644 * This function is provided for diagnostic purposes only. | |
645 */ | |
646 std::vector<int> getExactTimePoints() const; | |
647 | |
648 /** | |
649 * Return the number of channels this stretcher was constructed | |
650 * with. | |
651 */ | |
652 size_t getChannelCount() const; | |
653 | |
654 /** | |
655 * Force the stretcher to calculate a stretch profile. Normally | |
656 * this happens automatically for the first process() call in | |
657 * offline mode. | |
658 * | |
659 * This function is provided for diagnostic purposes only. | |
660 */ | |
661 void calculateStretch(); | |
662 | |
663 /** | |
664 * Set the level of debug output. The value may be from 0 (errors | |
665 * only) to 3 (very verbose, with audible ticks in the output at | |
666 * phase reset points). The default is whatever has been set | |
667 * using setDefaultDebugLevel, or 0 if that function has not been | |
668 * called. | |
669 */ | |
670 void setDebugLevel(int level); | |
671 | |
672 /** | |
673 * Set the default level of debug output for subsequently | |
674 * constructed stretchers. | |
675 * | |
676 * @see setDebugLevel | |
677 */ | |
678 static void setDefaultDebugLevel(int level); | |
679 | |
680 protected: | |
681 class Impl; | |
682 Impl *m_d; | |
683 }; | |
684 | |
685 } | |
686 | |
687 #endif |