You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
implDecodeforFlacDecoder{fndecode_sample(&mutself,buf:&[u8],out:&mut[i16]) -> Result<usize, anyhow::Error>{letmut fr = FrameReader::new(std::io::Cursor::new(buf));letmut c = 0;letmut v = std::mem::take(&mutself.dec_buf);loop{ifletOk(Some(block)) = fr.read_next_or_eof(v){for(a, b)in block.stereo_samples(){
out[c + 0] = a asi16;
out[c + 1] = b asi16;
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 bufferOk(c)}}
I've made a branch with an API change which allows passing a mutable reference, but this breaks the FlacSamples and FlacIntoSamples iterators
The text was updated successfully, but these errors were encountered:
Yes, this is a limitation of the current design. For a future version, I think I would split it into a lower-level API that reads and decodes one block, with higher level iterator-like functions built on top. (For the audio data it’s not a big change, but especially for the metadata frames, right now we either have to read all of them and store them, or skip over them, there is no way to stream them and inspect only the interesting ones. For that I think a split into a lower-level API and a higher-level one makes sense.)
If you’re in a context where Vec::resize is fine though, I suppose allocating is acceptable, so maybe it’s okay to assign v = Vec::new() in the Err case?
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:I've made a branch with an API change which allows passing a mutable reference, but this breaks the
FlacSamples
andFlacIntoSamples
iteratorsThe text was updated successfully, but these errors were encountered: