diff --git a/lib_isar/isar_stat.h b/lib_isar/isar_stat.h index b244370dd3eceed843c49f02de1087c21a0e0b9e..4ed75ee97e81e4ff1ebacd476bfc4f36f5732eb3 100644 --- a/lib_isar/isar_stat.h +++ b/lib_isar/isar_stat.h @@ -350,9 +350,9 @@ typedef struct { float *real; float *imag; - uint32_t capacity; - uint32_t write_pos; - uint32_t read_pos; + int32_t capacity; + int32_t write_pos; + int32_t read_pos; int16_t is_full; } ISAR_CLDFB_RINGBUF, *ISAR_CLDFB_RINGBUF_HANDLE; diff --git a/lib_rend/ivas_cldfb_ring_buffer.c b/lib_rend/ivas_cldfb_ring_buffer.c index 5d1d2a055cbb50b71f732330d2091d252b3bf1d7..669227540e063f5d156efa86fd99ad5676c27867 100644 --- a/lib_rend/ivas_cldfb_ring_buffer.c +++ b/lib_rend/ivas_cldfb_ring_buffer.c @@ -75,7 +75,7 @@ static int16_t ivas_cldfb_ringbuf_IsFull( /*---------------------------------------------------------------------* * ivas_CLDFB_RINGBUF_Open() * - * Allocate a ring buffer for CLDFB data with the given capacity of CLDFB columns. + * Allocates 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. @@ -88,7 +88,7 @@ ivas_error ivas_CLDFB_RINGBUF_Open( ISAR_CLDFB_RINGBUF_HANDLE h; int32_t capacity; - capacity = capacity_columns * CLDFB_NO_CHANNELS_MAX; + capacity = (int32_t) capacity_columns * CLDFB_NO_CHANNELS_MAX; if ( ( h = malloc( sizeof( ISAR_CLDFB_RINGBUF ) ) ) == NULL ) { @@ -119,7 +119,7 @@ ivas_error ivas_CLDFB_RINGBUF_Open( /*---------------------------------------------------------------------* * ivas_CLDFB_RINGBUF_Close() * - * Dellocate CLDFB ring buffer. The given handle will be set to NULL. + * Dellocates CLDFB ring buffer. The given handle will be set to NULL. *---------------------------------------------------------------------*/ void ivas_CLDFB_RINGBUF_Close( @@ -190,7 +190,7 @@ void ivas_CLDFB_RINGBUF_Push( /*---------------------------------------------------------------------* * ivas_CLDFB_RINGBUF_Pop() * - * Pop a single column from the front of the CLDFB ring buffer into real and imag arrays. + * Pops a single column from the front of the CLDFB ring buffer into real and imag arrays. *---------------------------------------------------------------------*/ void ivas_CLDFB_RINGBUF_Pop( @@ -229,7 +229,7 @@ void ivas_CLDFB_RINGBUF_Pop( * Returns total number of buffered samples (including number of channels) *---------------------------------------------------------------------*/ -static uint32_t ivas_cldfb_ringbuf_total_size( +static int32_t ivas_cldfb_ringbuf_total_size( ISAR_CLDFB_RINGBUF_HANDLE h ) { if ( ivas_cldfb_ringbuf_IsFull( h ) ) @@ -265,8 +265,8 @@ 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 ); - uint32_t offset, uidx; + int32_t num_floats = ivas_cldfb_ringbuf_total_size( h ); + int32_t offset; assert( -num_floats <= idx && idx <= num_floats ); @@ -280,14 +280,13 @@ void ivas_CLDFB_RINGBUF_GetByIdx( } else { - uidx = (uint32_t) -idx; - if ( uidx <= h->write_pos ) + if ( -idx <= h->write_pos ) { - offset = h->write_pos - uidx; + offset = h->write_pos + idx; } else { - offset = h->write_pos + h->capacity - uidx; + offset = h->write_pos + h->capacity + idx; } } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 56cd7bed4d49b4e1968916cbe3ca19ccaf962741..112c6ac73ef0cecc89e9b23c51ff556ba8a60f6d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1599,8 +1599,8 @@ void ivas_rend_closeCldfbRend( ivas_error ivas_TD_RINGBUF_Open( TD_RINGBUF_HANDLE *ph, /* i/o: Ring buffer handle */ - const uint32_t capacity_per_channel, /* i : Number of samples stored per channel */ - const uint16_t num_channels /* i : Number of channels */ + const int16_t capacity_per_channel, /* i : Number of samples stored per channel */ + const int16_t num_channels /* i : Number of channels */ ); void ivas_TD_RINGBUF_Close( @@ -1611,46 +1611,46 @@ void ivas_TD_RINGBUF_Close( void ivas_TD_RINGBUF_PushInterleaved( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const float *data, /* i : Input audio in interleaved channels layout */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to push */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to push */ ); void ivas_TD_RINGBUF_PushChannels( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const float *p_channels[], /* i : Array of pointers to each input channel */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to store */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to store */ ); void ivas_TD_RINGBUF_PushConstant( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const float value, /* i : Value to push */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to push */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to push */ ); void ivas_TD_RINGBUF_PopChannels( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ float *p_channels[], /* i : Array of pointers to each output channel */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to pop */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to pop */ ); #else void ivas_TD_RINGBUF_Push( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const float *data, /* i : Input data */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to store */ + const uint16_t num_samples_per_channel /* i : Number of samples per channel to store */ ); void ivas_TD_RINGBUF_PushZeros( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const uint32_t num_samples_per_channel /* i : Number of zeros per channel to store */ + const uint16_t num_samples_per_channel /* i : Number of zeros per channel to store */ ); void ivas_TD_RINGBUF_Pop( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ float *data, /* i : Output data */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to retrieve*/ + const uint16_t num_samples_per_channel /* i : Number of samples per channel to retrieve*/ ); #endif -uint32_t ivas_TD_RINGBUF_Size( +int16_t ivas_TD_RINGBUF_Size( const TD_RINGBUF_HANDLE h /* i : Ring buffer handle */ ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 6730875f6c39f5bc185b2323ca286e20576bc899..4a2a2b0fb585432173f3ab8e31c08ebc5a2ead77 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1382,11 +1382,11 @@ typedef struct typedef struct { - float *data; /* samples in interleaved layout */ - uint32_t capacity; - uint16_t num_channels; - uint32_t write_pos; - uint32_t read_pos; + float *data; /* samples in interleaved layout, e.g. for channels A, B, C, samples are stored: A1, B1, C1, A2, B2, C2, ... */ + int32_t capacity; /* max number of float values that can be stored */ + int16_t num_channels; + int32_t write_pos; + int32_t read_pos; int16_t is_full; } TD_RINGBUF_DATA, *TD_RINGBUF_HANDLE; diff --git a/lib_rend/ivas_td_ring_buffer.c b/lib_rend/ivas_td_ring_buffer.c index f1fdab3af8143b15aaa1583ea998bca7d1c72a18..98b3e4d15b8de980fcf8fa1b3d289ed1147ea48a 100644 --- a/lib_rend/ivas_td_ring_buffer.c +++ b/lib_rend/ivas_td_ring_buffer.c @@ -31,6 +31,7 @@ *******************************************************************************************************/ #include +#include #include #include "ivas_error_utils.h" #include "ivas_prot_rend.h" @@ -42,7 +43,13 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static uint32_t ivas_td_ringbuf_total_size( +/*---------------------------------------------------------------------* + * ivas_td_ringbuf_total_size() + * + * Returns total number of buffered samples (including number of channels) + *---------------------------------------------------------------------*/ + +static int32_t ivas_td_ringbuf_total_size( TD_RINGBUF_HANDLE h ) { if ( h->is_full ) @@ -61,7 +68,7 @@ static uint32_t ivas_td_ringbuf_total_size( static int16_t ivas_td_ringbuf_has_space_for_num_samples( TD_RINGBUF_HANDLE h, - const uint32_t num_samples ) + const int32_t num_samples ) { return (int16_t) ( ivas_td_ringbuf_total_size( h ) + num_samples <= h->capacity ); } @@ -69,20 +76,20 @@ static int16_t ivas_td_ringbuf_has_space_for_num_samples( #ifdef FIX_1119_SPLIT_RENDERING_VOIP static void ivas_td_ringbuf_push_interleaved( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const float *data, /* i : Input audio in interleaved channels layout */ - const uint32_t num_samples_per_channel, /* i : Number of samples per channel to push */ - const uint16_t read_stride /* i: : 1 for normal operation, 0 for reading from a single input value */ + TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ + const float *data, /* i : Input audio in interleaved channels layout */ + const int16_t num_samples_per_channel, /* i : Number of samples per channel to push */ + const int16_t read_stride /* i: : 1 for normal operation, 0 for reading from a single input value */ ) { - uint32_t s, read_s; + int32_t s, read_s; assert( h != NULL ); assert( data != NULL ); assert( read_stride == 0 || read_stride == 1 ); - assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) ); + assert( ivas_td_ringbuf_has_space_for_num_samples( h, (int32_t) num_samples_per_channel * h->num_channels ) ); - for ( s = 0, read_s = 0; s < num_samples_per_channel * h->num_channels; ++s, read_s += read_stride ) + for ( s = 0, read_s = 0; s < (int32_t) num_samples_per_channel * h->num_channels; ++s, read_s += read_stride ) { h->data[h->write_pos] = data[read_s]; ++h->write_pos; @@ -110,21 +117,21 @@ static void ivas_td_ringbuf_push_interleaved( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_Open() * - * Allocate a ring buffer for TD data with the given capacity of TD samples per channel. + * Allocates a ring buffer for TD data with the given capacity of TD samples per channel. * * May return IVAS_ERR_FAILED_ALLOC on failed allocation, or IVAS_ERR_OK otherwise. *---------------------------------------------------------------------*/ ivas_error ivas_TD_RINGBUF_Open( - TD_RINGBUF_HANDLE *ph, /* i/o: Ring buffer handle */ - const uint32_t capacity_per_channel, /* i : Number of samples stored per channel */ - const uint16_t num_channels /* i : Number of channels */ + TD_RINGBUF_HANDLE *ph, /* i/o: Ring buffer handle */ + const int16_t capacity_per_channel, /* i : Number of samples stored per channel */ + const int16_t num_channels /* i : Number of channels */ ) { TD_RINGBUF_HANDLE h; - uint32_t capacity; + int32_t capacity; - capacity = capacity_per_channel * num_channels; + capacity = (int32_t) capacity_per_channel * num_channels; h = malloc( sizeof( TD_RINGBUF_DATA ) ); if ( h == NULL ) @@ -153,8 +160,7 @@ ivas_error ivas_TD_RINGBUF_Open( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_Close() * - * Dellocate TD ring buffer. The given handle will be set to NULL. - + * Dellocates TD ring buffer. The given handle will be set to NULL. *---------------------------------------------------------------------*/ void ivas_TD_RINGBUF_Close( @@ -190,13 +196,13 @@ void ivas_TD_RINGBUF_Close( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PushInterleaved() * - * Push samples from a buffer with interleaved channel layout onto the back of the TD ring buffer. + * Pushes samples from a buffer with interleaved channel layout onto the back of the TD ring buffer. *---------------------------------------------------------------------*/ void ivas_TD_RINGBUF_PushInterleaved( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const float *data, /* i : Input audio in interleaved channels layout */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to push */ + TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ + const float *data, /* i : Input audio in interleaved channels layout */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to push */ ) { ivas_td_ringbuf_push_interleaved( h, data, num_samples_per_channel, 1 ); @@ -208,13 +214,13 @@ void ivas_TD_RINGBUF_PushInterleaved( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PushChannels() * - * Push samples from channel pointers onto the back of the TD ring buffer. + * Pushes samples from channel pointers onto the back of the TD ring buffer. *---------------------------------------------------------------------*/ void ivas_TD_RINGBUF_PushChannels( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const float *p_channels[], /* i : Array of pointers to each input channel */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to push */ + TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ + const float *p_channels[], /* i : Array of pointers to each input channel */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to push */ ) #else /*---------------------------------------------------------------------* @@ -227,12 +233,12 @@ void ivas_TD_RINGBUF_PushChannels( void ivas_TD_RINGBUF_Push( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const float *data, /* i : Input data */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to store */ + const uint16_t num_samples_per_channel /* i : Number of samples per channel to store */ ) #endif { - uint32_t s; - uint16_t c; + int32_t s; + int16_t c; #ifdef FIX_1119_SPLIT_RENDERING_VOIP assert( h != NULL ); @@ -242,7 +248,7 @@ void ivas_TD_RINGBUF_Push( assert( p_channels[c] != NULL ); } #endif - assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) ); + assert( ivas_td_ringbuf_has_space_for_num_samples( h, (int32_t) num_samples_per_channel * h->num_channels ) ); for ( s = 0; s < num_samples_per_channel; ++s ) { @@ -275,13 +281,13 @@ void ivas_TD_RINGBUF_Push( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PushConstant() * - * Push samples with a constant value onto the back of the TD ring buffer. + * Pushes samples with a constant value onto the back of the TD ring buffer. *---------------------------------------------------------------------*/ void ivas_TD_RINGBUF_PushConstant( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const float value, /* i : Value to push */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to push */ + TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ + const float value, /* i : Value to push */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to push */ ) { ivas_td_ringbuf_push_interleaved( h, &value, num_samples_per_channel, 0 ); @@ -297,11 +303,10 @@ void ivas_TD_RINGBUF_PushConstant( void ivas_TD_RINGBUF_PushZeros( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const uint32_t num_samples_per_channel /* i : Number of zeros per channel to store */ + const uint16_t num_samples_per_channel /* i : Number of zeros per channel to store */ ) { - uint32_t s; - uint16_t c; + uint16_t c, s; assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) ); if ( !num_samples_per_channel ) @@ -337,13 +342,13 @@ void ivas_TD_RINGBUF_PushZeros( /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PopChannels() * - * Pop samples from the front of the TD ring buffer to an array of channel pointers. + * Pops samples from the front of the TD ring buffer to an array of channel pointers. *---------------------------------------------------------------------*/ void ivas_TD_RINGBUF_PopChannels( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - float *p_channels[], /* i : Array of pointers to each output channel */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to pop */ + TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ + float *p_channels[], /* i : Array of pointers to each output channel */ + const int16_t num_samples_per_channel /* i : Number of samples per channel to pop */ ) #else /*---------------------------------------------------------------------* @@ -355,12 +360,12 @@ void ivas_TD_RINGBUF_PopChannels( void ivas_TD_RINGBUF_Pop( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ float *data, /* i : Output data */ - const uint32_t num_samples_per_channel /* i : Number of samples per channel to retrieve */ + const uint16_t num_samples_per_channel /* i : Number of samples per channel to retrieve */ ) #endif { - uint32_t s; - uint16_t c; + int32_t s; + int16_t c; #ifdef FIX_1119_SPLIT_RENDERING_VOIP assert( h != NULL ); @@ -370,7 +375,7 @@ void ivas_TD_RINGBUF_Pop( assert( p_channels[c] != NULL ); } #endif - assert( ivas_td_ringbuf_total_size( h ) >= num_samples_per_channel * h->num_channels ); + assert( ivas_td_ringbuf_total_size( h ) >= (int32_t) num_samples_per_channel * h->num_channels ); for ( s = 0; s < num_samples_per_channel; ++s ) { @@ -412,9 +417,9 @@ void ivas_TD_RINGBUF_Pop( * Returns number of buffered samples per channel. *---------------------------------------------------------------------*/ -uint32_t ivas_TD_RINGBUF_Size( +int16_t ivas_TD_RINGBUF_Size( const TD_RINGBUF_HANDLE h /* i : Ring buffer handle */ ) { - return ivas_td_ringbuf_total_size( h ) / (uint32_t) h->num_channels; + return (int16_t) ( ivas_td_ringbuf_total_size( h ) / h->num_channels ); } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4bb1024aae19eae7aa5e70822b9296b8052eef83..b0435968b3db7ed6dde714ca9d98e8b7e5c42d69 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1507,7 +1507,7 @@ static ivas_error alignInputDelay( if ( preDelay > 0 ) { - if ( ( error = ivas_TD_RINGBUF_Open( &inputBase->delayBuffer, ringBufferSize, inputAudio.config.numChannels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_TD_RINGBUF_Open( &inputBase->delayBuffer, (int16_t) ringBufferSize, inputAudio.config.numChannels ) ) != IVAS_ERR_OK ) { return error; } @@ -1515,7 +1515,7 @@ static ivas_error alignInputDelay( /* for the first frame we need to push zeros to align the input delay to the global delay * and then push a frame of actual data */ #ifdef FIX_1119_SPLIT_RENDERING_VOIP - ivas_TD_RINGBUF_PushConstant( inputBase->delayBuffer, 0, preDelay ); + ivas_TD_RINGBUF_PushConstant( inputBase->delayBuffer, 0, (int16_t) preDelay ); #else ivas_TD_RINGBUF_PushZeros( inputBase->delayBuffer, preDelay ); #endif @@ -1538,20 +1538,20 @@ static ivas_error alignInputDelay( /* push in the new input data and pop to retrieve a complete input frame * if we are flushing the inputs, we don't push in any new data */ numSamplesToPush = flushInputs ? 0 : inputAudio.config.numSamplesPerChannel; - numSamplesToPop = flushInputs ? ivas_TD_RINGBUF_Size( inputBase->delayBuffer ) : (uint32_t) inputAudio.config.numSamplesPerChannel; + numSamplesToPop = flushInputs ? (uint32_t) ivas_TD_RINGBUF_Size( inputBase->delayBuffer ) : (uint32_t) inputAudio.config.numSamplesPerChannel; #ifdef FIX_1119_SPLIT_RENDERING_VOIP for ( i = 0; i < inputAudio.config.numChannels; ++i ) { p_read_channels[i] = inputAudio.data + i * numSamplesToPush; } - ivas_TD_RINGBUF_PushChannels( inputBase->delayBuffer, p_read_channels, numSamplesToPush ); + ivas_TD_RINGBUF_PushChannels( inputBase->delayBuffer, p_read_channels, (int16_t) numSamplesToPush ); for ( i = 0; i < inputAudio.config.numChannels; ++i ) { p_write_channels[i] = inputBase->inputBuffer.data + i * numSamplesToPop; } - ivas_TD_RINGBUF_PopChannels( inputBase->delayBuffer, p_write_channels, numSamplesToPop ); + ivas_TD_RINGBUF_PopChannels( inputBase->delayBuffer, p_write_channels, (int16_t) numSamplesToPop ); #else ivas_TD_RINGBUF_Push( inputBase->delayBuffer, inputAudio.data, numSamplesToPush ); ivas_TD_RINGBUF_Pop( inputBase->delayBuffer, inputBase->inputBuffer.data, numSamplesToPop );