refactor(audio): remove commented debug info and clean up tracing usage

This commit is contained in:
Mercurio 2025-06-21 13:05:16 +02:00
parent df1df2a294
commit 5d42526121

View file

@ -9,7 +9,7 @@ use symphonia::core::formats::{FormatOptions, FormatReader};
use symphonia::core::io::MediaSourceStream;
use symphonia::core::meta::MetadataOptions;
use symphonia::core::probe::Hint;
use tracing::{//info!, debug, error, warn};
use tracing::{error, warn};
pub struct AsioPlayer {
device: Device,
@ -38,7 +38,7 @@ impl AsioPlayer {
let mut devices = host.output_devices()?;
let device = devices.next()
.ok_or_else(|| anyhow::anyhow!("No ASIO output device found"))?;
//info!!("Using ASIO device: {}", device.name()?);
//info!("Using ASIO device: {}", device.name()?);
Ok(Self {
device,
@ -75,17 +75,17 @@ impl AsioPlayer {
}
self.forced_sample_rate = Some(sample_rate);
//info!!("Forced sample rate set to {} Hz", sample_rate);
//info!("Forced sample rate set to {} Hz", sample_rate);
Ok(())
}
pub fn clear_sample_rate(&mut self) {
self.forced_sample_rate = None;
////info!!("Sample rate forcing cleared - will use automatic selection");
//info!("Sample rate forcing cleared - will use automatic selection");
}
pub async fn play_url(&mut self, url: &str) -> Result<()> {
////info!!("Starting playback of: {}", url);
//info!("Starting playback of: {}", url);
// Stop any existing playback
self.stop()?;
@ -104,7 +104,7 @@ impl AsioPlayer {
stream.play()?;
self.start_time = Some(Instant::now());
self.paused_position = None;
//info!!("Playback started");
//info!("Playback started");
}
Ok(())
@ -127,7 +127,7 @@ impl AsioPlayer {
buffer.paused = true;
}
//info!!("Playback paused");
//info!("Playback paused");
Ok(())
} else {
Err(anyhow::anyhow!("No active stream to pause"))
@ -150,7 +150,7 @@ impl AsioPlayer {
}
stream.play()?;
//info!!("Playback resumed");
//info!("Playback resumed");
Ok(())
} else {
Err(anyhow::anyhow!("No active stream to resume"))
@ -176,9 +176,10 @@ impl AsioPlayer {
self.start_time = None;
self.paused_position = None;
////info!!("Playback stopped and buffer cleared");
//info!("Playback stopped and buffer cleared");
Ok(())
} else {
// Not an error if already stopped
Ok(())
}
}
@ -206,7 +207,7 @@ impl AsioPlayer {
}
}
////info!!("Seeked to position: {:.1}%", position * 100.0);
//info!("Seeked to position: {:.1}%", position * 100.0);
Ok(())
} else {
Err(anyhow::anyhow!("No active stream to seek"))
@ -220,7 +221,7 @@ impl AsioPlayer {
if let Some(buffer) = &self.stream_buffer {
let mut buffer = buffer.lock().unwrap();
buffer.volume = volume;
////info!!("Volume set to: {:.0}%", volume * 100.0);
//info!("Volume set to: {:.0}%", volume * 100.0);
}
Ok(())
@ -241,12 +242,12 @@ impl AsioPlayer {
}
async fn download_and_decode(&self, url: &str) -> Result<(Vec<f32>, u32, u16, u64)> {
debug!("Downloading audio from: {}", url);
//debug!("Downloading audio from: {}", url);
let response = reqwest::get(url).await?;
let bytes = response.bytes().await?;
debug!("Downloaded {} bytes, decoding...", bytes.len());
//debug!("Downloaded {} bytes, decoding...", bytes.len());
// Create media source
let cursor = std::io::Cursor::new(bytes);
@ -276,7 +277,7 @@ impl AsioPlayer {
let mut decoder = symphonia::default::get_codecs()
.make(&track.codec_params, &decoder_opts)?;
////info!!!("Decoding: {} channels, {} Hz", channels, sample_rate);
//info!("Decoding: {} channels, {} Hz", channels, sample_rate);
let mut samples = Vec::new();
@ -348,12 +349,12 @@ impl AsioPlayer {
}
}
_ => {
debug!("Unsupported audio format");
//debug!("Unsupported audio format");
}
}
}
Err(e) => {
debug!("Decode error: {}", e);
//debug!("Decode error: {}", e);
break;
}
}
@ -366,7 +367,7 @@ impl AsioPlayer {
let num_frames = samples.len() / channels as usize;
let duration_ms = (num_frames as f64 / sample_rate as f64 * 1000.0) as u64;
//info!!("Decoded {} samples, duration: {}ms", samples.len(), duration_ms);
//info!("Decoded {} samples, duration: {}ms", samples.len(), duration_ms);
Ok((samples, sample_rate, channels, duration_ms))
}
@ -386,7 +387,7 @@ impl AsioPlayer {
config.channels() == source_channels {
selected_config = Some(config.with_sample_rate(SampleRate(forced_rate)));
target_sample_rate = forced_rate;
//info!!("Using forced sample rate: {} Hz", forced_rate);
//info!("Using forced sample rate: {} Hz", forced_rate);
break;
}
}
@ -446,7 +447,7 @@ impl AsioPlayer {
self.device.default_output_config()?
};
//info!!("Selected config: {} channels, {} Hz, format: {:?}",
//info!("Selected config: {} channels, {} Hz, format: {:?}",
//config.channels(), config.sample_rate().0, config.sample_format());
// Resample if necessary
@ -521,7 +522,7 @@ impl AsioPlayer {
fn build_f32_stream(&mut self, config: StreamConfig, audio_buffer: Arc<Mutex<StreamBuffer>>) -> Result<()> {
let stream = self.device.build_output_stream(
&config,
move |data: &mut [f32], _: &cpal::OutputCallback//info!| {
move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
let mut buffer = audio_buffer.lock().unwrap();
// If paused, just output silence
@ -566,7 +567,7 @@ impl AsioPlayer {
fn build_i32_stream(&mut self, config: StreamConfig, audio_buffer: Arc<Mutex<StreamBuffer>>) -> Result<()> {
let stream = self.device.build_output_stream(
&config,
move |data: &mut [i32], _: &cpal::OutputCallback//info!| {
move |data: &mut [i32], _: &cpal::OutputCallbackInfo| {
let mut buffer = audio_buffer.lock().unwrap();
// If paused, just output silence
@ -601,7 +602,7 @@ impl AsioPlayer {
fn build_i16_stream(&mut self, config: StreamConfig, audio_buffer: Arc<Mutex<StreamBuffer>>) -> Result<()> {
let stream = self.device.build_output_stream(
&config,
move |data: &mut [i16], _: &cpal::OutputCallback//info!| {
move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
let mut buffer = audio_buffer.lock().unwrap();
// If paused, just output silence