summaryrefslogtreecommitdiff
path: root/src/retain.rs
diff options
context:
space:
mode:
authorozpv <39195175+ozpv@users.noreply.github.com>2026-05-16 22:42:51 -0500
committerGitHub <noreply@github.com>2026-05-16 22:42:51 -0500
commit728e5d8395d74e72be86b5fad75acaa6fb219bc7 (patch)
tree3d29f165048af2ddc1f068c0a7675f3d7da510d6 /src/retain.rs
parent12ae71759075a98deed5728d972c50e7131c726f (diff)
account for latency
Diffstat (limited to 'src/retain.rs')
-rw-r--r--src/retain.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/retain.rs b/src/retain.rs
index bc3934a..49730e1 100644
--- a/src/retain.rs
+++ b/src/retain.rs
@@ -1,11 +1,18 @@
-use hashbrown::HashSet;
use num_complex::Complex;
+use rustc_hash::FxHashSet;
#[inline(always)]
pub fn retain_top_n_magnitudes(fft_real_signal: &mut [Complex<f32>], n: usize) {
// you'd be keeping the entire signal
+ // or keeping nothing at all
if n >= fft_real_signal.len() {
return;
+ } else if n == 0 {
+ for phasor in fft_real_signal {
+ *phasor = Complex::ZERO;
+ }
+
+ return;
}
let mut indexed = fft_real_signal
@@ -20,11 +27,11 @@ pub fn retain_top_n_magnitudes(fft_real_signal: &mut [Complex<f32>], n: usize) {
let top_indices = indexed[target..]
.iter()
.map(|&(i, _)| i)
- .collect::<HashSet<usize>>();
+ .collect::<FxHashSet<usize>>();
- for (i, val) in fft_real_signal.iter_mut().enumerate() {
+ for (i, phasor) in fft_real_signal.iter_mut().enumerate() {
if !top_indices.contains(&i) {
- *val = Complex::ZERO;
+ *phasor = Complex::ZERO;
}
}
}