/// Requantize long block samples in `buf`.
Requantize long block samples in `buf`.
Requantize long block samples in ` buf ` .
fn requantize_long(channel: &GranuleChannel, bands: &[usize], buf: &mut [f32; 576]) {
    // For long 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
    //      B = scalefac_multiplier * (scalefacs[gr][ch][sfb] + (preflag[gr] * pretab[sfb]))
    //
    // Note: The samples in buf are the result of s(i)^(4/3) for each sample i.
    debug_assert!(bands.len() <= 23);
    // The preemphasis table is from table B.6 in ISO/IEC 11172-3.
    const PRE_EMPHASIS: [u8; 22] = [
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0,
    ];
    // Calculate A, it is constant for the entire requantization.
    let a = i32::from(channel.global_gain) - 210;
    let scalefac_shift = if channel.scalefac_scale { 2 } else { 1 };
    // Requantize each scale-factor band in buf.
    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;
        }
        // Lookup the pre-emphasis amount if required.
        let pre_emphasis = if channel.preflag { PRE_EMPHASIS[i] } else { 0 };
        // Calculate B.
        let b = i32::from((channel.scalefacs[i] + pre_emphasis) << scalefac_shift);
        // Calculate 2^(0.25*A) * 2^(-B). This can be rewritten as 2^{ 0.25 * (A - 4 * B) }.
        // Since scalefac_shift was multiplies by 4 above, the final equation becomes
        // 2^{ 0.25 * (A - B) }.
        let pow2ab = f64::powf(2.0, 0.25 * f64::from(a - b)) as f32;
        // Calculate the ending sample index for the scale-factor band, clamping it to the length of
        // the sample buffer.
        let band_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..band_end] {
            *sample *= pow2ab;
        }
    }
}
fn requantize_long ( channel : & GranuleChannel , bands : & [ usize ] , buf : & mut [ f32 ; 576 ] ) { // For long 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 //      B = scalefac_multiplier * (scalefacs[gr][ch][sfb] + (preflag[gr] * pretab[sfb])) // // Note: The samples in buf are the result of s(i)^(4/3) for each sample i. debug_assert ! ( bands len ( ) 23 ) ; // The preemphasis table is from table B.6 in ISO/IEC 11172-3. const PRE_EMPHASIS : [ u8 ; 22 ] = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 , 3 , 2 , 0 , ] ; // Calculate A, it is constant for the entire requantization. let a = i32 :: from ( channel . global_gain ) - 210 ; let scalefac_shift = if channel . scalefac_scale { 2 } else { 1 } ; // Requantize each scale-factor band in buf. 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 ; } // Lookup the pre-emphasis amount if required. let pre_emphasis = if channel . preflag { PRE_EMPHASIS [ i ] } else { 0 } ; // Calculate B. let b = i32 :: from ( ( channel . scalefacs [ i ] + pre_emphasis ) << scalefac_shift ) ; // Calculate 2^(0.25*A) * 2^(-B). This can be rewritten as 2^{ 0.25 * (A - 4 * B) }. // Since scalefac_shift was multiplies by 4 above, the final equation becomes // 2^{ 0.25 * (A - B) }. let pow2ab = f64 :: powf ( 2.0 , 0.25 * f64 :: from ( a - b ) ) as f32 ; // Calculate the ending sample index for the scale-factor band, clamping it to the length of // the sample buffer. let band_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 .. band_end ] { * sample *= pow2ab ; } } }
Requantize long block samples in `buf`.
Requantize long block samples in ` buf ` .
channel
&GranuleChannel
bands
&[usize]
buf
&mut [f32; 576]