(
&self,
config: &Self::Configuration,
cx: ConstructProcessorContext,
)
| 132 | ))) |
| 133 | // TODO: If and when the scheduler gets proper in-place processing support, use |
| 134 | // in-place processing for this node. |
| 135 | } |
| 136 | |
| 137 | fn construct_processor( |
| 138 | &self, |
| 139 | config: &Self::Configuration, |
| 140 | cx: ConstructProcessorContext, |
| 141 | ) -> Result<impl AudioNodeProcessor, NodeError> { |
| 142 | let sample_rate = cx.stream_info.sample_rate; |
| 143 | let smooth_config = SmootherConfig { |
| 144 | smooth_seconds: self.smooth_seconds, |
| 145 | ..Default::default() |
| 146 | }; |
| 147 | |
| 148 | let max_frames: usize = |
| 149 | (config.max_impulse_length_seconds * (sample_rate.get() as f64)).ceil() as usize; |
| 150 | |
| 151 | // TODO: Ask the creator of `fft-convolver` to add a `with_capacity` method so we don't |
| 152 | // need to use this workaround. |
| 153 | let mut tmp_impulse = vec![0.0; max_frames]; |
| 154 | tmp_impulse[0] = 1.0; |
| 155 | |
| 156 | let mut convolver: Vec<FFTConvolver<f32>> = (0..config.channels.get().get()) |
| 157 | .map(|_| { |
| 158 | let mut c = FFTConvolver::default(); |
| 159 | c.init(config.partition_size, &tmp_impulse).unwrap(); |
| 160 | c |
| 161 | }) |
| 162 | .collect(); |
| 163 | |
| 164 | let did_init_first_impulse = if let Some(s) = &self.impulse_response { |
| 165 | if s.len_frames() > max_frames as u64 { |
| 166 | return Err(ImpulseTooLongError { |
| 167 | got_len_seconds: s.len_frames() as f64 / cx.stream_info.sample_rate_recip, |
| 168 | max_len_seconds: config.max_impulse_length_seconds, |
| 169 | } |
| 170 | .into()); |
| 171 | } |
| 172 | |
| 173 | if s.num_channels().get() < config.channels.get().get() as usize { |
| 174 | // Assume a mono impulse response and set it to all channels. |
| 175 | let impulse_slice = s.channel(0).unwrap(); |
| 176 | |
| 177 | for c in convolver.iter_mut() { |
| 178 | c.set_response(impulse_slice).unwrap(); |
| 179 | c.reset(); |
| 180 | } |
| 181 | } else { |
| 182 | for (ch_i, c) in convolver.iter_mut().enumerate() { |
| 183 | c.set_response(s.channel(ch_i).unwrap()).unwrap(); |
| 184 | c.reset(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | true |
| 189 | } else { |
| 190 | false |
| 191 | }; |
nothing calls this directly
no test coverage detected