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
{{ message }}
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
Sorry, this is probably a silly error on my part, but I can't figure this one out.
I'm trying to load samples from an array of Vorbis bytes. I currently have this naive start:
pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
let reader = OggStreamReader::new(Cursor::new(bytes))
.map_err(|e| err_msg("Failed to create stream reader"))?;
let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
let audio_channels = reader.ident_hdr.audio_channels;
let decoded: Vec<i16> = Vec::new();
/*while let Some(samples) = reader.read_dec_packet_itl()? {
decoded.append(&mut samples);
}*/
self.0.new_buffer(decoded, sample_rate)
.map_err(|e| err_msg("Error creating buffer"))
}
That case doesn't work. Neither does the case where the block is uncommented and, in theory, I'm appending decoded samples to a larger byte vec I'll ultimately pass to the buffer creation call. If I do:
pub fn new_buffer(&self, bytes: &[u8]) -> Result<Buffer, Error> {
let reader = OggStreamReader::new(Cursor::new(bytes))
.map_err(|e| err_msg("Failed to create stream reader"))?;
let sample_rate = reader.ident_hdr.audio_sample_rate as i32;
let audio_channels = reader.ident_hdr.audio_channels;
let decoded: Vec<i16> = Vec::new();
while let Some(samples) = reader.read_dec_packet_itl()? {
//decoded.append(&mut samples);
self.0.new_buffer(samples, sample_rate);
}
self.0.new_buffer(decoded, sample_rate)
.map_err(|e| err_msg("Error creating buffer"))
}
That seems to work, in so far as it creates a buffer with the freshly-loaded samples in the loop, but the last buffer creation call with decoded still fails.
If I scatter around println! calls, I'm told that the samples are Vec<i16>. That's what my decoded buffer is as well, so I don't know what I'm getting wrong. I've tried a few type annotation combinations, but I can't get a match. What am I missing here?
P.s. I know I'll likely ultimately want to switch to streaming, but I'm just working with short samples now, and am trying to build up complexity over time. Thanks for any help!
The text was updated successfully, but these errors were encountered:
As per the documentation, Context::new_buffer takes type parameters that identify what sample format it uses. If the compiler can't infer it, then you'll need to supply them manually, such as new_buffer::<alto::Stereo, _>(...).
Oh, sorry. Where are those docs? I looked through the source and
examples, and couldn't see any examples of using type parameters with
new_buffer. I must have missed something else. Or maybe the generated
docs would have given me more context? One of my more recent struggles
with Rust seems to be figuring out what type annotations to use when
calling functions like this. I've stumbled over that with other
libraries recently too.
Thanks.
No problem; rust signatures can be pretty dense, especially in the beginning. The auto-generated docs always contain the full list of type parameters and their required bounds, which is what you'll want to check out first when you get errors that say things like "annotations required" or "cannot infer".
docs.rs is a site that automatically updates with every crate's generated documentation, which is super helpful. The generated docs for new_buffer, show that it takes 2 type parameters, the first being the sample format F, and the second being some type B that satisfies the AsBufferData bound for sample format F. In most cases this buffer type will just be a slice of samples.
Sorry, this is probably a silly error on my part, but I can't figure this one out.
I'm trying to load samples from an array of Vorbis bytes. I currently have this naive start:
That case doesn't work. Neither does the case where the block is uncommented and, in theory, I'm appending decoded samples to a larger byte vec I'll ultimately pass to the buffer creation call. If I do:
That seems to work, in so far as it creates a buffer with the freshly-loaded samples in the loop, but the last buffer creation call with
decoded
still fails.If I scatter around
println!
calls, I'm told that the samples areVec<i16>
. That's what my decoded buffer is as well, so I don't know what I'm getting wrong. I've tried a few type annotation combinations, but I can't get a match. What am I missing here?P.s. I know I'll likely ultimately want to switch to streaming, but I'm just working with short samples now, and am trying to build up complexity over time. Thanks for any help!
The text was updated successfully, but these errors were encountered: