Commit ed974298 authored by bayers's avatar bayers
Browse files

Merge remote-tracking branch 'remotes/forge/5ms_api_sgi_merge' into 5ms_api_main_merge

parents 995e7d4a 8c837c38
Loading
Loading
Loading
Loading
+99 −22
Original line number Diff line number Diff line
@@ -1839,6 +1839,10 @@ static ivas_error decodeG192(
    IVAS_VECTOR3 Pos;
    int16_t vec_pos_update, vec_pos_len;

#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_SPLIT_REND_BITS splitRendBits;
    SplitFileReadWrite *hSplitRendFileReadWrite;
#endif

    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
    {
@@ -1901,6 +1905,15 @@ static ivas_error decodeG192(
        nOutSamples = (int16_t) ( arg.output_Fs / 1000 * DEFAULT_FETCH_FRAMESIZE_MS );
        vec_pos_len = 1;
    }

#ifdef SPLIT_REND_WITH_HEAD_ROT
    splitRendBits.bits_buf = splitRendBitsBuf;
    splitRendBits.bits_read = 0;
    splitRendBits.bits_written = 0;
    splitRendBits.buf_len = MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES;
    hSplitRendFileReadWrite = NULL;
#endif

    /*------------------------------------------------------------------------------------------*
     * Loop for every packet (frame) of bitstream data
     * - Read the bitstream packet
@@ -1951,11 +1964,25 @@ static ivas_error decodeG192(
        {
            IVAS_QUATERNION Quaternion;

#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( headRotReader == NULL )
            {
                    Quaternion.w = -3.0f;
                    Quaternion.x = 0.0f;
                    Quaternion.y = 0.0f;
                    Quaternion.z = 0.0f;
            }
            else
            {
#endif
                if ( ( error = HeadRotationFileReading( headRotReader, &Quaternion, &Pos ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) );
                    goto cleanup;
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif


            if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos
@@ -2048,12 +2075,23 @@ static ivas_error decodeG192(
                    goto cleanup;
                }
            }
            error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nOutChannels * nSamplesRendered, &nSamplesRendered_loop, &needNewFrame

#ifdef SPLIT_REND_WITH_HEAD_ROT
    ,
    NULL /* TODO(sgi): pass IVAS_SPLIT_REND_BITS_HANDLE or change API so that split rendering has its dedicated GetSamples function */
            if ( arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_CODED || arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_PCM )
            {
                error = IVAS_DEC_GetSplitBinaural(hIvasDec, &splitRendBits, &nSamplesRendered_loop, &needNewFrame );
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
                if ( error != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSplitBinaural: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
            }
            else
            {
#endif
             );
                error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nOutChannels * nSamplesRendered, &nSamplesRendered_loop, &needNewFrame );
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
                if ( error != IVAS_ERR_OK )
@@ -2061,6 +2099,9 @@ static ivas_error decodeG192(
                    fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif


        } while ( nSamplesRendered < nOutSamples && error == IVAS_ERR_OK );
@@ -2097,7 +2138,8 @@ static ivas_error decodeG192(
                    &nOutChannels,
                    &numObj
#ifdef SPLIT_REND_WITH_HEAD_ROT
    ,NULL /* TODO(sgi): see #else branch for reference */
                    ,
                    &hSplitRendFileReadWrite
#endif
                    );
                if ( error != IVAS_ERR_OK )
@@ -2114,6 +2156,28 @@ static ivas_error decodeG192(
        /* Write current frame */
        if ( decodedGoodFrame )
        {
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( ( hSplitRendFileReadWrite != NULL ) && ( arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_CODED ) )
            {
                if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written,
                                                         splitRendBits.codec, splitRendBits.pose_correction ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nUnable to write to bitstream file!\n" );
                    goto cleanup;
                }
            }
            else
            {
                if ( ( hSplitRendFileReadWrite != NULL ) && ( arg.outputFormat == IVAS_DEC_OUTPUT_SPLIT_BINAURAL_PCM ) )
                {
                    if ( split_rend_write_bitstream_to_file( hSplitRendFileReadWrite, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written,
                                                             splitRendBits.codec, splitRendBits.pose_correction ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nUnable to write to bitstream file!\n" );
                        goto cleanup;
                    }
                }
#endif
                if ( delayNumSamples < nOutSamples )
                {
                    if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK )
@@ -2127,6 +2191,9 @@ static ivas_error decodeG192(
                {
                    delayNumSamples -= nOutSamples;
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif
        }

        /* Write ISm metadata to external file(s) */
@@ -2375,11 +2442,18 @@ static ivas_error decodeG192(

    /* add zeros at the end to have equal length of synthesized signals */
    memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) );
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( afWriter != NULL )
    {
#endif
        if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) );
            goto cleanup;
        }
#ifdef SPLIT_REND_WITH_HEAD_ROT
    }
#endif

    /*------------------------------------------------------------------------------------------*
     * Close files and deallocate resources
@@ -2389,6 +2463,9 @@ static ivas_error decodeG192(

cleanup:

#ifdef SPLIT_REND_WITH_HEAD_ROT
    split_rend_reader_writer_close( &hSplitRendFileReadWrite );
#endif
    AudioFileWriter_close( &afWriter );
    MasaFileWriter_close( &masaWriter );
#ifdef DEBUGGING
+5 −1
Original line number Diff line number Diff line
@@ -1730,9 +1730,13 @@ void ivas_rend_CldfbMultiBinRendProcess(
    for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    {
#endif
        for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
        for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) /* FhG@Dolby: this looks suspicious */
        {
#ifdef API_5MS
            idx = slot_idx;
#else
            idx = sf_idx * MAX_PARAM_SPATIAL_SUBFRAMES + slot_idx;
#endif
            for ( ch_idx = 0; ch_idx < hCldfbRend->nInChannels; ch_idx++ )
            {
                mvr2r( &Cldfb_In_Real[ch_idx][idx][0], &Cldfb_RealBuffer_sfIn[ch_idx][slot_idx][0], hCldfbRend->max_band );
+96 −8
Original line number Diff line number Diff line
@@ -853,7 +853,7 @@ ivas_error IVAS_DEC_GetSamples(
    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                  */
    bool *needNewFrame           /* indication that the decoder needs a new frame                                */
#ifdef SPLIT_REND_WITH_HEAD_ROT
#if defined SPLIT_REND_WITH_HEAD_ROT && !defined API_5MS
    ,
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits /* o : bitstream output for split rendering mode*/
#endif
@@ -979,6 +979,99 @@ ivas_error IVAS_DEC_GetSamples(
}
#endif

#if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT
ivas_error IVAS_DEC_GetSplitBinaural(
    IVAS_DEC_HANDLE hIvasDec,    /* i/o: IVAS decoder handle                                                     */
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits,  /* o : bitstream output for split rendering mode*/
    int16_t *nOutSamples,        /* o  : number of samples per channel written to output buffer                  */
    bool *needNewFrame           /* indication that the decoder needs a new frame                                */
)
{
    Decoder_Struct *st_ivas;
    AUDIO_CONFIG output_config;
    int32_t output_Fs;
    float output[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k];
    int16_t output_int[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k]; /* TODO(sgi): Need conversion */
    int16_t numSamplesPerChannel;
    int16_t i, j;
    ivas_error error;

    error = IVAS_ERR_OK;
    st_ivas = hIvasDec->st_ivas;
    output_config = st_ivas->hDecoderConfig->output_config;
    output_Fs = st_ivas->hDecoderConfig->output_Fs;
    numSamplesPerChannel = output_Fs / FRAMES_PER_SEC; /* TODO(sgi): Accommodate 5ms framing */

    if ( output_config != AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != AUDIO_CONFIG_BINAURAL_SPLIT_PCM  )
    {
        return IVAS_ERR_WRONG_PARAMS;
    }

    *nOutSamples = 0;

    while ( error == IVAS_ERR_OK )
    {
        int16_t nOutSamplesLocal;

        /* Decode and render */
        if ( ( error = IVAS_DEC_GetSamples(
                   hIvasDec,
                   numSamplesPerChannel,
                   output_int,
                   &nOutSamplesLocal,
                   needNewFrame ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        *nOutSamples += nOutSamplesLocal;

        /*split rendering process calls*/
        IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend;
        int16_t max_band;
        int16_t pcm_out;
        int16_t numPoses;

        hSplitBinRend = &st_ivas->splitBinRend;

        ivas_set_split_rend_setup(hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, hSplitRendBits );

        numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;

        /* [tmp] convert int back to float and change buffer layout */
        for (i = 0; i < numSamplesPerChannel; ++i)
        {
            for (j = 0; j < BINAURAL_CHANNELS * numPoses; ++j)
            {
                output[j][i] = (float) output_int[i * BINAURAL_CHANNELS * numPoses + j];
            }
        }

        max_band = (int16_t) ( ( BINAURAL_MAXBANDS * output_Fs ) / 48000 );
        pcm_out = ( output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;

        error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend,
                                                    st_ivas->hHeadTrackData->Quaternion,
                                                    st_ivas->hRenderConfig->split_rend_config.splitRendBitRate,
                                                    st_ivas->hRenderConfig->split_rend_config.codec,
                                                    hSplitBinRend->hSplitRendBits,
                                                    hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural,
                                                    hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural,
                                                    max_band, output, 1,
                                                    st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV,
                                                    pcm_out );
        if ( error != IVAS_ERR_OK )
        {
            return error;
        }

        free( st_ivas->splitBinRend.hMultiBinCldfbData );
    }

    return error;
}
#endif


/*---------------------------------------------------------------------*
 * IVAS_DEC_Setup( )
@@ -2267,12 +2360,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
            nSamplesToRender = nSamplesPerChannel - nSamplesRendered;

            /* render IVAS frames  directly to the output buffer */
            if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nSamplesRendered * nOutChannels, &nSamplesRendered_loop, &tmp
#ifdef SPLIT_REND_WITH_HEAD_ROT
    ,
    NULL /* TODO(sgi): pass hSplitRendBits here or create separate get samples function for split rendering */
#endif
            ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nSamplesRendered * nOutChannels, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK )
            {
                return error;
            }
+10 −1
Original line number Diff line number Diff line
@@ -188,12 +188,21 @@ ivas_error IVAS_DEC_GetSamples(
    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                  */
#endif
#ifdef SPLIT_REND_WITH_HEAD_ROT
#if defined SPLIT_REND_WITH_HEAD_ROT && !defined API_5MS
    ,
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits  /* o : bitstream output for split rendering mode*/
#endif
);

#if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT
ivas_error IVAS_DEC_GetSplitBinaural(
    IVAS_DEC_HANDLE hIvasDec,    /* i/o: IVAS decoder handle                                                     */
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits,  /* o : bitstream output for split rendering mode*/
    int16_t *nOutSamples,        /* o  : number of samples per channel written to output buffer                  */
    bool *needNewFrame           /* indication that the decoder needs a new frame                                */
);
#endif

/*! r: error code */
ivas_error IVAS_DEC_GetObjectMetadata(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
+5 −1
Original line number Diff line number Diff line
@@ -1495,7 +1495,7 @@ void ivas_renderSplitUpdateNoCorrectionPoseData(
ivas_error ivas_renderMultiBinToSplitBinaural(
    SPLIT_REND_WRAPPER *hSplitBin,
#ifdef API_5MS
	const IVAS_QUATERNION headPosition[MAX_PARAM_SPATIAL_SUBFRAMES],
	const IVAS_QUATERNION headPosition,
#else
	const IVAS_QUATERNION headPositions[MAX_PARAM_SPATIAL_SUBFRAMES],
#endif
@@ -1513,7 +1513,11 @@ ivas_error ivas_renderMultiBinToSplitBinaural(

void ivas_rend_CldfbSplitPreRendProcess(
    const BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend,
#ifdef API_5MS
	const IVAS_QUATERNION headPosition,
#else
	const IVAS_QUATERNION headPositions[MAX_PARAM_SPATIAL_SUBFRAMES],
#endif
    MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,
    float Cldfb_In_BinReal[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
    float Cldfb_In_BinImag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
Loading