Commit 6f6c1ff3 authored by multrus's avatar multrus
Browse files

Merge branch 'align-ring-buffers-with-basop' into 'main'

Back-port changes to ring buffers from BASOP development

See merge request !2355
parents 4fc9b046 17546da7
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
+10 −11
Original line number Diff line number Diff line
@@ -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;
        }
    }

+10 −10
Original line number Diff line number Diff line
@@ -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                      */
);

+5 −5
Original line number Diff line number Diff line
@@ -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;
+51 −46
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
*******************************************************************************************************/

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#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 );
}
@@ -71,18 +78,18 @@ static int16_t ivas_td_ringbuf_has_space_for_num_samples(
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 */
    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                     */
    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        */
    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    */
    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   */
    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     */
    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 );
}
Loading