fn requantize_short(
    channel: &GranuleChannel,
    bands: &[usize],
    switch: usize,
    buf: &mut [f32; 576],
) {
    // For short blocks dequantization and scaling is governed by the following equation:
    //
    //                     xr(i) = s(i)^(4/3) * 2^(0.25*A) * 2^(-B)
    // where:
    //       s(i) is the decoded Huffman sample
    //      xr(i) is the dequantized sample
    // and:
    //      A = global_gain[gr] - 210 - (8 * subblock_gain[gr][win])
    //      B = scalefac_multiplier * scalefacs[gr][ch][sfb][win]
    //
    // Note: The samples in buf are the result of s(i)^(4/3) for each sample i.
    debug_assert!(bands.len() <= 40);

    // Calculate the window-independant part of A: global_gain[gr] - 210.
    let gain = i32::from(channel.global_gain) - 210;

    // Calculate A for each window.
    let a = [
        gain - 8 * i32::from(channel.subblock_gain[0]),
        gain - 8 * i32::from(channel.subblock_gain[1]),
        gain - 8 * i32::from(channel.subblock_gain[2]),
    ];

    // Likweise, the scalefac_multiplier is constant for the granule. The actual scale is multiplied
    // by 4 to combine the two pow2 operations into one by adding the exponents. The sum of the
    // exponent is multiplied by 0.25 so B must be multiplied by 4 to counter the quartering. A
    // bitshift operation is used for the actual multiplication, so scalefac_multiplier is named
    // scalefac_shift in this case.
    let scalefac_shift = if channel.scalefac_scale { 2 } else { 1 };

    for (i, (start, end)) in bands.iter().zip(&bands[1..]).enumerate() {
        // Do not requantize bands starting after the rzero sample since all samples from there on
        // are 0.
        if *start > channel.rzero {
            break;
        }

        // Calculate B.
        let b = i32::from(channel.scalefacs[switch + i] << scalefac_shift);

        // Calculate 2^(0.25*A) * 2^(-B). This can be rewritten as 2^{ 0.25 * (A - 4 * B) }.
        // Since scalefac_shift multiplies by 4 above, the final equation becomes
        // 2^{ 0.25 * (A - B) }.
        let pow2ab = f64::powf(2.0,  0.25 * f64::from(a[i % 3] - b)) as f32;

        // Clamp the ending sample index to the rzero sample index. Since samples starting from
        // rzero are 0, there is no point in requantizing them.
        let win_end = min(*end, channel.rzero);

        // The sample buffer contains s(i)^(4/3), now multiply in 2^(0.25*A) * 2^(-B) to get
        // xr(i).
        for sample in &mut buf[*start..win_end] {
            *sample *= pow2ab;
        }
    }

}
/// Requantize short block samples in `buf` starting at scale-factor band `sfb_init`.
Requantize short block samples in `buf` starting at scale-factor band `sfb_init`.
Requantize short block samples in ` buf ` starting at scale - factor band ` sfb_init ` .
fn requantize_short(
    channel: &GranuleChannel,
    bands: &[usize],
    switch: usize,
    buf: &mut [f32; 576],
) {
    // For short blocks dequantization and scaling is governed by the following equation:
    //
    //                     xr(i) = s(i)^(4/3) * 2^(0.25*A) * 2^(-B)
    // where:
    //       s(i) is the decoded Huffman sample
    //      xr(i) is the dequantized sample
    // and:
    //      A = global_gain[gr] - 210 - (8 * subblock_gain[gr][win])
    //      B = scalefac_multiplier * scalefacs[gr][ch][sfb][win]
    //
    // Note: The samples in buf are the result of s(i)^(4/3) for each sample i.
    debug_assert!(bands.len() <= 40);
    // Calculate the window-independant part of A: global_gain[gr] - 210.
    let gain = i32::from(channel.global_gain) - 210;
    // Calculate A for each window.
    let a = [
        gain - 8 * i32::from(channel.subblock_gain[0]),
        gain - 8 * i32::from(channel.subblock_gain[1]),
        gain - 8 * i32::from(channel.subblock_gain[2]),
    ];
    // Likweise, the scalefac_multiplier is constant for the granule. The actual scale is multiplied
    // by 4 to combine the two pow2 operations into one by adding the exponents. The sum of the
    // exponent is multiplied by 0.25 so B must be multiplied by 4 to counter the quartering. A
    // bitshift operation is used for the actual multiplication, so scalefac_multiplier is named
    // scalefac_shift in this case.
    let scalefac_shift = if channel.scalefac_scale { 2 } else { 1 };
    for (i, (start, end)) in bands.iter().zip(&bands[1..]).enumerate() {
        // Do not requantize bands starting after the rzero sample since all samples from there on
        // are 0.
        if *start > channel.rzero {
            break;
        }
        // Calculate B.
        let b = i32::from(channel.scalefacs[switch + i] << scalefac_shift);
        // Calculate 2^(0.25*A) * 2^(-B). This can be rewritten as 2^{ 0.25 * (A - 4 * B) }.
        // Since scalefac_shift multiplies by 4 above, the final equation becomes
        // 2^{ 0.25 * (A - B) }.
        let pow2ab = f64::powf(2.0,  0.25 * f64::from(a[i % 3] - b)) as f32;
        // Clamp the ending sample index to the rzero sample index. Since samples starting from
        // rzero are 0, there is no point in requantizing them.
        let win_end = min(*end, channel.rzero);
        // The sample buffer contains s(i)^(4/3), now multiply in 2^(0.25*A) * 2^(-B) to get
        // xr(i).
        for sample in &mut buf[*start..win_end] {
            *sample *= pow2ab;
        }
    }
}
fn requantize_short ( channel : & GranuleChannel , bands : & [ usize ] , switch : usize , buf : & mut [ f32 ; 576 ] , ) { // For short blocks dequantization and scaling is governed by the following equation: // //                     xr(i) = s(i)^(4/3) * 2^(0.25*A) * 2^(-B) // where: //       s(i) is the decoded Huffman sample //      xr(i) is the dequantized sample // and: //      A = global_gain[gr] - 210 - (8 * subblock_gain[gr][win]) //      B = scalefac_multiplier * scalefacs[gr][ch][sfb][win] // // Note: The samples in buf are the result of s(i)^(4/3) for each sample i. debug_assert ! ( bands len ( ) 40 ) ; // Calculate the window-independant part of A: global_gain[gr] - 210. let gain = i32 :: from ( channel . global_gain ) - 210 ; // Calculate A for each window. let a = [ gain - 8 * i32 :: from ( channel . subblock_gain [ 0 ] ) , gain - 8 * i32 :: from ( channel . subblock_gain [ 1 ] ) , gain - 8 * i32 :: from ( channel . subblock_gain [ 2 ] ) , ] ; // Likweise, the scalefac_multiplier is constant for the granule. The actual scale is multiplied // by 4 to combine the two pow2 operations into one by adding the exponents. The sum of the // exponent is multiplied by 0.25 so B must be multiplied by 4 to counter the quartering. A // bitshift operation is used for the actual multiplication, so scalefac_multiplier is named // scalefac_shift in this case. let scalefac_shift = if channel . scalefac_scale { 2 } else { 1 } ; for ( i , ( start , end ) ) in bands . iter ( ) . zip ( & bands [ 1 .. ] ) . enumerate ( ) { // Do not requantize bands starting after the rzero sample since all samples from there on // are 0. if * start > channel . rzero { break ; } // Calculate B. let b = i32 :: from ( channel . scalefacs [ switch + i ] << scalefac_shift ) ; // Calculate 2^(0.25*A) * 2^(-B). This can be rewritten as 2^{ 0.25 * (A - 4 * B) }. // Since scalefac_shift multiplies by 4 above, the final equation becomes // 2^{ 0.25 * (A - B) }. let pow2ab = f64 :: powf ( 2.0 , 0.25 * f64 :: from ( a [ i % 3 ] - b ) ) as f32 ; // Clamp the ending sample index to the rzero sample index. Since samples starting from // rzero are 0, there is no point in requantizing them. let win_end = min ( * end , channel . rzero ) ; // The sample buffer contains s(i)^(4/3), now multiply in 2^(0.25*A) * 2^(-B) to get // xr(i). for sample in & mut buf [ * start .. win_end ] { * sample *= pow2ab ; } } }
Requantize short block samples in `buf` starting at scale-factor band `sfb_init`.
Requantize short block samples in ` buf ` starting at scale - factor band ` sfb_init ` .
channel
&GranuleChannel
bands
&[usize]
switch
usize
buf
&mut [f32; 576]
channel
&GranuleChannel
bands
&[usize]
switch
usize
buf
&mut [f32; 576]