Commit 999f17fd authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

add external renderer support for mono/stereo upmix

parent 964def59
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@

/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
#define FIX_1466_EXTREND                                /* FhG: issue 1466: enable rendering of mono/stereo to other formats in the external renderer */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */


+113 −0
Original line number Diff line number Diff line
@@ -1262,11 +1262,26 @@ static bool isIoConfigPairSupported(
    const AUDIO_CONFIG inConfig,
    const AUDIO_CONFIG outConfig )
{
#ifdef FIX_1466_EXTREND
    /* input config cannot be binaural */
    if ( ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) &&
         ( inConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && inConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    {
        return false;
    }

    /* output config cannot be object based */
    if ( getAudioConfigType( outConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED )
    {
        return false;
    }
#else
    /* Rendering mono or stereo to binaural is not supported */
    if ( ( inConfig == IVAS_AUDIO_CONFIG_MONO || inConfig == IVAS_AUDIO_CONFIG_STEREO ) && getAudioConfigType( outConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL )
    {
        return false;
    }
#endif

    /* If not returned so far, config pair is supported */
    return true;
@@ -2208,15 +2223,47 @@ static ivas_error updateMcPanGainsForAmbiOut(
{
    int16_t ch_in, ch_out, lfeIdx;
    int16_t numNonLfeInChannels, outAmbiOrder;
#ifdef FIX_1466_EXTREND
    AUDIO_CONFIG inConfig;
#endif
    const float *spkAzi, *spkEle;
    ivas_error error;

#ifdef FIX_1466_EXTREND
    inConfig = inputMc->base.inConfig;

#endif
    if ( ( error = getAmbisonicsOrder( outConfig, &outAmbiOrder ) ) != IVAS_ERR_OK )
    {
        return error;
    }

#ifdef FIX_1466_EXTREND
    if ( inConfig == IVAS_AUDIO_CONFIG_MONO ||
         inConfig == IVAS_AUDIO_CONFIG_STEREO )
    {
        setZeroPanMatrix( inputMc->panGains );
        if ( inConfig == IVAS_AUDIO_CONFIG_MONO )
        {
            /* W = Mono */
            inputMc->panGains[0][0] = 1.f;
        }
        else
        {
            /* W = 0.5 * ( L + R ) */
            inputMc->panGains[0][0] = 0.5f;
            inputMc->panGains[0][1] = 0.5f;
            /* Y = 0.5 * ( L - R ) */
            inputMc->panGains[1][0] = 0.5f;
            inputMc->panGains[1][1] = -0.5f;
        }

        return IVAS_ERR_OK;
    }
    else if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM )
#else
    if ( inputMc->base.inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM )
#endif
    {
        if ( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ) != IVAS_ERR_OK )
        {
@@ -2272,6 +2319,26 @@ static ivas_error updateMcPanGainsForAmbiOut(
    return IVAS_ERR_OK;
}

#ifdef FIX_1466_EXTREND
static ivas_error updateMcPanGainsForBinauralOut(
    input_mc *inputMc )
{
    setZeroPanMatrix( inputMc->panGains );
    if ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO )
    {
        inputMc->panGains[0][0] = ( inputMc->nonDiegeticPanGain + 1.f ) * 0.5f;
        inputMc->panGains[0][1] = 1.f - inputMc->panGains[0][0];
    }
    else
    {
        /* stereo passthrough */
        inputMc->panGains[0][0] = 1.f;
        inputMc->panGains[1][1] = 1.f;
    }

    return IVAS_ERR_OK;
}
#endif

static ivas_error updateMcPanGains(
    input_mc *inputMc,
@@ -2293,6 +2360,15 @@ static ivas_error updateMcPanGains(
            error = updateMcPanGainsForAmbiOut( inputMc, outConfig );
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL:
#ifdef FIX_1466_EXTREND
            if ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO || inputMc->base.inConfig == IVAS_AUDIO_CONFIG_STEREO )
            {
                error = updateMcPanGainsForBinauralOut( inputMc );
                break;
            }

            /* not mono or stereo */
#endif
            switch ( outConfig )
            {
                case IVAS_AUDIO_CONFIG_BINAURAL:
@@ -2351,6 +2427,13 @@ static ivas_error initMcBinauralRendering(
    int32_t binauralDelayNs;
    int32_t outSampleRate;
    int8_t useTDRend;
#ifdef FIX_1466_EXTREND

    if ( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO || inputMc->base.inConfig == IVAS_AUDIO_CONFIG_STEREO )
    {
        return IVAS_ERR_OK;
    }
#endif

    /* Allocate TD binaural renderer for custom loudspeaker layouts (regardless of headrotation)
      or planar MC layouts with headrotation, CREND for the rest */
@@ -6246,6 +6329,27 @@ static ivas_error renderActiveInputsIsm(
    return IVAS_ERR_OK;
}

#ifdef FIX_1466_EXTREND
static void renderMonoStereoToBinaural(
    const input_mc *mcInput,
    IVAS_REND_AudioBuffer outAudio )
{
    int16_t i;
    IVAS_REND_AudioBuffer inAudio;

    push_wmops( "renderMonoStereoToBinaural" );
    inAudio = mcInput->base.inputBuffer;

    for ( i = 0; i < inAudio.config.numChannels; ++i )
    {
        renderBufferChannel( inAudio, i, mcInput->panGains[i], outAudio );
    }

    pop_wmops();

    return;
}
#endif

static ivas_error renderLfeToBinaural(
    const input_mc *mcInput,
@@ -6846,6 +6950,15 @@ static ivas_error renderInputMc(
            renderMcToSba( mcInput, outAudio );
            break;
        case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL:
#ifdef FIX_1466_EXTREND
            if ( mcInput->base.inConfig == IVAS_AUDIO_CONFIG_MONO || mcInput->base.inConfig == IVAS_AUDIO_CONFIG_STEREO )
            {
                renderMonoStereoToBinaural( mcInput, outAudio );
                break;
            }

            /* not mono or stereo */
#endif
            switch ( outConfig )
            {
                case IVAS_AUDIO_CONFIG_BINAURAL: