Commit 53ab50df authored by vaclav's avatar vaclav
Browse files

allocate IVAS_SPLIT_REND_BITS_DATA as part of st_ivas

parent 26fd76c1
Loading
Loading
Loading
Loading
+13 −30
Original line number Diff line number Diff line
@@ -1983,11 +1983,13 @@ static ivas_error initOnFirstGoodFrame(
    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * decodeG192()
 *
 * Read G.192 bitstream and decode in regular decoder
 *---------------------------------------------------------------------*/

#ifdef API_5MS
static ivas_error decodeG192(
    DecArguments arg,
@@ -2038,10 +2040,8 @@ static ivas_error decodeG192(
    IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS];
    IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
    int16_t vec_pos_update, vec_pos_len;

#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_SPLIT_REND_BITS_DATA splitRendBits;
    SplitFileReadWrite *splitRendWriter;
    SplitFileReadWrite *splitRendWriter = NULL;
#endif

    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
@@ -2110,17 +2110,6 @@ static ivas_error decodeG192(
        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 = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES;
    splitRendBits.codec = IVAS_SPLIT_REND_CODEC_DEFAULT;
    splitRendBits.pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
    splitRendBits.codec_frame_size_ms = 0;
    splitRendWriter = NULL;
#endif

    /*------------------------------------------------------------------------------------------*
     * Loop for every packet (frame) of bitstream data
     * - Read the bitstream packet
@@ -2204,8 +2193,7 @@ static ivas_error decodeG192(
                {
                    if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ),
                                 RotationFileReader_getFilePath( headRotReader ) );
                        fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) );
                        goto cleanup;
                    }
                }
@@ -2333,32 +2321,29 @@ static ivas_error decodeG192(
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
            {
                error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ),
                                                            &splitRendBits, &nSamplesRendered_loop, &needNewFrame );
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
                if ( error != IVAS_ERR_OK )
                if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBitsBuf, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
            }
            else
            {
#endif
                error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender,
                if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender,
#if defined API_5MS && defined SPLIT_REND_WITH_HEAD_ROT
                                                    IVAS_DEC_PCM_INT16, (void *)
#endif
                                                                            ( pcmBuf + nOutChannels * nSamplesRendered ),
                                             &nSamplesRendered_loop, &needNewFrame );
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
                if ( error != IVAS_ERR_OK )
                                                    &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif
@@ -2412,7 +2397,6 @@ static ivas_error decodeG192(
#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
            {
#if 0
                IVAS_SPLIT_REND_BITS_DATA splitRendBits;

                if ( ( error = IVAS_DEC_GetSplitRendBits( hIvasDec, &splitRendBits ) ) != IVAS_ERR_OK )
@@ -2420,7 +2404,6 @@ static ivas_error decodeG192(
                    fprintf( stderr, "\nError in IVAS_DEC_SplitRendBits: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
#endif

                if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits.bits_buf, &splitRendBits.bits_read, &splitRendBits.bits_written, splitRendBits.codec, splitRendBits.pose_correction
#ifdef API_5MS
+14 −12
Original line number Diff line number Diff line
@@ -1111,7 +1111,7 @@ ivas_error IVAS_DEC_GetSamples(
ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    IVAS_DEC_HANDLE hIvasDec,  /* i/o: IVAS decoder handle                                     */
    void *pcmBuf_out,          /* o  : output synthesis signal for BINAURAL_SPLIT_PCM          */
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o  : bitstream output for split rendering mode               */
    uint8_t *splitRendBitsBuf, /* o  : output split rendering bits                             */
    int16_t *nOutSamples,      /* o  : number of samples per channel written to output buffer  */
    bool *needNewFrame         /* o  : indication that the decoder needs a new frame           */
)
@@ -1141,9 +1141,12 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    output_Fs = st_ivas->hDecoderConfig->output_Fs;
    numSamplesPerChannelToDecode = (int16_t) ( output_Fs / FRAMES_PER_SEC );

    *needNewFrame = FALSE;
    *needNewFrame = false;
    hSplitBinRend = &st_ivas->hSplitBinRend;
    ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, hSplitRendBits );
    if ( ( error = ivas_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBitsBuf ) ) != IVAS_ERR_OK )
    {
        return error;
    }
    numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;

    if ( st_ivas->hDecoderConfig->Opt_5ms &&
@@ -1232,13 +1235,11 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    pcm_out = ( output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
    td_input = st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC;

    error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, st_ivas->hHeadTrackData->Quaternions[0], st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, st_ivas->hRenderConfig->split_rend_config.codec,
    if ( ( error = ivas_renderMultiBinToSplitBinaural( &hSplitBinRend->splitrend, st_ivas->hHeadTrackData->Quaternions[0], st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, st_ivas->hRenderConfig->split_rend_config.codec,
#ifdef API_5MS
                                                       st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms,
#endif
                                                hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural,
                                                hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, max_band, pOutput, 1, td_input, pcm_out );
    if ( error != IVAS_ERR_OK )
                                                       hSplitBinRend->hSplitRendBits, hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural, hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural, max_band, pOutput, 1, td_input, pcm_out ) ) != IVAS_ERR_OK )
    {
        return error;
    }
@@ -4322,6 +4323,7 @@ ivas_error IVAS_DEC_GetSplitRendBits(
    splitRendBits->buf_len = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->buf_len;
    splitRendBits->codec = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec;
    splitRendBits->pose_correction = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->pose_correction;
    splitRendBits->codec_frame_size_ms = hIvasDec->st_ivas->hSplitBinRend.hSplitRendBits->codec_frame_size_ms;

    return IVAS_ERR_OK;
}
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ ivas_error IVAS_DEC_GetSamples(
ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    void *pcmBuf_out,                           /* o  : output synthesis signal for BINAURAL_SPLIT_PCM                          */
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits, /* o  : bitstream output for split rendering mode                               */
    uint8_t *splitRendBitsBuf,                  /* o  : output split rendering bits                                             */
    int16_t *nOutSamples,                       /* o  : number of samples per channel written to output buffer                  */
    bool *needNewFrame                          /* o  :indication that the decoder needs a new frame                            */
);
+6 −7
Original line number Diff line number Diff line
@@ -1377,8 +1377,10 @@ ivas_error ivas_orient_trk_Process(
#ifdef API_5MS
void ivas_set_split_rend_ht_setup(
    IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend,
    COMBINED_ORIENTATION_HANDLE hCombinedOrientationData );
    COMBINED_ORIENTATION_HANDLE hCombinedOrientationData 
);
#endif

/*----------------------------------------------------------------------------------*
 * Split binaural renderer prototypes
 *----------------------------------------------------------------------------------*/
@@ -1387,11 +1389,7 @@ ivas_error ivas_set_split_rend_setup(
    IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, 
    IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, 
    COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,       /* i/o: combined orientation handle    */
#ifdef API_5MS
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits
#else
    uint8_t *splitRendBitsBuf
#endif
);

void ivas_init_split_rend_handles( 
@@ -1422,7 +1420,8 @@ ivas_error ivas_splitBinLCLDEncOpen(
    BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc,
    const int32_t iSampleRate,
    const int16_t iChannels,
    const int32_t iDataRate );
    const int32_t iDataRate 
);

void ivas_splitBinLCLDEncClose( 
	BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc 
+22 −20
Original line number Diff line number Diff line
@@ -1822,6 +1822,8 @@ void ivas_set_split_rend_ht_setup(
    return;
}
#endif


/*-------------------------------------------------------------------------*
 * ivas_set_split_rend_setup()
 *
@@ -1832,21 +1834,27 @@ ivas_error ivas_set_split_rend_setup(
    IVAS_DEC_SPLIT_REND_WRAPPER *hSplitBinRend,
    IVAS_SPLIT_REND_CONFIG_DATA *hSplitBinConfig,
    COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,
#ifdef API_5MS
    IVAS_SPLIT_REND_BITS_HANDLE hSplitRendBits
#else
    uint8_t *splitRendBitsBuf
#endif
)
    uint8_t *splitRendBitsBuf )
{
    int16_t sf, i, j;
#ifndef API_5MS

#ifdef API_5MS
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( ( hSplitBinRend->hSplitRendBits = (IVAS_SPLIT_REND_BITS_HANDLE) malloc( sizeof( IVAS_SPLIT_REND_BITS_DATA ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split renderer Bits buffer\n" ) );
    }
#endif

    hSplitBinRend->hSplitRendBits->bits_buf = splitRendBitsBuf;
    hSplitBinRend->hSplitRendBits->bits_written = 0;
    hSplitBinRend->hSplitRendBits->bits_read = 0;
#else
    hSplitBinRend->hSplitRendBits = hSplitRendBits;
    hSplitBinRend->hSplitRendBits->bits_written = 0;
    hSplitBinRend->hSplitRendBits->buf_len = IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES;
    hSplitBinRend->hSplitRendBits->codec = IVAS_SPLIT_REND_CODEC_DEFAULT;
    hSplitBinRend->hSplitRendBits->pose_correction = IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
    hSplitBinRend->hSplitRendBits->codec_frame_size_ms = 0;
#endif

    if ( ( hSplitBinRend->hMultiBinCldfbData = (IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( IVAS_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
@@ -2609,19 +2617,13 @@ ivas_error ivas_renderMultiBinToSplitBinaural(
        target_md_bits = ivas_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out ) * L_FRAME48k / 48000;

        actual_md_bits = pBits->bits_written;
        ivas_rend_CldfbSplitPreRendProcess(
            hSplitBin->hBinHrSplitPreRend,
        ivas_rend_CldfbSplitPreRendProcess( hSplitBin->hBinHrSplitPreRend,
#ifdef API_5MS
                                            headPosition,
#else
                                            headPositions,
#endif
            &hSplitBin->multiBinPoseData,
            Cldfb_In_BinReal,
            Cldfb_In_BinImag,
            pBits,
            target_md_bits,
            low_res_pre_rend_rot );
                                            &hSplitBin->multiBinPoseData, Cldfb_In_BinReal, Cldfb_In_BinImag, pBits, target_md_bits, low_res_pre_rend_rot );
    }

    if ( pcm_out == 0 )