Sound output now works correctly

This commit is contained in:
Pierre Krieger 2014-12-15 16:26:55 +01:00
parent 9598f68d3c
commit 1a556514b0
4 changed files with 34 additions and 19 deletions

View file

@ -18,7 +18,7 @@ fn main() {
});
loop {
let mut buffer = channel.append_data(1, cpal::SamplesRate(44100));
let mut buffer = channel.append_data(1, cpal::SamplesRate(44100), 32768);
for sample in buffer.samples() {
let value = data_source.next().unwrap();

View file

@ -13,27 +13,25 @@ fn main() {
let packet = packet.unwrap();
let vorbis::Packet { channels, rate, data, .. } = packet;
let mut data = data.iter();
let mut next_sample = None;
let mut data = data.as_slice();
loop {
let mut buffer = channel.append_data(channels, cpal::SamplesRate(rate as u32));
if data.len() == 0 {
continue 'main;
}
let mut buffer = channel.append_data(channels, cpal::SamplesRate(rate as u32), data.len());
let mut buffer = buffer.samples();
loop {
if next_sample.is_none() {
match data.next() {
Some(sample) => {
next_sample = Some(*sample as u16)
},
None => {
continue 'main;
}
}
}
let next_sample = match data.get(0) {
Some(s) => *s,
None => continue 'main
};
if let Some(output) = buffer.next() {
*output = next_sample.take().unwrap();
*output = next_sample as u16;
data = data.slice_from(1);
} else {
break;
}