|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] |
|
|
pub struct MarineConfig { |
|
|
|
|
|
|
|
|
|
|
|
pub clip_threshold: f32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub ema_period_alpha: f32, |
|
|
|
|
|
|
|
|
|
|
|
pub ema_amp_alpha: f32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub min_period: u32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub max_period: u32, |
|
|
|
|
|
|
|
|
|
|
|
pub jitter_low: f32, |
|
|
|
|
|
|
|
|
|
|
|
pub jitter_high: f32, |
|
|
} |
|
|
|
|
|
impl MarineConfig { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub const fn speech_default(sample_rate: u32) -> Self { |
|
|
|
|
|
let min_period = sample_rate / 4000; |
|
|
let max_period = sample_rate / 60; |
|
|
|
|
|
Self { |
|
|
clip_threshold: 1e-3, |
|
|
ema_period_alpha: 0.01, |
|
|
ema_amp_alpha: 0.01, |
|
|
min_period, |
|
|
max_period, |
|
|
jitter_low: 0.02, |
|
|
jitter_high: 0.60, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub const fn high_sensitivity(sample_rate: u32) -> Self { |
|
|
let min_period = sample_rate / 8000; |
|
|
let max_period = sample_rate / 40; |
|
|
|
|
|
Self { |
|
|
clip_threshold: 5e-4, |
|
|
ema_period_alpha: 0.05, |
|
|
ema_amp_alpha: 0.05, |
|
|
min_period, |
|
|
max_period, |
|
|
jitter_low: 0.01, |
|
|
jitter_high: 0.50, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub const fn tts_validation(sample_rate: u32) -> Self { |
|
|
let min_period = sample_rate / 4000; |
|
|
let max_period = sample_rate / 80; |
|
|
|
|
|
Self { |
|
|
clip_threshold: 1e-3, |
|
|
ema_period_alpha: 0.02, |
|
|
ema_amp_alpha: 0.02, |
|
|
min_period, |
|
|
max_period, |
|
|
jitter_low: 0.015, |
|
|
jitter_high: 0.40, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl Default for MarineConfig { |
|
|
fn default() -> Self { |
|
|
|
|
|
Self::speech_default(22050) |
|
|
} |
|
|
} |
|
|
|
|
|
#[cfg(test)] |
|
|
mod tests { |
|
|
use super::*; |
|
|
|
|
|
#[test] |
|
|
fn test_speech_default_periods() { |
|
|
let config = MarineConfig::speech_default(22050); |
|
|
assert!(config.min_period < config.max_period); |
|
|
assert_eq!(config.min_period, 22050 / 4000); |
|
|
assert_eq!(config.max_period, 22050 / 60); |
|
|
} |
|
|
|
|
|
#[test] |
|
|
fn test_different_sample_rates() { |
|
|
let config_22k = MarineConfig::speech_default(22050); |
|
|
let config_44k = MarineConfig::speech_default(44100); |
|
|
let config_48k = MarineConfig::speech_default(48000); |
|
|
|
|
|
|
|
|
assert!(config_44k.max_period > config_22k.max_period); |
|
|
assert!(config_48k.max_period > config_44k.max_period); |
|
|
} |
|
|
} |
|
|
|