pub(super) fn reorder(
    header: &FrameHeader,
    channel: &GranuleChannel,
    buf: &mut [f32; 576]
) {
    // Only short blocks are reordered.
    if let BlockType::Short { is_mixed } = channel.block_type {
        // Every short block is split into 3 equally sized windows as illustrated below (e.g. for
        // a short scale factor band with win_len=4):
        //
        //    <- Window #1 ->  <- Window #2 ->  <- Window #3 ->
        //   [ 0 | 1 | 2 | 3 ][ 4 | 5 | 6 | 7 ][ 8 | 9 | a | b ]
        //    <-----  3 * Short Scale Factor Band Width  ----->
        //
        // Reordering interleaves the samples of each window as follows:
        //
        //   [ 0 | 4 | 8 | 1 | 5 | 9 | 2 | 6 | a | 3 | 7 | b ]
        //    <----  3 * Short Scale Factor Band Width  ---->
        //
        // Basically, reordering interleaves the 3 windows the same way that 3 planar audio buffers
        // would be interleaved.
        debug_assert!(channel.rzero <= 576);

        // In mixed blocks, only the short bands can be re-ordered. Determine the applicable bands.
        let bands = if is_mixed {
            let switch = SFB_MIXED_SWITCH_POINT[header.sample_rate_idx];
            &SFB_MIXED_BANDS[header.sample_rate_idx][switch..]
        }
        else {
            &SFB_SHORT_BANDS[header.sample_rate_idx]
        };

        let start = bands[0];

        // TODO: Frankly, this is wasteful... Consider swapping between two internal buffers so we
        // can avoid initializing this to 0 every frame. Unsafe is not allowed in codec's so this
        // can't be left uninitialized.
        let mut reorder_buf = [0f32; 576];

        let mut i = start;

        for (((s0, s1), s2), s3) in bands.iter()
                                         .zip(&bands[1..])
                                         .zip(&bands[2..])
                                         .zip(&bands[3..])
                                         .step_by(3) {

            // The three short sample windows.
            let win0 = &buf[*s0..*s1];
            let win1 = &buf[*s1..*s2];
            let win2 = &buf[*s2..*s3];

            // Interleave the three short sample windows.
            // TODO: This could likely be sped up with SIMD.
            for ((w0, w1), w2) in win0.iter().zip(win1).zip(win2) {
                reorder_buf[i+0] = *w0;
                reorder_buf[i+1] = *w1;
                reorder_buf[i+2] = *w2;
                i += 3;
            }
        }

        // TODO: It is possible for i to exceed rzero, does that make sense? Or should it simply
        // copy between [start..rzero]? Probably not... since an entire scale factor band /should/
        // be processed...

        // Copy reordered samples from the reorder buffer to the actual sample buffer.
        buf[start..i].copy_from_slice(&reorder_buf[start..i]);
    }
}
/// Reorder samples that are part of short blocks into sub-band order.
Reorder samples that are part of short blocks into sub-band order.
Reorder samples that are part of short blocks into sub - band order .
pub(super) fn reorder(
    header: &FrameHeader,
    channel: &GranuleChannel,
    buf: &mut [f32; 576]
) {
    // Only short blocks are reordered.
    if let BlockType::Short { is_mixed } = channel.block_type {
        // Every short block is split into 3 equally sized windows as illustrated below (e.g. for
        // a short scale factor band with win_len=4):
        //
        //    <- Window #1 ->  <- Window #2 ->  <- Window #3 ->
        //   [ 0 | 1 | 2 | 3 ][ 4 | 5 | 6 | 7 ][ 8 | 9 | a | b ]
        //    <-----  3 * Short Scale Factor Band Width  ----->
        //
        // Reordering interleaves the samples of each window as follows:
        //
        //   [ 0 | 4 | 8 | 1 | 5 | 9 | 2 | 6 | a | 3 | 7 | b ]
        //    <----  3 * Short Scale Factor Band Width  ---->
        //
        // Basically, reordering interleaves the 3 windows the same way that 3 planar audio buffers
        // would be interleaved.
        debug_assert!(channel.rzero <= 576);
        // In mixed blocks, only the short bands can be re-ordered. Determine the applicable bands.
        let bands = if is_mixed {
            let switch = SFB_MIXED_SWITCH_POINT[header.sample_rate_idx];
            &SFB_MIXED_BANDS[header.sample_rate_idx][switch..]
        }
        else {
            &SFB_SHORT_BANDS[header.sample_rate_idx]
        };
        let start = bands[0];
        // TODO: Frankly, this is wasteful... Consider swapping between two internal buffers so we
        // can avoid initializing this to 0 every frame. Unsafe is not allowed in codec's so this
        // can't be left uninitialized.
        let mut reorder_buf = [0f32; 576];
        let mut i = start;
        for (((s0, s1), s2), s3) in bands.iter()
                                         .zip(&bands[1..])
                                         .zip(&bands[2..])
                                         .zip(&bands[3..])
                                         .step_by(3) {
            // The three short sample windows.
            let win0 = &buf[*s0..*s1];
            let win1 = &buf[*s1..*s2];
            let win2 = &buf[*s2..*s3];
            // Interleave the three short sample windows.
            // TODO: This could likely be sped up with SIMD.
            for ((w0, w1), w2) in win0.iter().zip(win1).zip(win2) {
                reorder_buf[i+0] = *w0;
                reorder_buf[i+1] = *w1;
                reorder_buf[i+2] = *w2;
                i += 3;
            }
        }
        // TODO: It is possible for i to exceed rzero, does that make sense? Or should it simply
        // copy between [start..rzero]? Probably not... since an entire scale factor band /should/
        // be processed...
        // Copy reordered samples from the reorder buffer to the actual sample buffer.
        buf[start..i].copy_from_slice(&reorder_buf[start..i]);
    }
}
pub ( super ) fn reorder ( header : & FrameHeader , channel : & GranuleChannel , buf : & mut [ f32 ; 576 ] ) { // Only short blocks are reordered. if let BlockType :: Short { is_mixed } = channel . block_type { // Every short block is split into 3 equally sized windows as illustrated below (e.g. for // a short scale factor band with win_len=4): // //    <- Window #1 ->  <- Window #2 ->  <- Window #3 -> //   [ 0 | 1 | 2 | 3 ][ 4 | 5 | 6 | 7 ][ 8 | 9 | a | b ] //    <-----  3 * Short Scale Factor Band Width  -----> // // Reordering interleaves the samples of each window as follows: // //   [ 0 | 4 | 8 | 1 | 5 | 9 | 2 | 6 | a | 3 | 7 | b ] //    <----  3 * Short Scale Factor Band Width  ----> // // Basically, reordering interleaves the 3 windows the same way that 3 planar audio buffers // would be interleaved. debug_assert ! ( channel rzero 576 ) ; // In mixed blocks, only the short bands can be re-ordered. Determine the applicable bands. let bands = if is_mixed { let switch = SFB_MIXED_SWITCH_POINT [ header . sample_rate_idx ] ; & SFB_MIXED_BANDS [ header . sample_rate_idx ] [ switch .. ] } else { & SFB_SHORT_BANDS [ header . sample_rate_idx ] } ; let start = bands [ 0 ] ; // TODO: Frankly, this is wasteful... Consider swapping between two internal buffers so we // can avoid initializing this to 0 every frame. Unsafe is not allowed in codec's so this // can't be left uninitialized. let mut reorder_buf = [ 0f32 ; 576 ] ; let mut i = start ; for ( ( ( s0 , s1 ) , s2 ) , s3 ) in bands . iter ( ) . zip ( & bands [ 1 .. ] ) . zip ( & bands [ 2 .. ] ) . zip ( & bands [ 3 .. ] ) . step_by ( 3 ) { // The three short sample windows. let win0 = & buf [ * s0 .. * s1 ] ; let win1 = & buf [ * s1 .. * s2 ] ; let win2 = & buf [ * s2 .. * s3 ] ; // Interleave the three short sample windows. // TODO: This could likely be sped up with SIMD. for ( ( w0 , w1 ) , w2 ) in win0 . iter ( ) . zip ( win1 ) . zip ( win2 ) { reorder_buf [ i + 0 ] = * w0 ; reorder_buf [ i + 1 ] = * w1 ; reorder_buf [ i + 2 ] = * w2 ; i += 3 ; } } // TODO: It is possible for i to exceed rzero, does that make sense? Or should it simply // copy between [start..rzero]? Probably not... since an entire scale factor band /should/ // be processed... // Copy reordered samples from the reorder buffer to the actual sample buffer. buf [ start .. i ] . copy_from_slice ( & reorder_buf [ start .. i ] ) ; } }
Reorder samples that are part of short blocks into sub-band order.
Reorder samples that are part of short blocks into sub - band order .
header
&FrameHeader
channel
&GranuleChannel
buf
&mut [f32; 576]
header
&FrameHeader
channel
&GranuleChannel
buf
&mut [f32; 576]