Loading lib_com/bits_alloc_fx.c +160 −8 Original line number Diff line number Diff line Loading @@ -601,6 +601,158 @@ static ivas_error acelp_FCB_allocator( return error; } static ivas_error acelp_FCB_allocator_ivas( Word16 *nBits, /* i/o: available bit-budget */ Word16 fixed_cdk_index[], /* o : codebook index */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ const Word16 tc_subfr, /* i : TC subframe index */ const Word16 fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */ ) { Word16 cdbk, sfr, step; Word16 nBits_tmp; Word16 *p_fixed_cdk_index; Word16 max_n; ivas_error error; // PMT("Not floating point computation, but fixed point operator are still missing ") error = IVAS_ERR_OK; move32(); cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ move16(); p_fixed_cdk_index = fixed_cdk_index; move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); IF( GE_16( tc_subfr, L_SUBFR ) && fix_first ) { Word16 i; FOR( i = 0; i < nb_subfr; i++ ) { *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) ); move16(); } return error; } /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ sfr = 0; move16(); IF( fix_first ) { *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) ); move16(); sfr = 1; move16(); p_fixed_cdk_index++; nb_subfr = 3; move16(); } /* distribute the bit-budget equally between subframes */ IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */ { max_n = 6; move16(); } ELSE { max_n = ACELP_FIXED_CDK_NB; move16(); } FOR( cdbk = 0; cdbk < max_n; cdbk++ ) { IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) ) { BREAK; } } cdbk = sub( cdbk, 1 ); set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); nBits_tmp = 0; move16(); IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); move16(); } ELSE { nBits_tmp = 0; move16(); } *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) ); move16(); /* try to increase the FCB bit-budget of the first subframe(s) */ IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); WHILE( GE_16( *nBits, step ) ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); move16(); p_fixed_cdk_index++; } /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ IF( LT_16( fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) ); test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { fixed_cdk_index[sfr]++; *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { sfr++; fixed_cdk_index[sfr]++; *nBits = sub( *nBits, step ); move16(); } } } } /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ IF( GE_16( tc_subfr, L_SUBFR ) ) { Word16 tempr; SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) { SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } } /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ IF( GT_16( L_subfr, L_SUBFR ) ) { Word16 i, j; FOR( i = 0; i < nb_subfr; i++ ) { j = fixed_cdk_index[i]; move16(); fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; move16(); } } return error; } /*-------------------------------------------------------------------* * config_acelp1() Loading Loading @@ -2373,11 +2525,11 @@ ivas_error config_acelp1_IVAS( IF( GE_16( bits, 16 ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_cfg->fixed_cdk_index[1] = -1; move16(); } Loading Loading @@ -2492,17 +2644,17 @@ ivas_error config_acelp1_IVAS( { IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), nb_subfr ) ) ) /* enough bits for all fcb */ { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; move16(); } ELSE IF( GE_32( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; move16(); acelp_cfg->fixed_cdk_index[1] = -1; Loading @@ -2512,7 +2664,7 @@ ivas_error config_acelp1_IVAS( } ELSE IF( GE_32( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; move16(); acelp_cfg->fixed_cdk_index[0] = -1; Loading @@ -2538,11 +2690,11 @@ ivas_error config_acelp1_IVAS( { bits = 100; /* 9 kbps for fcb */ move16(); acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } } } Loading Loading
lib_com/bits_alloc_fx.c +160 −8 Original line number Diff line number Diff line Loading @@ -601,6 +601,158 @@ static ivas_error acelp_FCB_allocator( return error; } static ivas_error acelp_FCB_allocator_ivas( Word16 *nBits, /* i/o: available bit-budget */ Word16 fixed_cdk_index[], /* o : codebook index */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ const Word16 tc_subfr, /* i : TC subframe index */ const Word16 fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */ ) { Word16 cdbk, sfr, step; Word16 nBits_tmp; Word16 *p_fixed_cdk_index; Word16 max_n; ivas_error error; // PMT("Not floating point computation, but fixed point operator are still missing ") error = IVAS_ERR_OK; move32(); cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ move16(); p_fixed_cdk_index = fixed_cdk_index; move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); IF( GE_16( tc_subfr, L_SUBFR ) && fix_first ) { Word16 i; FOR( i = 0; i < nb_subfr; i++ ) { *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) ); move16(); } return error; } /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ sfr = 0; move16(); IF( fix_first ) { *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) ); move16(); sfr = 1; move16(); p_fixed_cdk_index++; nb_subfr = 3; move16(); } /* distribute the bit-budget equally between subframes */ IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */ { max_n = 6; move16(); } ELSE { max_n = ACELP_FIXED_CDK_NB; move16(); } FOR( cdbk = 0; cdbk < max_n; cdbk++ ) { IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) ) { BREAK; } } cdbk = sub( cdbk, 1 ); set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); nBits_tmp = 0; move16(); IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); move16(); } ELSE { nBits_tmp = 0; move16(); } *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) ); move16(); /* try to increase the FCB bit-budget of the first subframe(s) */ IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); WHILE( GE_16( *nBits, step ) ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); move16(); p_fixed_cdk_index++; } /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ IF( LT_16( fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) ); test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { fixed_cdk_index[sfr]++; *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { sfr++; fixed_cdk_index[sfr]++; *nBits = sub( *nBits, step ); move16(); } } } } /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ IF( GE_16( tc_subfr, L_SUBFR ) ) { Word16 tempr; SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) { SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } } /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ IF( GT_16( L_subfr, L_SUBFR ) ) { Word16 i, j; FOR( i = 0; i < nb_subfr; i++ ) { j = fixed_cdk_index[i]; move16(); fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; move16(); } } return error; } /*-------------------------------------------------------------------* * config_acelp1() Loading Loading @@ -2373,11 +2525,11 @@ ivas_error config_acelp1_IVAS( IF( GE_16( bits, 16 ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_cfg->fixed_cdk_index[1] = -1; move16(); } Loading Loading @@ -2492,17 +2644,17 @@ ivas_error config_acelp1_IVAS( { IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), nb_subfr ) ) ) /* enough bits for all fcb */ { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; move16(); } ELSE IF( GE_32( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; move16(); acelp_cfg->fixed_cdk_index[1] = -1; Loading @@ -2512,7 +2664,7 @@ ivas_error config_acelp1_IVAS( } ELSE IF( GE_32( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; move16(); acelp_cfg->fixed_cdk_index[0] = -1; Loading @@ -2538,11 +2690,11 @@ ivas_error config_acelp1_IVAS( { bits = 100; /* 9 kbps for fcb */ move16(); acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE { acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } } } Loading