/// Perform joint stereo decoding on the channel pair.
Perform joint stereo decoding on the channel pair.
Perform joint stereo decoding on the channel pair .
pub(super) fn stereo(
    header: &FrameHeader,
    granule: &mut Granule,
    ch: &mut [[f32; 576]; 2],
) -> Result<()> {
    // Determine whether mid-side, and/or intensity stereo coding is used.
    let (mid_side, intensity) = match header.channel_mode {
        ChannelMode::JointStereo(Mode::Layer3 { mid_side, intensity }) => (mid_side, intensity),
        ChannelMode::JointStereo(Mode::Intensity { .. }) => {
            // This function only supports decoding Layer 3 stereo encodings, it is a fundamental
            // error in the decoder logic if layer 1 or 2 stereo encodings are being decoded with
            // this function.
            panic!("invalid mode extension for layer 3 stereo decoding")
        },
        _ => return Ok(()),
    };
    // The block types must be the same.
    if granule.channels[0].block_type != granule.channels[1].block_type {
        return decode_error("stereo channel pair block_type mismatch");
    }
    // Split the sample buffer into two channels.
    let (ch0, ch1) = {
        let (ch0, ch1) = ch.split_first_mut().unwrap();
        (ch0, &mut ch1[0])
    };
    // Joint stereo processing as specified in layer 3 is a combination of mid-side, and intensity
    // encoding schemes. Each scale-factor band may use either mid-side, intensity, or no stereo
    // encoding. The type of encoding used for each scale-factor band is determined by the MPEG
    // bitstream version, the mode extension, the block type, and the content of the scale-factor
    // bands.
    let end = max(granule.channels[0].rzero, granule.channels[1].rzero);
    // Decode intensity stereo coded bands if it is enabled and get the intensity bound.
    let is_bound = if intensity {
        // Decode intensity stereo coded bands based on bitstream version and block type.
        match granule.channels[1].block_type {
            BlockType::Short { is_mixed } if header.is_mpeg1() => {
                process_intensity_short_block_mpeg1(header, granule, is_mixed, mid_side, ch0, ch1)
            },
            BlockType::Short { is_mixed } => {
                process_intensity_short_block_mpeg2(header, granule, is_mixed, mid_side, ch0, ch1)
            },
            _ => {
                process_intensity_long_block(header, granule, mid_side, ch0, ch1)
            }
        }
    }
    // If intensity stereo coding is not enabled, then the intensity bound is up-to the maximum
    // rzero.
    else {
        end
    };
    // If mid-side stereo coding is enabled, all samples up to the intensity bound should be
    // decoded as mid-side stereo.
    if mid_side && is_bound > 0 {
        process_mid_side(&mut ch0[0..is_bound], &mut ch1[0..is_bound]);
    }
    // With joint stereo encoding, there is usually a mismatch between the number of samples 
    // initially read from the bitstream for each channel. This count is stored as the rzero sample
    // index. However, after joint stereo decoding, both channels will have the same number of
    // samples. Update rzero for both channels with the actual number of samples.
    if intensity || mid_side {
        granule.channels[0].rzero = end;
        granule.channels[1].rzero = end;
    }
    Ok(())
}
pub ( super ) fn stereo ( header : & FrameHeader , granule : & mut Granule , ch : & mut [ [ f32 ; 576 ] ; 2 ] , ) -> Result < ( ) > { // Determine whether mid-side, and/or intensity stereo coding is used. let ( mid_side , intensity ) = match header . channel_mode { ChannelMode :: JointStereo ( Mode :: Layer3 { mid_side , intensity } ) => ( mid_side , intensity ) , ChannelMode :: JointStereo ( Mode :: Intensity { .. } ) => { // This function only supports decoding Layer 3 stereo encodings, it is a fundamental // error in the decoder logic if layer 1 or 2 stereo encodings are being decoded with // this function. panic ! ( " " ) } , _ => return Ok ( ( ) ) , } ; // The block types must be the same. if granule . channels [ 0 ] . block_type != granule . channels [ 1 ] . block_type { return decode_error ( " " ) ; } // Split the sample buffer into two channels. let ( ch0 , ch1 ) = { let ( ch0 , ch1 ) = ch . split_first_mut ( ) . unwrap ( ) ; ( ch0 , & mut ch1 [ 0 ] ) } ; // Joint stereo processing as specified in layer 3 is a combination of mid-side, and intensity // encoding schemes. Each scale-factor band may use either mid-side, intensity, or no stereo // encoding. The type of encoding used for each scale-factor band is determined by the MPEG // bitstream version, the mode extension, the block type, and the content of the scale-factor // bands. let end = max ( granule . channels [ 0 ] . rzero , granule . channels [ 1 ] . rzero ) ; // Decode intensity stereo coded bands if it is enabled and get the intensity bound. let is_bound = if intensity { // Decode intensity stereo coded bands based on bitstream version and block type. match granule . channels [ 1 ] . block_type { BlockType :: Short { is_mixed } if header . is_mpeg1 ( ) => { process_intensity_short_block_mpeg1 ( header , granule , is_mixed , mid_side , ch0 , ch1 ) } , BlockType :: Short { is_mixed } => { process_intensity_short_block_mpeg2 ( header , granule , is_mixed , mid_side , ch0 , ch1 ) } , _ => { process_intensity_long_block ( header , granule , mid_side , ch0 , ch1 ) } } } // If intensity stereo coding is not enabled, then the intensity bound is up-to the maximum // rzero. else { end } ; // If mid-side stereo coding is enabled, all samples up to the intensity bound should be // decoded as mid-side stereo. if mid_side && is_bound > 0 { process_mid_side ( & mut ch0 [ 0 .. is_bound ] , & mut ch1 [ 0 .. is_bound ] ) ; } // With joint stereo encoding, there is usually a mismatch between the number of samples  // initially read from the bitstream for each channel. This count is stored as the rzero sample // index. However, after joint stereo decoding, both channels will have the same number of // samples. Update rzero for both channels with the actual number of samples. if intensity || mid_side { granule . channels [ 0 ] . rzero = end ; granule . channels [ 1 ] . rzero = end ; } Ok ( ( ) ) }
Perform joint stereo decoding on the channel pair.
Perform joint stereo decoding on the channel pair .
header
&FrameHeader
granule
&mut Granule
ch
&mut [[f32; 576]; 2]