Mercurial > hg > aimc
comparison src/Modules/SSI/ModuleSSI.cc @ 237:af02b6addf7a
- Added support for movies!
author | tomwalters |
---|---|
date | Thu, 21 Oct 2010 01:46:39 +0000 |
parents | 73c6d61440ad |
children | 0a3342606855 |
comparison
equal
deleted
inserted
replaced
236:4fb328f81012 | 237:af02b6addf7a |
---|---|
55 false); | 55 false); |
56 | 56 |
57 // Time from the zero-lag line of the SAI from which to start searching | 57 // Time from the zero-lag line of the SAI from which to start searching |
58 // for a maximum in the input SAI's temporal profile. | 58 // for a maximum in the input SAI's temporal profile. |
59 pitch_search_start_ms_ = parameters_->DefaultFloat( | 59 pitch_search_start_ms_ = parameters_->DefaultFloat( |
60 "ssi.pitch_search_start_ms", 2.0f); | 60 "ssi.pitch_search_start_ms", 2.0f); |
61 | 61 |
62 // Total width in cycles of the whole SSI | 62 // Total width in cycles of the whole SSI |
63 ssi_width_cycles_ = parameters_->DefaultFloat("ssi.width_cycles", 10.0f); | 63 ssi_width_cycles_ = parameters_->DefaultFloat("ssi.width_cycles", 10.0f); |
64 | 64 |
65 // Set to true to make the cycles axis logarithmic (ie indexing by gamma | 65 // Set to true to make the cycles axis logarithmic (ie indexing by gamma |
97 "truncated at %d samples wide. This corresponds to a width " | 97 "truncated at %d samples wide. This corresponds to a width " |
98 "of %f cycles."), ssi_width_cycles_, buffer_length_, | 98 "of %f cycles."), ssi_width_cycles_, buffer_length_, |
99 ssi_width_samples_, cycles); | 99 ssi_width_samples_, cycles); |
100 ssi_width_cycles_ = cycles; | 100 ssi_width_cycles_ = cycles; |
101 } | 101 } |
102 for (int i = 0; i < input.channel_count(); ++i) { | |
103 output_.set_centre_frequency(i, input.centre_frequency(i)); | |
104 } | |
105 | |
102 output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_); | 106 output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_); |
103 return true; | 107 return true; |
104 } | 108 } |
105 | 109 |
106 void ModuleSSI::ResetInternal() { | 110 void ModuleSSI::ResetInternal() { |
157 float gamma_min = -1.0f; | 161 float gamma_min = -1.0f; |
158 float gamma_max = log2(ssi_width_cycles_); | 162 float gamma_max = log2(ssi_width_cycles_); |
159 | 163 |
160 for (int ch = 0; ch < channel_count_; ++ch) { | 164 for (int ch = 0; ch < channel_count_; ++ch) { |
161 float centre_frequency = input.centre_frequency(ch); | 165 float centre_frequency = input.centre_frequency(ch); |
166 float cycle_samples = sample_rate_ / centre_frequency; | |
162 | 167 |
163 float channel_weight = 1.0f; | 168 float channel_weight = 1.0f; |
164 int cutoff_index = buffer_length_ - 1; | 169 int cutoff_index = buffer_length_ - 1; |
165 if (do_pitch_cutoff_) { | 170 if (do_pitch_cutoff_) { |
166 if (pitch_index < cutoff_index) { | 171 if (pitch_index < cutoff_index) { |
167 if (weight_by_cutoff_) { | 172 if (weight_by_cutoff_) { |
168 channel_weight = static_cast<float>(buffer_length_) | 173 channel_weight = static_cast<float>(buffer_length_) |
169 / static_cast<float>(pitch_index); | 174 / static_cast<float>(pitch_index); |
170 } | 175 } |
171 cutoff_index = pitch_index; | 176 cutoff_index = pitch_index; |
172 } | 177 } |
173 } | 178 } |
174 | 179 |
175 // tanh(3) is about 0.995. Seems reasonable. | 180 // tanh(3) is about 0.995. Seems reasonable. |
176 float smooth_pitch_constant = smooth_offset_cycles_ * 3.0f; | 181 float smooth_pitch_constant = 3.0f / smooth_offset_cycles_; |
177 float pitch_h = 0.0f; | 182 float pitch_h = 0.0f; |
178 if (do_smooth_offset_) { | 183 if (do_smooth_offset_) { |
179 if (log_cycles_axis_) { | 184 pitch_h = static_cast<float>(pitch_index) / cycle_samples; |
180 float gamma = gamma_min + (gamma_max - gamma_min) | |
181 * static_cast<float>(pitch_index) | |
182 / static_cast<float>(ssi_width_samples_); | |
183 pitch_h = pow(2.0f, gamma); | |
184 } else { | |
185 pitch_h = static_cast<float>(pitch_index) * ssi_width_cycles_ | |
186 / static_cast<float>(ssi_width_samples_); | |
187 } | |
188 } | 185 } |
189 | 186 |
190 // Copy the buffer from input to output, addressing by h-value | 187 // Copy the buffer from input to output, addressing by h-value. |
191 for (int i = 0; i < ssi_width_samples_; ++i) { | 188 for (int i = 0; i < ssi_width_samples_; ++i) { |
192 float h; | 189 float h; |
193 float cycle_samples = sample_rate_ / centre_frequency; | |
194 if (log_cycles_axis_) { | 190 if (log_cycles_axis_) { |
195 float gamma = gamma_min + (gamma_max - gamma_min) | 191 float gamma = gamma_min + (gamma_max - gamma_min) |
196 * static_cast<float>(i) | 192 * static_cast<float>(i) |
197 / static_cast<float>(ssi_width_samples_); | 193 / static_cast<float>(ssi_width_samples_); |
198 h = pow(2.0f, gamma); | 194 h = pow(2.0f, gamma); |
211 | 207 |
212 float weight = channel_weight; | 208 float weight = channel_weight; |
213 | 209 |
214 if (do_smooth_offset_ && do_pitch_cutoff_) { | 210 if (do_smooth_offset_ && do_pitch_cutoff_) { |
215 // Smoothing around the pitch cutoff line. | 211 // Smoothing around the pitch cutoff line. |
216 weight *= (1.0f + tanh(smooth_pitch_constant * (pitch_h - h))) / 2.0f; | 212 float pitch_weight = (1.0f + tanh((pitch_h - h) |
213 * smooth_pitch_constant)) / 2.0f; | |
214 weight *= pitch_weight; | |
215 //LOG_INFO("Channel %d, Sample %d. Pitch weight: %f", ch, i, pitch_weight); | |
217 } | 216 } |
218 | 217 |
219 if (weight_by_scaling_) { | 218 if (weight_by_scaling_) { |
220 if (centre_frequency > pivot_cf_) { | 219 if (centre_frequency > pivot_cf_) { |
221 weight *= (centre_frequency / pivot_cf_); | 220 weight *= (centre_frequency / pivot_cf_); |