|
|
|
|
|
|
|
|
|
|
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)] |
|
|
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] |
|
|
pub struct SaliencePacket { |
|
|
|
|
|
|
|
|
|
|
|
pub j_p: f32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub j_a: f32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub h_score: f32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub s_score: f32, |
|
|
|
|
|
|
|
|
|
|
|
pub energy: f32, |
|
|
|
|
|
|
|
|
|
|
|
pub sample_index: u64, |
|
|
} |
|
|
|
|
|
impl SaliencePacket { |
|
|
|
|
|
pub fn new( |
|
|
j_p: f32, |
|
|
j_a: f32, |
|
|
h_score: f32, |
|
|
s_score: f32, |
|
|
energy: f32, |
|
|
sample_index: u64, |
|
|
) -> Self { |
|
|
Self { |
|
|
j_p, |
|
|
j_a, |
|
|
h_score, |
|
|
s_score, |
|
|
energy, |
|
|
sample_index, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn combined_jitter(&self) -> f32 { |
|
|
(self.j_p + self.j_a) / 2.0 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn is_high_quality(&self, threshold: f32) -> bool { |
|
|
self.s_score >= threshold |
|
|
} |
|
|
|
|
|
|
|
|
pub fn is_damaged(&self, jitter_threshold: f32) -> bool { |
|
|
self.combined_jitter() > jitter_threshold |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)] |
|
|
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] |
|
|
pub enum SalienceMarker { |
|
|
|
|
|
Peak(SaliencePacket), |
|
|
|
|
|
Fracture, |
|
|
|
|
|
Noise, |
|
|
|
|
|
Insufficient, |
|
|
} |
|
|
|
|
|
#[cfg(test)] |
|
|
mod tests { |
|
|
use super::*; |
|
|
|
|
|
#[test] |
|
|
fn test_combined_jitter() { |
|
|
let packet = SaliencePacket::new(0.1, 0.3, 1.0, 0.8, 0.5, 0); |
|
|
assert!((packet.combined_jitter() - 0.2).abs() < 0.001); |
|
|
} |
|
|
|
|
|
#[test] |
|
|
fn test_is_high_quality() { |
|
|
let good = SaliencePacket::new(0.01, 0.02, 1.0, 0.95, 0.5, 0); |
|
|
let bad = SaliencePacket::new(0.5, 0.6, 0.5, 0.3, 0.5, 0); |
|
|
|
|
|
assert!(good.is_high_quality(0.8)); |
|
|
assert!(!bad.is_high_quality(0.8)); |
|
|
} |
|
|
|
|
|
#[test] |
|
|
fn test_is_damaged() { |
|
|
let good = SaliencePacket::new(0.01, 0.02, 1.0, 0.95, 0.5, 0); |
|
|
let bad = SaliencePacket::new(0.5, 0.6, 0.5, 0.3, 0.5, 0); |
|
|
|
|
|
assert!(!good.is_damaged(0.3)); |
|
|
assert!(bad.is_damaged(0.3)); |
|
|
} |
|
|
} |
|
|
|