diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 94df1d68bd2bb50100a98f3e46588d98c38ea94a..9a73e1a01db9c998b17c2f1229fba9158a7443ff 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1517,4 +1517,16 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( const Word16 nchan_in /* i : number of input channels */ ); +void configureFdCngDec_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ + const Word16 bwidth, + const Word32 total_brate, + const Word16 L_frame, + const Word16 last_L_frame, + const Word16 element_mode ); + +void synchonize_channels_mdct_sid_fx( + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const Word16 n /* i : channel number */ +); #endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 606997c5f08504a259e10dd0b19321a99fedaf30..0e3d94e8be6be2b8c99cf2679f06719787b153f1 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -8746,4 +8746,12 @@ void v_mult16_fixed( const Word16 N /* i : Vector length */ ); +void configureFdCngDec( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ + const Word16 bwidth, + const Word32 total_brate, + const Word16 L_frame, + const Word16 last_L_frame, + const Word16 element_mode ); + #endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 5ad4f1699a6e9e697012a78604bb23835bbe3a72..cced3bdda1b95f0b72db3d08cc2cf448c8d9a96c 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -370,6 +370,226 @@ void configureFdCngDec_flt( return; } +#ifdef IVAS_FLOAT_FIXED +void configureFdCngDec_fx( + HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */ + const Word16 bwidth, + const Word32 total_brate, + const Word16 L_frame, + const Word16 last_L_frame, + const Word16 element_mode ) +{ + Word16 j, stopBandFR; + HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom; + + hsCom->CngBandwidth = bwidth; + move16(); + IF ( EQ_16( hsCom->CngBandwidth, FB ) ) + { + hsCom->CngBandwidth = SWB; + move16(); + } + test(); + IF ( NE_32( total_brate, FRAME_NO_DATA ) && NE_32( total_brate, SID_2k40 ) ) + { + hsCom->CngBitrate = total_brate; + move32(); + } + ELSE IF ( EQ_32( hsCom->CngBitrate, -1 ) ) + { + /* set minimum active CBR bitrate IF CngBitrate is uninitialized */ + IF ( GT_16( element_mode, EVS_MONO ) ) + { + hsCom->CngBitrate = IVAS_13k2; + move32(); + } + ELSE + { + hsCom->CngBitrate = ACELP_7k20; + move32(); + } + } + + /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */ + /* This may need adjustment in the future IF 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */ + IF ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + hsCom->CngBitrate = IVAS_48k; + move32(); + } + hsCom->numSlots = 16; + move32(); + + /* NB configuration */ + IF ( EQ_16( bwidth, NB ) ) + { + hsCom->FdCngSetup = FdCngSetup_nb; + hsCom->numCoreBands = 16; + move16(); + hsCom->regularStopBand = 16; + move16(); + } + + /* WB configuration */ + ELSE IF ( EQ_16( bwidth, WB ) ) + { + /* FFT 6.4kHz, no CLDFB */ + test(); + test(); + IF ( LE_32( hsCom->CngBitrate, ACELP_8k00 ) && EQ_16( L_frame, L_FRAME ) ) + { + hsCom->FdCngSetup = FdCngSetup_wb1; + hsCom->numCoreBands = 16; + move16(); + hsCom->regularStopBand = 16; + move16(); + } + /* FFT 6.4kHz, CLDFB 8.0kHz */ + ELSE IF ( LE_32( hsCom->CngBitrate, ACELP_13k20 ) || EQ_16( L_frame, L_FRAME ) ) + { + hsCom->FdCngSetup = FdCngSetup_wb2; + hsCom->numCoreBands = 16; + move16(); + hsCom->regularStopBand = 20; + move16(); + IF ( EQ_16( L_frame, L_FRAME16k ) ) + { + hsCom->FdCngSetup = FdCngSetup_wb2; + hsCom->numCoreBands = 20; + move16(); + hsCom->regularStopBand = 20; + move16(); + hsCom->FdCngSetup.fftlen = 640; + move16(); + hsCom->FdCngSetup.stopFFTbin = 256; + move16(); + } + } + /* FFT 8.0kHz, no CLDFB */ + ELSE + { + hsCom->FdCngSetup = FdCngSetup_wb3; + hsCom->numCoreBands = 20; + move16(); + hsCom->regularStopBand = 20; + move16(); + } + } + + /* SWB/FB configuration */ + ELSE + { + /* FFT 6.4kHz, CLDFB 14kHz */ + IF ( EQ_16( L_frame, L_FRAME ) ) + { + hsCom->FdCngSetup = FdCngSetup_swb1; + hsCom->numCoreBands = 16; + move16(); + hsCom->regularStopBand = 35; + move16(); + } + /* FFT 8.0kHz, CLDFB 16kHz */ + ELSE + { + hsCom->FdCngSetup = FdCngSetup_swb2; + hsCom->numCoreBands = 20; + move16(); + hsCom->regularStopBand = 40; + move16(); + test(); + IF ( EQ_16( last_L_frame, L_FRAME ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + hsCom->regularStopBand = 35; + move16(); + } + } + } + + + hsCom->fftlen = hsCom->FdCngSetup.fftlen; + move16(); + hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; + move16(); + + /* Configure the SID quantizer and the Comfort Noise Generator */ + + hsCom->startBand = 2; + move16(); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + /* remove floating point dependency */ + initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); + initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); + + IF ( EQ_16( hsCom->stopFFTbin, 160 ) ) + { + hsCom->nFFTpart = 17; + move16(); + } + ELSE IF ( EQ_16( hsCom->stopFFTbin, 256 ) ) + { + hsCom->nFFTpart = 20; + move16(); + } + ELSE + { + hsCom->nFFTpart = 21; + move16(); + } + hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); + FOR ( j = 0; j < hsCom->nCLDFBpart; j++ ) + { + hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; // TODO remove floating point dependency + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + move16(); + } + + stopBandFR = 40; //(Word16)floor(1000.f /*Hz*/ / 25.f /*Hz/Bin*/); + move16(); + IF ( GT_16( stopBandFR, hsCom->stopFFTbin ) ) + { + stopBandFR = hsCom->stopFFTbin; + move16(); + } + + initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_shaping_norm, &hFdCngDec->psize_shaping_norm_exp, hFdCngDec->psize_inv_shaping, stopBandFR ); + /* remove floating point dependency */ + initPartitions_flt( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping_float, hFdCngDec->psize_inv_shaping_float, stopBandFR ); + + hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; + move16(); + + SWITCH ( hsCom->fftlen ) + { + case 512: + hsCom->olapWinAna_fx = olapWinAna512_fx; + hsCom->fftSineTab_fx = NULL; + hsCom->olapWinSyn_fx = olapWinSyn256_fx; + + /* TODO: remove floating point dependency */ + hsCom->fftSineTab_flt = NULL; + hsCom->olapWinAna_flt = olapWinAna512; + hsCom->olapWinSyn_flt = olapWinSyn256; + BREAK; + case 640: + hsCom->olapWinAna_fx = olapWinAna640_fx; + hsCom->fftSineTab_fx = fftSineTab640_fx; + hsCom->olapWinSyn_fx = olapWinSyn320_fx; + + /* remove floating point dependency */ + hsCom->fftSineTab_flt = fftSineTab640; + hsCom->olapWinAna_flt = olapWinAna640; + hsCom->olapWinSyn_flt = olapWinSyn320; + BREAK; + default: + assert( !"Unsupported FFT length for FD-based CNG" ); + BREAK; + } + hsCom->frameSize = shr( hsCom->fftlen, 1 ); + + return; +} +#endif /*------------------------------------------------------------------- * deleteFdCngDec_flt() diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 2a4a865601047147c91593509e8e9a52014c61be..29ef301bcef38ce32f31fbef9a368c47ba15cde5 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -212,8 +212,11 @@ ivas_error ivas_core_dec( #else ivas_decision_matrix_dec( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); #endif - +#ifdef IVAS_FLOAT_FIXED + synchonize_channels_mdct_sid_fx( sts, n ); +#else synchonize_channels_mdct_sid( sts, n ); +#endif if ( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ { diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index f6a6dbb2a61ec379f099202da932754188ba23eb..0364477fc6814caa557b13ed6edcc6f6460b177a 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -62,10 +62,25 @@ static void ivas_jbm_dec_tc_buffer_playout( Decoder_Struct *st_ivas, const uint1 static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const Word16 nCldfbTs ); +#else static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t nCldfbTs ); +#endif +#ifdef IVAS_FLOAT_FIXED +static Word16 ceil_fx16( Word16 inp, Word16 Q ); +static Word16 ceil_fx16( Word16 inp, Word16 Q ) { + Word16 ret = shr( inp, Q ); + IF( inp & ( ( 1 << Q ) - 1) > 0) { + ret = ret + 1; + } + return ret; +} +#endif + /*--------------------------------------------------------------------------* * ivas_jbm_dec_tc() * @@ -4927,6 +4942,69 @@ void ivas_jbm_dec_tc_buffer_close( void ivas_jbm_dec_td_renderers_adapt_subframes( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) +#ifdef IVAS_FLOAT_FIXED +{ + Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, exp, tmp1, tmp2, s1, s2; + UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; + + //nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; + tmp = BASOP_Util_Divide3216_Scale(st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &exp); + tmp = shr(tmp, -1 - exp ); + tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp); + nMaxSlotsPerSubframe = shr( tmp, ( 15 - exp ) ); + + //nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; + tmp = BASOP_Util_Divide1616_Scale(st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp); + nSlotsAvailable = shr( tmp, ( 15 - exp ) ); + + st_ivas->hTcBuffer->num_slots = nSlotsAvailable; + move16(); + //st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; + st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity ); + nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); + st_ivas->hTcBuffer->nb_subframes = 0; + move16(); + + IF ( nSlotsInFirstSubframe > 0 ) + { + st_ivas->hTcBuffer->nb_subframes = 1; + nSlotsAvailable -= nSlotsInFirstSubframe; + } + + //st_ivas->hTcBuffer->nb_subframes += (int16_t) ceilf( (float) nSlotsAvailable / (float) nMaxSlotsPerSubframe ); + s1 = norm_s(nSlotsAvailable) - 1; + s2 = norm_s(nMaxSlotsPerSubframe); + + tmp1 = shl( nSlotsAvailable, s1 ); + tmp2 = shl( nMaxSlotsPerSubframe, s2 ); + + tmp = div_s(tmp1, tmp2); + st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16(tmp, ( 15 - ( s2 - s1 ) ) ) ); + + nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe; + set_s( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes ); + + IF ( nSlotsInFirstSubframe > 0 ) + { + st_ivas->hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe; + move16(); + } + + IF ( nSlotsInLastSubframe > 0 ) + { + st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe; + move16(); + } + + st_ivas->hTcBuffer->slots_rendered = 0; + move16(); + st_ivas->hTcBuffer->subframes_rendered = 0; + move16(); + + return; +} +#else { int16_t nMaxSlotsPerSubframe, nSlotsAvailable; uint16_t nSlotsInLastSubframe, nSlotsInFirstSubframe; @@ -4963,6 +5041,7 @@ void ivas_jbm_dec_td_renderers_adapt_subframes( return; } +#endif /*--------------------------------------------------------------------------* @@ -5238,6 +5317,30 @@ void ivas_jbm_dec_copy_tc_no_tsm( ivas_error ivas_jbm_dec_metadata_open( Decoder_Struct *st_ivas ) +#ifdef IVAS_FLOAT_FIXED +{ + JBM_METADATA_HANDLE hJbmMetadata; + IF ( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) ); + } + hJbmMetadata->sf_write_idx = 0; + move16(); + hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + + hJbmMetadata->slot_write_idx = 0; + move16(); + hJbmMetadata->slot_read_idx = 0; + move16(); + hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); + + st_ivas->hJbmMetadata = hJbmMetadata; + + return IVAS_ERR_OK; +} +#else { JBM_METADATA_HANDLE hJbmMetadata; if ( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL ) @@ -5255,6 +5358,8 @@ ivas_error ivas_jbm_dec_metadata_open( return IVAS_ERR_OK; } +#endif + /*--------------------------------------------------------------------------* @@ -5265,6 +5370,43 @@ ivas_error ivas_jbm_dec_metadata_open( static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas ) +#ifdef IVAS_FLOAT_FIXED +{ + Word16 sf, dir, band; + JBM_METADATA_HANDLE hJbmMetadata; + MASA_DECODER_EXT_OUT_META *extOutMeta; + Word16 write_idx; + + hJbmMetadata = st_ivas->hJbmMetadata; + extOutMeta = st_ivas->hMasa->data.extOutMeta; + + FOR ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length; + move16(); + FOR ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band]; + move16(); + hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band]; + hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band]; + } + } + + FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band]; + hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band]; + } + + hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections; + } + + return; +} +#else { int16_t sf, dir, band; JBM_METADATA_HANDLE hJbmMetadata; @@ -5299,6 +5441,8 @@ static void ivas_jbm_dec_copy_masa_meta_to_buffer( return; } +#endif + /*--------------------------------------------------------------------------* @@ -5309,6 +5453,43 @@ static void ivas_jbm_dec_copy_masa_meta_to_buffer( static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef IVAS_FLOAT_FIXED + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +) +{ + Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; + Word16 num_slots_in_subfr; + JBM_METADATA_HANDLE hJbmMetadata; + Word16 slot_idx; + Word16 write_idx, sf_index; + + /* Set values */ + hJbmMetadata = st_ivas->hJbmMetadata; + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + + /* Map input subframes to slots */ + ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map ); + + FOR ( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ ) + { + write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length; + move16(); + + hJbmMetadata->sf_to_slot_map[write_idx] = sf_index; + move16(); + } + + hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length; + move16(); + hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + + return; +} +#else const int16_t nCldfbTs /* i : number of CLDFB time slots */ ) { @@ -5338,6 +5519,7 @@ static void ivas_jbm_masa_sf_to_slot_map( return; } +#endif /*--------------------------------------------------------------------------* @@ -5349,6 +5531,74 @@ static void ivas_jbm_masa_sf_to_slot_map( void ivas_jbm_masa_sf_to_sf_map( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) +#ifdef IVAS_FLOAT_FIXED +{ + Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES]; + JBM_METADATA_HANDLE hJbmMetadata; + MASA_DECODER_EXT_OUT_META *extOutMeta; + Word16 slot_read_idx, sf_read_idx; + Word16 sf_idx; + Word16 dir, band; + UWord8 numberOfDirections; + + /* Set values */ + hJbmMetadata = st_ivas->hJbmMetadata; + extOutMeta = st_ivas->hMasa->data.extOutMeta; + + /* Map slots to subframes */ + FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + slot_read_idx = ( add( hJbmMetadata->slot_read_idx, 2 ) ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */ + move16(); + sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx]; + move16(); + hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + } + + /* Copy mapped metadata to the EXT meta buffer for writing */ + FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + sf_read_idx = sf_to_sf_map[sf_idx]; + move16(); + + FOR ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band]; + move16(); + extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band]; + extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band]; + } + } + + FOR ( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band]; + extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band]; + } + } + + /* Determine the number of directions for the frame to be written */ + numberOfDirections = 0; + FOR ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + sf_read_idx = sf_to_sf_map[sf_idx]; + move16(); + + IF ( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 ) + { + numberOfDirections = 1; + BREAK; + } + } + + extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections; + + return; +} +#else { int16_t sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES]; JBM_METADATA_HANDLE hJbmMetadata; @@ -5409,3 +5659,4 @@ void ivas_jbm_masa_sf_to_sf_map( return; } +#endif \ No newline at end of file diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 35ba2d4c805c9ab598f82a596b9aa91391a8e64b..fb827e887c774ce291776711b873ed001148ac61 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -43,8 +43,6 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" #endif // IVAS_FLOAT_FIXED -#include "prot_fx1.h" -#include "prot_fx2.h" /*-------------------------------------------------------------------* @@ -910,6 +908,53 @@ ivas_error initMdctStereoDtxData( * Synchronize channels in SID frame in MDCT stereo *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void synchonize_channels_mdct_sid_fx( + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const Word16 n /* i : channel number */ +) +{ + Decoder_State *st; + + st = sts[n]; + + IF ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_32( st->total_brate, SID_2k40 ) ) + { + IF ( EQ_16( n, 1 ) ) + { + /* synchronize channels */ + sts[1]->L_frame = sts[0]->L_frame; + move16(); + sts[1]->cng_type = sts[0]->cng_type; + move16(); + sts[1]->bwidth = sts[0]->bwidth; + move16(); + /* TODO remove floating point dependency */ + sts[0]->hFdCngDec->hFdCngCom->coherence_flt = sts[1]->hFdCngDec->hFdCngCom->coherence_flt; /* coherence is stored in sts[1] - see ivas_decision_matrix_dec() */ + sts[0]->hFdCngDec->hFdCngCom->coherence_fx = sts[1]->hFdCngDec->hFdCngCom->coherence_fx; + move16(); + sts[0]->hFdCngDec->hFdCngCom->no_side_flag = sts[1]->hFdCngDec->hFdCngCom->no_side_flag; + move16(); + + /* configure when there is a switching from DFT CNG to MDCT CNG */ + IF ( EQ_16( sts[0]->first_CNG, 1 ) && EQ_16( sts[1]->first_CNG, 0 ) ) + { + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->element_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } + } + + IF ( EQ_16( sts[0]->first_CNG, 0 ) ) + { + /* configure CNG after reading first side info from SID to get correct values for L_frame and bwidth if first SID is also first valid frame */ + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->element_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } + } + + return; +} +#endif + + void synchonize_channels_mdct_sid( Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ const int16_t n /* i : channel number */