Commit b425bfe9 authored by sagnowski's avatar sagnowski
Browse files

Make float interface the default in decoder

parent 2b327e5b
Loading
Loading
Loading
Loading
+83 −18
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@
#include "wmc_auto.h"
#include "render_config_reader.h"

#ifdef FLOAT_INTERFACE_DEC_REND
#include <math.h>
#endif

#define WMC_TOOL_SKIP

@@ -117,6 +120,10 @@ typedef struct

#endif

#ifdef FLOAT_INTERFACE_DEC_REND
    bool useInt16Interface;
#endif

} DecArguments;


@@ -138,6 +145,9 @@ static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBs
static int16_t app_own_random( int16_t *seed );
static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( char *forcedRendModeChar );
#endif
#ifdef FLOAT_INTERFACE_DEC_REND
static int16_t float2int( float x );
#endif


/*------------------------------------------------------------------------------------------*
@@ -722,6 +732,10 @@ static bool parseCmdlIVAS_dec(
    arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192;
    arg->no_diegetic_pan = 0.f;

#ifdef FLOAT_INTERFACE_DEC_REND
    arg->useInt16Interface = false;
#endif

    /*-----------------------------------------------------------------*
     * Initialization
     *-----------------------------------------------------------------*/
@@ -949,6 +963,13 @@ static bool parseCmdlIVAS_dec(
            }
            i++;
        }
#ifdef FLOAT_INTERFACE_DEC_REND
        else if ( strcmp( argv_to_upper, "-int16_api" ) == 0 )
        {
            arg->useInt16Interface = true;
            i++;
        }
#endif

        /*-----------------------------------------------------------------*
         * Option not recognized
@@ -1100,6 +1121,9 @@ static void usage_dec( void )
    fprintf( stdout, "-render_config file : Renderer configuration file\n" );
    fprintf( stdout, "-no_diegetic_pan    : panning mono no dietic sound to stereo -1<= pan <=1,\n" );
    fprintf( stdout, "                      left or l or 1->left, right or r or -1->right, center or c or  0->middle\n" );
#ifdef FLOAT_INTERFACE_DEC_REND
    fprintf( stdout, "-int16_api          : Force int16 library interface to be used\n" );
#endif
    fprintf( stdout, "-q                  : Quiet mode, no frame counter\n" );
    fprintf( stdout, "                      default is deactivated\n" );
#ifdef DEBUG_MODE_INFO
@@ -1112,6 +1136,27 @@ static void usage_dec( void )
    return;
}

#ifdef FLOAT_INTERFACE_DEC_REND
/* Same conversion as in mvr2s(). Used to keep BE between float and int interface of the decoder */
static int16_t float2int( float x )
{
    const float max16b_flt = 32767.0f;
    const float min16b_flt = -32768.0f;
    
    x = (float) floor( x + 0.5f );

    if ( x > max16b_flt )
    {
        x = max16b_flt;
    }
    else if ( x < min16b_flt )
    {
        x = min16b_flt;
    }
    return x;
}
#endif

#ifdef DEBUGGING
/*---------------------------------------------------------------------*
 * app_own_random()
@@ -1360,9 +1405,8 @@ static ivas_error decodeG192(
    nOutSamples = arg.output_Fs / 50; /* TODO(sgi): Get from API */

    bool outputFileIsFloat = false; /* TODO(sgi):  */
    bool useInt16Interface = true;  /* TODO(sgi):  */

    if ( useInt16Interface )
    if ( arg.useInt16Interface )
    {
        audioDecBufInt = malloc( nOutChannels * nOutSamples * sizeof( int16_t ) );
    }
@@ -1448,7 +1492,7 @@ static ivas_error decodeG192(
        }

#ifdef FLOAT_INTERFACE_DEC_REND
        if ( useInt16Interface )
        if ( arg.useInt16Interface )
        {
            if ( ( error = IVAS_DEC_GetSamplesInt( hIvasDec, audioDecBufInt, &nOutSamples ) ) != IVAS_ERR_OK )
            {
@@ -1458,13 +1502,11 @@ static ivas_error decodeG192(
        }
        else
        {
            error = IVAS_ERR_NOT_IMPLEMENTED;
            if ( ( error = IVAS_DEC_GetSamplesFloat( hIvasDec, audioDecBufFloat, &nOutSamples ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError: could not get samples from decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            // if ( ( error = IVAS_DEC_GetSamplesFloat( hIvasDec, tmpFloatBuf, &nOutSamples ) ) != IVAS_ERR_OK )
            // {
            //     fprintf( stderr, "\nError: could not get samples from decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
            //     goto cleanup;
            // }
            }
        }
#else
        /* Run decoder for one frame (get rendered output) */
@@ -1527,13 +1569,35 @@ static ivas_error decodeG192(
                else
                {
                    if ( outputFileIsFloat )
                    {
                        if ( arg.useInt16Interface )
                        {
                            copyBufferPackedIntToInterleavedFloat( audioDecBufInt, nOutSamples, audioWriteBufFloat, nOutSamples, nOutChannels );
                        }
                        else
                        {
                            copyBufferPackedFloatToInterleavedFloat( audioDecBufFloat, nOutSamples, audioWriteBufFloat, nOutSamples, nOutChannels );
                        }

                        error = IVAS_ERR_NOT_IMPLEMENTED;
                        // if ( ( error = AudioFileWriter_writeFloat( afWriter, &audioDecBufFloat[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
                        // {
                        //     fprintf( stderr, "\nOutput audio file writer error\n" );
                        //     goto cleanup;
                        // }

                        goto cleanup;
                    }
                    else
                    {
                        if ( arg.useInt16Interface )
                        {
                            copyBufferPackedIntToInterleavedInt( audioDecBufInt, nOutSamples, audioWriteBufInt, nOutSamples, nOutChannels );
                        }
                        else
                        {
                            copyBufferPackedFloatToInterleavedInt( audioDecBufFloat, nOutSamples, audioWriteBufInt, nOutSamples, nOutChannels, float2int );
                        }

                        if ( ( error = AudioFileWriter_write( afWriter, &audioWriteBufInt[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
                        {
@@ -1541,6 +1605,7 @@ static ivas_error decodeG192(
                            goto cleanup;
                        }
                    }
                }
#else
                if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
                {
+1 −1
Original line number Diff line number Diff line
@@ -789,7 +789,7 @@ int main(
            /* Do buffer conversions */
            if ( inputFileIsFloat )
            {
                copyBufferInterleavedFloatToPackedInt( audioReadBufFloat, numSamplesRead, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels );
                copyBufferInterleavedFloatToPackedInt( audioReadBufFloat, numSamplesRead, audioFeedBufInt, pcmBufNumSamplesPerChannel, pcmBufNumChannels, NULL );
            }
            else
            {
+22 −4
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@
#include "buffer_conversions.h"
#include "options.h"

#include <stdlib.h>

#ifdef FLOAT_INTERFACE_ENC

/*--------------------------------------------------------------------------*
@@ -79,7 +81,8 @@ void copyBufferInterleavedFloatToPackedInt(
    const int16_t srcBufferTotalNumSamples,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t dstBufferNumChannels,
    int16_t ( *float2int )( float ) )
{
    int16_t chnl, smpl, i;

@@ -90,10 +93,17 @@ void copyBufferInterleavedFloatToPackedInt(
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        {
            if ( i < srcBufferTotalNumSamples )
            {
                if ( float2int == NULL )
                {
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = (int16_t) srcBuffer[i];
                }
                else
                {
                    dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = float2int( srcBuffer[i] );
                }
            }
            else
            {
                dstBuffer[chnl * dstBufferNumSamplesPerChannel + smpl] = 0;
            }
@@ -215,7 +225,8 @@ void copyBufferPackedFloatToInterleavedInt(
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels )
    const int16_t dstBufferNumChannels,
    int16_t ( *float2int )( float ) )
{
    int16_t chnl, smpl;

@@ -224,10 +235,17 @@ void copyBufferPackedFloatToInterleavedInt(
        for ( chnl = 0; chnl < dstBufferNumChannels; ++chnl )
        {
            if ( smpl < srcBufferNumSamplesPerChannel )
            {
                if ( float2int == NULL )
                {
                    dstBuffer[smpl * dstBufferNumChannels + chnl] = (int16_t) srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl];
                }
                else
                {
                    dstBuffer[smpl * dstBufferNumChannels + chnl] = float2int( srcBuffer[chnl * srcBufferNumSamplesPerChannel + smpl] );
                }
            }
            else
            {
                dstBuffer[smpl * dstBufferNumChannels + chnl] = 0;
            }
+9 −5
Original line number Diff line number Diff line
@@ -50,7 +50,9 @@ void copyBufferInterleavedFloatToPackedInt(
    const int16_t srcBufferTotalNumSamples, /* TODO(sgi): Change to num samples per channel */
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const int16_t dstBufferNumChannels,
    int16_t ( *float2int )( float ) /* i  : Custom float-to-int conversion function. If NULL, conversion will be done via a simple cast. */
);

void copyBufferInterleavedIntToPackedFloat(
    const int16_t *srcBuffer,
@@ -78,7 +80,9 @@ void copyBufferPackedFloatToInterleavedInt(
    const int16_t srcBufferNumSamplesPerChannel,
    int16_t *dstBuffer,
    const int16_t dstBufferNumSamplesPerChannel,
    const int16_t dstBufferNumChannels );
    const int16_t dstBufferNumChannels,
    int16_t ( *float2int )( float ) /* i  : Custom float-to-int conversion function. If NULL, conversion will be done via a simple cast. */
);

void copyBufferPackedIntToInterleavedFloat(
    const int16_t *srcBuffer,