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

Subfunctions for ivas_td_binaural_open converted to fxd point.

[x]Few functions added/cleaned up:
TDREND_MIX_Init,TDREND_MIX_SetDistAttenModel,TDREND_SRC_Init,
TDREND_SRC_SPATIAL_Init,TDREND_SRC_REND_Init,TDREND_SPATIAL_VecInit,
TDREND_MIX_AddSrc_fx,TDREND_MIX_SRC_SetPos,TDREND_MIX_SRC_SetPlayState_fx,
TDREND_SRC_SPATIAL_SetDirAtten_fx,TDREND_MIX_SRC_SetDirAtten_fx
[x] Few BASOP updates and initializations.
parent 594a1ac4
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -6051,6 +6051,14 @@ void ivas_omasa_modify_masa_energy_ratios(
/*----------------------------------------------------------------------------------*
 * TD Binaural Object renderer
 *----------------------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
ivas_error ivas_td_binaural_open_fx(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure  */
    Word16 * SrcInd,         /*Temporarily used to store the updated value of SrcInd*/
    Word16 *num_src,
    Word16 *directivity_fx
);
#endif // IVAS_FLOAT_FIXED

ivas_error ivas_td_binaural_open(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
+82 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#include "prot_fx2.h"
#endif // IVAS_FLOAT_FIXED

/*-------------------------------------------------------------------------*
@@ -196,10 +197,91 @@ static ivas_error ivas_ism_bitrate_switching_dec(
            /* Open the TD Binaural renderer */
            if ( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL )
            {
#ifdef IVAS_FLOAT_FIXED
#if 1 /*Cleanup changes: float to fixed */
                Word16 directivity_fx[IVAS_MAX_NUM_OBJECTS * 3];
                Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
                Word16 num_src;
                FOR( Word16 i = 0; i < 4; i++ )
                {
                    directivity_fx[i * 3] = floatToFixed( st_ivas->hRenderConfig->directivity[i * 3], 6 );
                    directivity_fx[i * 3 + 1] = floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 1], 6 );
                    directivity_fx[i * 3 + 2] = floatToFixed( st_ivas->hRenderConfig->directivity[i * 3 + 2], 15 );
                }
#endif
                IF ( ( error = ivas_td_binaural_open_fx( st_ivas , SrcInd,&num_src, directivity_fx) ) != IVAS_ERR_OK )
                {
                    return error;
                }
#if 1 // Cleanup changes for ivas_td_binaural_open: fixed to float
                st_ivas->hBinRendererTd->Gain = 1.0f; /*1.0f Q15*/
                fixedToFloat_arr( st_ivas->hBinRendererTd->Listener_p->Pos_fx, st_ivas->hBinRendererTd->Listener_p->Pos, 15, 3 );
                fixedToFloat_arr( st_ivas->hBinRendererTd->Listener_p->Vel_fx, st_ivas->hBinRendererTd->Listener_p->Vel, 15, 3 );
                fixedToFloat_arr( st_ivas->hBinRendererTd->Listener_p->Front_fx, st_ivas->hBinRendererTd->Listener_p->Front, 15, 3 );
                fixedToFloat_arr( st_ivas->hBinRendererTd->Listener_p->Up_fx, st_ivas->hBinRendererTd->Listener_p->Up, 15, 3 );
                fixedToFloat_arr( st_ivas->hBinRendererTd->Listener_p->Right_fx, st_ivas->hBinRendererTd->Listener_p->Right, 15, 3 );
                TDREND_DirAtten_t *DirAtten_p = st_ivas->hBinRendererTd->DirAtten_p;
                DirAtten_p->ConeInnerAngle = fixedToFloat( DirAtten_p->ConeInnerAngle_fx, 6 );
                DirAtten_p->ConeOuterAngle = fixedToFloat( DirAtten_p->ConeOuterAngle_fx, 6 );
                DirAtten_p->ConeOuterGain = fixedToFloat( DirAtten_p->ConeOuterGain_fx, 15 );
                Word16 nchan_rend = num_src;
                IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
                {
                    nchan_rend--; /* Skip LFE channel -- added to the others */
                }
                FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
                {
                    TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
                    IF( Src_p->SrcSpatial_p != NULL )
                    {
                        Src_p->SrcSpatial_p->DirAtten.ConeInnerAngle = 360.0f;
                        Src_p->SrcSpatial_p->DirAtten.ConeOuterAngle = 360.0f;
                        Src_p->SrcSpatial_p->DirAtten.ConeOuterGain = 1.0f;
                        Src_p->SrcSpatial_p->DistAtten.RefDist = 1.0f;
                        Src_p->SrcSpatial_p->DistAtten.MaxDist = 15.75f; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */
                        Src_p->SrcSpatial_p->DistAtten.RollOffFactor = 1.0f;
                        FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ )
                        {
                            fixedToFloat_arr( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, 15, 3 );
                            fixedToFloat_arr( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, 15, 3 );
                        }
                    }
                    FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ )
                    {
                        Src_p->SrcRend_p->SrcGainMin_p[nC] = 0.0f;
                        Src_p->SrcRend_p->SrcGain_p[nC] = 1.0f;
                        Src_p->SrcRend_p->SrcGainMax_p[nC] = 1.0f;
                    }
                    FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ )
                    {
                        Src_p->SrcRend_p->DirGain_p[nC] = 1.0f;
                        Src_p->SrcRend_p->DistGain_p[nC] = 1.0f;
                    }
                    set_f( Src_p->mem_itd, 0.0f, ITD_MEM_LEN );
                    set_f( Src_p->mem_hrf_left, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 );
                    set_f( Src_p->mem_hrf_right, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 );
                    set_f( Src_p->hrf_left_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH );
                    set_f( Src_p->hrf_right_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH );
                    Src_p->hrf_left_prev[0] = 1;
                    Src_p->hrf_right_prev[0] = 1;
                    Src_p->azim_prev = 0.0f;
                    Src_p->elev_prev = 0.0f;
                    Src_p->Gain = 1.0f;
                    Src_p->prevGain = 1.0f;
                    TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
                    fixedToFloat_arr( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, 15, 3 );
                    fixedToFloat_arr( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, 15, 3 );
                    SrcSpatial_p->DirAtten.ConeInnerAngle = fixedToFloat( SrcSpatial_p->DirAtten.ConeInnerAngle_fx, 6 );
                    SrcSpatial_p->DirAtten.ConeOuterAngle = fixedToFloat( SrcSpatial_p->DirAtten.ConeOuterAngle_fx, 6 );
                    SrcSpatial_p->DirAtten.ConeOuterGain = fixedToFloat( SrcSpatial_p->DirAtten.ConeOuterGain_fx, 15 );
                }
#endif
#else
                if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
#endif // IVAS_FLOAT_FIXED
                if ( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
                {
                    if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
+18 −0
Original line number Diff line number Diff line
@@ -51,6 +51,24 @@
 *
 * Open and initialize TD Object binaural renderer
 *---------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
ivas_error ivas_td_binaural_open_fx(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure  */
    Word16 * SrcInd,         /*Temporarily used to store the updated value of SrcInd*/
    Word16 *num_src,
    Word16 *directivity_fx
)
{
    *num_src = st_ivas->nchan_transport;
    move16();
    IF ( EQ_16( st_ivas->ism_mode , ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode , ISM_SBA_MODE_DISC ) )
    {
        *num_src = st_ivas->nchan_ism;
        move16();
    }
    return ivas_td_binaural_open_unwrap_fx( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, *num_src, st_ivas->ivas_format, st_ivas->transport_config, directivity_fx, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns, SrcInd );
}
#endif // IVAS_FLOAT_FIXED

ivas_error ivas_td_binaural_open(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
+221 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#include "prot_fx1.h"
#include "prot_fx2.h"
#include "debug.h"
#include "ivas_rom_com_fx.h"
#define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) )
#define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) )
#endif
@@ -55,6 +56,12 @@ static void TDREND_Clear_Update_flags( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRe

static void angles_to_vec( const float radius, const float azimuth, const float elevation, float *vec );

static void angles_to_vec_fx(
    const Word16 radius,    /* i  : radius                              */
    const Word32 azimuth,   /* i  : Azimuth angle                       */
    const Word32 elevation, /* i  : Elevation angle                     */
    Word16 *vec             /* o  : Pos/Dir vector                      */
);

/*---------------------------------------------------------------------*
 * ivas_td_binaural_open_unwrap()
@@ -62,6 +69,203 @@ static void angles_to_vec( const float radius, const float azimuth, const float
 * Call TD open/init function without st_ivas
 *---------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
ivas_error ivas_td_binaural_open_unwrap_fx(
    TDREND_HRFILT_FiltSet_t **hHrtfTD,                  /* i/o: HR filter model (from file or NULL) */
    const Word32 output_Fs,                             /* i  : Output sampling rate                */
    const Word16 nchan_transport,                       /* i  : Number of channels                  */
    const IVAS_FORMAT ivas_format,                      /* i  : IVAS format (ISM/MC)                */
    const AUDIO_CONFIG transport_config,                /* i  : Transport configuration             */
    const Word16 *directivity,                           /* i  : Directivity pattern (used for ISM)  */
    const IVAS_OUTPUT_SETUP hTransSetup,                /* i  : Loudspeaker layout                  */
    BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o  : TD renderer handle                  */
    Word32 *binaural_latency_ns,                         /* i  : Binauralization delay               */
    Word16 *SrcInd 
)
{
    BINAURAL_TD_OBJECT_RENDERER_HANDLE pBinRendTd;
    TDREND_PosType_t PosType;
    Word16 nS;
    const Word32 *ls_azimuth_fx, *ls_elevation_fx;
    Word16 Pos_fx[3];
    Word16 Dir_fx[3];
    TDREND_DirAtten_t *DirAtten_p;
    Word16 nchan_rend;
    ivas_error error;

    error = IVAS_ERR_OK;

    IF( ( pBinRendTd = malloc( sizeof( BINAURAL_TD_OBJECT_RENDERER ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    IF( ( pBinRendTd->TdRend_MixSpatSpec_p = malloc( sizeof( TDREND_MixSpatSpec_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    IF( ( pBinRendTd->DirAtten_p = malloc( sizeof( TDREND_DirAtten_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }
    IF( ( pBinRendTd->Listener_p = malloc( sizeof( TDREND_MIX_Listener_t ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD renderer\n" ) );
    }

    pBinRendTd->NumOfSrcs = 0;
    pBinRendTd->MaxSrcInd = -1;

    move16();
    move16();
    /* Mixer spatial setup */
    pBinRendTd->TdRend_MixSpatSpec_p->UseCommonDistAttenModel = TRUE;
    pBinRendTd->TdRend_MixSpatSpec_p->DistAttenModel = 0; /* 0=Turned off, else use TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED */
    move16();

    IF( ( error = TDREND_MIX_Init_fx( pBinRendTd, hHrtfTD, pBinRendTd->TdRend_MixSpatSpec_p, output_Fs ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    /* Set the attenuation (or can set MixSpatSpec.DistAttenModel above) */
    IF( ( error = TDREND_MIX_SetDistAttenModel( pBinRendTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    /* Add sources to module and mixer, headphones */
    PosType = TDREND_POSTYPE_ABSOLUTE; /* or TDREND_POSTYPE_RELATIVE_TO_LISTENER */

    nchan_rend = nchan_transport;
    move16();
    IF( EQ_16( ivas_format, MC_FORMAT ) && NE_16( transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    {
        nchan_rend--; /* Skip LFE channel -- added to the others */
    }

    FOR( nS = 0; nS < nchan_rend; nS++ )
    {
        IF( ( error = TDREND_MIX_AddSrc_fx( pBinRendTd, &SrcInd[nS], PosType ) ) != IVAS_ERR_OK )
        {
            return error;
        }
    }
    IF( EQ_16( ivas_format, MC_FORMAT ) )
    {
        SWITCH( transport_config )
        {
            case IVAS_AUDIO_CONFIG_5_1:
                ls_azimuth_fx = ls_azimuth_CICP6_fx;
                ls_elevation_fx = ls_elevation_CICP6_fx;
                BREAK;
            case IVAS_AUDIO_CONFIG_7_1:
                ls_azimuth_fx = ls_azimuth_CICP12_fx;
                ls_elevation_fx = ls_elevation_CICP12_fx;
                BREAK;
            case IVAS_AUDIO_CONFIG_5_1_2:
                ls_azimuth_fx = ls_azimuth_CICP14_fx;
                ls_elevation_fx = ls_elevation_CICP14_fx;
                BREAK;
            case IVAS_AUDIO_CONFIG_5_1_4:
                ls_azimuth_fx = ls_azimuth_CICP16_fx;
                ls_elevation_fx = ls_elevation_CICP16_fx;
                BREAK;
            case IVAS_AUDIO_CONFIG_7_1_4:
                ls_azimuth_fx = ls_azimuth_CICP19_fx;
                ls_elevation_fx = ls_elevation_CICP19_fx;
                BREAK;
            case IVAS_AUDIO_CONFIG_LS_CUSTOM:
                ls_azimuth_fx = hTransSetup.ls_azimuth_fx;
                ls_elevation_fx = hTransSetup.ls_elevation_fx;
                BREAK;
            default:
                ls_azimuth_fx = NULL;
                ls_elevation_fx = NULL;
        }

        DirAtten_p = pBinRendTd->DirAtten_p;

        FOR( nS = 0; nS < nchan_rend; nS++ )
        {
            /* Set source positions according to loudspeaker layout */
            angles_to_vec_fx( 32767, ls_azimuth_fx[nS], ls_elevation_fx[nS], Pos_fx );

            Dir_fx[0] = 32767;
            move16();
            Dir_fx[1] = 0;
            move16();
            Dir_fx[2] = 0;
            move16();
            /* Source directivity info */
            DirAtten_p->ConeInnerAngle_fx = 23040;
            move16();
            DirAtten_p->ConeOuterAngle_fx = 23040;
            move16();
            DirAtten_p->ConeOuterGain_fx = 32767;
            move16();

            TDREND_SRC_SPATIAL_t *SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p;
            // floatToFixed_arr( SrcSpatial_p->Pos_p, SrcSpatial_p->Pos_p_fx, 15, 3 );
            IF( ( error = TDREND_MIX_SRC_SetPos_fx( pBinRendTd, nS, Pos_fx ) ) != IVAS_ERR_OK )
            {
                return error;
            }
            IF( ( error = TDREND_MIX_SRC_SetDir_fx( pBinRendTd, nS, Dir_fx ) ) != IVAS_ERR_OK )
            {
                return error;
            }
            IF( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ) != IVAS_ERR_OK )
            {
                return error;
            }
            /*TDREND_SRC_SPATIAL_t **/ SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p;
            IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }

    IF( EQ_16( ivas_format, ISM_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) )
    {
        DirAtten_p = pBinRendTd->DirAtten_p;

        FOR( nS = 0; nS < nchan_rend; nS++ )
        {
            IF( NULL == directivity )
            {
                DirAtten_p->ConeInnerAngle_fx = 23040; /* Front cone */
                DirAtten_p->ConeOuterAngle_fx = 23040; /* Back cone */
                DirAtten_p->ConeOuterGain_fx = 32767;  /* Back attenuation */
            }
            ELSE
            {
                DirAtten_p->ConeInnerAngle_fx = directivity[nS * 3];
                DirAtten_p->ConeOuterAngle_fx = directivity[nS * 3 + 1];
                DirAtten_p->ConeOuterGain_fx = directivity[nS * 3 + 2];
            }
            move16();
            move16();
            move16();
            IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }

    *hBinRendererTd = pBinRendTd;

    IF( NE_16( ivas_format, MASA_ISM_FORMAT ) && NE_16( ivas_format, SBA_ISM_FORMAT ) )
    {
        // To be removed later
        ( *hBinRendererTd )->HrFiltSet_p->latency_s_fx = floatToFixed( ( *hBinRendererTd )->HrFiltSet_p->latency_s, 31 );
        *binaural_latency_ns = Mult_32_32( ( *hBinRendererTd )->HrFiltSet_p->latency_s_fx, 1000000000 );
    }

    return error;
}
#endif // IVAS_FLOAT_FIXED
ivas_error ivas_td_binaural_open_unwrap(
    TDREND_HRFILT_FiltSet_t **hHrtfTD,                  /* i/o: HR filter model (from file or NULL) */
    const int32_t output_Fs,                            /* i  : Output sampling rate                */
@@ -817,6 +1021,23 @@ ivas_error ivas_td_binaural_renderer_ext(
 *
 * Convert azimuth and elevation angles to position/orientation vector
 *---------------------------------------------------------------------*/
#ifdef IVAS_FLOAT_FIXED
static void angles_to_vec_fx(
    const Word16 radius,    /* i  : radius                              */
    const Word32 azimuth,   /* i  : Azimuth angle                       */
    const Word32 elevation, /* i  : Elevation angle                     */
    Word16 *vec             /* o  : Pos/Dir vector                      */
)
{
    Word16 elevation_fx, azimuth_fx;
    elevation_fx =(Word16)L_shr( Mult_32_16( elevation, 91 ), 22 );
    azimuth_fx = (Word16)L_shr( Mult_32_16( azimuth, 91 ), 22 );
    vec[0] = mult( radius, mult( getCosWord16R2( imult1616( elevation_fx, 91 ) ), getCosWord16R2( imult1616( azimuth_fx, 91 ) ) ) );
    vec[1] = mult( radius, mult( getCosWord16R2( imult1616( elevation_fx, 91 ) ), getSineWord16R2( imult1616( azimuth_fx, 91 ) ) ) );
    vec[2] = mult( radius, getSineWord16R2( imult1616( elevation_fx, 91 ) ) );
    return;
}
#endif // IVAS_FLOAT_FIXED

static void angles_to_vec(
    const float radius,    /* i  : radius                              */
+196 −7

File changed.

Preview size limit exceeded, changes collapsed.

Loading