From 204b912025811a7f8669a2071ac8f14d8155f261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:35:22 +0300 Subject: [PATCH] perf: :zap: I was wasting first decoded samples --- streamer/src/playing.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/streamer/src/playing.rs b/streamer/src/playing.rs index b22416e..34028b7 100644 --- a/streamer/src/playing.rs +++ b/streamer/src/playing.rs @@ -211,10 +211,15 @@ async fn process_audio( window: WindowFunction::BlackmanHarris2, }; - let chunk_size = match decode_audio(&mut format, track_id, &mut decoder) { - Some((audio_decoded_left_channel, _)) => audio_decoded_left_channel.len(), - None => return, - }; + let (chunk_size, audio_decoded_left, audio_decoded_right) = + match decode_audio(&mut format, track_id, &mut decoder) { + Some((audio_decoded_left_channel, audio_decoded_right_channel)) => ( + audio_decoded_left_channel.len(), + audio_decoded_left_channel, + audio_decoded_right_channel, + ), + None => return, + }; let mut resampler = SincFixedIn::::new( output_device_sample_rate as f64 / audio_sample_rate as f64, @@ -225,6 +230,14 @@ async fn process_audio( ) .unwrap(); + let (audio_resampled_left, audio_resampled_right) = + resample_audio(audio_decoded_left, audio_decoded_right, &mut resampler); + + for (single_left, single_right) in audio_resampled_left.iter().zip(&audio_resampled_right) { + let _ = decoded_to_playing_sender.send(*single_left as f32); + let _ = decoded_to_playing_sender.send(*single_right as f32); + } + loop { let (mut audio_decoded_left, mut audio_decoded_right) = (vec![], vec![]);