The realtime process method. This is always called in a realtime thread, so do not perform any realtime-unsafe operations.
(
&mut self,
// Information about the process block.
info: &ProcInfo,
// The buffers of data to process.
// If the node is currently bypassed, then this will be
| 219 | // This is always called in a realtime thread, so do not perform any |
| 220 | // realtime-unsafe operations. |
| 221 | fn process( |
| 222 | &mut self, |
| 223 | // Information about the process block. |
| 224 | info: &ProcInfo, |
| 225 | // The buffers of data to process. |
| 226 | // If the node is currently bypassed, then this will be `None`. |
| 227 | buffers: ProcBuffers, |
| 228 | // Extra buffers and utilities. |
| 229 | _extra: &mut ProcExtra, |
| 230 | ) -> ProcessStatus { |
| 231 | let mut frames_processed = 0; |
| 232 | while frames_processed < info.frames { |
| 233 | let process_frames = |
| 234 | (info.frames - frames_processed).min(self.window_frames - self.num_squared_values); |
| 235 | |
| 236 | for &s in buffers.inputs[0][frames_processed..frames_processed + process_frames].iter() |
| 237 | { |
| 238 | self.squares += s * s; |
| 239 | } |
| 240 | |
| 241 | self.num_squared_values += process_frames; |
| 242 | frames_processed += process_frames; |
| 243 | |
| 244 | if self.num_squared_values == self.window_frames { |
| 245 | let mean = self.squares / self.window_frames as f32; |
| 246 | let rms = mean.sqrt(); |
| 247 | |
| 248 | let latest_read_count = self.shared_state.read_count.load(Ordering::Acquire); |
| 249 | let previous_rms = self.shared_state.rms_value.load(Ordering::Relaxed); |
| 250 | |
| 251 | if latest_read_count != self.last_read_count || rms > previous_rms { |
| 252 | self.shared_state.rms_value.store(rms, Ordering::Relaxed); |
| 253 | } |
| 254 | |
| 255 | self.squares = 0.0; |
| 256 | self.num_squared_values = 0; |
| 257 | self.last_read_count = latest_read_count; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // There are no outputs in this node. |
| 262 | ProcessStatus::Bypass |
| 263 | } |
| 264 | |
| 265 | // Called when a new stream has been created. Because the new stream may have a |
| 266 | // different sample rate from the old one, make sure to update any calculations |