Commit 21394295 authored by sagnowski's avatar sagnowski
Browse files

Fix packed output from decoder

parent d760bd0b
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
@@ -131,6 +131,61 @@ static int16_t app_own_random( int16_t *seed );
static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( char *forcedRendModeChar );
#endif

#ifdef FLOAT_INTERFACE_DEC_REND
/* TODO(sgi): move to lib_util, re-use between renderer, encoder and decoder */
/*--------------------------------------------------------------------------*
 * copyBufferPackedFloatToInterleavedInt()
 *
 *
 *--------------------------------------------------------------------------*/

static void copyBufferPackedFloatToInterleavedInt(
    const float *inBuffer,
    const int16_t numSamplesPerChannel,
    const int16_t numChannels,
    int16_t *outBuffer )
{
    int16_t chnl, smpl;

    for ( chnl = 0; chnl < numChannels; ++chnl )
    {
        for ( smpl = 0; smpl < numSamplesPerChannel; ++smpl )
        {
            /* TODO(sgi): This is not bit-exact with what is done in ivas_syn_output() */
            outBuffer[smpl * numChannels + chnl] = inBuffer[chnl * numSamplesPerChannel + smpl];
        }
    }

    return;
}

/* TODO(sgi): move to lib_util, re-use between renderer, encoder and decoder */
/*--------------------------------------------------------------------------*
 * copyBufferPackedFloatToInterleavedInt()
 *
 *
 *--------------------------------------------------------------------------*/

static void copyBufferPackedIntToInterleavedInt(
    const int16_t *inBuffer,
    const int16_t numSamplesPerChannel,
    const int16_t numChannels,
    int16_t *outBuffer )
{
    int16_t chnl, smpl;

    for ( chnl = 0; chnl < numChannels; ++chnl )
    {
        for ( smpl = 0; smpl < numSamplesPerChannel; ++smpl )
        {
            outBuffer[smpl * numChannels + chnl] = inBuffer[chnl * numSamplesPerChannel + smpl];
        }
    }

    return;
}
#endif


/*------------------------------------------------------------------------------------------*
 * main()
@@ -1384,12 +1439,33 @@ static ivas_error decodeG192(
            }
        }

#ifdef FLOAT_INTERFACE_DEC_REND
        bool useFloat = false; /* TODO(sgi): get from input file type or command line flag */
        if (useFloat)
        {
            // /* TODO(sgi): Don't allocate on every frame, use correct size */
            // 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
        {
            if ( ( error = IVAS_DEC_GetSamplesInt( hIvasDec, pcmBuf, &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) */
        if ( ( error = IVAS_DEC_GetSamples( hIvasDec, pcmBuf, &nOutSamples ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: could not get samples from decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
            goto cleanup;
        }
#endif

        /* Continue checking for first good frame until it is found */
        if ( !decodedGoodFrame )
@@ -1434,7 +1510,14 @@ static ivas_error decodeG192(
        {
            if ( delayNumSamples < nOutSamples )
            {
#ifdef FLOAT_INTERFACE_DEC_REND
                int16_t pcmBufInterleaved[MAX_OUTPUT_PCM_BUFFER_SIZE];
                copyBufferPackedIntToInterleavedInt(pcmBuf, nOutSamples, nOutChannels, pcmBufInterleaved);

                if ( ( error = AudioFileWriter_write( afWriter, &pcmBufInterleaved[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
#else
                if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
#endif
                {
                    fprintf( stderr, "\nOutput audio file writer error\n" );
                    goto cleanup;
+1 −1
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ ivas_error ivas_compute_core_buffers(
/*! r: number of clipped samples */
uint32_t ivas_syn_output(
#ifdef FLOAT_INTERFACE_DEC_REND
    float* synth[],                                             /* i/o: float synthesis signal                  */
    float* synth,                                               /* i/o: float synthesis signal as packed buffer */
#else
    float synth[][L_FRAME48k],                                  /* i/o: float synthesis signal                  */
#endif
+14 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ void mvc2c(
/*! r: number of clipped samples */
uint32_t ivas_syn_output(
#ifdef FLOAT_INTERFACE_DEC_REND
    float* synth[],             /* i/o: float synthesis signal              */
    float* synth,               /* i/o: float synthesis signal as packed buffer */
#else
    float synth[][L_FRAME48k],  /* i/o: float synthesis signal              */
#endif
@@ -124,14 +124,26 @@ uint32_t ivas_syn_output(
    int16_t *synth_out          /* o  : integer 16 bits synthesis signal    */
)
{
#ifndef FLOAT_INTERFACE_DEC_REND
    int16_t i, n;
    int16_t synth_loc[L_FRAME48k];
#endif
    uint32_t noClipping = 0;

    /*-----------------------------------------------------------------*
     * float to integer conversion with saturation control
     *-----------------------------------------------------------------*/

#ifdef FLOAT_INTERFACE_DEC_REND
    noClipping += mvr2s( synth, synth_out, n_channels * output_frame );

#ifdef DEBUG_MODE_LFE /* TODO(sgi): will be broken by conversion from interleaved to packed buffers */
    if ( n == LFE_CHANNEL )
    {
        dbgwrite( synth_loc, sizeof( int16_t ), output_frame, 1, "./lfe_out.raw" );
    }
#endif
#else
    for ( n = 0; n < n_channels; n++ )
    {
        noClipping += mvr2s( synth[n], synth_loc, output_frame );
@@ -147,6 +159,7 @@ uint32_t ivas_syn_output(
            synth_out[i * n_channels + n] = synth_loc[i];
        }
    }
#endif

    return noClipping;
}
+1 −1
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@
#define FLOAT_INTERFACE_ENC_BE_HACKS
#endif

// #define FLOAT_INTERFACE_DEC_REND
#define FLOAT_INTERFACE_DEC_REND

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+8 −8
Original line number Diff line number Diff line
@@ -669,13 +669,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial(


/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSamples( )
 * IVAS_DEC_GetSamplesInt( )
 *
 * Main function to decode to PCM data
 *---------------------------------------------------------------------*/

#ifdef FLOAT_INTERFACE_DEC_REND
ivas_error IVAS_DEC_GetSamples(
ivas_error IVAS_DEC_GetSamplesInt(
    IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                                     */
    int16_t *pcmBuf,          /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels  */
    int16_t *nOutSamples      /* o  : number of samples per channel written to output buffer                  */
@@ -684,7 +684,6 @@ ivas_error IVAS_DEC_GetSamples(
    ivas_error error;
    /* TODO(sgi): Optimize */
    float output[16 * 48000 / 50];
    float* output_channels[MAX_OUTPUT_CHANNELS];
    int16_t output_frame, nchan_out;

    if ( ( error = IVAS_DEC_GetSamplesFloat(hIvasDec, output, nOutSamples) ) != IVAS_ERR_OK )
@@ -712,12 +711,10 @@ ivas_error IVAS_DEC_GetSamples(
     * Lib user only provides the mono buffer, so additional space needs to be allocated within the library
     * for the first step when `num_channels(bitstream_format) > num_channels(output_format)`.
     */
    save_channel_pointers(output, nchan_out, output_frame, output_channels);

#ifdef DEBUGGING
    hIvasDec->st_ivas->noClipping +=
#endif
        ivas_syn_output( output_channels, output_frame, nchan_out, pcmBuf );
        ivas_syn_output( output, output_frame, nchan_out, pcmBuf );


    return IVAS_ERR_OK;
@@ -1482,7 +1479,7 @@ ivas_error IVAS_DEC_VoIP_FeedFrame(
    return IVAS_ERR_OK;
}


/* TODO(sgi): float interface for VoIP */
/*---------------------------------------------------------------------*
 * IVAS_DEC_VoIP_GetSamples( )
 *
@@ -1575,8 +1572,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
        }
        else
        {

#ifdef FLOAT_INTERFACE_DEC_REND
            if ( ( error = IVAS_DEC_GetSamplesInt( hIvasDec, hVoIP->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_GetSamples( hIvasDec, hVoIP->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
Loading