mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 14:14:21 +00:00
Merge pull request #11 from tomaka/fix-iter-len
Fix samples being dropped out
This commit is contained in:
commit
f3a4c6e170
1 changed files with 7 additions and 3 deletions
|
@ -23,21 +23,25 @@ pub fn convert_and_write<I, S>(samples: I, output: &mut UnknownTypeBuffer)
|
|||
{
|
||||
let samples = samples.chain(iter::repeat(Sample::zero_value()));
|
||||
|
||||
// note that it is important to do `buffer.zip(samples)` instead of `samples.zip(buffer)`
|
||||
// otherwise when the buffer's iterator is exhausted the value obtained from `samples` is
|
||||
// discarded
|
||||
|
||||
match output {
|
||||
&mut UnknownTypeBuffer::U16(ref mut buffer) => {
|
||||
for (i, o) in samples.zip(buffer.iter_mut()) {
|
||||
for (o, i) in buffer.iter_mut().zip(samples) {
|
||||
*o = i.to_u16();
|
||||
}
|
||||
},
|
||||
|
||||
&mut UnknownTypeBuffer::I16(ref mut buffer) => {
|
||||
for (i, o) in samples.zip(buffer.iter_mut()) {
|
||||
for (o, i) in buffer.iter_mut().zip(samples) {
|
||||
*o = i.to_i16();
|
||||
}
|
||||
},
|
||||
|
||||
&mut UnknownTypeBuffer::F32(ref mut buffer) => {
|
||||
for (i, o) in samples.zip(buffer.iter_mut()) {
|
||||
for (o, i) in buffer.iter_mut().zip(samples) {
|
||||
*o = i.to_f32();
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue