From ba61e9a73be35370a04f2c961837ecad827c57ed Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Jul 2025 14:53:23 +0200 Subject: [PATCH 1/8] framework-related and formal improvements --- Workspace_msvc/lib_dec.vcxproj | 5 +- Workspace_msvc/lib_dec.vcxproj.filters | 11 +- Workspace_msvc/lib_isar.vcxproj | 2 +- apps/decoder.c | 45 ++--- lib_com/ivas_prot.h | 37 ++++ lib_dec/cldfb_ring_buffer.h | 108 ----------- ...ring_buffer.c => ivas_cldfb_ring_buffer.c} | 155 ++++++++++----- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_mc_param_dec.c | 2 +- lib_dec/ivas_mc_paramupmix_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 2 +- lib_dec/ivas_osba_dec.c | 2 +- lib_dec/ivas_stat_dec.h | 7 +- lib_dec/lib_dec.c | 182 +++++++++--------- lib_dec/lib_dec.h | 11 +- lib_isar/isar_prot.h | 6 +- lib_isar/isar_splitRend_lcld_enc.c | 8 +- lib_isar/isar_stat.h | 13 ++ lib_rend/ivas_dirac_dec_binaural_functions.c | 4 +- lib_rend/lib_rend.c | 5 +- 20 files changed, 300 insertions(+), 309 deletions(-) delete mode 100644 lib_dec/cldfb_ring_buffer.h rename lib_dec/{cldfb_ring_buffer.c => ivas_cldfb_ring_buffer.c} (56%) diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 944e264667..a8639d192c 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -147,7 +147,6 @@ - @@ -207,6 +206,7 @@ + @@ -313,7 +313,6 @@ - @@ -350,4 +349,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 5197d66457..e081cb0870 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -277,9 +277,6 @@ decoder_all_c - - decoder_all_c - decoder_all_c @@ -518,11 +515,11 @@ decoder_all_c + + decoder_ivas_c + - - decoder_h - decoder_h @@ -575,4 +572,4 @@ {c33b80b3-67ce-466b-91c0-4adfc9efcb5c} - + \ No newline at end of file diff --git a/Workspace_msvc/lib_isar.vcxproj b/Workspace_msvc/lib_isar.vcxproj index fceeb731ce..5bee827041 100644 --- a/Workspace_msvc/lib_isar.vcxproj +++ b/Workspace_msvc/lib_isar.vcxproj @@ -197,4 +197,4 @@ - + \ No newline at end of file diff --git a/apps/decoder.c b/apps/decoder.c index abf7468d2b..4fde8aa1c5 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -171,12 +171,11 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, #ifdef FIX_1119_SPLIT_RENDERING_VOIP - ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#else +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); #endif - IVAS_DEC_HANDLE hIvasDec, - int16_t *pcmBuf ); static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs ); #ifdef DEBUGGING static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); @@ -757,11 +756,11 @@ int main( if ( arg.voipMode ) { - error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, #ifdef FIX_1119_SPLIT_RENDERING_VOIP - &splitRendBits, + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, hIvasDec, pcmBuf ); +#else + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, hIvasDec, pcmBuf ); #endif - hIvasDec, pcmBuf ); } else { @@ -1906,7 +1905,6 @@ static ivas_error initOnFirstGoodFrame( else #endif { - if ( *pRemainingDelayNumSamples < *numOutSamples ) { if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) @@ -2115,7 +2113,7 @@ static ivas_error decodeG192( #ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( !isSplitRend ) { - /* Ensure split rendering output struct is not used when not outputting to a split rendering format */ + /* Ensure split rendering output struct is not used when not outputting to a split rendering output configuration */ splitRendBits = NULL; } #endif @@ -2455,11 +2453,11 @@ static ivas_error decodeG192( } /* decode transport channels, do TSM and feed to renderer */ - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - isSplitRend, +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) #endif - splitRendBits ) ) != IVAS_ERR_OK ) { return error; } @@ -3380,15 +3378,11 @@ static ivas_error decodeVoIP( #ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( isSplitRend ) { - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, #ifdef SUPPORT_JBM_TRACEFILE - writeJbmTraceFileFrameWrapper, - jbmTraceWriter, + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, nOutSamples, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif - &bitstreamReadDone, - &nSamplesRendered, - ¶metersAvailableForEditing, - systemTime_ms ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSplitBinauralBitstream: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3398,7 +3392,7 @@ static ivas_error decodeVoIP( { #endif #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &bitstreamReadDone, &nSamplesRendered, ¶meterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif @@ -3490,15 +3484,13 @@ static ivas_error decodeVoIP( { #ifndef FIX_1119_SPLIT_RENDERING_VOIP SplitFileReadWrite *splitRendWriter = NULL; -#endif - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, +#endif #ifdef FIX_1119_SPLIT_RENDERING_VOIP - &vec_pos_len, + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, #else - NULL, + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, #endif - delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -3523,6 +3515,7 @@ static ivas_error decodeVoIP( goto cleanup; } } + if ( !isSplitCoded ) { #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8121030b1c..283d96ff4b 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5195,6 +5195,43 @@ void ivas_binaural_add_LFE( float *output_f[] /* o : synthesized core-coder transport channels/DirAC output */ ); +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + +/*---------------------------------------------------------------------------------* + * Multi-pose ring buffer Prototypes +*-----------------------------------------------------------------------------------*/ + +ivas_error ivas_CLDFB_RINGBUF_Open( + ISAR_CLDFB_RINGBUF_HANDLE *ph, + const int16_t capacity_columns +); + +void ivas_CLDFB_RINGBUF_Close( + ISAR_CLDFB_RINGBUF_HANDLE *ph +); + +void ivas_CLDFB_RINGBUF_Push( + ISAR_CLDFB_RINGBUF_HANDLE h, + const float *real, + const float *imag, + const int16_t num_bands +); + +void ivas_CLDFB_RINGBUF_Pop( + ISAR_CLDFB_RINGBUF_HANDLE h, + float *real, + float *imag, + const int16_t num_bands +); + +void ivas_CLDFB_RINGBUF_GetByIdx( + ISAR_CLDFB_RINGBUF_HANDLE h, + float **p_real, + float **p_imag, + const int16_t idx +); + +#endif /*----------------------------------------------------------------------------------* * renderer prototypes diff --git a/lib_dec/cldfb_ring_buffer.h b/lib_dec/cldfb_ring_buffer.h deleted file mode 100644 index 68143bdfa0..0000000000 --- a/lib_dec/cldfb_ring_buffer.h +++ /dev/null @@ -1,108 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -#ifndef CLDFB_RING_BUFFER_H -#define CLDFB_RING_BUFFER_H - -#include "ivas_error.h" -#include - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - -typedef struct CldfbRingBuf *CLDFB_RINGBUF_HANDLE; - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_Open() - * - * Allocate a ring buffer for CLDFB data with the given capacity of CLDFB columns. - * Each column is expected to contain at most CLDFB_NO_CHANNELS_MAX frequency bands. - * - * May return IVAS_ERR_FAILED_ALLOC on failed allocation, or IVAS_ERR_OK otherwise. - *---------------------------------------------------------------------*/ -ivas_error CLDFB_RINGBUF_Open( CLDFB_RINGBUF_HANDLE *ph, int16_t capacity_columns ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_Close() - * - * Dellocate CLDFB ring buffer. The given handle will be set to NULL. - *---------------------------------------------------------------------*/ -void CLDFB_RINGBUF_Close( CLDFB_RINGBUF_HANDLE *ph ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_Push() - * - * Push a single column onto the back of the CLDFB ring buffer from real and imag arrays. - *---------------------------------------------------------------------*/ -void CLDFB_RINGBUF_Push( CLDFB_RINGBUF_HANDLE h, const float *real, const float *imag, uint16_t num_bands ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_Pop() - * - * Pop a single column from the front of the CLDFB ring buffer into real and imag arrays. - *---------------------------------------------------------------------*/ -void CLDFB_RINGBUF_Pop( CLDFB_RINGBUF_HANDLE h, float *real, float *imag, uint16_t num_bands ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_GetByIdx() - * - * Get pointers into a specific column in the CLDFB ring buffer based on given index. - * Non-negative indices access from the front of the ring buffer, negative indexes access - * from the back, similar to Python arrays. For example: - * - * - index 0 accesses the front of the buffer, i.e. the oldest CLDFB column in the queue. - * - index -1 accesses the back of the buffer, i.e. the newest (last pushed) CLDFB column in the queue. - *---------------------------------------------------------------------*/ -void CLDFB_RINGBUF_GetByIdx( CLDFB_RINGBUF_HANDLE h, float **p_real, float **p_imag, int16_t idx ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_IsEmpty() - * - * Returns 1 if the ring buffer is empty, or 0 otherwise. - *---------------------------------------------------------------------*/ -int16_t CLDFB_RINGBUF_IsEmpty( CLDFB_RINGBUF_HANDLE h ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_IsFull() - * - * Returns 1 if the ring buffer is full, or 0 otherwise. - *---------------------------------------------------------------------*/ -int16_t CLDFB_RINGBUF_IsFull( CLDFB_RINGBUF_HANDLE h ); - -/*---------------------------------------------------------------------* - * CLDFB_RINGBUF_Size() - * - * Returns the number of CLDFB columns currently stored in the ring buffer. - *---------------------------------------------------------------------*/ -uint16_t CLDFB_RINGBUF_Size( CLDFB_RINGBUF_HANDLE h ); - -#endif /* FIX_1119_SPLIT_RENDERING_VOIP */ -#endif diff --git a/lib_dec/cldfb_ring_buffer.c b/lib_dec/ivas_cldfb_ring_buffer.c similarity index 56% rename from lib_dec/cldfb_ring_buffer.c rename to lib_dec/ivas_cldfb_ring_buffer.c index c6be06b1ea..01ce9cd7c0 100644 --- a/lib_dec/cldfb_ring_buffer.c +++ b/lib_dec/ivas_cldfb_ring_buffer.c @@ -30,33 +30,63 @@ *******************************************************************************************************/ -#include "cldfb_ring_buffer.h" +#include +#include "options.h" #include "cnst.h" #include "prot.h" -#include "ivas_error_utils.h" +#include "ivas_prot.h" #include -#include -#include +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "wmc_auto.h" #ifdef FIX_1119_SPLIT_RENDERING_VOIP -struct CldfbRingBuf +/*---------------------------------------------------------------------* + * CLDFB_RINGBUF_IsEmpty() + * + * Returns 1 if the ring buffer is empty, or 0 otherwise. + *---------------------------------------------------------------------*/ + +static int16_t ivas_CLDFB_RINGBUF_IsEmpty( + ISAR_CLDFB_RINGBUF_HANDLE h ) +{ + return (int16_t) ( h->read_pos == h->write_pos && !h->is_full ); +} + +/*---------------------------------------------------------------------* + * CLDFB_RINGBUF_IsFull() + * + * Returns 1 if the ring buffer is full, or 0 otherwise. + *---------------------------------------------------------------------*/ + +static int16_t ivas_CLDFB_RINGBUF_IsFull( + ISAR_CLDFB_RINGBUF_HANDLE h ) { - float *real; - float *imag; - uint32_t capacity; - uint32_t write_pos; - uint32_t read_pos; - int16_t is_full; -}; - -ivas_error CLDFB_RINGBUF_Open( CLDFB_RINGBUF_HANDLE *ph, int16_t capacity_columns ) + return h->is_full; +} + + +/*---------------------------------------------------------------------* + * ivas_CLDFB_RINGBUF_Open() + * + * Allocate a ring buffer for CLDFB data with the given capacity of CLDFB columns. + * Each column is expected to contain at most CLDFB_NO_CHANNELS_MAX frequency bands. + * + * May return IVAS_ERR_FAILED_ALLOC on failed allocation, or IVAS_ERR_OK otherwise. + *---------------------------------------------------------------------*/ + +ivas_error ivas_CLDFB_RINGBUF_Open( + ISAR_CLDFB_RINGBUF_HANDLE *ph, + const int16_t capacity_columns ) { - CLDFB_RINGBUF_HANDLE h; + ISAR_CLDFB_RINGBUF_HANDLE h; int32_t capacity; + capacity = capacity_columns * CLDFB_NO_CHANNELS_MAX; - if ( ( h = malloc( sizeof( struct CldfbRingBuf ) ) ) == NULL ) + if ( ( h = malloc( sizeof( ISAR_CLDFB_RINGBUF_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for CLDFB ring buffer\n" ); } @@ -81,9 +111,17 @@ ivas_error CLDFB_RINGBUF_Open( CLDFB_RINGBUF_HANDLE *ph, int16_t capacity_column return IVAS_ERR_OK; } -void CLDFB_RINGBUF_Close( CLDFB_RINGBUF_HANDLE *ph ) + +/*---------------------------------------------------------------------* + * ivas_CLDFB_RINGBUF_Close() + * + * Dellocate CLDFB ring buffer. The given handle will be set to NULL. + *---------------------------------------------------------------------*/ + +void ivas_CLDFB_RINGBUF_Close( + ISAR_CLDFB_RINGBUF_HANDLE *ph ) { - CLDFB_RINGBUF_HANDLE h; + ISAR_CLDFB_RINGBUF_HANDLE h; if ( ph == NULL ) { @@ -111,13 +149,24 @@ void CLDFB_RINGBUF_Close( CLDFB_RINGBUF_HANDLE *ph ) return; } -void CLDFB_RINGBUF_Push( CLDFB_RINGBUF_HANDLE h, const float *real, const float *imag, uint16_t num_bands ) + +/*---------------------------------------------------------------------* + * ivas_CLDFB_RINGBUF_Push() + * + * Push a single column onto the back of the CLDFB ring buffer from real and imag arrays. + *---------------------------------------------------------------------*/ + +void ivas_CLDFB_RINGBUF_Push( + ISAR_CLDFB_RINGBUF_HANDLE h, + const float *real, + const float *imag, + const int16_t num_bands ) { assert( num_bands <= CLDFB_NO_CHANNELS_MAX ); - assert( !CLDFB_RINGBUF_IsFull( h ) ); + assert( !ivas_CLDFB_RINGBUF_IsFull( h ) ); - mvr2r( real, &h->real[h->write_pos], (int16_t) num_bands ); - mvr2r( imag, &h->imag[h->write_pos], (int16_t) num_bands ); + mvr2r( real, &h->real[h->write_pos], num_bands ); + mvr2r( imag, &h->imag[h->write_pos], num_bands ); h->write_pos += CLDFB_NO_CHANNELS_MAX; if ( h->write_pos == h->capacity ) @@ -133,18 +182,29 @@ void CLDFB_RINGBUF_Push( CLDFB_RINGBUF_HANDLE h, const float *real, const float return; } -void CLDFB_RINGBUF_Pop( CLDFB_RINGBUF_HANDLE h, float *real, float *imag, uint16_t num_bands ) + +/*---------------------------------------------------------------------* + * ivas_CLDFB_RINGBUF_Pop() + * + * Pop a single column from the front of the CLDFB ring buffer into real and imag arrays. + *---------------------------------------------------------------------*/ + +void ivas_CLDFB_RINGBUF_Pop( + ISAR_CLDFB_RINGBUF_HANDLE h, + float *real, + float *imag, + const int16_t num_bands ) { assert( num_bands <= CLDFB_NO_CHANNELS_MAX ); - assert( !CLDFB_RINGBUF_IsEmpty( h ) ); + assert( !ivas_CLDFB_RINGBUF_IsEmpty( h ) ); if ( real != NULL ) { - mvr2r( &h->real[h->read_pos], real, (int16_t) num_bands ); + mvr2r( &h->real[h->read_pos], real, num_bands ); } if ( imag != NULL ) { - mvr2r( &h->imag[h->read_pos], imag, (int16_t) num_bands ); + mvr2r( &h->imag[h->read_pos], imag, num_bands ); } h->read_pos += CLDFB_NO_CHANNELS_MAX; @@ -161,10 +221,12 @@ void CLDFB_RINGBUF_Pop( CLDFB_RINGBUF_HANDLE h, float *real, float *imag, uint16 return; } + /* Returns total number of buffered samples (including number of channels) */ -static uint32_t total_size( CLDFB_RINGBUF_HANDLE h ) +static uint32_t CLDFB_RINGBUF_total_size( + ISAR_CLDFB_RINGBUF_HANDLE h ) { - if ( CLDFB_RINGBUF_IsFull( h ) ) + if ( ivas_CLDFB_RINGBUF_IsFull( h ) ) { return h->capacity; } @@ -173,14 +235,31 @@ static uint32_t total_size( CLDFB_RINGBUF_HANDLE h ) { return h->write_pos - h->read_pos; } + /* else wrap around */ return h->write_pos + h->capacity - h->read_pos; } -void CLDFB_RINGBUF_GetByIdx( CLDFB_RINGBUF_HANDLE h, float **p_real, float **p_imag, int16_t col_idx ) + +/*---------------------------------------------------------------------* + * ivas_CLDFB_RINGBUF_GetByIdx() + * + * Get pointers into a specific column in the CLDFB ring buffer based on given index. + * Non-negative indices access from the front of the ring buffer, negative indexes access + * from the back, similar to Python arrays. For example: + * + * - index 0 accesses the front of the buffer, i.e. the oldest CLDFB column in the queue. + * - index -1 accesses the back of the buffer, i.e. the newest (last pushed) CLDFB column in the queue. + *---------------------------------------------------------------------*/ + +void ivas_CLDFB_RINGBUF_GetByIdx( + ISAR_CLDFB_RINGBUF_HANDLE h, + float **p_real, + float **p_imag, + const int16_t col_idx ) { int32_t idx = col_idx * CLDFB_NO_CHANNELS_MAX; - int32_t num_floats = (int32_t) total_size( h ); + int32_t num_floats = (int32_t) CLDFB_RINGBUF_total_size( h ); uint32_t offset; assert( -num_floats <= idx && idx <= num_floats ); @@ -196,21 +275,7 @@ void CLDFB_RINGBUF_GetByIdx( CLDFB_RINGBUF_HANDLE h, float **p_real, float **p_i *p_real = &h->real[offset]; *p_imag = &h->imag[offset]; -} - -int16_t CLDFB_RINGBUF_IsEmpty( CLDFB_RINGBUF_HANDLE h ) -{ - return (int16_t) ( h->read_pos == h->write_pos && !h->is_full ); -} -int16_t CLDFB_RINGBUF_IsFull( CLDFB_RINGBUF_HANDLE h ) -{ - return h->is_full; -} - -uint16_t CLDFB_RINGBUF_Size( CLDFB_RINGBUF_HANDLE h ) -{ - return (uint16_t) ( total_size( h ) / CLDFB_NO_CHANNELS_MAX ); + return; } - #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 0ea8d67a6a..b53d8cc200 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1670,7 +1670,7 @@ static void binRenderer_split( for ( ch = 0; ch < nchan_out; ch++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_Push( + ivas_CLDFB_RINGBUF_Push( hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx], diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index bb013b8d78..b0ce85ce51 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -1787,7 +1787,7 @@ void ivas_param_mc_dec_render( for ( ch = 0; ch < nchan_out_cldfb; ch++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_Push( + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 8fddef8ac8..ccae387180 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -791,7 +791,7 @@ static void ivas_mc_paramupmix_dec_sf( for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_Push( + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 3ea63bfdf3..f92d987c3f 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -800,7 +800,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( /* note: this intentionally differs from OSBA by: no scaling by 0.5 */ #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots ); + ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots ); v_add( re, Cldfb_RealBuffer, re, num_cldfb_bands ); v_add( im, Cldfb_ImagBuffer, im, num_cldfb_bands ); #else diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index e251f4da7a..582fc08b65 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -185,7 +185,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm( cldfbAnalysis_ts( &( output_f[n][num_cldfb_bands * slot_idx] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, num_cldfb_bands, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n] ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots ); + ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots ); for ( b = 0; b < num_cldfb_bands; b++ ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 53651d186a..6cc208cf8b 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -40,9 +40,6 @@ #include "stat_dec.h" #include "ivas_stat_com.h" #include "ivas_stat_rend.h" -#ifdef FIX_1119_SPLIT_RENDERING_VOIP -#include "cldfb_ring_buffer.h" -#endif /*----------------------------------------------------------------------------------* @@ -831,8 +828,8 @@ typedef struct float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; } ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA, *ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE; -#endif +#endif typedef struct { #ifdef FIX_1119_SPLIT_RENDERING_VOIP @@ -849,7 +846,7 @@ typedef struct typedef struct { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_HANDLE hMultiBinCldfbData[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; + ISAR_CLDFB_RINGBUF_HANDLE hMultiBinCldfbData[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; #else ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE hMultiBinCldfbData; /*scratch buffer for frame by frame processing*/ #endif diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index bdb69ab8fc..0160b48549 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -114,11 +114,11 @@ static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, c static ivas_error evs_dec_main( Decoder_Struct *st_ivas ); static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); -static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - const int16_t isSplitRend, +#ifdef FIX_1119_SPLIT_RENDERING_VOIP +static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); +#else +static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, const int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); #endif - ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const uint16_t nTransportChannels ); static PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ); static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int32_t offset ); @@ -1147,11 +1147,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( * Setup all decoder parts (IVAS decoder, ISAR) *-----------------------------------------------------------------*/ - if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - isSplitRend, +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, splitRendBits ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) #endif - splitRendBits ) ) != IVAS_ERR_OK ) { return error; } @@ -1841,11 +1841,19 @@ ivas_error IVAS_DEC_GetSamplesRenderer( #ifdef FIX_1119_SPLIT_RENDERING_VOIP +/*---------------------------------------------------------------------* + * isar_get_frame_size( ) + * + * + *---------------------------------------------------------------------*/ + static int16_t isar_get_frame_size( - Decoder_Struct *st_ivas ) + Decoder_Struct *st_ivas /* i : IVAS decoder handle */ +) { int32_t output_Fs; int16_t nSamplesPerChannel; + output_Fs = st_ivas->hDecoderConfig->output_Fs; if ( st_ivas->hDecoderConfig->render_framesize != IVAS_RENDER_FRAMESIZE_20MS && @@ -1863,27 +1871,29 @@ static int16_t isar_get_frame_size( return nSamplesPerChannel; } + +/*---------------------------------------------------------------------* + * isar_render_poses( ) + * + * + *---------------------------------------------------------------------*/ + static ivas_error isar_render_poses( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ - float **p_head_pose_buf, - int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* o : indication that the decoder needs a new frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ + float **p_head_pose_buf, /* o : PCM buffer with head-pose data */ + int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { - Decoder_Struct *st_ivas; float pcmBuf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k]; int16_t i, j; ivas_error error; - ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; int16_t numPoses; - error = IVAS_ERR_OK; - st_ivas = hIvasDec->st_ivas; *needNewFrame = false; - hSplitBinRend = st_ivas->hSplitBinRend; - numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; + numPoses = hIvasDec->st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; /* init flush buffer for rate switch if not already initizalized */ if ( hIvasDec->flushbuffer == NULL ) @@ -1902,6 +1912,7 @@ static ivas_error isar_render_poses( { return error; } + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { return IVAS_ERR_OK; @@ -1919,15 +1930,19 @@ static ivas_error isar_render_poses( return error; } + +/*---------------------------------------------------------------------* + * isar_generate_metadata_and_bitstream( ) + * + * + *---------------------------------------------------------------------*/ + static ivas_error isar_generate_metadata_and_bitstream( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - float **p_head_pose_buf, - ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float **p_head_pose_buf, /* i/o: PCM buffer with head-pose data */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ ) { - Decoder_Struct *st_ivas; - AUDIO_CONFIG output_config; - int32_t output_Fs; ivas_error error; ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; int16_t max_band; @@ -1939,14 +1954,10 @@ static ivas_error isar_generate_metadata_and_bitstream( float *p_Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; float *p_Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; - error = IVAS_ERR_OK; - st_ivas = hIvasDec->st_ivas; - output_config = st_ivas->hDecoderConfig->output_config; - output_Fs = st_ivas->hDecoderConfig->output_Fs; hSplitBinRend = st_ivas->hSplitBinRend; - max_band = (int16_t) ( ( BINAURAL_MAXBANDS * output_Fs ) / 48000 ); - pcm_out_flag = ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; + max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_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; if ( !td_input ) @@ -1959,20 +1970,13 @@ static ivas_error isar_generate_metadata_and_bitstream( { /* Save pointers to first CLDFB column in the ring buffer. Allows us to save * significant amounts of memory by not copying CLDFB values into a separate buffer. */ - CLDFB_RINGBUF_GetByIdx( - hSplitBinRend->hMultiBinCldfbData[i], - &p_Cldfb_RealBuffer_Binaural[i][j], - &p_Cldfb_ImagBuffer_Binaural[i][j], - 0 ); + ivas_CLDFB_RINGBUF_GetByIdx( hSplitBinRend->hMultiBinCldfbData[i], &p_Cldfb_RealBuffer_Binaural[i][j], &p_Cldfb_ImagBuffer_Binaural[i][j], 0 ); + /* Pop the CLDFB column we just saved pointers to. This is fine as long as we use * the saved columns only before any new columns are pushed to the buffer - the new * columns could potentially overwrite the old columns we wanted to use. * This requirement is fulfilled in this case. */ - CLDFB_RINGBUF_Pop( - hSplitBinRend->hMultiBinCldfbData[i], - NULL, - NULL, - CLDFB_NO_CHANNELS_MAX ); + ivas_CLDFB_RINGBUF_Pop( hSplitBinRend->hMultiBinCldfbData[i], NULL, NULL, CLDFB_NO_CHANNELS_MAX ); } } } @@ -2036,7 +2040,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( ivas_error error; float head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; float *p_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; - int32_t i; + int16_t i; int16_t pcm_out_flag; int16_t numSamplesPerChannelToOutput; @@ -2045,7 +2049,6 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - error = IVAS_ERR_UNKNOWN; st_ivas = hIvasDec->st_ivas; if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) @@ -2061,18 +2064,17 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( p_head_pose_buf[i] = head_pose_buf[i]; } - error = isar_render_poses( hIvasDec, numSamplesPerChannelToOutput, p_head_pose_buf, nOutSamples, needNewFrame ); - if ( error != IVAS_ERR_OK ) + if ( ( error = isar_render_poses( hIvasDec, numSamplesPerChannelToOutput, p_head_pose_buf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) { return error; } + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { return IVAS_ERR_OK; } - error = isar_generate_metadata_and_bitstream( hIvasDec, p_head_pose_buf, splitRendBits ); - if ( error != IVAS_ERR_OK ) + if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, splitRendBits ) ) != IVAS_ERR_OK ) { return error; } @@ -2285,7 +2287,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } #endif - return error; + return IVAS_ERR_OK; } @@ -3681,13 +3683,16 @@ ivas_error IVAS_DEC_TSM_SetQuality( #endif #ifdef FIX_1119_SPLIT_RENDERING_VOIP + /*---------------------------------------------------------------------* * ivas_dec_voip_get_samples_common( ) * * Main function to output one frame in VoIP. Holds common code for * regular output configs and split rendering configs. *---------------------------------------------------------------------*/ + static ivas_error ivas_dec_voip_get_samples_common + #else /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) @@ -3703,7 +3708,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ #ifdef FIX_1119_SPLIT_RENDERING_VOIP - ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ + float **p_head_pose_buf, /* i : PCM buffer with head-pose data */ #endif #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, @@ -3724,11 +3730,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples int16_t result; ivas_error error; uint8_t nOutChannels; - #ifdef FIX_1119_SPLIT_RENDERING_VOIP int32_t i; - float head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; - float *p_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; #endif if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->hVoIP == NULL ) @@ -3753,8 +3756,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples { return IVAS_ERROR( IVAS_ERR_NOT_IMPLEMENTED, "Split rendering is not integrated with VoIP mode" ); } -#endif +#endif /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ while ( *nSamplesRendered < nSamplesPerChannel ) { @@ -3776,7 +3779,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; dataUnit = NULL; - /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); if ( result != 0 ) @@ -3900,13 +3902,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples { if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) { - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, #ifdef FIX_1119_SPLIT_RENDERING_VOIP - splitRendBits + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) #else - 0, NULL + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, NULL ) ) != IVAS_ERR_OK ) #endif - ) ) != IVAS_ERR_OK ) { return error; } @@ -3929,12 +3929,12 @@ ivas_error IVAS_DEC_VoIP_GetSamples } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + if ( splitRendBits != NULL ) { /* Move output pointers forward */ for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) { - p_head_pose_buf[i] = &head_pose_buf[i][*nSamplesRendered]; + p_head_pose_buf[i] += *nSamplesRendered; } /* Render head poses from time-scaled transport channels */ @@ -3942,6 +3942,12 @@ ivas_error IVAS_DEC_VoIP_GetSamples { return error; } + + /* Set pointers back to the beginning of head pose buffers */ + for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) + { + p_head_pose_buf[i] -= *nSamplesRendered; + } } else { @@ -3961,25 +3967,16 @@ ivas_error IVAS_DEC_VoIP_GetSamples } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( hIvasDec->hasDecodedFirstGoodFrame && - ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || - hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + if ( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL ) { - /* Set pointers to beginning of head pose buffers */ - for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) - { - p_head_pose_buf[i] = head_pose_buf[i]; - } - /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */ - error = isar_generate_metadata_and_bitstream( hIvasDec, p_head_pose_buf, splitRendBits ); - if ( error != IVAS_ERR_OK ) + if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, splitRendBits ) ) != IVAS_ERR_OK ) { return error; } /* Synthesise PCM output if split PCM */ - if ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { if ( st_ivas->hDecoderConfig->render_framesize == IVAS_RENDER_FRAMESIZE_5MS ) { @@ -4004,6 +4001,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples } #ifdef FIX_1119_SPLIT_RENDERING_VOIP + /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) * @@ -4011,10 +4009,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_GetSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ - void *pcmBuf, /* o : output synthesis signal */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + void *pcmBuf, /* o : output synthesis signal */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter, @@ -4028,9 +4025,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return ivas_dec_voip_get_samples_common( hIvasDec, nSamplesPerChannel, - pcmType, + IVAS_DEC_PCM_INT16, pcmBuf, NULL, + NULL, #ifdef SUPPORT_JBM_TRACEFILE jbmWriterFn, jbmWriter, @@ -4044,27 +4042,27 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ void *pcmBuf, /* o : output synthesis signal */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, - void *jbmWriter + void *jbmWriter, #endif - , bool *bitstreamReadDone, /* o : flag indicating that bitstream was read */ uint16_t *nSamplesRendered, /* o : number of samples rendered */ bool *parametersAvailableForEditing, /* o : indicates whether objects editing is available */ const uint32_t systemTimestamp_ms /* i : current system timestamp */ ) { - ivas_error error = IVAS_ERR_UNKNOWN; - int16_t nSamplesPerChannel = 0; + int16_t i; + float head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; + float *pp_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; - if ( ( error = IVAS_DEC_GetRenderFramesizeSamples( hIvasDec, &nSamplesPerChannel ) ) != IVAS_ERR_OK ) + /* Set pointers to beginning of head pose buffers */ + for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) { - fprintf( stderr, "\nError getting render frame size in samples\n" ); - return error; + pp_head_pose_buf[i] = head_pose_buf[i]; } return ivas_dec_voip_get_samples_common( @@ -4073,6 +4071,7 @@ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_PCM_INT16, pcmBuf, splitRendBits, + pp_head_pose_buf, #ifdef SUPPORT_JBM_TRACEFILE jbmWriterFn, jbmWriter, @@ -5186,7 +5185,7 @@ static ivas_error ivas_create_handle_isar( isar_init_split_rend_handles( &hSplitBinRend->splitrend ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP - for ( i = 0; i < (int16_t) ( MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS ); ++i ) + for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { hSplitBinRend->hMultiBinCldfbData[i] = NULL; } @@ -5219,11 +5218,11 @@ static void ivas_destroy_handle_isar( if ( *hSplitBinRend != NULL ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - for ( i = 0; i < (int16_t) ( MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS ); ++i ) + for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { if ( ( *hSplitBinRend )->hMultiBinCldfbData[i] != NULL ) { - CLDFB_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinCldfbData[i] ); + ivas_CLDFB_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinCldfbData[i] ); } } #else @@ -5439,11 +5438,10 @@ static ivas_error ivas_dec_init_split_rend( if ( cldfb_in_flag ) { - for ( i = 0; i < (int16_t) ( num_poses * BINAURAL_CHANNELS ); ++i ) + for ( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i ) { /* note: this is intra-frame heap memory */ - error = CLDFB_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinCldfbData[i], CLDFB_NO_COL_MAX ); - if ( error != IVAS_ERR_OK ) + if ( ( error = ivas_CLDFB_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinCldfbData[i], CLDFB_NO_COL_MAX ) ) != IVAS_ERR_OK ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 73c55bd1f0..181417c70a 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -311,7 +311,9 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ +#ifndef FIX_1119_SPLIT_RENDERING_VOIP const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ +#endif void *pcmBuf, /* o : output synthesis signal */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, @@ -327,17 +329,16 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ void *pcmBuf, /* o : output synthesis signal */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, - void* jbmWriter + void* jbmWriter, #endif - , bool *bitstreamReadDone, /* o : flag indicating that bitstream was read */ - uint16_t *nSamplesRendered, - bool *parametersAvailableForEditing, + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + bool *parametersAvailableForEditing, /* o : indicates whether objects editing is available */ const uint32_t systemTimestamp_ms /* i : current system timestamp */ ); #endif diff --git a/lib_isar/isar_prot.h b/lib_isar/isar_prot.h index f842b0a53b..53d70184f0 100644 --- a/lib_isar/isar_prot.h +++ b/lib_isar/isar_prot.h @@ -189,13 +189,13 @@ void isar_splitBinLCLDEncClose( void isar_splitBinLCLDEncProcess( ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE hSplitBinLCLDEnc, /* i/o: ISAR LCLD encoder handle */ #ifdef FIX_1119_SPLIT_RENDERING_VOIP - float *Cldfb_In_Real[][CLDFB_NO_COL_MAX], - float *Cldfb_In_Imag[][CLDFB_NO_COL_MAX], + float *Cldfb_In_Real[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ + float *Cldfb_In_Imag[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag. part */ #else float Cldfb_In_Real[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_In_Imag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], #endif - const int32_t available_bits, + const int32_t available_bits, /* i : available bit-budget */ ISAR_SPLIT_REND_BITS_HANDLE pBits /* i/o: ISAR bits handle */ ); diff --git a/lib_isar/isar_splitRend_lcld_enc.c b/lib_isar/isar_splitRend_lcld_enc.c index 171b5162b3..1ecb83887b 100644 --- a/lib_isar/isar_splitRend_lcld_enc.c +++ b/lib_isar/isar_splitRend_lcld_enc.c @@ -159,14 +159,14 @@ void isar_splitBinLCLDEncClose( void isar_splitBinLCLDEncProcess( ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE hSplitBinLCLDEnc, /* i/o: ISAR LCLD encoder handle */ #ifdef FIX_1119_SPLIT_RENDERING_VOIP - float *Cldfb_In_Real[][CLDFB_NO_COL_MAX], - float *Cldfb_In_Imag[][CLDFB_NO_COL_MAX], + float *Cldfb_In_Real[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ + float *Cldfb_In_Imag[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag. part */ #else float Cldfb_In_Real[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_In_Imag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], #endif - const int32_t available_bits, - ISAR_SPLIT_REND_BITS_HANDLE pBits /* i/o: ISAR bits handle */ + const int32_t available_bits, /* i : available bit-budget */ + ISAR_SPLIT_REND_BITS_HANDLE pBits /* i/o: ISAR bits handle */ ) { int32_t iBitsWritten, itr, available_bits_itr, rem_itr, available_bits_local; diff --git a/lib_isar/isar_stat.h b/lib_isar/isar_stat.h index 587c3c8ea7..0e0577d570 100644 --- a/lib_isar/isar_stat.h +++ b/lib_isar/isar_stat.h @@ -345,4 +345,17 @@ typedef struct } SPLIT_REND_WRAPPER; +#ifdef FIX_1119_SPLIT_RENDERING_VOIP +typedef struct +{ + float *real; + float *imag; + uint32_t capacity; + uint32_t write_pos; + uint32_t read_pos; + int16_t is_full; + +} ISAR_CLDFB_RINGBUF_DATA, *ISAR_CLDFB_RINGBUF_HANDLE; +#endif + #endif /* ISAR_STAT_H */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 33328e365c..98f05e7b8e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -796,7 +796,7 @@ static void ivas_dirac_dec_binaural_internal( for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_Push( + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], @@ -873,7 +873,7 @@ static void ivas_dirac_dec_binaural_internal( for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - CLDFB_RINGBUF_Push( + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 9401b9e553..7edde29027 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7462,11 +7462,10 @@ static ivas_error getSamplesInternal( int16_t ch; int16_t i, ro_md_flag; float *tmpBinaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS], tmpBinaural_buff[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][L_FRAME48k]; - #ifdef FIX_1119_SPLIT_RENDERING_VOIP float *p_Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; float *p_Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; - int32_t j; + int16_t j; for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) { @@ -7521,7 +7520,7 @@ static ivas_error getSamplesInternal( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, #endif - ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From d76762fdab6169deda87e038aad73c6a9255a6dd Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 5 Aug 2025 17:22:08 +0200 Subject: [PATCH 2/8] address comments --- apps/decoder.c | 4 +-- lib_dec/ivas_cldfb_ring_buffer.c | 8 ++++-- lib_dec/lib_dec.c | 26 ++++++++++++++++---- lib_dec/lib_dec.h | 4 +-- lib_rend/ivas_dirac_dec_binaural_functions.c | 13 ++-------- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 4fde8aa1c5..21d9c66873 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3379,7 +3379,7 @@ static ivas_error decodeVoIP( if ( isSplitRend ) { #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, nOutSamples, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSplitBinauralBitstream( hIvasDec, (void *) pcmBuf, splitRendBits, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif @@ -3392,7 +3392,7 @@ static ivas_error decodeVoIP( { #endif #ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &bitstreamReadDone, &nSamplesRendered, ¶meterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_cldfb_ring_buffer.c b/lib_dec/ivas_cldfb_ring_buffer.c index 01ce9cd7c0..82f79687ff 100644 --- a/lib_dec/ivas_cldfb_ring_buffer.c +++ b/lib_dec/ivas_cldfb_ring_buffer.c @@ -42,9 +42,12 @@ #include "wmc_auto.h" #ifdef FIX_1119_SPLIT_RENDERING_VOIP +/*---------------------------------------------------------------------* + * CLDFB ring-buffer functions needed in split-rendering outputs + *---------------------------------------------------------------------*/ /*---------------------------------------------------------------------* - * CLDFB_RINGBUF_IsEmpty() + * ivas_CLDFB_RINGBUF_IsEmpty() * * Returns 1 if the ring buffer is empty, or 0 otherwise. *---------------------------------------------------------------------*/ @@ -55,8 +58,9 @@ static int16_t ivas_CLDFB_RINGBUF_IsEmpty( return (int16_t) ( h->read_pos == h->write_pos && !h->is_full ); } + /*---------------------------------------------------------------------* - * CLDFB_RINGBUF_IsFull() + * ivas_CLDFB_RINGBUF_IsFull() * * Returns 1 if the ring buffer is full, or 0 otherwise. *---------------------------------------------------------------------*/ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0160b48549..25865123b0 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -4009,9 +4009,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_GetSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - void *pcmBuf, /* o : output synthesis signal */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *pcmBuf, /* o : output synthesis signal */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter, @@ -4025,7 +4026,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return ivas_dec_voip_get_samples_common( hIvasDec, nSamplesPerChannel, - IVAS_DEC_PCM_INT16, + pcmType, pcmBuf, NULL, NULL, @@ -4039,10 +4040,17 @@ ivas_error IVAS_DEC_VoIP_GetSamples( systemTimestamp_ms ); } + +/*---------------------------------------------------------------------* + * IVAS_DEC_VoIP_GetSplitBinauralBitstream( ) + * + * Main function to decode one split-rendering frame in VoIP + *---------------------------------------------------------------------*/ + /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ #ifdef SUPPORT_JBM_TRACEFILE @@ -4058,6 +4066,14 @@ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( int16_t i; float head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; float *pp_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; + ivas_error error = IVAS_ERR_UNKNOWN; + int16_t nSamplesPerChannel = 0; + + if ( ( error = IVAS_DEC_GetRenderFramesizeSamples( hIvasDec, &nSamplesPerChannel ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError getting render frame size in samples\n" ); + return error; + } /* Set pointers to beginning of head pose buffers */ for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 181417c70a..18298954c4 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -311,9 +311,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ -#endif void *pcmBuf, /* o : output synthesis signal */ #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, @@ -329,7 +327,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ #ifdef SUPPORT_JBM_TRACEFILE diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 98f05e7b8e..0e314632d3 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -796,11 +796,7 @@ static void ivas_dirac_dec_binaural_internal( for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - ivas_CLDFB_RINGBUF_Push( - st_ivas->hSplitBinRend->hMultiBinCldfbData[ch], - tmp_Cldfb_out_re[ch][i], - tmp_Cldfb_out_im[ch][i], - CLDFB_NO_CHANNELS_MAX ); + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], CLDFB_NO_CHANNELS_MAX ); #else mvr2r( tmp_Cldfb_out_re[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); mvr2r( tmp_Cldfb_out_im[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); @@ -861,7 +857,6 @@ static void ivas_dirac_dec_binaural_internal( hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); - /* re-use reverb and decorr from main direction for the sides */ ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe, tmp_Cldfb_out_re, tmp_Cldfb_out_im, @@ -873,11 +868,7 @@ static void ivas_dirac_dec_binaural_internal( for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP - ivas_CLDFB_RINGBUF_Push( - st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], - tmp_Cldfb_out_re[ch][i], - tmp_Cldfb_out_im[ch][i], - CLDFB_NO_CHANNELS_MAX ); + ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], CLDFB_NO_CHANNELS_MAX ); #else mvr2r( tmp_Cldfb_out_re[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[pos_idx * BINAURAL_CHANNELS + ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); mvr2r( tmp_Cldfb_out_im[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[pos_idx * BINAURAL_CHANNELS + ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); -- GitLab From ce4f93c05a7d3575cffacfb4f7d6e97215102e89 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Mon, 11 Aug 2025 09:56:59 +0200 Subject: [PATCH 3/8] Remove unneeded postfix from struct name ISAR_CLDFB_RINGBUF_DATA --- lib_dec/ivas_cldfb_ring_buffer.c | 2 +- lib_isar/isar_stat.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_cldfb_ring_buffer.c b/lib_dec/ivas_cldfb_ring_buffer.c index 82f79687ff..fdabe30fe8 100644 --- a/lib_dec/ivas_cldfb_ring_buffer.c +++ b/lib_dec/ivas_cldfb_ring_buffer.c @@ -90,7 +90,7 @@ ivas_error ivas_CLDFB_RINGBUF_Open( capacity = capacity_columns * CLDFB_NO_CHANNELS_MAX; - if ( ( h = malloc( sizeof( ISAR_CLDFB_RINGBUF_DATA ) ) ) == NULL ) + if ( ( h = malloc( sizeof( ISAR_CLDFB_RINGBUF ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for CLDFB ring buffer\n" ); } diff --git a/lib_isar/isar_stat.h b/lib_isar/isar_stat.h index 0e0577d570..b244370dd3 100644 --- a/lib_isar/isar_stat.h +++ b/lib_isar/isar_stat.h @@ -355,7 +355,7 @@ typedef struct uint32_t read_pos; int16_t is_full; -} ISAR_CLDFB_RINGBUF_DATA, *ISAR_CLDFB_RINGBUF_HANDLE; +} ISAR_CLDFB_RINGBUF, *ISAR_CLDFB_RINGBUF_HANDLE; #endif #endif /* ISAR_STAT_H */ -- GitLab From 3d3cc22cc9695ab618002aec144bd7b9242b5248 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Mon, 11 Aug 2025 11:08:12 +0200 Subject: [PATCH 4/8] Ensure splitRendBits is not NULL when outputting to split rendering config --- lib_dec/lib_dec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 25865123b0..0de65e331a 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3750,7 +3750,14 @@ ivas_error IVAS_DEC_VoIP_GetSamples return IVAS_ERR_WRONG_PARAMS; } -#ifndef FIX_1119_SPLIT_RENDERING_VOIP +#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || + hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && + splitRendBits == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } +#else if ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { -- GitLab From ab4e5f4778b0c737b291dd76d10db0cbc536821d Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Thu, 14 Aug 2025 10:38:52 +0200 Subject: [PATCH 5/8] Keep function name prefixes consistent in ivas_cldfb_ring_buffer.c --- lib_dec/ivas_cldfb_ring_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_cldfb_ring_buffer.c b/lib_dec/ivas_cldfb_ring_buffer.c index fdabe30fe8..bc0e2c6ee0 100644 --- a/lib_dec/ivas_cldfb_ring_buffer.c +++ b/lib_dec/ivas_cldfb_ring_buffer.c @@ -227,7 +227,7 @@ void ivas_CLDFB_RINGBUF_Pop( /* Returns total number of buffered samples (including number of channels) */ -static uint32_t CLDFB_RINGBUF_total_size( +static uint32_t ivas_CLDFB_RINGBUF_total_size( ISAR_CLDFB_RINGBUF_HANDLE h ) { if ( ivas_CLDFB_RINGBUF_IsFull( h ) ) @@ -263,7 +263,7 @@ void ivas_CLDFB_RINGBUF_GetByIdx( const int16_t col_idx ) { int32_t idx = col_idx * CLDFB_NO_CHANNELS_MAX; - int32_t num_floats = (int32_t) CLDFB_RINGBUF_total_size( h ); + int32_t num_floats = (int32_t) ivas_CLDFB_RINGBUF_total_size( h ); uint32_t offset; assert( -num_floats <= idx && idx <= num_floats ); -- GitLab From 6b196ffc73ce9c29d27f39a46ea016b85fdf45a1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 10 Sep 2025 12:02:40 +0200 Subject: [PATCH 6/8] update --- Workspace_msvc/lib_dec.vcxproj | 1 - Workspace_msvc/lib_dec.vcxproj.filters | 3 - Workspace_msvc/lib_rend.vcxproj | 1 + Workspace_msvc/lib_rend.vcxproj.filters | 3 + lib_dec/lib_dec.c | 69 ++++++++++++++----- .../ivas_cldfb_ring_buffer.c | 25 ++++--- lib_rend/lib_rend.c | 3 +- 7 files changed, 70 insertions(+), 35 deletions(-) rename {lib_dec => lib_rend}/ivas_cldfb_ring_buffer.c (92%) diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index a8639d192c..3c7ea3e597 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -206,7 +206,6 @@ - diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index e081cb0870..8eddbb60a0 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -515,9 +515,6 @@ decoder_all_c - - decoder_ivas_c - diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index 854c99a979..1d55ed1942 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -138,6 +138,7 @@ + diff --git a/Workspace_msvc/lib_rend.vcxproj.filters b/Workspace_msvc/lib_rend.vcxproj.filters index 2d1d7d46c0..f290958973 100644 --- a/Workspace_msvc/lib_rend.vcxproj.filters +++ b/Workspace_msvc/lib_rend.vcxproj.filters @@ -119,6 +119,9 @@ rend_c + + rend_c + diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 8fa078af78..8a437c4c4f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -130,8 +130,8 @@ static ivas_error ivas_create_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *h static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out ); static int16_t get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP -static int16_t get_render_frame_size_samples( Decoder_Struct *st_ivas ); -static int16_t ivas_dec_split_rend_cldfb_in( Decoder_Struct *st_ivas ); +static int16_t get_render_frame_size_samples( const DECODER_CONFIG_HANDLE hDecoderConfig ); +static int16_t ivas_dec_split_rend_cldfb_in( const RENDERER_TYPE renderer_type ); #endif static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesRendered ); @@ -641,13 +641,23 @@ ivas_error IVAS_DEC_GetRenderFramesize( return IVAS_ERR_OK; } + #ifdef FIX_1119_SPLIT_RENDERING_VOIP -static int16_t get_render_frame_size_samples( Decoder_Struct *st_ivas ) +/*---------------------------------------------------------------------* + * get_render_frame_size_samples( ) + * + * + *---------------------------------------------------------------------*/ + +static int16_t get_render_frame_size_samples( + const DECODER_CONFIG_HANDLE hDecoderConfig /* i : configuration structure */ +) { - return (int16_t) ( st_ivas->hDecoderConfig->output_Fs * st_ivas->hDecoderConfig->render_framesize / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ); + return (int16_t) ( hDecoderConfig->output_Fs * hDecoderConfig->render_framesize / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ); } #endif + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeSamples( ) * @@ -665,7 +675,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( } #ifdef FIX_1119_SPLIT_RENDERING_VOIP - *render_framesize = get_render_frame_size_samples( hIvasDec->st_ivas ); + *render_framesize = get_render_frame_size_samples( hIvasDec->st_ivas->hDecoderConfig ); #else *render_framesize = (int16_t) ( hIvasDec->st_ivas->hDecoderConfig->output_Fs * hIvasDec->st_ivas->hDecoderConfig->render_framesize / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ); #endif @@ -673,6 +683,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeMs( ) * @@ -1904,6 +1915,7 @@ static ivas_error isar_render_poses( ) { float pcmBuf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k]; + Decoder_Struct *st_ivas; ivas_error error; int16_t i, j, numPoses; @@ -1914,7 +1926,9 @@ static ivas_error isar_render_poses( *needNewFrame = false; - numPoses = hIvasDec->st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; + st_ivas = hIvasDec->st_ivas; + + numPoses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; /* init flush buffer for rate switch if not already initizalized */ if ( hIvasDec->flushbuffer == NULL ) @@ -1939,9 +1953,9 @@ static ivas_error isar_render_poses( return IVAS_ERR_OK; } - if ( !ivas_dec_split_rend_cldfb_in( hIvasDec->st_ivas ) ) + if ( !ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ) ) { - ivas_TD_RINGBUF_PushInterleaved( hIvasDec->st_ivas->hSplitBinRend->hMultiBinTdData, pcmBuf, *nOutSamples ); + ivas_TD_RINGBUF_PushInterleaved( st_ivas->hSplitBinRend->hMultiBinTdData, pcmBuf, *nOutSamples ); } /* change buffer layout */ @@ -3792,6 +3806,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples } #endif + /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ while ( *nSamplesRendered < nSamplesPerChannel ) { @@ -4003,7 +4018,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples #ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL ) { - if ( !ivas_dec_split_rend_cldfb_in( st_ivas ) ) + if ( !ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ) ) { ivas_TD_RINGBUF_PopChannels( hIvasDec->st_ivas->hSplitBinRend->hMultiBinTdData, p_head_pose_buf, *nSamplesRendered ); } @@ -4083,7 +4098,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSplitBinauralBitstream( ) * - * Main function to decode one split-rendering frame in VoIP + * Main function to decode one split-rendering frame in VoIP *---------------------------------------------------------------------*/ /*! r: error code */ @@ -5456,17 +5471,33 @@ static ivas_error ivas_dec_reconfig_split_rend( return IVAS_ERR_OK; } + #ifdef FIX_1119_SPLIT_RENDERING_VOIP -static int16_t ivas_dec_split_rend_cldfb_in( Decoder_Struct *st_ivas ) -{ +/*-------------------------------------------------------------------* + * ivas_dec_split_rend_cldfb_in() + * + * + *-------------------------------------------------------------------*/ - return st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || - st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM; +static int16_t ivas_dec_split_rend_cldfb_in( + const RENDERER_TYPE renderer_type /* i : renderer type */ +) +{ + if ( renderer_type == RENDERER_BINAURAL_FASTCONV || + renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || + renderer_type == RENDERER_BINAURAL_PARAMETRIC || + renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + return 1; + } + else + { + return 0; + } } #endif + /*-------------------------------------------------------------------* * ivas_dec_init_split_rend() * @@ -5488,7 +5519,7 @@ static ivas_error ivas_dec_init_split_rend( cldfb_in_flag = 0; #ifdef FIX_1119_SPLIT_RENDERING_VOIP - cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas ); + cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ); #else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || @@ -5501,6 +5532,7 @@ static ivas_error ivas_dec_init_split_rend( #ifdef FIX_1119_SPLIT_RENDERING_VOIP ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->sr_pose_pred_axis : DEFAULT_AXIS ); + num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; assert( num_poses <= MAX_HEAD_ROT_POSES ); @@ -5517,8 +5549,7 @@ static ivas_error ivas_dec_init_split_rend( } else { - error = ivas_TD_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinTdData, get_render_frame_size_samples( st_ivas ), num_poses * BINAURAL_CHANNELS ); - if ( error != IVAS_ERR_OK ) + if ( ( error = ivas_TD_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinTdData, get_render_frame_size_samples( st_ivas->hDecoderConfig ), num_poses * BINAURAL_CHANNELS ) ) != IVAS_ERR_OK ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); } diff --git a/lib_dec/ivas_cldfb_ring_buffer.c b/lib_rend/ivas_cldfb_ring_buffer.c similarity index 92% rename from lib_dec/ivas_cldfb_ring_buffer.c rename to lib_rend/ivas_cldfb_ring_buffer.c index ec4a30be0f..5d1d2a055c 100644 --- a/lib_dec/ivas_cldfb_ring_buffer.c +++ b/lib_rend/ivas_cldfb_ring_buffer.c @@ -47,12 +47,12 @@ *---------------------------------------------------------------------*/ /*---------------------------------------------------------------------* - * ivas_CLDFB_RINGBUF_IsEmpty() + * ivas_cldfb_ringbuf_IsEmpty() * * Returns 1 if the ring buffer is empty, or 0 otherwise. *---------------------------------------------------------------------*/ -static int16_t ivas_CLDFB_RINGBUF_IsEmpty( +static int16_t ivas_cldfb_ringbuf_IsEmpty( ISAR_CLDFB_RINGBUF_HANDLE h ) { return (int16_t) ( h->read_pos == h->write_pos && !h->is_full ); @@ -60,12 +60,12 @@ static int16_t ivas_CLDFB_RINGBUF_IsEmpty( /*---------------------------------------------------------------------* - * ivas_CLDFB_RINGBUF_IsFull() + * ivas_cldfb_ringbuf_IsFull() * * Returns 1 if the ring buffer is full, or 0 otherwise. *---------------------------------------------------------------------*/ -static int16_t ivas_CLDFB_RINGBUF_IsFull( +static int16_t ivas_cldfb_ringbuf_IsFull( ISAR_CLDFB_RINGBUF_HANDLE h ) { return h->is_full; @@ -167,7 +167,7 @@ void ivas_CLDFB_RINGBUF_Push( const int16_t num_bands ) { assert( num_bands <= CLDFB_NO_CHANNELS_MAX ); - assert( !ivas_CLDFB_RINGBUF_IsFull( h ) ); + assert( !ivas_cldfb_ringbuf_IsFull( h ) ); mvr2r( real, &h->real[h->write_pos], num_bands ); mvr2r( imag, &h->imag[h->write_pos], num_bands ); @@ -200,7 +200,7 @@ void ivas_CLDFB_RINGBUF_Pop( const int16_t num_bands ) { assert( num_bands <= CLDFB_NO_CHANNELS_MAX ); - assert( !ivas_CLDFB_RINGBUF_IsEmpty( h ) ); + assert( !ivas_cldfb_ringbuf_IsEmpty( h ) ); if ( real != NULL ) { @@ -223,11 +223,16 @@ void ivas_CLDFB_RINGBUF_Pop( } -/* Returns total number of buffered samples (including number of channels) */ -static uint32_t ivas_CLDFB_RINGBUF_total_size( +/*---------------------------------------------------------------------* + * ivas_cldfb_ringbuf_total_size() + * + * Returns total number of buffered samples (including number of channels) + *---------------------------------------------------------------------*/ + +static uint32_t ivas_cldfb_ringbuf_total_size( ISAR_CLDFB_RINGBUF_HANDLE h ) { - if ( ivas_CLDFB_RINGBUF_IsFull( h ) ) + if ( ivas_cldfb_ringbuf_IsFull( h ) ) { return h->capacity; } @@ -260,7 +265,7 @@ void ivas_CLDFB_RINGBUF_GetByIdx( const int16_t col_idx ) { int32_t idx = col_idx * CLDFB_NO_CHANNELS_MAX; - int32_t num_floats = (int32_t) ivas_CLDFB_RINGBUF_total_size( h ); + int32_t num_floats = (int32_t) ivas_cldfb_ringbuf_total_size( h ); uint32_t offset, uidx; assert( -num_floats <= idx && idx <= num_floats ); diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a0d737fce2..8a16ff77b8 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1480,7 +1480,7 @@ static ivas_error alignInputDelay( int32_t numSamplesToPush, numSamplesToPop; uint32_t ringBufferSize, preDelay; #ifdef FIX_1119_SPLIT_RENDERING_VOIP - int32_t i; + int16_t i; const float *p_read_channels[MAX_INPUT_CHANNELS]; float *p_write_channels[MAX_INPUT_CHANNELS]; #endif @@ -7864,7 +7864,6 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( IVAS_REND_AudioBufferConfig *pSplitEncBufConfig; ISAR_SPLIT_REND_CONFIG_HANDLE pSplitRendConfig; ISAR_SPLIT_REND_BITS_DATA bits; - #ifdef FIX_1119_SPLIT_RENDERING_VOIP float *p_Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; float *p_Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; -- GitLab From 9255c1265fad88780dab22b8147a015e66d60ec9 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 12 Sep 2025 15:41:23 +0200 Subject: [PATCH 7/8] Fix incorrectly merged changes from 3bdd36d26dd83ffc46add1ce012533bf1d7f6d9f --- lib_dec/lib_dec.c | 51 +++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 8a437c4c4f..008c033210 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1909,7 +1909,6 @@ static int16_t isar_get_frame_size( static ivas_error isar_render_poses( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ - float **p_head_pose_buf, /* o : PCM buffer with head-pose data */ int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) @@ -1917,7 +1916,7 @@ static ivas_error isar_render_poses( float pcmBuf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k]; Decoder_Struct *st_ivas; ivas_error error; - int16_t i, j, numPoses; + int16_t numPoses; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1958,15 +1957,6 @@ static ivas_error isar_render_poses( ivas_TD_RINGBUF_PushInterleaved( st_ivas->hSplitBinRend->hMultiBinTdData, pcmBuf, *nOutSamples ); } - /* change buffer layout */ - for ( i = 0; i < *nOutSamples; ++i ) - { - for ( j = 0; j < BINAURAL_CHANNELS * numPoses; ++j ) - { - p_head_pose_buf[j][i] = pcmBuf[i * BINAURAL_CHANNELS * numPoses + j]; - } - } - return error; } @@ -2100,12 +2090,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; numSamplesPerChannelToOutput = isar_get_frame_size( st_ivas ); - for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) - { - p_head_pose_buf[i] = head_pose_buf[i]; - } - - if ( ( error = isar_render_poses( hIvasDec, numSamplesPerChannelToOutput, p_head_pose_buf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) + if ( ( error = isar_render_poses( hIvasDec, numSamplesPerChannelToOutput, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) { return error; } @@ -2115,6 +2100,16 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( return IVAS_ERR_OK; } + for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) + { + p_head_pose_buf[i] = head_pose_buf[i]; + } + + if ( !ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ) ) + { + ivas_TD_RINGBUF_PopChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_head_pose_buf, *nOutSamples ); + } + if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, splitRendBits ) ) != IVAS_ERR_OK ) { return error; @@ -3771,9 +3766,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples int16_t result; ivas_error error; uint8_t nOutChannels; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - int16_t i; -#endif if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->hVoIP == NULL ) { @@ -3980,23 +3972,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples #ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( splitRendBits != NULL ) { - /* Move output pointers forward */ - for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) - { - p_head_pose_buf[i] += *nSamplesRendered; - } - /* Render head poses from time-scaled transport channels */ - if ( ( error = isar_render_poses( hIvasDec, nSamplesToRender, p_head_pose_buf, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) + if ( ( error = isar_render_poses( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) { return error; } - - /* Set pointers back to the beginning of head pose buffers */ - for ( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) - { - p_head_pose_buf[i] -= *nSamplesRendered; - } } else { @@ -5254,6 +5234,7 @@ static ivas_error ivas_create_handle_isar( isar_init_split_rend_handles( &hSplitBinRend->splitrend ); #ifdef FIX_1119_SPLIT_RENDERING_VOIP + hSplitBinRend->hMultiBinTdData = NULL; for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { hSplitBinRend->hMultiBinCldfbData[i] = NULL; @@ -5287,6 +5268,10 @@ static void ivas_destroy_handle_isar( if ( *hSplitBinRend != NULL ) { #ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( ( *hSplitBinRend )->hMultiBinTdData != NULL ) + { + ivas_TD_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinTdData ); + } for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { if ( ( *hSplitBinRend )->hMultiBinCldfbData[i] != NULL ) -- GitLab From a87ea2fdddba44b98972b3d1189bfefe076954ed Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 12 Sep 2025 15:56:16 +0200 Subject: [PATCH 8/8] Apply formatting patch --- lib_rend/lib_rend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 8a16ff77b8..2fea668620 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7953,7 +7953,7 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, #endif - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab