Change player architecture to avoid data losses
This commit is contained in:
parent
e26a8c4cb2
commit
6becac9780
|
@ -14,21 +14,30 @@ 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 {
|
||||||
|
if next_sample.is_none() {
|
||||||
match data.next() {
|
match data.next() {
|
||||||
Some(sample) => {
|
Some(sample) => {
|
||||||
*output = *sample as u16;
|
next_sample = Some(*sample as u16)
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
continue 'main;
|
continue 'main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(output) = buffer.next() {
|
||||||
|
*output = next_sample.take().unwrap();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue