pub fn decode<R: BitRead>(&mut self, reader: &mut R) -> Result<Samples> {
        self.swap_frames();

        let packet_kind = try!(reader.read_u8_bits(1));
        if packet_kind != PacketKind::Audio as u8 {
            return Err(Error::WrongPacketKind("Expected audio packet"));
        }
        let mode_count = self.setup.modes.len();
        let mode_idx = try!(reader.read_u8_bits((mode_count as u8).ilog() as usize - 1)) as usize;
        if mode_idx >= mode_count {
            return Err(Error::Undecodable("Invalid packet mode number"));
        }
        let mode = &self.setup.modes[mode_idx];

        if mode.frame_kind == FrameKind::Long {
            /* let is_prev_long_frame = */ try!(reader.read_bool());
            /* let is_next_long_frame = */ try!(reader.read_bool());
        }

        let frame_lens = self.header.frame_lens();
        let frame_len = frame_lens.get(mode.frame_kind);
        let frame_half_len = frame_len / 2;

        let mapping = &self.setup.mappings[mode.mapping as usize];

        // Begin decoding floors.
        for (channel, floor_y_list) in self.floor_y_list.iter_mut().enumerate() {
            let submap_idx = mapping.channel_to_submap[channel];
            let floor_idx = mapping.submaps[submap_idx].floor;
            let floor = &self.setup.floors[floor_idx];
            try!(floor.begin_decode(floor_y_list, reader, &self.setup.codebooks));
        }

        // Decode residues.
        {
            let mut zero_channels: Vec<_> = self.floor_y_list.iter().map(|f| f.is_empty()).collect();

            mapping.unzero_coupled_channels(&mut zero_channels);

            for submap in mapping.submaps.iter() {
                let residue_idx = submap.residue;
                let residue = &self.setup.residues[residue_idx];
                try!(residue.decode(reader,
                            &mut self.frame,
                            frame_half_len,
                            &submap.channels,
                            &zero_channels,
                            &self.setup.codebooks));
            }
        }

        mapping.decouple_channels(&mut self.frame, frame_half_len);

        // Finish decoding floors (synthesize and perform dot product with residues).
        for ((channel, result), floor_y_list) in self.frame.iter_mut().enumerate()
                                                        .zip(self.floor_y_list.iter()) {
            if !floor_y_list.is_empty() {
                let submap_idx = mapping.channel_to_submap[channel];
                let floor_idx = mapping.submaps[submap_idx].floor;
                let floor = &self.setup.floors[floor_idx];
                floor.finish_decode(result, floor_y_list);
            } else {
                for r in result[..frame_half_len].as_mut().iter_mut() {
                    *r = 0.0;
                }
            }
        }

        for channel in self.frame.iter_mut() {
            self.mdct[mode.frame_kind as usize].inverse(&mut channel[..frame_len]);
        }

        if let Some(prev_frame_kind) = self.prev_frame_kind {
            let window = self.windows.get(prev_frame_kind, mode.frame_kind);
            for (mut l, mut r) in self.prev_frame.iter_mut().zip(self.frame.iter_mut()) {
                window.overlap(&mut l, &mut r);
            }
            self.pos += window.len() as u64;
        }

        self.frame_kind = Some(mode.frame_kind);

        Ok(self.samples())
    }
/// Decodes an audio packet. Note if this is the first audio packet (either for a newly initialized
/// decoder instance or after a call to `reset()`) the returned samples will
/// be empty.
Decodes an audio packet. Note if this is the first audio packet (either for a newly initialized
decoder instance or after a call to `reset()`) the returned samples will
be empty.
Decodes an audio packet . Note if this is the first audio packet ( either for a newly initialized decoder instance or after a call to ` reset () ` ) the returned samples will be empty .
pub fn decode<R: BitRead>(&mut self, reader: &mut R) -> Result<Samples> {
        self.swap_frames();
        let packet_kind = try!(reader.read_u8_bits(1));
        if packet_kind != PacketKind::Audio as u8 {
            return Err(Error::WrongPacketKind("Expected audio packet"));
        }
        let mode_count = self.setup.modes.len();
        let mode_idx = try!(reader.read_u8_bits((mode_count as u8).ilog() as usize - 1)) as usize;
        if mode_idx >= mode_count {
            return Err(Error::Undecodable("Invalid packet mode number"));
        }
        let mode = &self.setup.modes[mode_idx];
        if mode.frame_kind == FrameKind::Long {
            /* let is_prev_long_frame = */ try!(reader.read_bool());
            /* let is_next_long_frame = */ try!(reader.read_bool());
        }
        let frame_lens = self.header.frame_lens();
        let frame_len = frame_lens.get(mode.frame_kind);
        let frame_half_len = frame_len / 2;
        let mapping = &self.setup.mappings[mode.mapping as usize];
        // Begin decoding floors.
        for (channel, floor_y_list) in self.floor_y_list.iter_mut().enumerate() {
            let submap_idx = mapping.channel_to_submap[channel];
            let floor_idx = mapping.submaps[submap_idx].floor;
            let floor = &self.setup.floors[floor_idx];
            try!(floor.begin_decode(floor_y_list, reader, &self.setup.codebooks));
        }
        // Decode residues.
        {
            let mut zero_channels: Vec<_> = self.floor_y_list.iter().map(|f| f.is_empty()).collect();
            mapping.unzero_coupled_channels(&mut zero_channels);
            for submap in mapping.submaps.iter() {
                let residue_idx = submap.residue;
                let residue = &self.setup.residues[residue_idx];
                try!(residue.decode(reader,
                            &mut self.frame,
                            frame_half_len,
                            &submap.channels,
                            &zero_channels,
                            &self.setup.codebooks));
            }
        }
        mapping.decouple_channels(&mut self.frame, frame_half_len);
        // Finish decoding floors (synthesize and perform dot product with residues).
        for ((channel, result), floor_y_list) in self.frame.iter_mut().enumerate()
                                                        .zip(self.floor_y_list.iter()) {
            if !floor_y_list.is_empty() {
                let submap_idx = mapping.channel_to_submap[channel];
                let floor_idx = mapping.submaps[submap_idx].floor;
                let floor = &self.setup.floors[floor_idx];
                floor.finish_decode(result, floor_y_list);
            } else {
                for r in result[..frame_half_len].as_mut().iter_mut() {
                    *r = 0.0;
                }
            }
        }
        for channel in self.frame.iter_mut() {
            self.mdct[mode.frame_kind as usize].inverse(&mut channel[..frame_len]);
        }
        if let Some(prev_frame_kind) = self.prev_frame_kind {
            let window = self.windows.get(prev_frame_kind, mode.frame_kind);
            for (mut l, mut r) in self.prev_frame.iter_mut().zip(self.frame.iter_mut()) {
                window.overlap(&mut l, &mut r);
            }
            self.pos += window.len() as u64;
        }
        self.frame_kind = Some(mode.frame_kind);
        Ok(self.samples())
    }
pub fn decode < R : BitRead > ( & mut self , reader : & mut R ) -> Result < Samples > { self . swap_frames ( ) ; let packet_kind = try ! ( reader read_u8_bits ( 1 ) ) ; if packet_kind != PacketKind :: Audio as u8 { return Err ( Error :: WrongPacketKind ( " " ) ) ; } let mode_count = self . setup . modes . len ( ) ; let mode_idx = try ! ( reader read_u8_bits ( ( mode_count as u8 ) ilog ( ) as usize 1 ) ) as usize ; if mode_idx >= mode_count { return Err ( Error :: Undecodable ( " " ) ) ; } let mode = & self . setup . modes [ mode_idx ] ; if mode . frame_kind == FrameKind :: Long { /* let is_prev_long_frame = */ try ! ( reader read_bool ( ) ) ; /* let is_next_long_frame = */ try ! ( reader read_bool ( ) ) ; } let frame_lens = self . header . frame_lens ( ) ; let frame_len = frame_lens . get ( mode . frame_kind ) ; let frame_half_len = frame_len / 2 ; let mapping = & self . setup . mappings [ mode . mapping as usize ] ; // Begin decoding floors. for ( channel , floor_y_list ) in self . floor_y_list . iter_mut ( ) . enumerate ( ) { let submap_idx = mapping . channel_to_submap [ channel ] ; let floor_idx = mapping . submaps [ submap_idx ] . floor ; let floor = & self . setup . floors [ floor_idx ] ; try ! ( floor begin_decode ( floor_y_list reader self setup codebooks ) ) ; } // Decode residues. { let mut zero_channels : Vec < _ > = self . floor_y_list . iter ( ) . map ( | f | f . is_empty ( ) ) . collect ( ) ; mapping . unzero_coupled_channels ( & mut zero_channels ) ; for submap in mapping . submaps . iter ( ) { let residue_idx = submap . residue ; let residue = & self . setup . residues [ residue_idx ] ; try ! ( residue decode ( reader mut self frame frame_half_len submap channels zero_channels self setup codebooks ) ) ; } } mapping . decouple_channels ( & mut self . frame , frame_half_len ) ; // Finish decoding floors (synthesize and perform dot product with residues). for ( ( channel , result ) , floor_y_list ) in self . frame . iter_mut ( ) . enumerate ( ) . zip ( self . floor_y_list . iter ( ) ) { if ! floor_y_list . is_empty ( ) { let submap_idx = mapping . channel_to_submap [ channel ] ; let floor_idx = mapping . submaps [ submap_idx ] . floor ; let floor = & self . setup . floors [ floor_idx ] ; floor . finish_decode ( result , floor_y_list ) ; } else { for r in result [ .. frame_half_len ] . as_mut ( ) . iter_mut ( ) { * r = 0.0 ; } } } for channel in self . frame . iter_mut ( ) { self . mdct [ mode . frame_kind as usize ] . inverse ( & mut channel [ .. frame_len ] ) ; } if let Some ( prev_frame_kind ) = self . prev_frame_kind { let window = self . windows . get ( prev_frame_kind , mode . frame_kind ) ; for ( mut l , mut r ) in self . prev_frame . iter_mut ( ) . zip ( self . frame . iter_mut ( ) ) { window . overlap ( & mut l , & mut r ) ; } self . pos += window . len ( ) as u64 ; } self . frame_kind = Some ( mode . frame_kind ) ; Ok ( self . samples ( ) ) }
Decodes an audio packet.
Decodes an audio packet .
&mut self
reader
&mut R
&mut self
reader
&mut R