Mercurial > hg > sonic-visualiser
comparison audioio/PhaseVocoderTimeStretcher.h @ 23:a2ad974b0c8c
...
author | Chris Cannam |
---|---|
date | Fri, 15 Sep 2006 13:46:45 +0000 |
parents | 80126455d169 |
children | e74f508db18c |
comparison
equal
deleted
inserted
replaced
22:80126455d169 | 23:a2ad974b0c8c |
---|---|
47 /** | 47 /** |
48 * Process a block. The input array contains the given number of | 48 * Process a block. The input array contains the given number of |
49 * samples (on each channel); the output must have space for | 49 * samples (on each channel); the output must have space for |
50 * lrintf(samples * m_ratio). | 50 * lrintf(samples * m_ratio). |
51 * | 51 * |
52 * This should work correctly for some ratios, e.g. small powers | 52 * This function isn't really recommended, and I may yet remove it. |
53 * of two. For other ratios it may drop samples -- use putInput | 53 * It should work correctly for some ratios, e.g. small powers of |
54 * in a loop followed by getOutput (when getAvailableOutputSamples | 54 * two, if transient sharpening is off. For other ratios it may |
55 * reports enough) instead. | 55 * drop samples -- use putInput in a loop followed by getOutput |
56 * (when getAvailableOutputSamples reports enough) instead. | |
56 * | 57 * |
57 * Do not mix process calls with putInput/getOutput calls. | 58 * Do not mix process calls with putInput/getOutput calls. |
58 */ | 59 */ |
59 void process(float **input, float **output, size_t samples); | 60 void process(float **input, float **output, size_t samples); |
60 | 61 |
61 /** | 62 /** |
62 * Return the number of samples that would need to be added via | 63 * Return the number of samples that would need to be added via |
63 * putInput in order to provoke the time stretcher into doing some | 64 * putInput in order to provoke the time stretcher into doing some |
64 * time stretching and making more output samples available. | 65 * time stretching and making more output samples available. |
66 * This will be an estimate, if transient sharpening is on. | |
65 */ | 67 */ |
66 size_t getRequiredInputSamples() const; | 68 size_t getRequiredInputSamples() const; |
67 | 69 |
68 /** | 70 /** |
69 * Put (and possibly process) a given number of input samples. | 71 * Put (and possibly process) a given number of input samples. |
70 * Number must not exceed the maxProcessInputBlockSize passed to | 72 * Number must not exceed the maxProcessInputBlockSize passed to |
71 * constructor. | 73 * constructor. |
72 */ | 74 */ |
73 void putInput(float **input, size_t samples); | 75 void putInput(float **input, size_t samples); |
74 | 76 |
77 /** | |
78 * Get the number of processed samples ready for reading. | |
79 */ | |
75 size_t getAvailableOutputSamples() const; | 80 size_t getAvailableOutputSamples() const; |
76 | 81 |
82 /** | |
83 * Get some processed samples. | |
84 */ | |
77 void getOutput(float **output, size_t samples); | 85 void getOutput(float **output, size_t samples); |
78 | 86 |
79 //!!! and reset? | 87 //!!! and reset? |
80 | 88 |
81 /** | 89 /** |
92 * Get the window size for FFT processing. | 100 * Get the window size for FFT processing. |
93 */ | 101 */ |
94 size_t getWindowSize() const { return m_wlen; } | 102 size_t getWindowSize() const { return m_wlen; } |
95 | 103 |
96 /** | 104 /** |
97 * Get the window type. | |
98 */ | |
99 // WindowType getWindowType() const { return m_window->getType(); } | |
100 | |
101 /** | |
102 * Get the stretch ratio. | 105 * Get the stretch ratio. |
103 */ | 106 */ |
104 float getRatio() const { return float(m_n2) / float(m_n1); } | 107 float getRatio() const { return float(m_n2) / float(m_n1); } |
105 | 108 |
106 /** | 109 /** |
108 */ | 111 */ |
109 bool getSharpening() const { return m_sharpen; } | 112 bool getSharpening() const { return m_sharpen; } |
110 | 113 |
111 /** | 114 /** |
112 * Get the latency added by the time stretcher, in sample frames. | 115 * Get the latency added by the time stretcher, in sample frames. |
116 * This will be exact if transient sharpening is off, or approximate | |
117 * if it is on. | |
113 */ | 118 */ |
114 size_t getProcessingLatency() const; | 119 size_t getProcessingLatency() const; |
115 | 120 |
116 protected: | 121 protected: |
117 /** | 122 /** |
118 * Process a single phase vocoder frame. | 123 * Process a single phase vocoder frame from "in" into |
119 * | 124 * m_freq[channel]. |
120 * Take m_wlen time-domain source samples from in, perform an FFT, | |
121 * phase shift, and IFFT, and add the results to out (presumably | |
122 * overlapping parts of existing data from prior frames). | |
123 * | |
124 * Also add to the modulation output the results of windowing a | |
125 * set of 1s with the resynthesis window -- this can then be used | |
126 * to ensure the output has the correct magnitude in cases where | |
127 * the window overlap varies or otherwise results in something | |
128 * other than a flat sum. | |
129 */ | 125 */ |
130 | 126 void analyseBlock(size_t channel, float *in); // into m_freq[channel] |
131 | 127 |
132 void analyseBlock(size_t channel, float *in); // into m_freq[channel] | 128 /** |
133 | 129 * Examine m_freq[0..m_channels-1] and return whether a percussive |
134 bool isTransient(); // operates on m_freq[0..m_channels-1] | 130 * transient is found. |
131 */ | |
132 bool isTransient(); | |
135 | 133 |
134 /** | |
135 * Resynthesise from m_freq[channel] adding in to "out", | |
136 * adjusting phases on the basis of a prior step size of lastStep. | |
137 * Also add the window shape in to the modulation array (if | |
138 * present) -- for use in ensuring the output has the correct | |
139 * magnitude afterwards. | |
140 */ | |
136 void synthesiseBlock(size_t channel, float *out, float *modulation, | 141 void synthesiseBlock(size_t channel, float *out, float *modulation, |
137 size_t lastStep); | 142 size_t lastStep); |
138 | 143 |
139 size_t m_sampleRate; | 144 size_t m_sampleRate; |
140 size_t m_channels; | 145 size_t m_channels; |