Function bodies 463 total
default_models function · rust · L121-L126 (6 LOC)core/src/llm/provider.rs
fn default_models() {
let a = Provider::Anthropic;
assert!(a.default_model().contains("sonnet"));
let o = Provider::OpenAI;
assert!(o.default_model().starts_with("gpt"));
}tier_models function · rust · L129-L137 (9 LOC)core/src/llm/provider.rs
fn tier_models() {
let a = Provider::Anthropic;
assert!(a.model_for_tier(ModelTier::Fast).contains("haiku"));
assert!(a.model_for_tier(ModelTier::Default).contains("sonnet"));
assert!(a.model_for_tier(ModelTier::Think).contains("opus"));
let o = Provider::OpenAI;
assert!(o.model_for_tier(ModelTier::Think).contains("pro"));
}tier_from_flags function · rust · L140-L144 (5 LOC)core/src/llm/provider.rs
fn tier_from_flags() {
assert_eq!(ModelTier::from_flags(false, false), ModelTier::Default);
assert_eq!(ModelTier::from_flags(true, false), ModelTier::Fast);
assert_eq!(ModelTier::from_flags(false, true), ModelTier::Think);
}compute function · rust · L94-L138 (45 LOC)core/src/session_data.rs
pub fn compute(
tier_counts: [usize; 3],
active_fraction: f32,
pitched_fraction: f32,
has_cpps: bool,
) -> Self {
let dominant_tier = if tier_counts[0] >= tier_counts[1] && tier_counts[0] >= tier_counts[2] {
1
} else if tier_counts[1] >= tier_counts[2] {
2
} else {
3
};
let analysis_quality = if dominant_tier == 1 && pitched_fraction > 0.5 {
"good"
} else if dominant_tier <= 2 && pitched_fraction > 0.3 {
"ok"
} else {
"trend_only"
}
.to_string();
let metrics_validity = MetricsValidity {
jitter: dominant_tier <= 2 && pitched_fraction > 0.3,
shimmer: dominant_tier <= 2,
hnr: dominant_tier <= 2,
cpps: has_cpps,
voice_breaks: if dominant_tier == 1 {
"valid".to_string()
} else if dominant_tier == 2 {
session_data_roundtrip function · rust · L273-L320 (48 LOC)core/src/session_data.rs
fn session_data_roundtrip() {
let session = SessionData {
date: "2026-02-08".into(),
recordings: SessionRecordings {
sustained: Some("data/recordings/2026-02-08/sustained.wav".into()),
scale: Some("data/recordings/2026-02-08/scale.wav".into()),
reading: None,
},
analysis: SessionAnalysis {
sustained: Some(SustainedAnalysis {
mpt_seconds: 8.3,
mean_f0_hz: 112.4,
f0_std_hz: 3.2,
jitter_local_percent: 2.1,
shimmer_local_percent: 5.8,
hnr_db: 12.3,
cpps_db: Some(6.5),
periodicity_mean: None,
detection_quality: None,
reliability: None,
}),
scale: Some(ScaleAnalysis {
pitch_floor_hz: 42.0,
pitch_ceilingreliability_good_quality function · rust · L323-L330 (8 LOC)core/src/session_data.rs
fn reliability_good_quality() {
let r = ReliabilityInfo::compute([80, 10, 10], 0.9, 0.7, true);
assert_eq!(r.dominant_tier, 1);
assert_eq!(r.analysis_quality, "good");
assert!(r.metrics_validity.jitter);
assert!(r.metrics_validity.cpps);
assert_eq!(r.metrics_validity.voice_breaks, "valid");
}reliability_ok_quality function · rust · L333-L339 (7 LOC)core/src/session_data.rs
fn reliability_ok_quality() {
let r = ReliabilityInfo::compute([20, 60, 20], 0.8, 0.4, true);
assert_eq!(r.dominant_tier, 2);
assert_eq!(r.analysis_quality, "ok");
assert!(r.metrics_validity.jitter);
assert_eq!(r.metrics_validity.voice_breaks, "trend_only");
}Repobility · code-quality intelligence · https://repobility.com
reliability_trend_only function · rust · L342-L349 (8 LOC)core/src/session_data.rs
fn reliability_trend_only() {
let r = ReliabilityInfo::compute([5, 5, 90], 0.7, 0.1, false);
assert_eq!(r.dominant_tier, 3);
assert_eq!(r.analysis_quality, "trend_only");
assert!(!r.metrics_validity.jitter);
assert!(!r.metrics_validity.cpps);
assert_eq!(r.metrics_validity.voice_breaks, "unavailable");
}reliability_backward_compat function · rust · L352-L360 (9 LOC)core/src/session_data.rs
fn reliability_backward_compat() {
// Old JSON without reliability field should deserialize to None
let json = r#"{"mpt_seconds":5.0,"mean_f0_hz":100.0,"f0_std_hz":2.0,
"jitter_local_percent":1.0,"shimmer_local_percent":3.0,"hnr_db":10.0}"#;
let s: SustainedAnalysis = serde_json::from_str(json).unwrap();
assert!(s.reliability.is_none());
assert!(s.cpps_db.is_none());
assert!(s.detection_quality.is_none());
}conditions_roundtrip function · rust · L363-L382 (20 LOC)core/src/session_data.rs
fn conditions_roundtrip() {
let conditions = RecordingConditions {
time_of_day: "morning".into(),
fatigue_level: 7,
throat_cleared: true,
mucus_level: "high".into(),
hydration: "low".into(),
notes: Some("slept poorly".into()),
};
let json = serde_json::to_string(&conditions).unwrap();
let loaded: RecordingConditions = serde_json::from_str(&json).unwrap();
assert_eq!(loaded.time_of_day, "morning");
assert_eq!(loaded.fatigue_level, 7);
assert!(loaded.throat_cleared);
assert_eq!(loaded.mucus_level, "high");
assert_eq!(loaded.hydration, "low");
assert_eq!(loaded.notes.as_deref(), Some("slept poorly"));
}sz_raw_data_roundtrip function · rust · L385-L394 (10 LOC)core/src/session_data.rs
fn sz_raw_data_roundtrip() {
let raw = SzRawData {
s_durations: vec![12.0, 11.5],
z_durations: vec![10.0, 9.5],
};
let json = serde_json::to_string(&raw).unwrap();
let loaded: SzRawData = serde_json::from_str(&json).unwrap();
assert_eq!(loaded.s_durations, vec![12.0, 11.5]);
assert_eq!(loaded.z_durations, vec![10.0, 9.5]);
}fatigue_raw_data_roundtrip function · rust · L397-L406 (10 LOC)core/src/session_data.rs
fn fatigue_raw_data_roundtrip() {
let raw = FatigueRawData {
mpt_per_trial: vec![10.0, 9.0, 8.0],
effort_per_trial: vec![3, 4, 5],
};
let json = serde_json::to_string(&raw).unwrap();
let loaded: FatigueRawData = serde_json::from_str(&json).unwrap();
assert_eq!(loaded.mpt_per_trial, vec![10.0, 9.0, 8.0]);
assert_eq!(loaded.effort_per_trial, vec![3, 4, 5]);
}conditions_backward_compat function · rust · L409-L414 (6 LOC)core/src/session_data.rs
fn conditions_backward_compat() {
// Old JSON without conditions field should deserialize to None
let json = r#"{"date":"2026-01-01","recordings":{"sustained":null,"scale":null,"reading":null},"analysis":{"sustained":null,"scale":null,"reading":null}}"#;
let s: SessionData = serde_json::from_str(json).unwrap();
assert!(s.conditions.is_none());
}resolve_date function · rust · L4-L9 (6 LOC)core/src/util.rs
pub fn resolve_date(date: Option<&str>) -> anyhow::Result<NaiveDate> {
match date {
Some(s) => Ok(NaiveDate::parse_from_str(s, "%Y-%m-%d")?),
None => Ok(chrono::Local::now().date_naive()),
}
}peak_db function · rust · L13-L23 (11 LOC)core/src/util.rs
pub fn peak_db(samples: &[f32]) -> f32 {
let peak = samples
.iter()
.fold(0.0_f32, |max, &s| max.max(s.abs()));
if peak == 0.0 {
f32::NEG_INFINITY
} else {
20.0 * peak.log10()
}
}About: code-quality intelligence by Repobility · https://repobility.com
rms_db function · rust · L27-L40 (14 LOC)core/src/util.rs
pub fn rms_db(samples: &[f32]) -> f32 {
if samples.is_empty() {
return f32::NEG_INFINITY;
}
let sum_sq: f32 = samples.iter().map(|&s| s * s).sum();
let rms = (sum_sq / samples.len() as f32).sqrt();
if rms == 0.0 {
f32::NEG_INFINITY
} else {
20.0 * rms.log10()
}
}peak_db_full_scale function · rust · L71-L75 (5 LOC)core/src/util.rs
fn peak_db_full_scale() {
// A signal that hits exactly 1.0 should be 0 dB
let samples = vec![0.0, 0.5, 1.0, -0.5];
assert!((peak_db(&samples) - 0.0).abs() < 0.01);
}peak_db_half_scale function · rust · L78-L82 (5 LOC)core/src/util.rs
fn peak_db_half_scale() {
// Peak of 0.5 → 20*log10(0.5) ≈ -6.02 dB
let samples = vec![0.0, 0.5, -0.3];
assert!((peak_db(&samples) - (-6.02)).abs() < 0.1);
}peak_db_silence function · rust · L85-L89 (5 LOC)core/src/util.rs
fn peak_db_silence() {
let samples = vec![0.0, 0.0, 0.0];
assert!(peak_db(&samples).is_infinite());
assert!(peak_db(&samples).is_sign_negative());
}rms_db_full_scale_dc function · rust · L92-L96 (5 LOC)core/src/util.rs
fn rms_db_full_scale_dc() {
// Constant 1.0 → RMS = 1.0 → 0 dB
let samples = vec![1.0, 1.0, 1.0, 1.0];
assert!((rms_db(&samples) - 0.0).abs() < 0.01);
}rms_db_half_scale_dc function · rust · L99-L103 (5 LOC)core/src/util.rs
fn rms_db_half_scale_dc() {
// Constant 0.5 → RMS = 0.5 → -6.02 dB
let samples = vec![0.5, 0.5, 0.5, 0.5];
assert!((rms_db(&samples) - (-6.02)).abs() < 0.1);
}rms_db_silence function · rust · L106-L110 (5 LOC)core/src/util.rs
fn rms_db_silence() {
let samples = vec![0.0, 0.0, 0.0];
assert!(rms_db(&samples).is_infinite());
assert!(rms_db(&samples).is_sign_negative());
}rms_db_empty function · rust · L113-L115 (3 LOC)core/src/util.rs
fn rms_db_empty() {
assert!(rms_db(&[]).is_infinite());
}Repobility (the analyzer behind this table) · https://repobility.com
resolve_date_explicit function · rust · L118-L121 (4 LOC)core/src/util.rs
fn resolve_date_explicit() {
let date = resolve_date(Some("2026-02-08")).unwrap();
assert_eq!(date, NaiveDate::from_ymd_opt(2026, 2, 8).unwrap());
}resolve_date_today function · rust · L124-L127 (4 LOC)core/src/util.rs
fn resolve_date_today() {
let date = resolve_date(None).unwrap();
assert_eq!(date, chrono::Local::now().date_naive());
}resolve_date_invalid function · rust · L130-L132 (3 LOC)core/src/util.rs
fn resolve_date_invalid() {
assert!(resolve_date(Some("not-a-date")).is_err());
}linear_regression_known_slope function · rust · L135-L141 (7 LOC)core/src/util.rs
fn linear_regression_known_slope() {
// y = 2x + 1: points (0,1), (1,3), (2,5), (3,7)
let points = vec![(0.0, 1.0), (1.0, 3.0), (2.0, 5.0), (3.0, 7.0)];
let (slope, intercept) = linear_regression(&points);
assert!((slope - 2.0).abs() < 0.01, "Expected slope ~2.0, got {slope:.3}");
assert!((intercept - 1.0).abs() < 0.01, "Expected intercept ~1.0, got {intercept:.3}");
}linear_regression_flat function · rust · L144-L148 (5 LOC)core/src/util.rs
fn linear_regression_flat() {
let points = vec![(0.0, 5.0), (1.0, 5.0), (2.0, 5.0)];
let (slope, _intercept) = linear_regression(&points);
assert!(slope.abs() < 0.01, "Expected slope ~0, got {slope:.3}");
}linear_regression_declining function · rust · L151-L157 (7 LOC)core/src/util.rs
fn linear_regression_declining() {
// y = -1x + 10: points (0,10), (1,9), (2,8), (3,7), (4,6)
let points = vec![(0.0, 10.0), (1.0, 9.0), (2.0, 8.0), (3.0, 7.0), (4.0, 6.0)];
let (slope, intercept) = linear_regression(&points);
assert!((slope - (-1.0)).abs() < 0.01, "Expected slope ~-1.0, got {slope:.3}");
assert!((intercept - 10.0).abs() < 0.01, "Expected intercept ~10.0, got {intercept:.3}");
}linear_regression_too_few_points function · rust · L160-L164 (5 LOC)core/src/util.rs
fn linear_regression_too_few_points() {
let (slope, intercept) = linear_regression(&[(1.0, 2.0)]);
assert_eq!(slope, 0.0);
assert_eq!(intercept, 0.0);
}analyze_session function · rust · L19-L21 (3 LOC)src/analysis/analyzer.rs
pub fn analyze_session(date: &str, app_config: &AppConfig) -> Result<SessionData> {
analyze_session_with_conditions(date, app_config, None)
}Repobility · open methodology · https://repobility.com/research/
analyze_session_with_conditions function · rust · L24-L140 (117 LOC)src/analysis/analyzer.rs
pub fn analyze_session_with_conditions(
date: &str,
app_config: &AppConfig,
conditions: Option<RecordingConditions>,
) -> Result<SessionData> {
let sustained_pitch = app_config.analysis.pitch_config_for("sustained");
let scale_pitch = app_config.analysis.pitch_config_for("scale");
let reading_pitch = app_config.analysis.pitch_config_for("reading");
println!(
"Analyzing session {}...",
style(date).cyan()
);
println!();
let date_obj = util::resolve_date(Some(date))?;
// Find latest attempt for each exercise
let sustained_path = paths::latest_attempt_path(&date_obj, "sustained");
let scale_path = paths::latest_attempt_path(&date_obj, "scale");
let reading_path = paths::latest_attempt_path(&date_obj, "reading");
// Analyze each exercise that has a recording.
// We print results as we go so the user gets immediate feedback.
let thresholds = &app_config.analysis.thresholds;
let sustained = if let Soanalyze_exercise function · rust · L151-L167 (17 LOC)src/analysis/analyzer.rs
fn analyze_exercise<T, F>(name: &str, path: &Path, analyze_fn: F) -> Result<T>
where
F: FnOnce(&[f32], u32) -> Result<T>,
{
println!(" {} {name}", style(">>").cyan());
let (samples, spec) = wav::load_samples(path)
.with_context(|| format!("Failed to load {}", path.display()))?;
let duration = samples.len() as f32 / spec.sample_rate as f32;
println!(" Loaded: {:.1}s, {} Hz", duration, spec.sample_rate);
let result = analyze_fn(&samples, spec.sample_rate)?;
println!();
Ok(result)
}print_sustained_results function · rust · L168-L207 (40 LOC)src/analysis/analyzer.rs
fn print_sustained_results(r: &SustainedAnalysis, t: &crate::config::ThresholdConfig) {
println!(" MPT: {:.1}s", r.mpt_seconds);
println!(" Mean F0: {:.1} Hz", r.mean_f0_hz);
println!(" F0 std: {:.1} Hz", r.f0_std_hz);
println!(
" Jitter: {:.2}% {}",
r.jitter_local_percent,
threshold_label(r.jitter_local_percent, t.jitter_pathological)
);
println!(
" Shimmer: {:.2}% {}",
r.shimmer_local_percent,
threshold_label(r.shimmer_local_percent, t.shimmer_pathological)
);
println!(
" HNR: {:.1} dB {}",
r.hnr_db,
hnr_label(r.hnr_db, t)
);
if let Some(cpps) = r.cpps_db {
println!(
" CPPS: {:.1} dB {}",
cpps,
cpps_label(cpps)
);
}
if let Some(p) = r.periodicity_mean {
println!(" Periodicity: {:.2}", p);
}
if let Some(ref rel) = r.reliability {
println!(
print_scale_results function · rust · L208-L213 (6 LOC)src/analysis/analyzer.rs
fn print_scale_results(r: &ScaleAnalysis) {
println!(" Floor: {:.1} Hz", r.pitch_floor_hz);
println!(" Ceiling: {:.1} Hz", r.pitch_ceiling_hz);
println!(" Range: {:.1} Hz ({:.1} semitones)", r.range_hz, r.range_semitones);
}print_reading_results function · rust · L214-L240 (27 LOC)src/analysis/analyzer.rs
fn print_reading_results(r: &ReadingAnalysis) {
println!(" Mean F0: {:.1} Hz", r.mean_f0_hz);
println!(" F0 std: {:.1} Hz", r.f0_std_hz);
println!(
" F0 range: {:.1} - {:.1} Hz",
r.f0_range_hz.0, r.f0_range_hz.1
);
println!(" Breaks: {}", r.voice_breaks);
println!(" Voiced: {:.0}%", r.voiced_fraction * 100.0);
if let Some(cpps) = r.cpps_db {
println!(
" CPPS: {:.1} dB {}",
cpps,
cpps_label(cpps)
);
}
if let Some(ref rel) = r.reliability {
println!(
" Quality: {} (active {:.0}%, pitched {:.0}%, tier {})",
style(&rel.analysis_quality).cyan(),
rel.active_fraction * 100.0,
rel.pitched_fraction * 100.0,
rel.dominant_tier,
);
}
}threshold_label function · rust · L243-L249 (7 LOC)src/analysis/analyzer.rs
fn threshold_label(value: f32, threshold: f32) -> String {
if value <= threshold {
format!("{}", style("(normal)").green())
} else {
format!("{}", style("(elevated)").yellow())
}
}cpps_label function · rust · L252-L260 (9 LOC)src/analysis/analyzer.rs
fn cpps_label(cpps: f32) -> String {
if cpps >= 5.0 {
format!("{}", style("(normal)").green())
} else if cpps >= 3.0 {
format!("{}", style("(mild dysphonia)").yellow())
} else {
format!("{}", style("(significant dysphonia)").red())
}
}hnr_label function · rust · L263-L271 (9 LOC)src/analysis/analyzer.rs
fn hnr_label(hnr: f32, t: &crate::config::ThresholdConfig) -> String {
if hnr >= t.hnr_normal {
format!("{}", style("(healthy)").green())
} else if hnr >= t.hnr_low {
format!("{}", style("(improving)").yellow())
} else {
format!("{}", style("(low)").red())
}
}Repobility · code-quality intelligence · https://repobility.com
print_sz_results function · rust · L272-L284 (13 LOC)src/analysis/analyzer.rs
fn print_sz_results(sz: &SzAnalysis) {
println!(" {} S/Z ratio", style(">>").cyan());
println!(" Mean /s/: {:.1}s", sz.mean_s);
println!(" Mean /z/: {:.1}s", sz.mean_z);
let label = if sz.sz_ratio > 1.4 {
format!("{}", style("(elevated — possible glottal air leak)").yellow())
} else {
format!("{}", style("(normal)").green())
};
println!(" Ratio: {:.2} {}", sz.sz_ratio, label);
println!();
}print_fatigue_results function · rust · L285-L312 (28 LOC)src/analysis/analyzer.rs
fn print_fatigue_results(f: &FatigueAnalysis) {
println!(" {} Vocal fatigue", style(">>").cyan());
for (i, mpt) in f.mpt_per_trial.iter().enumerate() {
let cpps_str = f.cpps_per_trial[i]
.map(|c| format!(", CPPS={c:.1}dB"))
.unwrap_or_default();
println!(
" Trial {}: {:.1}s{}, effort={}",
i + 1,
mpt,
cpps_str,
f.effort_per_trial[i],
);
}
let label = if f.mpt_slope < -0.3 {
format!("{}", style("(declining — vocal fatigue)").yellow())
} else if f.mpt_slope > 0.3 {
format!("{}", style("(improving — warming up)").green())
} else {
format!("{}", style("(stable — good endurance)").green())
};
println!(" MPT slope: {:+.2}s/trial {}", f.mpt_slope, label);
if f.cpps_slope.abs() > 0.001 {
println!(" CPPS slope: {:+.2}dB/trial", f.cpps_slope);
}
println!();
}rms_db function · rust · L38-L45 (8 LOC)src/audio/capture.rs
pub fn rms_db(&self) -> f32 {
let rms = f32::from_bits(self.live_rms.load(Ordering::Relaxed));
if rms > 0.0 {
20.0 * rms.log10()
} else {
f32::NEG_INFINITY
}
}waveform_snapshot function · rust · L48-L53 (6 LOC)src/audio/capture.rs
pub fn waveform_snapshot(&self) -> Vec<f32> {
self.waveform_buffer
.lock()
.map(|buf| buf.iter().copied().collect())
.unwrap_or_default()
}pitch_hz function · rust · L56-L64 (9 LOC)src/audio/capture.rs
pub fn pitch_hz(&self) -> Option<f32> {
let bits = self.live_pitch.load(Ordering::Relaxed);
if bits == 0 {
None
} else {
let hz = f32::from_bits(bits);
if hz > 0.0 { Some(hz) } else { None }
}
}is_silent function · rust · L67-L69 (3 LOC)src/audio/capture.rs
pub fn is_silent(&self) -> bool {
self.rms_db() < SILENCE_THRESHOLD_DB
}start_capture function · rust · L79-L237 (159 LOC)src/audio/capture.rs
pub fn start_capture(
enable_pitch: bool,
) -> Result<(AudioState, cpal::Stream, JoinHandle<Vec<f32>>)> {
let host = cpal::default_host();
let device = host
.default_input_device()
.context("No default input device found")?;
let config = device
.default_input_config()
.context("Failed to get default input config")?;
let sample_rate = config.sample_rate().0;
let channels = config.channels() as usize;
let format = config.sample_format();
let (tx, rx) = mpsc::channel::<Vec<f32>>();
let live_rms = Arc::new(AtomicU32::new(0_f32.to_bits()));
let stop = Arc::new(AtomicBool::new(false));
let waveform_buffer = Arc::new(Mutex::new(VecDeque::with_capacity(WAVEFORM_BUFFER_SIZE)));
let live_pitch = Arc::new(AtomicU32::new(0));
let stop_stream = Arc::clone(&stop);
let rms_stream = Arc::clone(&live_rms);
let waveform_stream = Arc::clone(&waveform_buffer);
let stream = match format {
SampleForcompute_rms function · rust · L240-L246 (7 LOC)src/audio/capture.rs
pub fn compute_rms(samples: &[f32]) -> f32 {
if samples.is_empty() {
return 0.0;
}
let sum_sq: f32 = samples.iter().map(|&s| s * s).sum();
(sum_sq / samples.len() as f32).sqrt()
}About: code-quality intelligence by Repobility · https://repobility.com
compute_rms_silence function · rust · L253-L255 (3 LOC)src/audio/capture.rs
fn compute_rms_silence() {
assert_eq!(compute_rms(&[0.0, 0.0, 0.0]), 0.0);
}compute_rms_empty function · rust · L258-L260 (3 LOC)src/audio/capture.rs
fn compute_rms_empty() {
assert_eq!(compute_rms(&[]), 0.0);
}compute_rms_dc_signal function · rust · L263-L266 (4 LOC)src/audio/capture.rs
fn compute_rms_dc_signal() {
let rms = compute_rms(&[0.5, 0.5, 0.5, 0.5]);
assert!((rms - 0.5).abs() < 0.001);
}