feat(audio): add internal bit-depth diagnostic capture
Lock-free OR-mask analysis of f32 samples converted to i32, bypassing PipeWire processing entirely. DiagnosticSource wraps the audio source at decode level for both rodio and ALSA Direct paths. Tauri commands: start_bitdepth_capture / stop_bitdepth_capture. cc
This commit is contained in:
1 parent
3253e05263
commit
af624d4642
5 files changed
+255
-8
No files matched your search
@@ -1,7 +1,12 @@
|
||||
//! Audio diagnostics commands for detecting actual hardware sample rate
|
||||
//! and verifying effective bit depth of the audio pipeline.
|
||||
|
||||
use std::fs;
|
||||
|
||||
use tauri::Manager;
|
||||
use crate::AppState;
|
||||
use crate::audio::BitDepthResult;
|
||||
|
||||
/// Hardware audio status
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct HardwareAudioStatus {
|
||||
@@ -71,3 +76,34 @@ pub fn get_hardware_audio_status() -> Result<HardwareAudioStatus, String> {
|
||||
is_active: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Start bit-depth diagnostic capture on the currently playing audio.
|
||||
/// Samples are analyzed on-the-fly with zero allocation (OR-mask of i32 values).
|
||||
/// Call `stop_bitdepth_capture` after a few seconds to get the result.
|
||||
#[tauri::command]
|
||||
pub fn start_bitdepth_capture(
|
||||
app: tauri::AppHandle,
|
||||
) -> Result<String, String> {
|
||||
let state = app.state::<AppState>();
|
||||
let sample_rate = state.player.state.get_sample_rate();
|
||||
if sample_rate == 0 {
|
||||
return Err("No audio playing — cannot start capture".to_string());
|
||||
}
|
||||
// Default to 2 channels (stereo) — SharedState doesn't track channels
|
||||
state.player.diagnostic.start_capture(sample_rate, 2);
|
||||
Ok(format!("Capture started at {}Hz", sample_rate))
|
||||
}
|
||||
|
||||
/// Stop bit-depth capture and return analysis.
|
||||
///
|
||||
/// The `effective_bits` field is the key result:
|
||||
/// - 24 → source data has 24-bit precision (f32 pipeline working)
|
||||
/// - 16 → source data truncated to 16-bit (bug)
|
||||
/// - Other values → intermediate precision or pipeline issue
|
||||
#[tauri::command]
|
||||
pub fn stop_bitdepth_capture(
|
||||
app: tauri::AppHandle,
|
||||
) -> Result<BitDepthResult, String> {
|
||||
let state = app.state::<AppState>();
|
||||
Ok(state.player.diagnostic.stop_and_analyze())
|
||||
}
|
||||
Reference in new issue
Block a user