Mercurial > hg > sonic-visualiser
comparison audioio/PhaseVocoderTimeStretcher.h @ 14:085f34c73939
* IntegerTimeStretcher -> PhaseVocoderTimeStretcher (no longer confined to
integer multiples)
author | Chris Cannam |
---|---|
date | Wed, 13 Sep 2006 11:06:28 +0000 |
parents | audioio/IntegerTimeStretcher.h@00ed645f4175 |
children | cc566264c935 |
comparison
equal
deleted
inserted
replaced
13:00ed645f4175 | 14:085f34c73939 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _PHASE_VOCODER_TIME_STRETCHER_H_ | |
17 #define _PHASE_VOCODER_TIME_STRETCHER_H_ | |
18 | |
19 #include "base/Window.h" | |
20 #include "base/RingBuffer.h" | |
21 | |
22 #include <fftw3.h> | |
23 | |
24 /** | |
25 * A time stretcher that alters the performance speed of audio, | |
26 * preserving pitch. This uses the simple phase vocoder technique | |
27 * from DAFX pp275-276, adding a block-based stream oriented API. | |
28 * | |
29 * Causes significant transient smearing, but sounds good for steady | |
30 * notes and is generally predictable. | |
31 */ | |
32 | |
33 class PhaseVocoderTimeStretcher | |
34 { | |
35 public: | |
36 PhaseVocoderTimeStretcher(float ratio, | |
37 size_t maxProcessInputBlockSize, | |
38 size_t inputIncrement = 64, | |
39 size_t windowSize = 2048, | |
40 WindowType windowType = HanningWindow); | |
41 virtual ~PhaseVocoderTimeStretcher(); | |
42 | |
43 /** | |
44 * Process a block. The input array contains the given number of | |
45 * samples; the output has enough space for samples * m_ratio. | |
46 */ | |
47 void process(float *input, float *output, size_t samples); | |
48 | |
49 /** | |
50 * Get the hop size for input. Smaller values may produce better | |
51 * results, at a cost in processing time. Larger values are | |
52 * faster but increase the likelihood of echo-like effects. The | |
53 * default is 64, which is usually pretty good, though heavy on | |
54 * processor power. | |
55 */ | |
56 size_t getInputIncrement() const { return m_n1; } | |
57 | |
58 /** | |
59 * Get the window size for FFT processing. Must be larger than | |
60 * the input and output increments. The default is 2048. | |
61 */ | |
62 size_t getWindowSize() const { return m_wlen; } | |
63 | |
64 /** | |
65 * Get the window type. The default is a Hanning window. | |
66 */ | |
67 WindowType getWindowType() const { return m_window->getType(); } | |
68 | |
69 float getRatio() const { return m_ratio; } | |
70 size_t getOutputIncrement() const { return getInputIncrement() * getRatio(); } | |
71 size_t getProcessingLatency() const; | |
72 | |
73 protected: | |
74 /** | |
75 * Process a single phase vocoder frame. | |
76 * | |
77 * Take m_wlen time-domain source samples from in, perform an FFT, | |
78 * phase shift, and IFFT, and add the results to out (presumably | |
79 * overlapping parts of existing data from prior frames). | |
80 * | |
81 * Also add to the modulation output the results of windowing a | |
82 * set of 1s with the resynthesis window -- this can then be used | |
83 * to ensure the output has the correct magnitude in cases where | |
84 * the window overlap varies or otherwise results in something | |
85 * other than a flat sum. | |
86 */ | |
87 void processBlock(float *in, float *out, float *modulation); | |
88 | |
89 float m_ratio; | |
90 size_t m_n1; | |
91 size_t m_n2; | |
92 size_t m_wlen; | |
93 Window<float> *m_window; | |
94 | |
95 fftwf_complex *m_time; | |
96 fftwf_complex *m_freq; | |
97 float *m_dbuf; | |
98 float *m_prevPhase; | |
99 float *m_prevAdjustedPhase; | |
100 | |
101 fftwf_plan m_plan; | |
102 fftwf_plan m_iplan; | |
103 | |
104 RingBuffer<float> m_inbuf; | |
105 RingBuffer<float> m_outbuf; | |
106 float *m_mashbuf; | |
107 float *m_modulationbuf; | |
108 }; | |
109 | |
110 #endif |