aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio.rs')
-rw-r--r--src/audio.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/audio.rs b/src/audio.rs
index 7218f84..386c041 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -197,6 +197,37 @@ fn audio_thread(
197 Some(device_sample_rate as f64 / data.sample_rate as f64); 197 Some(device_sample_rate as f64 / data.sample_rate as f64);
198 } 198 }
199 199
200 // Pre-decode some samples before starting playback to prevent buffer underrun
201 let channels = data.channels as usize;
202 for _ in 0..50 {
203 match data.format.next_packet() {
204 Ok(packet) => {
205 match data.decoder.decode(&packet) {
206 Ok(decoded) => {
207 let spec = *decoded.spec();
208 let mut sample_buf =
209 symphonia::core::audio::SampleBuffer::<f32>::new(
210 decoded.capacity() as u64, spec
211 );
212 sample_buf.copy_interleaved_ref(decoded);
213 let samples = sample_buf.samples();
214
215 let resampled = if let Some(ratio) = data.resample_ratio {
216 resample_linear(samples, ratio, channels)
217 } else {
218 samples.to_vec()
219 };
220
221 data.sample_buffer.extend(resampled);
222 }
223 Err(_) => break,
224 }
225 }
226 Err(_) => break,
227 }
228 }
229 data.buffer_pos = 0;
230
200 let stream_config: cpal::StreamConfig = 231 let stream_config: cpal::StreamConfig =
201 device.default_output_config().unwrap().into(); 232 device.default_output_config().unwrap().into();
202 233