-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
Hi!
I'm trying to use claxon in an embedded environment and would like to reuse the decode buffer, but I'm not figuring out how to do this when I might have multiple frames to decode in a single buffer:
impl Decode for FlacDecoder {
fn decode_sample(&mut self, buf: &[u8], out: &mut [i16]) -> Result<usize, anyhow::Error> {
let mut fr = FrameReader::new(std::io::Cursor::new(buf));
let mut c = 0;
let mut v = std::mem::take(&mut self.dec_buf);
loop {
if let Ok(Some(block)) = fr.read_next_or_eof(v) {
for (a, b) in block.stereo_samples() {
out[c + 0] = a as i16;
out[c + 1] = b as i16;
c += 2;
}
v = block.into_buffer();
} else {
break;
}
}
// self.dec_buf = v;
// can't do this, `v` was moved into `read_next_or_eof`
// and both the `Err` and `Ok(None)` cases would lose the buffer
Ok(c)
}
}I've made a branch with an API change which allows passing a mutable reference, but this breaks the FlacSamples and FlacIntoSamples iterators
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels