Mercurial > hg > aimc
comparison trunk/src/Modules/SSI/ModuleSSI.cc @ 420:733a11a65f3d
- Allow processing without re-initialization.
author | tom@acousticscale.org |
---|---|
date | Tue, 26 Oct 2010 04:48:56 +0000 |
parents | a908972d234e |
children |
comparison
equal
deleted
inserted
replaced
419:31d2b3f2c13b | 420:733a11a65f3d |
---|---|
101 } | 101 } |
102 for (int i = 0; i < input.channel_count(); ++i) { | 102 for (int i = 0; i < input.channel_count(); ++i) { |
103 output_.set_centre_frequency(i, input.centre_frequency(i)); | 103 output_.set_centre_frequency(i, input.centre_frequency(i)); |
104 } | 104 } |
105 | 105 |
106 h_.resize(ssi_width_samples_, 0.0); | |
107 float gamma_min = -1.0f; | |
108 float gamma_max = log2(ssi_width_cycles_); | |
109 for (int i = 0; i < ssi_width_samples_; ++i) { | |
110 if (log_cycles_axis_) { | |
111 float gamma = gamma_min + (gamma_max - gamma_min) | |
112 * static_cast<float>(i) | |
113 / static_cast<float>(ssi_width_samples_); | |
114 h_[i]= pow(2.0f, gamma); | |
115 } else { | |
116 h_[i] = static_cast<float>(i) * ssi_width_cycles_ | |
117 / static_cast<float>(ssi_width_samples_); | |
118 } | |
119 } | |
120 | |
106 output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_); | 121 output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_); |
107 return true; | 122 return true; |
108 } | 123 } |
109 | 124 |
110 void ModuleSSI::ResetInternal() { | 125 void ModuleSSI::ResetInternal() { |
155 | 170 |
156 int pitch_index = buffer_length_ - 1; | 171 int pitch_index = buffer_length_ - 1; |
157 if (do_pitch_cutoff_) { | 172 if (do_pitch_cutoff_) { |
158 pitch_index = ExtractPitchIndex(input); | 173 pitch_index = ExtractPitchIndex(input); |
159 } | 174 } |
160 | |
161 float gamma_min = -1.0f; | |
162 float gamma_max = log2(ssi_width_cycles_); | |
163 | 175 |
164 for (int ch = 0; ch < channel_count_; ++ch) { | 176 for (int ch = 0; ch < channel_count_; ++ch) { |
165 float centre_frequency = input.centre_frequency(ch); | 177 float centre_frequency = input.centre_frequency(ch); |
166 float cycle_samples = sample_rate_ / centre_frequency; | 178 float cycle_samples = sample_rate_ / centre_frequency; |
167 | 179 |
184 pitch_h = static_cast<float>(pitch_index) / cycle_samples; | 196 pitch_h = static_cast<float>(pitch_index) / cycle_samples; |
185 } | 197 } |
186 | 198 |
187 // Copy the buffer from input to output, addressing by h-value. | 199 // Copy the buffer from input to output, addressing by h-value. |
188 for (int i = 0; i < ssi_width_samples_; ++i) { | 200 for (int i = 0; i < ssi_width_samples_; ++i) { |
189 float h; | 201 |
190 if (log_cycles_axis_) { | |
191 float gamma = gamma_min + (gamma_max - gamma_min) | |
192 * static_cast<float>(i) | |
193 / static_cast<float>(ssi_width_samples_); | |
194 h = pow(2.0f, gamma); | |
195 } else { | |
196 h = static_cast<float>(i) * ssi_width_cycles_ | |
197 / static_cast<float>(ssi_width_samples_); | |
198 } | |
199 | |
200 // The index into the input array is a floating-point number, which is | 202 // The index into the input array is a floating-point number, which is |
201 // split into a whole part and a fractional part. The whole part and | 203 // split into a whole part and a fractional part. The whole part and |
202 // fractional part are found, and are used to linearly interpolate | 204 // fractional part are found, and are used to linearly interpolate |
203 // between input samples to yield an output sample. | 205 // between input samples to yield an output sample. |
204 double whole_part; | 206 double whole_part; |
205 float frac_part = modf(h * cycle_samples, &whole_part); | 207 float frac_part = modf(h_[i] * cycle_samples, &whole_part); |
206 int sample = floor(whole_part); | 208 int sample = floor(whole_part); |
207 | 209 |
208 float weight = channel_weight; | 210 float weight = channel_weight; |
209 | 211 |
210 if (do_smooth_offset_ && do_pitch_cutoff_) { | 212 if (do_smooth_offset_ && do_pitch_cutoff_) { |
211 // Smoothing around the pitch cutoff line. | 213 // Smoothing around the pitch cutoff line. |
212 float pitch_weight = (1.0f + tanh((pitch_h - h) | 214 float pitch_weight = (1.0f + tanh((pitch_h - h_[i]) |
213 * smooth_pitch_constant)) / 2.0f; | 215 * smooth_pitch_constant)) / 2.0f; |
214 weight *= pitch_weight; | 216 weight *= pitch_weight; |
215 //LOG_INFO("Channel %d, Sample %d. Pitch weight: %f", ch, i, pitch_weight); | 217 //LOG_INFO("Channel %d, Sample %d. Pitch weight: %f", ch, i, pitch_weight); |
216 } | 218 } |
217 | 219 |