Commit e9df5ed3 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'stereo_dft_dec_core_switching' into 'main'

stereo_dft_dec_core_switching module converted to fixed.

See merge request !32
parents 0e9358d9 6053fc69
Loading
Loading
Loading
Loading
Loading
+131 −0
Original line number Diff line number Diff line
@@ -5325,6 +5325,137 @@ void fft_fx(
    return;
}

void rfft_fx(
    Word32 *x,             /* i/o: values                    */
    const Word16 *w,       /* i  : window                    */
    const Word16 length, /* i  : length of fft             */
    const Word16 isign   /* i  : sign                      */
)
{
    Word16 i, sizeOfFft2, sizeOfFft4;
    Word32 tmp, t1, t2, t3, t4;
    Word16 s1, s2;

    sizeOfFft2 = length >> 1;
    sizeOfFft4 = length >> 2;
    SWITCH( sizeOfFft2 )
    {
        case 80:
            s1 = 409;
            s2 = -409;
            BREAK;
        case 128:
            s1 = 256;
            s2 = -256;
            BREAK;
        case 160:
            s1 = 204;
            s2 = -204;
            BREAK;
        case 320:
            s1 = 102;
            s2 = -102;
            BREAK;
        case 480:
            s1 = 68;
            s2 = -68;
            BREAK;
        default:
            s1 = -1;
            s2 = -1;
            printf( "Configuration not supported" );
            assert( 0 );
    }

    SWITCH ( isign )
    {

        case -1:

            fft_fx( x, x + 1, sizeOfFft2, 2 );

            tmp = L_add(x[0], x[1]);
            x[1] = L_sub(x[0], x[1]);
            x[0] = tmp;

            FOR ( i = 1; i <= sizeOfFft4; i++ )
            {
                t1 = L_sub(x[2 * i], x[length - 2 * i]);
                t2 = L_add(x[2 * i + 1], x[length - 2 * i + 1]);
                t3 = L_sub(Mpy_32_16_1(t1, w[i]), Mpy_32_16_1(t2, w[i + sizeOfFft4]));
                t4 = L_add(Mpy_32_16_1(t1, w[i + sizeOfFft4]), Mpy_32_16_1(t2, w[i]));
                t1 = L_add(x[2 * i], x[length - 2 * i]);
                t2 = L_sub(x[2 * i + 1], x[length - 2 * i + 1]);

                x[2 * i] = Mpy_32_16_1(L_sub(t1, t3), 16384);
                x[2 * i + 1] = Mpy_32_16_1(L_sub(t2, t4), 16384);
                x[length - 2 * i] = Mpy_32_16_1(L_add(t1, t3), 16384);
                x[length - 2 * i + 1] = Mpy_32_16_1(L_negate(L_add(t2, t4)), 16384);
            }

            BREAK;

        case +1:

            tmp = Mpy_32_16_1( L_add( x[0], x[1] ), 16384);
            x[1] = Mpy_32_16_1( L_sub( x[1], x[0] ), 16384);
            x[0] = tmp;

            FOR ( i = 1; i <= sizeOfFft4; i++ )
            {
                t1 = L_sub(x[2 * i], x[length - 2 * i]);
                t2 = L_add(x[2 * i + 1], x[length - 2 * i + 1]);
                t3 = L_add(Mpy_32_16_1(t1, w[i]), Mpy_32_16_1(t2, w[i + sizeOfFft4]));
                t4 = L_sub(Mpy_32_16_1(t2, w[i]), Mpy_32_16_1(t1, w[i + sizeOfFft4]));
                t1 = L_add(x[2 * i], x[length - 2 * i]);
                t2 = L_sub(x[2 * i + 1], x[length - 2 * i + 1]);

                x[2 * i] = Mpy_32_16_1(L_sub( t1, t3 ), 16384);
                x[2 * i + 1] = Mpy_32_16_1( L_sub( t4, t2 ), 16384);
                x[length - 2 * i] = Mpy_32_16_1(L_add( t1, t3 ), 16384);
                x[length - 2 * i + 1] = Mpy_32_16_1(L_add( t2, t4 ), 16384);
            }

            fft_fx( x, x + 1, sizeOfFft2, 2 );

            FOR ( i = 0; i < length; i += 2 )
            {
                x[i] = Mpy_32_16_1(x[i], s1);
                x[i + 1] = Mpy_32_16_1(x[i+1], s2);
            }

            BREAK;
    }

    return;
}

Word16 find_guarded_bits_fx( Word32 n )
{
    return n <= 1 ? 0 : n <= 2  ? 1
                    : n <= 4    ? 2
                    : n <= 8    ? 3
                    : n <= 16   ? 4
                    : n <= 32   ? 5
                    : n <= 64   ? 6
                    : n <= 128  ? 7
                    : n <= 256  ? 8
                    : n <= 512  ? 9
                    : n <= 1024 ? 10
                                : 11;
}

Word16 L_norm_arr( Word32 *arr, Word16 size )
{
    Word16 q = 31;
    FOR( int i = 0; i < size; i++ )
    if ( arr[i] != 0 )
    {
        q = s_min( q, norm_l( arr[i] ) );
    }
    return q;
}

#if 0
/* Functions are already in fixed point and available in fft.c file */

+3 −0
Original line number Diff line number Diff line
@@ -1484,6 +1484,9 @@ void stereo_dft_dec_core_switching(
void init_basic_allpass(
    basic_allpass_t *ap,                                        /* i/o: basic allpass structure             */
    const float *gains,                                         /* i  : allpass filter gains                */
#ifdef IVAS_FLOAT_FIXED
    const Word32 *gains_fx,
#endif
    const int16_t *delays                                       /* i  : allpass filter delays               */
);

+33 −0
Original line number Diff line number Diff line
@@ -234,4 +234,37 @@ void IGFDecReplicateTCX10State_fx(
    IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder          */
);

void stereo_dft_dec_analyze_fx(
    CPE_DEC_HANDLE hCPE,                                 /* i/o: CPE decoder structure               */
    const Word32 *input_fx,                              /* i  : input signal                        */
    Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o  : DFT buffers                         */
    const Word16 chan,                                   /* i  : channel number                      */
    const Word16 input_frame,                            /* i  : input frame size                    */
    const Word16 output_frame,                           /* i  : output frame size                   */
    const DFT_STEREO_DEC_ANA_TYPE ana_type,              /* i  : signal type to analyze              */
    const Word16 k_offset,                               /* i  : offset of DFT                       */
    const Word16 delay,                                  /* i  : delay in samples for input signal   */
    Word16 *q,
    Word16 *q_out_DFT 
);

void filter_with_allpass_fx(
    const Word32 *sig,   /* i  : allpass input signal                */
    Word32 *out,         /* o  : filtered output                     */
    const int16_t len,   /* i  : length of input                     */
    basic_allpass_t *ap  /* i/o: basic allpass structure             */
);

void stereo_dft_dec_core_switching_fx(
    CPE_DEC_HANDLE hCPE,                             /* i/o: CPE decoder structure               */
    Word32 output_fx[],                              /* i/o: synthesis @internal Fs              */
    Word32 synth_fx[],                               /* i/o: synthesis @output Fs                */
    Word32 hb_synth_fx[],                            /* i/o: hb synthesis                        */
    Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o  : DFT buffers                         */
    const Word16 output_frame,                       /* i  : output frame length                 */
    const Word16 use_cldfb_for_dft,                  /* i  : flag to use of CLDFB FOR DFT Stereo */
    const Word16 sba_dirac_stereo_dtx_flag,          /* i  : DTX indicator FOR SBA DirAC stereo  */
    Word16 *q,
    Word16 *q_DFT );

#endif
 No newline at end of file
+51 −0
Original line number Diff line number Diff line
@@ -195,5 +195,56 @@ const Word16 ivas_cos_twiddle_80_fx[ IVAS_80_PT_LEN >> 1 ] = {
  SHC( 0x26f4 ), SHC( 0x2223 ), SHC( 0x1d45 ), SHC( 0x185a ), SHC( 0x1367 ), SHC( 0x0e6b ), SHC( 0x096a ), SHC( 0x0465 ),
};

const Word16 dft_trigo_12k8_fx[STEREO_DFT_N_12k8_ENC / 4 + 1] =
{
	0, 402, 804, 1206, 1607, 2009, 2410, 2811, 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, 9512, 9896, 10278, 10659,
	11039, 11416, 11793, 12167, 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, 18204, 18537, 18868,
	19195, 19519, 19841, 20159, 20475, 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, 25330, 25583,
	25832, 26077, 26319, 26557, 26790, 27020, 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, 30273,
	30425, 30572, 30714, 30852, 30985, 31114, 31237, 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
	32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, 32767
};

const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1] =
{
	0, 160, 321, 482, 643, 804, 964, 1125, 1286, 1447, 1607, 1768, 1929, 2089, 2250, 2410, 2570, 2731, 2891, 3051, 3211, 3371, 3531, 3691, 3851, 4011, 4170, 4330, 4489,
	4648, 4808, 4967, 5126, 5284, 5443, 5602, 5760, 5918, 6076, 6234, 6392, 6550, 6707, 6865, 7022, 7179, 7336, 7493, 7649, 7805, 7961, 8117, 8273, 8429, 8584, 8739,
	8894, 9049, 9203, 9358, 9512, 9665, 9819, 9972, 10125, 10278, 10431, 10583, 10735, 10887, 11039, 11190, 11341, 11492, 11642, 11793, 11942, 12092, 12241, 12391,
	12539, 12688, 12836, 12984, 13131, 13278, 13425, 13572, 13718, 13864, 14010, 14155, 14300, 14444, 14589, 14732, 14876, 15019, 15162, 15304, 15446, 15588, 15729,
	15870, 16011, 16151, 16291, 16430, 16569, 16707, 16846, 16983, 17121, 17258, 17394, 17530, 17666, 17801, 17936, 18070, 18204, 18338, 18471, 18604, 18736, 18868,
	18999, 19130, 19260, 19390, 19519, 19648, 19777, 19905, 20032, 20159, 20286, 20412, 20538, 20663, 20787, 20911, 21035, 21158, 21281, 21403, 21524, 21645, 21766,
	21886, 22005, 22124, 22242, 22360, 22478, 22594, 22711, 22826, 22941, 23056, 23170, 23283, 23396, 23509, 23620, 23732, 23842, 23952, 24062, 24171, 24279, 24387,
	24494, 24600, 24706, 24812, 24916, 25021, 25124, 25227, 25330, 25431, 25532, 25633, 25733, 25832, 25931, 26029, 26126, 26223, 26319, 26415, 26509, 26604, 26697,
	26790, 26882, 26974, 27065, 27155, 27245, 27334, 27423, 27510, 27597, 27684, 27769, 27854, 27939, 28023, 28106, 28188, 28270, 28351, 28431, 28511, 28589, 28668,
	28745, 28822, 28898, 28974, 29049, 29123, 29196, 29269, 29341, 29412, 29482, 29552, 29621, 29690, 29758, 29825, 29891, 29956, 30021, 30085, 30149, 30211, 30273,
	30334, 30395, 30455, 30514, 30572, 30629, 30686, 30742, 30797, 30852, 30906, 30959, 31011, 31063, 31114, 31164, 31213, 31262, 31309, 31357, 31403, 31448, 31493,
	31537, 31581, 31623, 31665, 31706, 31746, 31785, 31824, 31862, 31899, 31936, 31971, 32006, 32040, 32074, 32106, 32138, 32169, 32199, 32229, 32257, 32285, 32312,
	32339, 32364, 32389, 32413, 32436, 32458, 32480, 32501, 32521, 32540, 32559, 32577, 32594, 32610, 32625, 32640, 32653, 32666, 32679, 32690, 32701, 32711, 32720,
	32728, 32736, 32742, 32748, 32753, 32758, 32761, 32764, 32766, 32767, 32767
};

const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1] =
{
	0, 107, 214, 321, 428, 536, 643, 750, 857, 964, 1072, 1179, 1286, 1393, 1500, 1607, 1714, 1822, 1929, 2036, 2143, 2250, 2357, 2464, 2570, 2677, 2784, 2891, 2998,
	3105, 3211, 3318, 3425, 3531, 3638, 3744, 3851, 3957, 4064, 4170, 4277, 4383, 4489, 4595, 4701, 4808, 4914, 5020, 5126, 5231, 5337, 5443, 5549, 5654, 5760, 5866,
	5971, 6076, 6182, 6287, 6392, 6497, 6602, 6707, 6812, 6917, 7022, 7127, 7231, 7336, 7440, 7545, 7649, 7753, 7857, 7961, 8065, 8169, 8273, 8377, 8480, 8584, 8687,
	8791, 8894, 8997, 9100, 9203, 9306, 9409, 9512, 9614, 9717, 9819, 9921, 10023, 10125, 10227, 10329, 10431, 10532, 10634, 10735, 10837, 10938, 11039, 11140, 11240,
	11341, 11442, 11542, 11642, 11742, 11843, 11942, 12042, 12142, 12241, 12341, 12440, 12539, 12638, 12737, 12836, 12934, 13033, 13131, 13229, 13327, 13425, 13523,
	13621, 13718, 13815, 13913, 14010, 14106, 14203, 14300, 14396, 14492, 14589, 14684, 14780, 14876, 14971, 15067, 15162, 15257, 15352, 15446, 15541, 15635, 15729,
	15823, 15917, 16011, 16104, 16197, 16291, 16384, 16476, 16569, 16661, 16754, 16846, 16938, 17029, 17121, 17212, 17303, 17394, 17485, 17576, 17666, 17756, 17846,
	17936, 18026, 18115, 18204, 18293, 18382, 18471, 18559, 18648, 18736, 18824, 18911, 18999, 19086, 19173, 19260, 19347, 19433, 19519, 19605, 19691, 19777, 19862,
	19947, 20032, 20117, 20202, 20286, 20370, 20454, 20538, 20621, 20704, 20787, 20870, 20953, 21035, 21117, 21199, 21281, 21362, 21443, 21524, 21605, 21685, 21766,
	21846, 21926, 22005, 22084, 22164, 22242, 22321, 22399, 22478, 22556, 22633, 22711, 22788, 22865, 22941, 23018, 23094, 23170, 23246, 23321, 23396, 23471, 23546,
	23620, 23695, 23769, 23842, 23916, 23989, 24062, 24134, 24207, 24279, 24351, 24422, 24494, 24565, 24636, 24706, 24777, 24847, 24916, 24986, 25055, 25124, 25193,
	25261, 25330, 25397, 25465, 25532, 25599, 25666, 25733, 25799, 25865, 25931, 25996, 26061, 26126, 26191, 26255, 26319, 26383, 26446, 26509, 26572, 26635, 26697,
	26759, 26821, 26882, 26944, 27004, 27065, 27125, 27185, 27245, 27305, 27364, 27423, 27481, 27539, 27597, 27655, 27712, 27769, 27826, 27883, 27939, 27995, 28050,
	28106, 28161, 28215, 28270, 28324, 28377, 28431, 28484, 28537, 28589, 28642, 28694, 28745, 28797, 28848, 28898, 28949, 28999, 29049, 29098, 29147, 29196, 29245,
	29293, 29341, 29388, 29435, 29482, 29529, 29575, 29621, 29667, 29712, 29758, 29802, 29847, 29891, 29935, 29978, 30021, 30064, 30106, 30149, 30190, 30232, 30273,
	30314, 30355, 30395, 30435, 30474, 30514, 30552, 30591, 30629, 30667, 30705, 30742, 30779, 30816, 30852, 30888, 30924, 30959, 30994, 31029, 31063, 31097, 31130,
	31164, 31197, 31229, 31262, 31294, 31325, 31357, 31387, 31418, 31448, 31478, 31508, 31537, 31566, 31595, 31623, 31651, 31679, 31706, 31733, 31759, 31785, 31811,
	31837, 31862, 31887, 31912, 31936, 31960, 31983, 32006, 32029, 32051, 32074, 32095, 32117, 32138, 32159, 32179, 32199, 32219, 32238, 32257, 32276, 32294, 32312,
	32330, 32347, 32364, 32381, 32397, 32413, 32428, 32444, 32458, 32473, 32487, 32501, 32514, 32528, 32540, 32553, 32565, 32577, 32588, 32599, 32610, 32620, 32630,
	32640, 32649, 32658, 32666, 32675, 32683, 32690, 32697, 32704, 32711, 32717, 32723, 32728, 32733, 32738, 32742, 32746, 32750, 32753, 32756, 32759, 32761, 32763,
	32765, 32766, 32767, 32767, 32767
};
/* clang-format on */
+3 −0
Original line number Diff line number Diff line
@@ -48,5 +48,8 @@ extern const Word16 ivas_sin_twiddle_160_fx[ IVAS_160_PT_LEN >> 1 ];
extern const Word16 ivas_cos_twiddle_160_fx[ IVAS_160_PT_LEN >> 1 ];
extern const Word16 ivas_sin_twiddle_80_fx[ IVAS_80_PT_LEN >> 1 ];
extern const Word16 ivas_cos_twiddle_80_fx[ IVAS_80_PT_LEN >> 1 ];
extern const Word16 dft_trigo_12k8_fx[STEREO_DFT_N_12k8_ENC / 4 + 1];
extern const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1];
extern const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1];

#endif
 No newline at end of file
Loading