mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Simple block of playback thread based on buffer size.
This commit is contained in:
parent
49fd48b42a
commit
587aa9c711
2 changed files with 10 additions and 2 deletions
|
@ -20,7 +20,7 @@ portaudio-rs = { version = "0.3.0", optional = true }
|
|||
libpulse-sys = { version = "0.0.0", optional = true }
|
||||
jack = { version = "0.5.3", optional = true }
|
||||
libc = { version = "0.2", optional = true }
|
||||
rodio = { version = "0.8.1", optional = true, default-features = false }
|
||||
rodio = { git = "https://github.com/tomaka/rodio", optional = true, default-features = false}
|
||||
|
||||
[features]
|
||||
alsa-backend = ["alsa"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::{Open, Sink};
|
||||
extern crate rodio;
|
||||
use std::io;
|
||||
use std::{io, thread, time};
|
||||
use std::process::exit;
|
||||
|
||||
pub struct RodioSink {
|
||||
|
@ -83,6 +83,14 @@ impl Sink for RodioSink {
|
|||
fn write(&mut self, data: &[i16]) -> io::Result<()> {
|
||||
let source = rodio::buffer::SamplesBuffer::new(2, 44100, data);
|
||||
self.rodio_sink.append(source);
|
||||
|
||||
// Chunk sizes seem to be about 256 to 3000 ish items long.
|
||||
// Assuming they're on average 1628 then a half second buffer is:
|
||||
// 44100 elements --> about 27 chunks
|
||||
while self.rodio_sink.len() > 26 {
|
||||
// sleep and wait for rodio to drain a bit
|
||||
thread::sleep(time::Duration::from_millis(10));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue