Commit 0a2166ca authored by vaclav's avatar vaclav
Browse files

Merge remote-tracking branch 'remotes/origin/main' into revision_of_todos

parents 105019c1 c7f3151e
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -202,14 +202,18 @@
    <ClCompile Include="..\lib_rend\ivas_sba_rendering.c" />
    <ClCompile Include="..\lib_rend\ivas_allrad_dec.c" />
    <ClCompile Include="..\lib_rend\ivas_crend.c" />
    <ClCompile Include="..\lib_rend\ivas_dirac_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_efap.c" />
    <ClCompile Include="..\lib_rend\ivas_limiter.c" />
    <ClCompile Include="..\lib_rend\ivas_masa_merge.c" />
    <ClCompile Include="..\lib_rend\ivas_mcmasa_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_hrFilt.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_mix.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_sfx.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_sources.c" />
    <ClCompile Include="..\lib_rend\ivas_objectRenderer_vec.c" />
    <ClCompile Include="..\lib_rend\ivas_omasa_ana.c" />
    <ClCompile Include="..\lib_rend\ivas_orient_trk.c" />
    <ClCompile Include="..\lib_rend\ivas_output_init.c" />
    <ClCompile Include="..\lib_rend\ivas_render_config.c" />
+173 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@
#include "ism_file_reader.h"
#include "ls_custom_file_reader.h"
#include "masa_file_reader.h"
#ifdef MASA_PREREND
#include "masa_file_writer.h"
#endif
#include "prot.h"
#include "render_config_reader.h"
#include "wmc_auto.h"
@@ -443,6 +446,9 @@ static int16_t getTotalNumInChannels(
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }
#ifdef MASA_PREREND
        IVAS_REND_GetNumAllObjects( hIvasRend, &numInputChannels ); /* In case of MASA output, modify the numInputChannels to contain all objects. Otherwise, keep the original value. */
#endif
        totalNumInChannels += numInputChannels;
    }

@@ -571,6 +577,9 @@ int main(
#endif
    RenderConfigReader *renderConfigReader = NULL;
    MasaFileReader *masaReaders[RENDERER_MAX_MASA_INPUTS];
#ifdef MASA_PREREND
    MasaFileWriter *masaWriter = NULL;
#endif
    IVAS_MASA_METADATA_HANDLE hMasaMetadata[RENDERER_MAX_MASA_INPUTS];
    char audioFilePath[FILENAME_MAX];
    AudioFileReader *audioReader = NULL;
@@ -721,6 +730,26 @@ int main(
        setupWithSingleFormatInput( args, audioFilePath, positionProvider, masaReaders );
    }

#ifdef MASA_PREREND
    /* Check that there is allowed configuration for MASA format output */
    if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
    {
        if ( args.inConfig.numMasaBuses == 0 )
        {
            fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
            fprintf( stderr, "\nMASA input is missing\n" );
            exit( -1 );
        }

        if ( args.inConfig.numAudioObjects == 0 && args.inConfig.numMultiChannelBuses == 0 && args.inConfig.numAmbisonicsBuses == 0 )
        {
            fprintf( stderr, "\nInvalid configuration - Merging to MASA output requires MASA input and at least one another input to be present\n" );
            fprintf( stderr, "\nNo object, multi-channel, or Ambisonic input present.\n" );
            exit( -1 );
        }
    }
#endif

    if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "Error opening file: %s\n", audioFilePath );
@@ -827,6 +856,25 @@ int main(
        }
    }

#ifdef MASA_PREREND
    /* Set up MASA writer for MASA output */
    if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
    {
        MasaFileWriter_open( args.outputFilePath, true, &masaWriter ); /* No delay for audio in renderer, so calling metadata writer in delayCompensated mode, i.e., no delay applied to meta */
        if ( masaWriter == NULL )
        {
            fprintf( stderr, "Could not open MASA metadata file %s\n", args.outputFilePath );
            exit( -1 );
        }
    }

    /* Set the total number of objects */
    if ( args.inConfig.numAudioObjects > 0 )
    {
        IVAS_REND_SetTotalNumberOfObjects( hIvasRend, args.inConfig.numAudioObjects );
    }
#endif

    IVAS_REND_LfePanMtx lfePanMatrix;

    /* parse input LFE panning matrix */
@@ -937,6 +985,14 @@ int main(
            fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
            exit( -1 );
        }

#ifdef MASA_PREREND
        /* With MASA output, all objects are handled at once, so add only one input having all objects in it */
        if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
        {
            break;
        }
#endif
    }

    for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
@@ -1165,6 +1221,43 @@ int main(

        for ( i = 0; i < args.inConfig.numAudioObjects; ++i )
        {
#ifdef MASA_PREREND
            if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
            {
                if ( i == 0 )
                {
                    IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, args.inConfig.numAudioObjects );

                    if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                        exit( -1 );
                    }
                }

                if ( ( error = IVAS_REND_FeedInputObjectMetadataToOMasa( hIvasRend, i, mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
            else
            {
                IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );

                if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }

                if ( ( error = IVAS_REND_FeedInputObjectMetadata( hIvasRend, ismIds[i], mtdBuffer.positions[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                    exit( -1 );
                }
            }
#else
            IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );

            if ( ( error = IVAS_REND_FeedInputAudio( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
@@ -1178,6 +1271,7 @@ int main(
                fprintf( stderr, "Error: %s\n", ivas_error_to_string( error ) );
                exit( -1 );
            }
#endif
        }

        for ( i = 0; i < args.inConfig.numAmbisonicsBuses; ++i )
@@ -1269,6 +1363,82 @@ int main(
            delayNumSamples -= (int16_t) outBufferSize;
        }

#ifdef MASA_PREREND
        /* Write MASA metadata for MASA outputs */
        if ( args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_REND_AUDIO_CONFIG_MASA2 )
        {
            IVAS_REND_AudioConfigType inputType1;
            IVAS_REND_AudioConfigType inputType2;
            MASA_DECODER_EXT_OUT_META_HANDLE hMetaOutput;
            int16_t numInputFormats;

            inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
            inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN;
            hMetaOutput = NULL;

            numInputFormats = 0;
            if ( args.inConfig.numAmbisonicsBuses > 0 )
            {
                numInputFormats++;
                inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS;
            }
            if ( args.inConfig.numMultiChannelBuses > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
                }
            }
            if ( args.inConfig.numMasaBuses > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
                }
            }
            if ( args.inConfig.numAudioObjects > 0 )
            {
                numInputFormats++;
                if ( inputType1 == IVAS_REND_AUDIO_CONFIG_TYPE_UNKNOWN )
                {
                    inputType1 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
                }
            }

            if ( numInputFormats == 1 )
            {
                IVAS_REND_GetMasaMetadata( hIvasRend, &hMetaOutput, inputType1 );
            }
            else
            {
                if ( args.inConfig.numAmbisonicsBuses > 0 && args.inConfig.numMultiChannelBuses > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }

                if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 ) && args.inConfig.numMasaBuses > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_MASA;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }

                if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 || args.inConfig.numMasaBuses > 0 ) && args.inConfig.numAudioObjects > 0 )
                {
                    inputType2 = IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED;
                    IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 );
                }
            }

            if ( ( error = MasaFileWriter_writeFrame( masaWriter, hMetaOutput ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( masaWriter ) );
            }
        }
#endif

        frame++;
        if ( !args.quietModeEnabled )
        {
@@ -1322,6 +1492,9 @@ int main(
    {
        LfeRoutingConfig_close( lfeRoutingConfigs[i] );
    }
#endif
#ifdef MASA_PREREND
    MasaFileWriter_close( &masaWriter );
#endif
    AudioFileReader_close( &audioReader );
    AudioFileWriter_close( &audioWriter );

lib_com/options.h

100755 → 100644
+5 −1
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@
#define FIX_TODO_NON_DIEGETIC_PAN_NOT_IMPLELENTED_IN_RENDERER /* ..\apps\renderer.c(240):  .... (todo: implementation)",*/
#define REMOVE_OBS_CODE                                 /* FhG: Remove unnecessary assignement after LFE cleanup (Issue #451)*/

#define FIX_TODO_FD_CNG_SBA_CLEANUP                     /* FhG: BE, address TODO comment in fd_cng_enc */
#define ENHANCED_STEREO_DMX                             /* Orange : Contribution 48 - Enhanced stereo downmix. */

#define BINAURAL_AUDIO_CMDLINE
@@ -167,9 +168,12 @@
#define FIX_506                                         /* FhG: Compiler warnings */
#define FIX_511_OPTIMIZE_PARAMBIN_GAIN_FETCH            /* Nokia: Issue 511, significant optimization of parametric binauralizer gain fetching. */
#define FIX_531_BWS_ISM_BFI                             /* VA: issue 531: fix MemorySanitizer: use-of-uninitialized-value in ISM2 rate switching with frame errors */
#define FIX_395_CNG_BW                                  /* Eri: Issue 395 - CNG bandwidth issue for unified stereo */

#define EXTERNAL_ORIENTATIONS                           /* Nokia: Contribution 41: (external) orientation information handling */

#define MASA_PREREND                                    /* Nokia: Contribution 42: Support for IVAS_rend to merge MASA + other format to MASA */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */

+34 −6
Original line number Diff line number Diff line
@@ -1034,7 +1034,9 @@ void FdCngEncodeMDCTStereoSID(
        ms_ptr[ch] = &logNoiseEst[ch][0];
        lr_out_ptr[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0];
    }
#ifdef DEBUGGING
    assert( sts[0]->hFdCngEnc->npartDec == sts[1]->hFdCngEnc->npartDec );
#endif
    N = sts[0]->hFdCngEnc->npartDec;
    set_f( weights, 1.f, NPART );

@@ -1275,12 +1277,21 @@ void FdCngEncodeDiracMDCTStereoSID(
        lr_out_ptr[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0];
    }
    set_f( weights, 1.f, NPART );
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
#ifdef DEBUGGING
    assert( N[0] == N[1] );
#endif
#endif

    /* apply log and save energy of original left and right channels */
    for ( ch = 0; ch < CPE_CHANNELS; ch++ )
    {
        E[ch] = 0.0f;
        for ( p = 0; p < NPART; p++ ) /* TODO Note:   NPART should likely be N[ch] if N[ch] may change */
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
        for ( p = 0; p < N[ch]; p++ )
#else
        for ( p = 0; p < NPART; p++ )
#endif
        {
            ms_ptr[ch][p] = 10.f * log10f( lr_in_ptr[ch][p] + EPSILON );
            E[ch] += ms_ptr[ch][p];
@@ -1288,10 +1299,15 @@ void FdCngEncodeDiracMDCTStereoSID(
    }

    /* M/S transform on log envelopes */
    convertToMS( NPART, ms_ptr[0], ms_ptr[1], 0.5f ); /* TODO Note:   NPART should likely be N[0] if N[0] may change */
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
    convertToMS( N[0], ms_ptr[0], ms_ptr[1], 0.5f );

    E[0] = sum_f( ms_ptr[0], NPART ); /* TODO Note:   NPART should likely be N[0] if N[0] may change */
    E[0] = sum_f( ms_ptr[0], N[0] );
#else
    convertToMS( NPART, ms_ptr[0], ms_ptr[1], 0.5f );

    E[0] = sum_f( ms_ptr[0], NPART );
#endif

    /* Quantize M noise shape */
    /* Normalize MSVQ input */
@@ -1326,7 +1342,11 @@ void FdCngEncodeDiracMDCTStereoSID(
    set_zero( ms_ptr[1], NPART );

    /* compute M gain */
    gain[0] = sum_f( ms_ptr[0], NPART ); /* TODO Note:   NPART should likely be N[0] if N[0] may change */
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
    gain[0] = sum_f( ms_ptr[0], N[0] );
#else
    gain[0] = sum_f( ms_ptr[0], NPART );
#endif
    gain[0] = ( E[0] - gain[0] ) / (float) N[0];
    apply_scale( &gain[0], sts[0]->hFdCngEnc->hFdCngCom->CngBandwidth, sts[0]->hDtxEnc->last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );

@@ -1338,7 +1358,11 @@ void FdCngEncodeDiracMDCTStereoSID(
    gain[1] = gain[0];

    /* undo M/S */
    convertToMS( NPART, ms_ptr[0], ms_ptr[1], 1.0f ); /* TODO Note:   NPART should likely be N[0] if N[0] may change */
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
    convertToMS( NPART, ms_ptr[0], ms_ptr[1], 1.0f );
#else
    convertToMS( N[0], ms_ptr[0], ms_ptr[1], 1.0f );
#endif

    /* restore channel noise envelopes */
    for ( ch = 0; ch < CPE_CHANNELS; ch++ )
@@ -1346,7 +1370,11 @@ void FdCngEncodeDiracMDCTStereoSID(
        HANDLE_FD_CNG_ENC hFdCngEnc = sts[ch]->hFdCngEnc;
        HANDLE_FD_CNG_COM hFdCngCom = hFdCngEnc->hFdCngCom;

        for ( p = 0; p < NPART; p++ ) /* TODO Note:   NPART should likely be N[0] if N[0] may change */
#ifdef FIX_TODO_FD_CNG_SBA_CLEANUP
        for ( p = 0; p < N[0]; p++ )
#else
        for ( p = 0; p < NPART; p++ )
#endif
        {
            lr_out_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
        }
+2 −1
Original line number Diff line number Diff line
@@ -574,8 +574,9 @@ ivas_error ivas_cpe_enc(
#ifdef DEBUG_MODE_DFT
                hCPE->hStereoDft->res_cod_bits = 0;
#endif

#ifndef FIX_395_CNG_BW
                stereo_dft_enc_update( hCPE->hStereoDft, min( SWB, sts[0]->max_bwidth ) );
#endif
            }
            else
            {
Loading