Change player architecture to avoid data losses

This commit is contained in:
Pierre Krieger 2014-12-15 15:40:38 +01:00
parent e26a8c4cb2
commit 6becac9780
1 changed files with 16 additions and 7 deletions

View File

@ -14,20 +14,29 @@ fn main() {
let vorbis::Packet { channels, rate, data, .. } = packet;
let mut data = data.iter();
let mut next_sample = None;
loop {
let mut buffer = channel.append_data(channels, cpal::SamplesRate(rate as u32));
let mut buffer = buffer.samples();
for output in buffer {
match data.next() {
Some(sample) => {
*output = *sample as u16;
},
None => {
continue 'main;
loop {
if next_sample.is_none() {
match data.next() {
Some(sample) => {
next_sample = Some(*sample as u16)
},
None => {
continue 'main;
}
}
}
if let Some(output) = buffer.next() {
*output = next_sample.take().unwrap();
} else {
break;
}
}
}
}