Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

error[E0283]: type annotations required: cannot resolve _: audio::alto::SampleFrame #37

Closed
ndarilek opened this issue Dec 31, 2017 · 3 comments

Comments

@ndarilek
Copy link

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!

@jpernst
Copy link
Owner

jpernst commented Jan 1, 2018

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, _>(...).

@ndarilek
Copy link
Author

ndarilek commented Jan 1, 2018 via email

@jpernst
Copy link
Owner

jpernst commented Jan 1, 2018

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.

@jpernst jpernst closed this as completed Jan 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants