Change player architecture to avoid data losses
This commit is contained in:
parent
e26a8c4cb2
commit
6becac9780
|
@ -14,20 +14,29 @@ fn main() {
|
||||||
let vorbis::Packet { channels, rate, data, .. } = packet;
|
let vorbis::Packet { channels, rate, data, .. } = packet;
|
||||||
|
|
||||||
let mut data = data.iter();
|
let mut data = data.iter();
|
||||||
|
let mut next_sample = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = channel.append_data(channels, cpal::SamplesRate(rate as u32));
|
let mut buffer = channel.append_data(channels, cpal::SamplesRate(rate as u32));
|
||||||
let mut buffer = buffer.samples();
|
let mut buffer = buffer.samples();
|
||||||
|
|
||||||
for output in buffer {
|
loop {
|
||||||
match data.next() {
|
if next_sample.is_none() {
|
||||||
Some(sample) => {
|
match data.next() {
|
||||||
*output = *sample as u16;
|
Some(sample) => {
|
||||||
},
|
next_sample = Some(*sample as u16)
|
||||||
None => {
|
},
|
||||||
continue 'main;
|
None => {
|
||||||
|
continue 'main;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(output) = buffer.next() {
|
||||||
|
*output = next_sample.take().unwrap();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue