aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio.rs')
-rw-r--r--src/audio.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/audio.rs b/src/audio.rs
index 86c88f7..4e26263 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -204,6 +204,8 @@ fn audio_thread(
204 let vol = vol.lock().map(|v| *v).unwrap_or(1.0); 204 let vol = vol.lock().map(|v| *v).unwrap_or(1.0);
205 205
206 if let Ok(mut audio_data) = audio_data_clone.lock() { 206 if let Ok(mut audio_data) = audio_data_clone.lock() {
207 let mut should_clear = false;
208
207 if let Some(ref mut state) = *audio_data { 209 if let Some(ref mut state) = *audio_data {
208 let channels = state.channels as usize; 210 let channels = state.channels as usize;
209 let mut offset = 0usize; 211 let mut offset = 0usize;
@@ -298,16 +300,17 @@ fn audio_thread(
298 if offset == 0 && state.sample_buffer.is_empty() { 300 if offset == 0 && state.sample_buffer.is_empty() {
299 ended.store(true, Ordering::SeqCst); 301 ended.store(true, Ordering::SeqCst);
300 is_playing_clone.store(false, Ordering::SeqCst); 302 is_playing_clone.store(false, Ordering::SeqCst);
301 // Clear audio data so we don't keep triggering ended 303 should_clear = true;
302 if let Ok(mut audio_data) = audio_data_clone.lock() {
303 *audio_data = None;
304 }
305 } 304 }
306 } else { 305 } else {
307 for sample in data.iter_mut() { 306 for sample in data.iter_mut() {
308 *sample = 0.0; 307 *sample = 0.0;
309 } 308 }
310 } 309 }
310
311 if should_clear {
312 *audio_data = None;
313 }
311 } 314 }
312 }, 315 },
313 |err| { 316 |err| {
@@ -319,7 +322,6 @@ fn audio_thread(
319 if let Err(e) = stream.play() { 322 if let Err(e) = stream.play() {
320 eprintln!("Failed to start stream: {}", e); 323 eprintln!("Failed to start stream: {}", e);
321 is_playing.store(false, Ordering::SeqCst); 324 is_playing.store(false, Ordering::SeqCst);
322 track_ended.store(true, Ordering::SeqCst);
323 } else { 325 } else {
324 current_stream = Some(stream); 326 current_stream = Some(stream);
325 } 327 }
@@ -327,14 +329,12 @@ fn audio_thread(
327 Err(e) => { 329 Err(e) => {
328 eprintln!("Failed to create stream: {}", e); 330 eprintln!("Failed to create stream: {}", e);
329 is_playing.store(false, Ordering::SeqCst); 331 is_playing.store(false, Ordering::SeqCst);
330 track_ended.store(true, Ordering::SeqCst);
331 } 332 }
332 } 333 }
333 } 334 }
334 Err(e) => { 335 Err(e) => {
335 eprintln!("Failed to open audio: {}", e); 336 eprintln!("Failed to open audio: {}", e);
336 is_playing.store(false, Ordering::SeqCst); 337 is_playing.store(false, Ordering::SeqCst);
337 track_ended.store(true, Ordering::SeqCst);
338 } 338 }
339 } 339 }
340 } 340 }