Commit 4048efa5 authored by Nicolas Roussin's avatar Nicolas Roussin
Browse files

Merge branch 'main' into 2142-implement-basop-w_min-and-w_max-functions

parents 2a233706 1961a83a
Loading
Loading
Loading
Loading
Loading
+70 −56
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
*******************************************************************************************************/

#include "lib_rend.h"
#include "typedef.h"
#include <assert.h>
#include <math.h>
#include <string.h>
@@ -195,7 +196,7 @@ typedef struct
    float lfeConfigElevation;
    bool lfeCustomRoutingEnabled;
    char inLfePanningMatrixFile[RENDERER_MAX_CLI_ARG_LENGTH];
    float syncMdDelay;
    int16_t syncMdDelay;
    IVAS_RENDER_FRAMESIZE render_framesize;
    uint16_t directivityPatternId[RENDERER_MAX_ISM_INPUTS];
    AcousticEnvironmentSequence aeSequence;
@@ -802,6 +803,7 @@ int main(
    SplitFileReadWrite *hSplitRendFileReadWrite;
    int16_t delayNumSamples_temp;
    int32_t delayTimeScale_temp;
    bool flushRendererLastFrame = false;
    int16_t numSamplesRead;
    int16_t delayNumSamples = -1;
    int16_t delayNumSamples_orig = 0;
@@ -847,8 +849,11 @@ int main(

    CmdlnArgs args = parseCmdlnArgs( argc, argv );

    if ( args.nonDiegeticPan && !( ( args.inConfig.numAudioObjects == 0 && args.inConfig.multiChannelBuses[0].audioConfig == IVAS_AUDIO_CONFIG_MONO ) ||
                                   ( args.inConfig.numAudioObjects > 0 && args.inConfig.audioObjects[0].audioConfig == IVAS_AUDIO_CONFIG_OBA && args.inConfig.numAudioObjects == 1 ) ) )
    if ( args.nonDiegeticPan &&
         !( ( args.inConfig.numAudioObjects == 0 &&
              args.inConfig.multiChannelBuses[0].audioConfig == IVAS_AUDIO_CONFIG_MONO ) ||
            ( args.inConfig.numAudioObjects > 0 &&
              args.inConfig.audioObjects[0].audioConfig == IVAS_AUDIO_CONFIG_OBA && args.inConfig.numAudioObjects == 1 ) ) )
    {
        fprintf( stderr, "\ninvalid configuration - non-diegetic panning requires mono or ISM1 input\n" );
        goto cleanup;
@@ -1178,7 +1183,10 @@ int main(
#endif

        /* sanity check */
        if ( ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL ) && ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) && ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && !is_split_pre_rend_mode( &args ) )
        if ( ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL ) &&
             ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) &&
             ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) &&
             !is_split_pre_rend_mode( &args ) )
        {
            fprintf( stderr, "\nExternal Renderer Config is supported only when binaural output configurations is used as output OR when Split pre-rendering mode is enabled. Exiting. \n" );
            goto cleanup;
@@ -1284,8 +1292,7 @@ int main(
#ifdef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS
        /* Set the metadata delay for objects */
#endif
        Word32 var1 = (Word32) ( args.syncMdDelay );
        IF( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, var1 ) ) != IVAS_ERR_OK )
        IF( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, args.syncMdDelay ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_REND_SetIsmMetadataDelay(): %s\n", ivas_error_to_string( error ) );
            goto cleanup;
@@ -1516,7 +1523,7 @@ int main(
    }

    Word16 numOutChannels;
    if ( ( error = IVAS_REND_NumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK )
    if ( ( error = IVAS_REND_GetNumOutChannels( hIvasRend, &numOutChannels ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_REND_NumOutChannels(): %s\n", ivas_error_to_string( error ) );
        goto cleanup;
@@ -1531,31 +1538,16 @@ int main(
        }
    }

    if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
    {
        if ( ( error = IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, &bitsBuffer.config.isar_frame_size_ms ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_REND_GetSplitRendBitstreamHeader(): %s!\n", ivas_error_to_string( error ) );
            goto cleanup;
        }

        if ( IVAS_REND_GetDelay_fx( hIvasRend, &delayNumSamples_temp, &delayTimeScale_temp ) != IVAS_ERR_OK )
    if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
    {
            fprintf( stderr, "\nUnable to get delay of renderer!\n" );
            goto cleanup;
        }
        char *outFile = args.outMetadataFilePath;

        if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outputFilePath, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms, bitsBuffer.config.isar_frame_size_ms, args.sampleRate, bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK )
        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
        {
            fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.outputFilePath );
            goto cleanup;
        }
            outFile = args.outputFilePath;
            audioWriter = NULL;
        }
    else
    {
        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
        {

        if ( ( error = IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, &bitsBuffer.config.isar_frame_size_ms ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_REND_GetSplitRendBitstreamHeader(): %s!\n", ivas_error_to_string( error ) );
@@ -1568,13 +1560,15 @@ int main(
            goto cleanup;
        }

            if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, args.outMetadataFilePath, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms, bitsBuffer.config.isar_frame_size_ms, args.sampleRate, bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK )
        if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, outFile, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms, bitsBuffer.config.isar_frame_size_ms, args.sampleRate, bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK )
        {
                fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.outMetadataFilePath );
            fprintf( stderr, "\nCould not open split rend metadata file %s\n", outFile );
            goto cleanup;
        }
    }

    if ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED )
    {
        if ( AudioFileWriter_open( &audioWriter, args.outputFilePath, args.sampleRate, numOutChannels ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nFailed to open file: %s\n", args.outputFilePath );
@@ -1667,6 +1661,7 @@ int main(
    outBuffer.pq_fact = &outBuffer.q_factor;
    Word16 subframe_len = (Word16) ( args.sampleRate / ( 200 ) ); // sample rate /FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES
    Word16 gd_bits = find_guard_bits( subframe_len );
    Word16 prev_q_fact = Q11;
    while ( 1 )
    {
        int16_t num_in_channels;
@@ -1719,19 +1714,28 @@ int main(
        if ( numSamplesRead == 0 )
        {
            /* end of input data */
            break;
            flushRendererLastFrame = true;
        }

        /* Convert from int to float and from interleaved to packed */
        if ( !flushRendererLastFrame )
        {
            Word16 Q_out;
            *outBuffer.pq_fact = 16 - ( gd_bits );
            convertInputBuffer_fx( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inInt32Buffer, *outBuffer.pq_fact, inBuffer.config.is_cldfb, cldfbAna, &Q_out );
            *outBuffer.pq_fact = Q_out;
            prev_q_fact = Q_out;
        }
        else
        {
            memset( inBuffer.data_fx, 0, inBuffer.config.numChannels * inBuffer.config.numSamplesPerChannel * sizeof( Word32 ) );
            *outBuffer.pq_fact = prev_q_fact;
        }

        int16_t num_subframes, sf_idx;
        num_subframes = (int16_t) args.render_framesize;

        if ( isCurrentFrameMultipleOf20ms )
        if ( isCurrentFrameMultipleOf20ms && !flushRendererLastFrame )
        {
            IsmPositionProvider_getNextFrame( positionProvider, &mtdBuffer );

@@ -1843,7 +1847,7 @@ int main(
            }

            IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.multiChannelBuses[i].inputChannelIndex, numChannels );
            if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, mcIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, mcIds[i], tmpBuffer, flushRendererLastFrame ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_REND_FeedInputAudio failed: %s\n", ivas_error_to_string( error ) );
                goto cleanup;
@@ -1857,7 +1861,7 @@ int main(
                if ( i == 0 )
                {
                    IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, args.inConfig.numAudioObjects );
                    if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                    if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, ismIds[i], tmpBuffer, flushRendererLastFrame ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nIVAS_REND_FeedInputAudio failed: %s\n", ivas_error_to_string( error ) );
                        goto cleanup;
@@ -1873,7 +1877,7 @@ int main(
            else
            {
                IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.audioObjects[i].inputChannelIndex, 1 );
                if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, ismIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
                if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, ismIds[i], tmpBuffer, flushRendererLastFrame ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nIVAS_REND_FeedInputAudio failed: %s\n", ivas_error_to_string( error ) );
                    goto cleanup;
@@ -1896,7 +1900,7 @@ int main(
            }

            IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.ambisonicsBuses[i].inputChannelIndex, numChannels );
            if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, sbaIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, sbaIds[i], tmpBuffer, flushRendererLastFrame ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_REND_FeedInputAudio failed: %s\n", ivas_error_to_string( error ) );
                goto cleanup;
@@ -1913,13 +1917,13 @@ int main(

            IVAS_REND_ReadOnlyAudioBuffer tmpBuffer = getReadOnlySubBuffer( inBuffer, (int16_t) args.inConfig.masaBuses[i].inputChannelIndex, numChannels );

            IF( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, masaIds[i], tmpBuffer ) ) != IVAS_ERR_OK )
            IF( ( error = IVAS_REND_FeedInputAudio_fx( hIvasRend, masaIds[i], tmpBuffer, flushRendererLastFrame ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_REND_FeedInputAudio failed: %s\n", ivas_error_to_string( error ) );
                goto cleanup;
            }

            if ( isCurrentFrameMultipleOf20ms )
            if ( isCurrentFrameMultipleOf20ms && !flushRendererLastFrame )
            {
                if ( masaReaders[i] != NULL )
                {
@@ -1982,7 +1986,7 @@ int main(
            zeroPad = delayNumSamples;
        }

        if ( is_split_pre_rend_mode( &args ) )
        if ( is_split_pre_rend_mode( &args ) && !flushRendererLastFrame )
        {
            if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead,
                                                     &bitsBuffer.config.bitsWritten ) != IVAS_ERR_OK )
@@ -1992,7 +1996,7 @@ int main(
            }
        }

        if ( audioWriter != NULL )
        if ( audioWriter != NULL && !flushRendererLastFrame )
        {
            if ( delayNumSamples * num_out_channels < outBufferSize )
            {
@@ -2013,7 +2017,7 @@ int main(
        bitsBuffer.config.bitsWritten = 0;

        /* Write MASA metadata for MASA outputs */
        if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 )
        if ( !flushRendererLastFrame && ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA1 || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_MASA2 ) )
        {
            IVAS_REND_AudioConfigType inputType1;
            IVAS_REND_AudioConfigType inputType2;
@@ -2085,7 +2089,8 @@ int main(
                    }
                }

                if ( ( args.inConfig.numAmbisonicsBuses > 0 || args.inConfig.numMultiChannelBuses > 0 || args.inConfig.numMasaBuses > 0 ) && args.inConfig.numAudioObjects > 0 )
                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;
                    if ( ( error = IVAS_REND_MergeMasaMetadata( hIvasRend, &hMetaOutput, inputType1, inputType2 ) ) != IVAS_ERR_OK )
@@ -2101,6 +2106,13 @@ int main(
            }
        }

        /* no new input was actually read, only delay buffers were flushed
         * therefore this is not a real frame */
        if ( flushRendererLastFrame )
        {
            break;
        }

        frame++;
        if ( !args.quietModeEnabled )
        {
@@ -2113,12 +2125,13 @@ int main(
#endif
    }

    /* add zeros at the end to have equal length of synthesized signals */
    /* add zeros at the end to have equal length of synthesized signals
     * the output buffer will contain either leftover input samples from delay aligned inputs
     * or zeros for padding */
    if ( audioWriter != NULL )
    {
        for ( zeroPadToWrite = zeroPad; zeroPadToWrite > frameSize_smpls; zeroPadToWrite -= frameSize_smpls )
        {
            memset( outInt16Buffer, 0, outBufferSize * sizeof( int16_t ) );
            if ( ( error = AudioFileWriter_write( audioWriter, outInt16Buffer, outBufferSize ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nOutput audio file writer error\n" );
@@ -2126,7 +2139,6 @@ int main(
            }
        }

        memset( outInt16Buffer, 0, zeroPadToWrite * outBuffer.config.numChannels * sizeof( int16_t ) );
        if ( ( error = AudioFileWriter_write( audioWriter, outInt16Buffer, zeroPadToWrite * outBuffer.config.numChannels ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nOutput audio file writer error\n" );
@@ -2136,9 +2148,10 @@ int main(
    }


    if ( args.inConfig.numAudioObjects != 0 && ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    if ( args.inConfig.numAudioObjects != 0 &&
         ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    {
        fprintf( stdout, "\n\nMetadata delayed %d subframes\n\n", (int16_t) round( args.syncMdDelay / ( 1000 / IVAS_NUM_FRAMES_PER_SEC / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) );
        fprintf( stdout, "\n\nMetadata delayed %d subframes\n\n", (int16_t) round( args.syncMdDelay / ( (float) BINAURAL_RENDERING_FRAME_SIZE_MS ) ) );
    }

    if ( !args.quietModeEnabled && args.delayCompensationEnabled )
@@ -3038,7 +3051,7 @@ static void parseOption(
        case CmdLnOptionId_syncMdDelay:
            assert( numOptionValues == 1 );
            /* Metadata Delay to sync with audio delay in ms */
            args->syncMdDelay = strtof( optionValues[0], NULL );
            args->syncMdDelay = (int16_t) strtol( optionValues[0], NULL, 10 );
            break;
        default:
            assert( 0 && "This should be unreachable - all command line options should be explicitly handled." );
@@ -3574,7 +3587,8 @@ static void parseObjectPosition(
    *positionDuration = (uint16_t) strtol( line, &endptr, 10 );
    readNextMetadataChunk( line, "\n" );

    read_values = (int16_t) sscanf( line, "%f,%f,%f,%f,%f,%f,%f,%f", &meta_prm[0], &meta_prm[1], &meta_prm[2], &meta_prm[3], &meta_prm[4], &meta_prm[5], &meta_prm[6], &meta_prm[7] );
    read_values = (int16_t) sscanf( line, "%f,%f,%f,%f,%f,%f,%f,%f",
                                    &meta_prm[0], &meta_prm[1], &meta_prm[2], &meta_prm[3], &meta_prm[4], &meta_prm[5], &meta_prm[6], &meta_prm[7] );

    if ( read_values < 2 )
    {
+2 −1
Original line number Diff line number Diff line
@@ -5235,7 +5235,7 @@ void evs_dec_previewFrame(
    return;
}


#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG
void dtx_read_padding_bits_fx(
    DEC_CORE_HANDLE st,
    const Word16 num_bits )
@@ -5253,3 +5253,4 @@ void dtx_read_padding_bits_fx(

    return;
}
#endif
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
    EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
  ====================================================================================*/

#include "ivas_cnst.h"
#include <assert.h>
#include <stdint.h>
#include "options.h"
@@ -161,8 +162,12 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale )
    hFdCngCom->exp_cldfb_periodog = 0;
    move16();

#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG
    set16_fx( hFdCngCom->coherence_fx, 16384 /* 0.5 in Q15 */, MDCT_ST_DTX_NUM_COHERENCE_BANDS );
#else
    hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */
    move16();
#endif

    set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN );
    set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN );
+5 −1
Original line number Diff line number Diff line
@@ -316,8 +316,12 @@ void hp20_fx_32_opt(
    prescale = s_min( prescale, diff );

    prescale = sub( 1 + HP20_FX_COEFF_SCALE, prescale );

#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC
    if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) || // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead
         LT_16( prescale_current_frame, prescale ) )                      // To avoid overflow in the subsequent shr() scaling for W_y1, W_y2, x2, and x1 calculations before the for loop.
#else
    if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) ) // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead
#endif
    {
        prescale_current_frame = prescale;
    }
+5 −0
Original line number Diff line number Diff line
@@ -889,6 +889,11 @@ enum fea_names
#define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN         20
#define MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE    3

#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG
#define MDCT_ST_DTX_NUM_COHERENCE_BANDS         5
#define MDCT_ST_DTX_FIRST_BAND_OFFSET           2
#endif

typedef enum {
    NOISE_GEN_MODE_UNDEF = -1,
    EQUAL_CORES = 0,
Loading