pub fn decode_frame<B: ByteStream>(
    reader: &mut B,
    header: &FrameHeader,
    state: &mut State,
    out: &mut AudioBuffer<f32>,
) -> Result<()> {

    // Initialize an empty FrameData to store the side_info and main_data portions of the
    // frame.
    let mut frame_data: FrameData = Default::default();

    let _crc = if header.has_crc {
        Some(reader.read_be_u16()?)
    }
    else {
        None
    };

    // Read side_info into the frame data.
    // TODO: Use a MonitorStream to compute the CRC.
    let side_info_len = bitstream::read_side_info(reader, &header, &mut frame_data)?;

    // Buffer main_data into the bit resevoir.
    let main_data_len = header.frame_size - side_info_len - if header.has_crc { 2 } else { 0 };

    state.resevoir.fill(
        reader,
        frame_data.main_data_begin as usize,
        main_data_len
    )?;

    // Read main_data: scale factors and spectral samples.
    read_main_data(&header, &mut frame_data, state)?;

    for gr in 0..header.n_granules() {
        // Each granule will yield 576 samples.
        out.render_reserved(Some(576));

        let granule = &mut frame_data.granules[gr];

        // Requantize all non-zero (big_values and count1 partition) spectral samples.
        requantize::requantize(&header, &granule.channels[0], &mut state.samples[gr][0]);

        // If there is a second channel...
        if header.channel_mode != ChannelMode::Mono {
            // Requantize all non-zero spectral samples in the second channel.
            requantize::requantize(&header, &granule.channels[1], &mut state.samples[gr][1]);

            // Apply joint stereo processing if it is used.
            stereo::stereo(&header, granule, &mut state.samples[gr])?;
        }

        // The next steps are independant of channel count.
        for ch in 0..header.n_channels() {
            // Reorder the spectral samples in short blocks into sub-band order.
            hybrid_synthesis::reorder(&header, &granule.channels[ch], &mut state.samples[gr][ch]);

            // Apply the anti-aliasing filter to all block types other than short.
            hybrid_synthesis::antialias(&granule.channels[ch], &mut state.samples[gr][ch]);

            // Perform hybrid-synthesis (IMDCT and windowing).
            hybrid_synthesis::hybrid_synthesis(
                &granule.channels[ch],
                &mut state.overlap[ch],
                &mut state.samples[gr][ch],
            );

            // Invert every second sample in every second sub-band to negate the frequency inversion
            // of the polyphase filterbank.
            hybrid_synthesis::frequency_inversion(&mut state.samples[gr][ch]);

            // Perform polyphase synthesis and generate PCM samples.
            let out_ch_samples = out.chan_mut(ch);

            synthesis::synthesis(
                &mut state.synthesis[ch],
                &mut state.samples[gr][ch],
                &mut out_ch_samples[(gr * 576)..((gr + 1) * 576)],
            );
        }
    }

    Ok(())
}
/// Decode the MPEG audio frame into an `AudioBuffer`.
Decode the MPEG audio frame into an `AudioBuffer`.
Decode the MPEG audio frame into an ` AudioBuffer ` .
pub fn decode_frame<B: ByteStream>(
    reader: &mut B,
    header: &FrameHeader,
    state: &mut State,
    out: &mut AudioBuffer<f32>,
) -> Result<()> {
    // Initialize an empty FrameData to store the side_info and main_data portions of the
    // frame.
    let mut frame_data: FrameData = Default::default();
    let _crc = if header.has_crc {
        Some(reader.read_be_u16()?)
    }
    else {
        None
    };
    // Read side_info into the frame data.
    // TODO: Use a MonitorStream to compute the CRC.
    let side_info_len = bitstream::read_side_info(reader, &header, &mut frame_data)?;
    // Buffer main_data into the bit resevoir.
    let main_data_len = header.frame_size - side_info_len - if header.has_crc { 2 } else { 0 };
    state.resevoir.fill(
        reader,
        frame_data.main_data_begin as usize,
        main_data_len
    )?;
    // Read main_data: scale factors and spectral samples.
    read_main_data(&header, &mut frame_data, state)?;
    for gr in 0..header.n_granules() {
        // Each granule will yield 576 samples.
        out.render_reserved(Some(576));
        let granule = &mut frame_data.granules[gr];
        // Requantize all non-zero (big_values and count1 partition) spectral samples.
        requantize::requantize(&header, &granule.channels[0], &mut state.samples[gr][0]);
        // If there is a second channel...
        if header.channel_mode != ChannelMode::Mono {
            // Requantize all non-zero spectral samples in the second channel.
            requantize::requantize(&header, &granule.channels[1], &mut state.samples[gr][1]);
            // Apply joint stereo processing if it is used.
            stereo::stereo(&header, granule, &mut state.samples[gr])?;
        }
        // The next steps are independant of channel count.
        for ch in 0..header.n_channels() {
            // Reorder the spectral samples in short blocks into sub-band order.
            hybrid_synthesis::reorder(&header, &granule.channels[ch], &mut state.samples[gr][ch]);
            // Apply the anti-aliasing filter to all block types other than short.
            hybrid_synthesis::antialias(&granule.channels[ch], &mut state.samples[gr][ch]);
            // Perform hybrid-synthesis (IMDCT and windowing).
            hybrid_synthesis::hybrid_synthesis(
                &granule.channels[ch],
                &mut state.overlap[ch],
                &mut state.samples[gr][ch],
            );
            // Invert every second sample in every second sub-band to negate the frequency inversion
            // of the polyphase filterbank.
            hybrid_synthesis::frequency_inversion(&mut state.samples[gr][ch]);
            // Perform polyphase synthesis and generate PCM samples.
            let out_ch_samples = out.chan_mut(ch);
            synthesis::synthesis(
                &mut state.synthesis[ch],
                &mut state.samples[gr][ch],
                &mut out_ch_samples[(gr * 576)..((gr + 1) * 576)],
            );
        }
    }
    Ok(())
}
pub fn decode_frame < B : ByteStream > ( reader : & mut B , header : & FrameHeader , state : & mut State , out : & mut AudioBuffer < f32 > , ) -> Result < ( ) > { // Initialize an empty FrameData to store the side_info and main_data portions of the // frame. let mut frame_data : FrameData = Default :: default ( ) ; let _crc = if header . has_crc { Some ( reader . read_be_u16 ( ) ? ) } else { None } ; // Read side_info into the frame data. // TODO: Use a MonitorStream to compute the CRC. let side_info_len = bitstream :: read_side_info ( reader , & header , & mut frame_data ) ? ; // Buffer main_data into the bit resevoir. let main_data_len = header . frame_size - side_info_len - if header . has_crc { 2 } else { 0 } ; state . resevoir . fill ( reader , frame_data . main_data_begin as usize , main_data_len ) ? ; // Read main_data: scale factors and spectral samples. read_main_data ( & header , & mut frame_data , state ) ? ; for gr in 0 .. header . n_granules ( ) { // Each granule will yield 576 samples. out . render_reserved ( Some ( 576 ) ) ; let granule = & mut frame_data . granules [ gr ] ; // Requantize all non-zero (big_values and count1 partition) spectral samples. requantize :: requantize ( & header , & granule . channels [ 0 ] , & mut state . samples [ gr ] [ 0 ] ) ; // If there is a second channel... if header . channel_mode != ChannelMode :: Mono { // Requantize all non-zero spectral samples in the second channel. requantize :: requantize ( & header , & granule . channels [ 1 ] , & mut state . samples [ gr ] [ 1 ] ) ; // Apply joint stereo processing if it is used. stereo :: stereo ( & header , granule , & mut state . samples [ gr ] ) ? ; } // The next steps are independant of channel count. for ch in 0 .. header . n_channels ( ) { // Reorder the spectral samples in short blocks into sub-band order. hybrid_synthesis :: reorder ( & header , & granule . channels [ ch ] , & mut state . samples [ gr ] [ ch ] ) ; // Apply the anti-aliasing filter to all block types other than short. hybrid_synthesis :: antialias ( & granule . channels [ ch ] , & mut state . samples [ gr ] [ ch ] ) ; // Perform hybrid-synthesis (IMDCT and windowing). hybrid_synthesis :: hybrid_synthesis ( & granule . channels [ ch ] , & mut state . overlap [ ch ] , & mut state . samples [ gr ] [ ch ] , ) ; // Invert every second sample in every second sub-band to negate the frequency inversion // of the polyphase filterbank. hybrid_synthesis :: frequency_inversion ( & mut state . samples [ gr ] [ ch ] ) ; // Perform polyphase synthesis and generate PCM samples. let out_ch_samples = out . chan_mut ( ch ) ; synthesis :: synthesis ( & mut state . synthesis [ ch ] , & mut state . samples [ gr ] [ ch ] , & mut out_ch_samples [ ( gr * 576 ) .. ( ( gr + 1 ) * 576 ) ] , ) ; } } Ok ( ( ) ) }
Decode the MPEG audio frame into an `AudioBuffer`.
Decode the MPEG audio frame into an ` AudioBuffer ` .
reader
&mut B
header
&FrameHeader
state
&mut State
out
&mut AudioBuffer<f32>
reader
&mut B
header
&FrameHeader
state
&mut State
out
&mut AudioBuffer<f32>