Loading lib_rend/ivas_dirac_dec_binaural_functions_fx.c +1 −424 Original line number Diff line number Diff line Loading @@ -5603,430 +5603,7 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( #endif else /* Other processing modes */ { float subframeEne; float subframeEneCh[2]; float normEnes[2]; float ratioAccOrig; float ratioAccNew; float ratio; float ismEneThis; float ismTargetEneThis; float ismTargetEneThisCh[2]; float totalTargetEneCh[2]; float totalTargetEne; float masaTargetEneThisCh[2]; float ismPreprocMtxNew[2][2]; float ismPreprocMtxIncrement[2][2]; float eneMove[2]; float enePreserve[2]; float ismRatioAcc; float remainderNormEne; float centeringFactor; float eneMoveThis; float enePreserveThis; float normVal; float eqVal; float outSlotRe[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float outSlotIm[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float newRatios[6]; float gainIsmThis; float gainMasaPow2; float nSlotDiv; float tempDivisor; float masaEneThisCh[2]; float ratioAccNewDivisor; gainMasaPow2 = 1.0f; if ( masaGainEdited ) { gainMasaPow2 = hMasaIsmData->gain_masa_edited_fx; gainMasaPow2 *= gainMasaPow2; } nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; nSlotDiv = 1.0f / ( (float) nSlots ); /* Determine panning gains and energies for each object */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { /* Get input and output panning gains */ ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], panGainsIn[ismDirIndex] ); if ( ismDirEdited[ismDirIndex] ) { ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism_edited[ismDirIndex], hMasaIsmData->elevation_ism_edited[ismDirIndex], panGainsOut[ismDirIndex] ); } else { /* When not edited, input and output pan gains are the same */ for ( ch = 0; ch < 2; ch++ ) { panGainsOut[ismDirIndex][ch] = panGainsIn[ismDirIndex][ch]; } } /* Determine pan enes */ for ( ch = 0; ch < 2; ch++ ) { panEnesOut[ismDirIndex][ch] = panGainsOut[ismDirIndex][ch] * panGainsOut[ismDirIndex][ch]; panEnesIn[ismDirIndex][ch] = panGainsIn[ismDirIndex][ch] * panGainsIn[ismDirIndex][ch]; } } /* Determine the highest band */ max_band = 0; #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif while ( max_band < MASA_FREQUENCY_BANDS && MASA_band_grouping_24[max_band] < nBins ) { max_band++; } #ifdef OBJ_EDITING_PARAMISM_BIN } else { while ( max_band < MAX_PARAM_ISM_NBANDS && hParamIsmDec->hParamIsm->band_grouping[max_band] < nBins ) { max_band++; } } #endif /* Init out array */ for ( int k = 0; k < nSlots; k++ ) { for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { set_zero( outSlotRe[ch][k], CLDFB_NO_CHANNELS_MAX ); set_zero( outSlotIm[ch][k], CLDFB_NO_CHANNELS_MAX ); } } /* Perform the processing in frequency bands */ for ( band_idx = 0; band_idx < max_band; band_idx++ ) { ratioAccOrig = 0.0f; ratioAccNew = 0.0f; ismRatioAcc = 0.0f; set_zero( subframeEneCh, 2 ); set_zero( ismPreprocMtxNew[0], 2 ); set_zero( ismPreprocMtxNew[1], 2 ); set_zero( eneMove, 2 ); set_zero( enePreserve, 2 ); #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif bin_lo = MASA_band_grouping_24[band_idx]; bin_hi = min( MASA_band_grouping_24[band_idx + 1], nBins ); #ifdef OBJ_EDITING_PARAMISM_BIN } else { bin_lo = hParamIsmDec->hParamIsm->band_grouping[band_idx]; bin_hi = min( hParamIsmDec->hParamIsm->band_grouping[band_idx + 1], nBins ); } #endif /* Determine transport normalized energies and subframe energy */ for ( slot = 0; slot < nSlots; slot++ ) { for ( ch = 0; ch < 2; ch++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { subframeEneCh[ch] += inRe_fx[ch][slot][bin] * inRe_fx[ch][slot][bin]; subframeEneCh[ch] += inIm_fx[ch][slot][bin] * inIm_fx[ch][slot][bin]; } } } subframeEne = subframeEneCh[0] + subframeEneCh[1]; totalTargetEneCh[0] = subframeEneCh[0]; totalTargetEneCh[1] = subframeEneCh[1]; masaEneThisCh[0] = subframeEneCh[0]; masaEneThisCh[1] = subframeEneCh[1]; /* Gain editing */ /* For each object, estimate new target energy per channel based on the applied gain */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { ratio = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; ratioAccOrig += ratio; /* Calculate MASA energy as a residual of original channel energies subtracted with ISM energies */ for ( ch = 0; ch < 2; ch++ ) { masaEneThisCh[ch] -= panEnesIn[ismDirIndex][ch] * ratio * subframeEne; } /* Calculate target energy, gained ratio for accumulation, and transports gains, if ism gain is edited */ if ( ismGainEdited[ismDirIndex] ) { gainIsmThis = hMasaIsmData->gain_ism_edited_fx[ismDirIndex]; /* ISM original energy */ ismEneThis = ratio * subframeEne; /* ISM target energy */ ismTargetEneThis = ( gainIsmThis * gainIsmThis ) * ismEneThis; ratio *= gainIsmThis * gainIsmThis; /* Determine panning energies and channel target energies */ for ( ch = 0; ch < 2; ch++ ) { ismTargetEneThisCh[ch] = panEnesIn[ismDirIndex][ch] * ismTargetEneThis; /* Ism target energy per channel */ totalTargetEneCh[ch] -= panEnesIn[ismDirIndex][ch] * ismEneThis; /* Reduce original ism energy */ totalTargetEneCh[ch] += ismTargetEneThisCh[ch]; /* Add ism target energy per channel */ } /* If separated ism edited, apply gain directly to the separated ism */ if ( ismDirIndex == hMasaIsmData->idx_separated_ism ) { /* Separated object gaining is done elsewhere with DIRAC renderer */ if ( st_ivas->renderer_type != RENDERER_DIRAC ) { /* Gain transport channel of separated ism */ for ( slot = 0; slot < nSlots; slot++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { inRe_fx[2][slot][bin] = gainIsmThis * inRe_fx[2][slot][bin]; inIm_fx[2][slot][bin] = gainIsmThis * inIm_fx[2][slot][bin]; } } } } } ratioAccNew += ratio; } #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif /* MASA original ratios */ ratio = hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin_lo] + hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin_lo]; ratioAccOrig += ratio; /* Estimate MASA original energies and determine adjusted target energies and gained ratio for accumulation, if a gain is applied to MASA */ if ( masaGainEdited ) { /* Gained MASA ratio */ ratio *= gainMasaPow2; /* Calculate MASA target energies and add to total target energy estimation */ for ( ch = 0; ch < 2; ch++ ) { masaEneThisCh[ch] = fmaxf( masaEneThisCh[ch], 0.0f ); /* MASA original energy per channel */ masaTargetEneThisCh[ch] = gainMasaPow2 * masaEneThisCh[ch]; /* MASA target energy per channel */ totalTargetEneCh[ch] -= masaEneThisCh[ch]; /* Reduce original energy per channel */ totalTargetEneCh[ch] += masaTargetEneThisCh[ch]; /* Add target energy per channel */ } } ratioAccNew += ratio; #ifdef OBJ_EDITING_PARAMISM_BIN } #endif /* Limit target energies to non-negative values */ for ( ch = 0; ch < 2; ch++ ) { totalTargetEneCh[ch] = max( totalTargetEneCh[ch], 0.0f ); } /* Diffuse ratio accumulation based on gaining */ if ( masaGainEdited ) { ratioAccNew += gainMasaPow2 * ( 1 - ratioAccOrig ); } else { ratioAccNew += ( 1.0f - ratioAccOrig ); } ratioAccNewDivisor = 1.0f / fmaxf( 1e-12f, ratioAccNew ); /* New target total energy ratio divider */ /* Determine and process object energy ratios based on gaining */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { newRatios[ismDirIndex + 2] = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; /* Determine original object energy ratio */ if ( ismGainEdited[ismDirIndex] ) { gainIsmThis = hMasaIsmData->gain_ism_edited_fx[ismDirIndex]; newRatios[ismDirIndex + 2] *= ( gainIsmThis * gainIsmThis ); /* Gain original object energy ratio, if edited */ } newRatios[ismDirIndex + 2] *= ratioAccNewDivisor; /* Divide with new target total ratio */ } /* Determine and process MASA energy ratios based on gaining */ newRatios[0] = hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin_lo]; newRatios[1] = hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin_lo]; if ( masaGainEdited ) { newRatios[0] *= gainMasaPow2; newRatios[1] *= gainMasaPow2; } newRatios[0] *= ratioAccNewDivisor; newRatios[1] *= ratioAccNewDivisor; /* Set adjusted energy ratios */ for ( bin = bin_lo; bin < bin_hi; bin++ ) { for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin] = newRatios[ismDirIndex + 2]; } hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin] = newRatios[0]; hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin] = newRatios[1]; } /* Direction editing */ /* Determine new energetic values after gaining */ totalTargetEne = totalTargetEneCh[0] + totalTargetEneCh[1]; tempDivisor = 1.0f / fmaxf( 1e-12f, totalTargetEne ); normEnes[0] = totalTargetEneCh[0] * tempDivisor; normEnes[1] = totalTargetEneCh[1] * tempDivisor; /* For each ismDir, determine moved and preserve energy ratio per channel */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { ratio = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; ismRatioAcc += ratio; if ( enableCentering ) { centeringFactor = fmaxf( 0.0f, 2.0f * fabsf( panEnesIn[ismDirIndex][0] - panEnesOut[ismDirIndex][0] ) - 1.0f ); for ( ch = 0; ch < 2; ch++ ) { panEnesOut[ismDirIndex][ch] *= ( 1.0f - centeringFactor ); panEnesOut[ismDirIndex][ch] += 0.5f * centeringFactor; } } for ( ch = 0; ch < 2; ch++ ) { eneMoveThis = fmaxf( 0.0f, panEnesIn[ismDirIndex][ch] - panEnesOut[ismDirIndex][ch] ); enePreserveThis = panEnesIn[ismDirIndex][ch] - eneMoveThis; eneMove[ch] += ratio * eneMoveThis; enePreserve[ch] += ratio * enePreserveThis; /* Subtract object parts from normEnes */ normEnes[ch] -= panEnesIn[ismDirIndex][ch] * ratio; } } /* Any remaining (non-object) energy is set to be preserved at both channels */ remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); /* Normalize */ for ( ch = 0; ch < 2; ch++ ) { enePreserve[ch] += fmaxf( 0.0f, normEnes[ch] + remainderNormEne / 2.0f ); normVal = 1.0f / fmaxf( EPSILON, eneMove[ch] + enePreserve[ch] ); normVal *= fminf( 10.0f, totalTargetEneCh[ch] / fmaxf( EPSILON, subframeEneCh[ch] ) ); eneMove[ch] *= normVal; enePreserve[ch] *= normVal; } /* Temporally average target energy */ hMasaIsmData->eneOrigIIR_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->eneOrigIIR_fx[band_idx] += totalTargetEne; /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix for * gaining objects and moving objects between left and right */ for ( ch = 0; ch < 2; ch++ ) { hMasaIsmData->eneMoveIIR_fx[ch][band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->eneMoveIIR_fx[ch][band_idx] += eneMove[ch] * totalTargetEne; hMasaIsmData->enePreserveIIR_fx[ch][band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->enePreserveIIR_fx[ch][band_idx] += enePreserve[ch] * totalTargetEne; normVal = 1.0f / fmaxf( EPSILON, hMasaIsmData->eneOrigIIR_fx[band_idx] ); ismPreprocMtxNew[ch][ch] = fminf( 4.0f, sqrtf( hMasaIsmData->enePreserveIIR_fx[ch][band_idx] * normVal ) ); ismPreprocMtxNew[1 - ch][ch] = fminf( 4.0f, sqrtf( hMasaIsmData->eneMoveIIR_fx[ch][band_idx] * normVal ) ); } /* Get increment value for temporal interpolation */ for ( inCh = 0; inCh < 2; inCh++ ) { for ( outCh = 0; outCh < 2; outCh++ ) { ismPreprocMtxIncrement[outCh][inCh] = ( ismPreprocMtxNew[outCh][inCh] - hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx] ) * nSlotDiv; } } /* Mix signals */ hMasaIsmData->preprocEneTarget_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->preprocEneRealized_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->preprocEneTarget_fx[band_idx] += totalTargetEne; for ( outCh = 0; outCh < 2; outCh++ ) { for ( slot = 0; slot < nSlots; slot++ ) { for ( inCh = 0; inCh < 2; inCh++ ) { hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx] += ismPreprocMtxIncrement[outCh][inCh]; for ( bin = bin_lo; bin < bin_hi; bin++ ) { outSlotRe[outCh][slot][bin] += inRe_fx[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx]; outSlotIm[outCh][slot][bin] += inIm_fx[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx]; } } for ( bin = bin_lo; bin < bin_hi; bin++ ) { hMasaIsmData->preprocEneRealized_fx[band_idx] += ( outSlotRe[outCh][slot][bin] * outSlotRe[outCh][slot][bin] ) + ( outSlotIm[outCh][slot][bin] * outSlotIm[outCh][slot][bin] ); } } } eqVal = fminf( 4.0f, sqrtf( hMasaIsmData->preprocEneTarget_fx[band_idx] / fmaxf( 1e-12f, hMasaIsmData->preprocEneRealized_fx[band_idx] ) ) ); for ( ch = 0; ch < 2; ch++ ) { for ( slot = 0; slot < nSlots; slot++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { inRe_fx[ch][slot][bin] = outSlotRe[ch][slot][bin] * eqVal; inIm_fx[ch][slot][bin] = outSlotIm[ch][slot][bin] * eqVal; } } } } #ifdef OBJ_EDITING_PARAMISM_BIN if ( !masaIsmMode ) { int16_t obj_idx1, obj_idx2; for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { bin_lo = hParamIsmDec->hParamIsm->band_grouping[band_idx]; bin_hi = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; obj_idx1 = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]; obj_idx2 = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]; for ( bin = bin_lo; bin < bin_hi; bin++ ) { hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin] = hMasaIsmData->energy_ratio_ism_fx[obj_idx1][dirac_read_idx][bin]; hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin] = hMasaIsmData->energy_ratio_ism_fx[obj_idx2][dirac_read_idx][bin]; } } } #endif assert( 0 && "Insert proper basop code here!" ); } return; Loading Loading
lib_rend/ivas_dirac_dec_binaural_functions_fx.c +1 −424 Original line number Diff line number Diff line Loading @@ -5603,430 +5603,7 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( #endif else /* Other processing modes */ { float subframeEne; float subframeEneCh[2]; float normEnes[2]; float ratioAccOrig; float ratioAccNew; float ratio; float ismEneThis; float ismTargetEneThis; float ismTargetEneThisCh[2]; float totalTargetEneCh[2]; float totalTargetEne; float masaTargetEneThisCh[2]; float ismPreprocMtxNew[2][2]; float ismPreprocMtxIncrement[2][2]; float eneMove[2]; float enePreserve[2]; float ismRatioAcc; float remainderNormEne; float centeringFactor; float eneMoveThis; float enePreserveThis; float normVal; float eqVal; float outSlotRe[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float outSlotIm[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float newRatios[6]; float gainIsmThis; float gainMasaPow2; float nSlotDiv; float tempDivisor; float masaEneThisCh[2]; float ratioAccNewDivisor; gainMasaPow2 = 1.0f; if ( masaGainEdited ) { gainMasaPow2 = hMasaIsmData->gain_masa_edited_fx; gainMasaPow2 *= gainMasaPow2; } nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; nSlotDiv = 1.0f / ( (float) nSlots ); /* Determine panning gains and energies for each object */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { /* Get input and output panning gains */ ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], panGainsIn[ismDirIndex] ); if ( ismDirEdited[ismDirIndex] ) { ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism_edited[ismDirIndex], hMasaIsmData->elevation_ism_edited[ismDirIndex], panGainsOut[ismDirIndex] ); } else { /* When not edited, input and output pan gains are the same */ for ( ch = 0; ch < 2; ch++ ) { panGainsOut[ismDirIndex][ch] = panGainsIn[ismDirIndex][ch]; } } /* Determine pan enes */ for ( ch = 0; ch < 2; ch++ ) { panEnesOut[ismDirIndex][ch] = panGainsOut[ismDirIndex][ch] * panGainsOut[ismDirIndex][ch]; panEnesIn[ismDirIndex][ch] = panGainsIn[ismDirIndex][ch] * panGainsIn[ismDirIndex][ch]; } } /* Determine the highest band */ max_band = 0; #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif while ( max_band < MASA_FREQUENCY_BANDS && MASA_band_grouping_24[max_band] < nBins ) { max_band++; } #ifdef OBJ_EDITING_PARAMISM_BIN } else { while ( max_band < MAX_PARAM_ISM_NBANDS && hParamIsmDec->hParamIsm->band_grouping[max_band] < nBins ) { max_band++; } } #endif /* Init out array */ for ( int k = 0; k < nSlots; k++ ) { for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { set_zero( outSlotRe[ch][k], CLDFB_NO_CHANNELS_MAX ); set_zero( outSlotIm[ch][k], CLDFB_NO_CHANNELS_MAX ); } } /* Perform the processing in frequency bands */ for ( band_idx = 0; band_idx < max_band; band_idx++ ) { ratioAccOrig = 0.0f; ratioAccNew = 0.0f; ismRatioAcc = 0.0f; set_zero( subframeEneCh, 2 ); set_zero( ismPreprocMtxNew[0], 2 ); set_zero( ismPreprocMtxNew[1], 2 ); set_zero( eneMove, 2 ); set_zero( enePreserve, 2 ); #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif bin_lo = MASA_band_grouping_24[band_idx]; bin_hi = min( MASA_band_grouping_24[band_idx + 1], nBins ); #ifdef OBJ_EDITING_PARAMISM_BIN } else { bin_lo = hParamIsmDec->hParamIsm->band_grouping[band_idx]; bin_hi = min( hParamIsmDec->hParamIsm->band_grouping[band_idx + 1], nBins ); } #endif /* Determine transport normalized energies and subframe energy */ for ( slot = 0; slot < nSlots; slot++ ) { for ( ch = 0; ch < 2; ch++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { subframeEneCh[ch] += inRe_fx[ch][slot][bin] * inRe_fx[ch][slot][bin]; subframeEneCh[ch] += inIm_fx[ch][slot][bin] * inIm_fx[ch][slot][bin]; } } } subframeEne = subframeEneCh[0] + subframeEneCh[1]; totalTargetEneCh[0] = subframeEneCh[0]; totalTargetEneCh[1] = subframeEneCh[1]; masaEneThisCh[0] = subframeEneCh[0]; masaEneThisCh[1] = subframeEneCh[1]; /* Gain editing */ /* For each object, estimate new target energy per channel based on the applied gain */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { ratio = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; ratioAccOrig += ratio; /* Calculate MASA energy as a residual of original channel energies subtracted with ISM energies */ for ( ch = 0; ch < 2; ch++ ) { masaEneThisCh[ch] -= panEnesIn[ismDirIndex][ch] * ratio * subframeEne; } /* Calculate target energy, gained ratio for accumulation, and transports gains, if ism gain is edited */ if ( ismGainEdited[ismDirIndex] ) { gainIsmThis = hMasaIsmData->gain_ism_edited_fx[ismDirIndex]; /* ISM original energy */ ismEneThis = ratio * subframeEne; /* ISM target energy */ ismTargetEneThis = ( gainIsmThis * gainIsmThis ) * ismEneThis; ratio *= gainIsmThis * gainIsmThis; /* Determine panning energies and channel target energies */ for ( ch = 0; ch < 2; ch++ ) { ismTargetEneThisCh[ch] = panEnesIn[ismDirIndex][ch] * ismTargetEneThis; /* Ism target energy per channel */ totalTargetEneCh[ch] -= panEnesIn[ismDirIndex][ch] * ismEneThis; /* Reduce original ism energy */ totalTargetEneCh[ch] += ismTargetEneThisCh[ch]; /* Add ism target energy per channel */ } /* If separated ism edited, apply gain directly to the separated ism */ if ( ismDirIndex == hMasaIsmData->idx_separated_ism ) { /* Separated object gaining is done elsewhere with DIRAC renderer */ if ( st_ivas->renderer_type != RENDERER_DIRAC ) { /* Gain transport channel of separated ism */ for ( slot = 0; slot < nSlots; slot++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { inRe_fx[2][slot][bin] = gainIsmThis * inRe_fx[2][slot][bin]; inIm_fx[2][slot][bin] = gainIsmThis * inIm_fx[2][slot][bin]; } } } } } ratioAccNew += ratio; } #ifdef OBJ_EDITING_PARAMISM_BIN if ( masaIsmMode ) { #endif /* MASA original ratios */ ratio = hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin_lo] + hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin_lo]; ratioAccOrig += ratio; /* Estimate MASA original energies and determine adjusted target energies and gained ratio for accumulation, if a gain is applied to MASA */ if ( masaGainEdited ) { /* Gained MASA ratio */ ratio *= gainMasaPow2; /* Calculate MASA target energies and add to total target energy estimation */ for ( ch = 0; ch < 2; ch++ ) { masaEneThisCh[ch] = fmaxf( masaEneThisCh[ch], 0.0f ); /* MASA original energy per channel */ masaTargetEneThisCh[ch] = gainMasaPow2 * masaEneThisCh[ch]; /* MASA target energy per channel */ totalTargetEneCh[ch] -= masaEneThisCh[ch]; /* Reduce original energy per channel */ totalTargetEneCh[ch] += masaTargetEneThisCh[ch]; /* Add target energy per channel */ } } ratioAccNew += ratio; #ifdef OBJ_EDITING_PARAMISM_BIN } #endif /* Limit target energies to non-negative values */ for ( ch = 0; ch < 2; ch++ ) { totalTargetEneCh[ch] = max( totalTargetEneCh[ch], 0.0f ); } /* Diffuse ratio accumulation based on gaining */ if ( masaGainEdited ) { ratioAccNew += gainMasaPow2 * ( 1 - ratioAccOrig ); } else { ratioAccNew += ( 1.0f - ratioAccOrig ); } ratioAccNewDivisor = 1.0f / fmaxf( 1e-12f, ratioAccNew ); /* New target total energy ratio divider */ /* Determine and process object energy ratios based on gaining */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { newRatios[ismDirIndex + 2] = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; /* Determine original object energy ratio */ if ( ismGainEdited[ismDirIndex] ) { gainIsmThis = hMasaIsmData->gain_ism_edited_fx[ismDirIndex]; newRatios[ismDirIndex + 2] *= ( gainIsmThis * gainIsmThis ); /* Gain original object energy ratio, if edited */ } newRatios[ismDirIndex + 2] *= ratioAccNewDivisor; /* Divide with new target total ratio */ } /* Determine and process MASA energy ratios based on gaining */ newRatios[0] = hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin_lo]; newRatios[1] = hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin_lo]; if ( masaGainEdited ) { newRatios[0] *= gainMasaPow2; newRatios[1] *= gainMasaPow2; } newRatios[0] *= ratioAccNewDivisor; newRatios[1] *= ratioAccNewDivisor; /* Set adjusted energy ratios */ for ( bin = bin_lo; bin < bin_hi; bin++ ) { for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin] = newRatios[ismDirIndex + 2]; } hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin] = newRatios[0]; hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin] = newRatios[1]; } /* Direction editing */ /* Determine new energetic values after gaining */ totalTargetEne = totalTargetEneCh[0] + totalTargetEneCh[1]; tempDivisor = 1.0f / fmaxf( 1e-12f, totalTargetEne ); normEnes[0] = totalTargetEneCh[0] * tempDivisor; normEnes[1] = totalTargetEneCh[1] * tempDivisor; /* For each ismDir, determine moved and preserve energy ratio per channel */ for ( ismDirIndex = 0; ismDirIndex < n_ism; ismDirIndex++ ) { ratio = hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin_lo]; ismRatioAcc += ratio; if ( enableCentering ) { centeringFactor = fmaxf( 0.0f, 2.0f * fabsf( panEnesIn[ismDirIndex][0] - panEnesOut[ismDirIndex][0] ) - 1.0f ); for ( ch = 0; ch < 2; ch++ ) { panEnesOut[ismDirIndex][ch] *= ( 1.0f - centeringFactor ); panEnesOut[ismDirIndex][ch] += 0.5f * centeringFactor; } } for ( ch = 0; ch < 2; ch++ ) { eneMoveThis = fmaxf( 0.0f, panEnesIn[ismDirIndex][ch] - panEnesOut[ismDirIndex][ch] ); enePreserveThis = panEnesIn[ismDirIndex][ch] - eneMoveThis; eneMove[ch] += ratio * eneMoveThis; enePreserve[ch] += ratio * enePreserveThis; /* Subtract object parts from normEnes */ normEnes[ch] -= panEnesIn[ismDirIndex][ch] * ratio; } } /* Any remaining (non-object) energy is set to be preserved at both channels */ remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); /* Normalize */ for ( ch = 0; ch < 2; ch++ ) { enePreserve[ch] += fmaxf( 0.0f, normEnes[ch] + remainderNormEne / 2.0f ); normVal = 1.0f / fmaxf( EPSILON, eneMove[ch] + enePreserve[ch] ); normVal *= fminf( 10.0f, totalTargetEneCh[ch] / fmaxf( EPSILON, subframeEneCh[ch] ) ); eneMove[ch] *= normVal; enePreserve[ch] *= normVal; } /* Temporally average target energy */ hMasaIsmData->eneOrigIIR_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->eneOrigIIR_fx[band_idx] += totalTargetEne; /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix for * gaining objects and moving objects between left and right */ for ( ch = 0; ch < 2; ch++ ) { hMasaIsmData->eneMoveIIR_fx[ch][band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->eneMoveIIR_fx[ch][band_idx] += eneMove[ch] * totalTargetEne; hMasaIsmData->enePreserveIIR_fx[ch][band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->enePreserveIIR_fx[ch][band_idx] += enePreserve[ch] * totalTargetEne; normVal = 1.0f / fmaxf( EPSILON, hMasaIsmData->eneOrigIIR_fx[band_idx] ); ismPreprocMtxNew[ch][ch] = fminf( 4.0f, sqrtf( hMasaIsmData->enePreserveIIR_fx[ch][band_idx] * normVal ) ); ismPreprocMtxNew[1 - ch][ch] = fminf( 4.0f, sqrtf( hMasaIsmData->eneMoveIIR_fx[ch][band_idx] * normVal ) ); } /* Get increment value for temporal interpolation */ for ( inCh = 0; inCh < 2; inCh++ ) { for ( outCh = 0; outCh < 2; outCh++ ) { ismPreprocMtxIncrement[outCh][inCh] = ( ismPreprocMtxNew[outCh][inCh] - hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx] ) * nSlotDiv; } } /* Mix signals */ hMasaIsmData->preprocEneTarget_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->preprocEneRealized_fx[band_idx] *= STEREO_PREPROCESS_IIR_FACTOR; hMasaIsmData->preprocEneTarget_fx[band_idx] += totalTargetEne; for ( outCh = 0; outCh < 2; outCh++ ) { for ( slot = 0; slot < nSlots; slot++ ) { for ( inCh = 0; inCh < 2; inCh++ ) { hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx] += ismPreprocMtxIncrement[outCh][inCh]; for ( bin = bin_lo; bin < bin_hi; bin++ ) { outSlotRe[outCh][slot][bin] += inRe_fx[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx]; outSlotIm[outCh][slot][bin] += inIm_fx[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][band_idx]; } } for ( bin = bin_lo; bin < bin_hi; bin++ ) { hMasaIsmData->preprocEneRealized_fx[band_idx] += ( outSlotRe[outCh][slot][bin] * outSlotRe[outCh][slot][bin] ) + ( outSlotIm[outCh][slot][bin] * outSlotIm[outCh][slot][bin] ); } } } eqVal = fminf( 4.0f, sqrtf( hMasaIsmData->preprocEneTarget_fx[band_idx] / fmaxf( 1e-12f, hMasaIsmData->preprocEneRealized_fx[band_idx] ) ) ); for ( ch = 0; ch < 2; ch++ ) { for ( slot = 0; slot < nSlots; slot++ ) { for ( bin = bin_lo; bin < bin_hi; bin++ ) { inRe_fx[ch][slot][bin] = outSlotRe[ch][slot][bin] * eqVal; inIm_fx[ch][slot][bin] = outSlotIm[ch][slot][bin] * eqVal; } } } } #ifdef OBJ_EDITING_PARAMISM_BIN if ( !masaIsmMode ) { int16_t obj_idx1, obj_idx2; for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { bin_lo = hParamIsmDec->hParamIsm->band_grouping[band_idx]; bin_hi = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; obj_idx1 = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]; obj_idx2 = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]; for ( bin = bin_lo; bin < bin_hi; bin++ ) { hSpatParamRendCom->energy_ratio1_fx[dirac_read_idx][bin] = hMasaIsmData->energy_ratio_ism_fx[obj_idx1][dirac_read_idx][bin]; hSpatParamRendCom->energy_ratio2_fx[dirac_read_idx][bin] = hMasaIsmData->energy_ratio_ism_fx[obj_idx2][dirac_read_idx][bin]; } } } #endif assert( 0 && "Insert proper basop code here!" ); } return; Loading