Commit 4e95bd87 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

rename TD ring buffer functions and add comments

parent f4215bf1
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -1582,6 +1582,50 @@ void ivas_rend_closeCldfbRend(
    CLDFB_REND_WRAPPER *pCldfbRend 
);

/*----------------------------------------------------------------------------------*
 * Time domain ring buffer prototypes
 *----------------------------------------------------------------------------------*/

typedef struct TdRingBuf *TD_RINGBUF_HANDLE;

ivas_error IVAS_TD_RINGBUF_Open(
    TD_RINGBUF_HANDLE *ph,
    uint32_t capacity_per_channel,
    uint16_t num_channels 
);

void IVAS_TD_RINGBUF_Close( 
    TD_RINGBUF_HANDLE *ph 
);

void IVAS_TD_RINGBUF_Push( 
    TD_RINGBUF_HANDLE h,
    const float *data,
    uint32_t num_samples_per_channel 
);

void IVAS_TD_RINGBUF_PushZeros( 
    TD_RINGBUF_HANDLE h,
    uint32_t num_samples_per_channel 
);

void IVAS_TD_RINGBUF_Pop( 
    TD_RINGBUF_HANDLE h, 
    float *data,
    uint32_t num_samples_per_channel 
);

int16_t IVAS_TD_RINGBUF_IsEmpty( 
    const TD_RINGBUF_HANDLE h 
);

uint32_t IVAS_TD_RINGBUF_Size(
     const TD_RINGBUF_HANDLE h 
);

void IVAS_TD_RINGBUF_Clear( 
    TD_RINGBUF_HANDLE h 
);

/* clang-format on */

+108 −39
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@
#include <assert.h>
#include <stdlib.h>
#include "ivas_error_utils.h"
#include "ivas_td_ring_buffer.h"
#include "ivas_prot_rend.h"
#include "options.h"
#include "wmc_auto.h"

struct TdRingBuf
@@ -46,7 +47,46 @@ struct TdRingBuf
    int16_t is_full;
};

ivas_error TD_RINGBUF_Open( TD_RINGBUF_HANDLE *ph, uint32_t capacity_per_channel, uint16_t num_channels )
/*-----------------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------------*/

static uint32_t ivas_td_ringbuf_total_size( TD_RINGBUF_HANDLE h )
{
    if ( h->is_full )
    {
        return h->capacity;
    }

    if ( h->read_pos <= h->write_pos )
    {
        return h->write_pos - h->read_pos;
    }
    /* else wrap around */
    return h->write_pos + h->capacity - h->read_pos;
}

static int16_t ivas_td_ringbuf_has_space_for_num_samples( TD_RINGBUF_HANDLE h, const uint32_t num_samples )
{
    return (int16_t) ( ivas_td_ringbuf_total_size( h ) + num_samples <= h->capacity );
}

/*-----------------------------------------------------------------------*
 * Global function definitions
 *-----------------------------------------------------------------------*/

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Open()
 *
 * Allocate 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 h;
    uint32_t capacity;
@@ -75,7 +115,14 @@ ivas_error TD_RINGBUF_Open( TD_RINGBUF_HANDLE *ph, uint32_t capacity_per_channel
    return IVAS_ERR_OK;
}

void TD_RINGBUF_Close( TD_RINGBUF_HANDLE *ph )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_Close()
 *
 * Dellocate TD ring buffer. The given handle will be set to NULL.
 *---------------------------------------------------------------------*/
void IVAS_TD_RINGBUF_Close(
    TD_RINGBUF_HANDLE *ph /* i/o: Ring buffer handle */
)
{
    TD_RINGBUF_HANDLE h;

@@ -101,33 +148,22 @@ void TD_RINGBUF_Close( TD_RINGBUF_HANDLE *ph )
    return;
}

/* Returns total number of buffered samples (includes number of channels) */
static uint32_t total_size( TD_RINGBUF_HANDLE h )
{
    if ( TD_RINGBUF_IsFull( h ) )
    {
        return h->capacity;
    }

    if ( h->read_pos <= h->write_pos )
    {
        return h->write_pos - h->read_pos;
    }
    /* else wrap around */
    return h->write_pos + h->capacity - h->read_pos;
}

static int16_t has_space_for_num_samples( TD_RINGBUF_HANDLE h, uint32_t num_samples )
{
    return (int16_t) ( total_size( h ) + num_samples <= h->capacity );
}

void TD_RINGBUF_Push( TD_RINGBUF_HANDLE h, const float *data, uint32_t num_samples_per_channel )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_Push()
 *
 * Push samples onto the back of the TD ring buffer.
 * Returns total number of buffered samples (includes number of channels)
 *---------------------------------------------------------------------*/
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   */
)
{
    uint32_t s;
    uint16_t c;

    assert( has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) );
    assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) );

    for ( s = 0; s < num_samples_per_channel; ++s )
    {
@@ -151,12 +187,20 @@ void TD_RINGBUF_Push( TD_RINGBUF_HANDLE h, const float *data, uint32_t num_sampl
    return;
}

void TD_RINGBUF_PushZeros( TD_RINGBUF_HANDLE h, uint32_t num_samples_per_channel )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_PushZeros()
 *
 * Push zero samples onto the back of the TD ring buffer.
 *---------------------------------------------------------------------*/
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 */
)
{
    uint32_t s;
    uint16_t c;

    assert( has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) );
    assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) );
    if ( !num_samples_per_channel )
    {
        return;
@@ -184,12 +228,21 @@ void TD_RINGBUF_PushZeros( TD_RINGBUF_HANDLE h, uint32_t num_samples_per_channel
    return;
}

void TD_RINGBUF_Pop( TD_RINGBUF_HANDLE h, float *data, uint32_t num_samples_per_channel )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_Pop()
 *
 * Pop samples from the front of the TD ring buffer.
 *---------------------------------------------------------------------*/
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    */
)
{
    uint32_t s;
    uint16_t c;

    assert( total_size( h ) >= num_samples_per_channel * h->num_channels );
    assert( ivas_td_ringbuf_total_size( h ) >= num_samples_per_channel * h->num_channels );

    for ( s = 0; s < num_samples_per_channel; ++s )
    {
@@ -213,22 +266,38 @@ void TD_RINGBUF_Pop( TD_RINGBUF_HANDLE h, float *data, uint32_t num_samples_per_
    return;
}

int16_t TD_RINGBUF_IsEmpty( TD_RINGBUF_HANDLE h )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_IsEmpty()
 *
 * Returns 1 if the ring buffer is empty, or 0 otherwise.
 *---------------------------------------------------------------------*/
int16_t IVAS_TD_RINGBUF_IsEmpty(
    const TD_RINGBUF_HANDLE h /* i  : Ring buffer handle */
)
{
    return (int16_t) ( h->read_pos == h->write_pos && !h->is_full );
}

int16_t TD_RINGBUF_IsFull( TD_RINGBUF_HANDLE h )
{
    return h->is_full;
}

uint32_t TD_RINGBUF_Size( TD_RINGBUF_HANDLE h )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_Size()
 *
 * Returns number of buffered samples per channel.
 *---------------------------------------------------------------------*/
uint32_t IVAS_TD_RINGBUF_Size(
    const TD_RINGBUF_HANDLE h /* i  : Ring buffer handle */
)
{
    return total_size( h ) / (uint32_t) h->num_channels;
    return ivas_td_ringbuf_total_size( h ) / (uint32_t) h->num_channels;
}

void TD_RINGBUF_Clear( TD_RINGBUF_HANDLE h )
/*---------------------------------------------------------------------*
 * TD_RINGBUF_Clear()
 *
 * Remove all samples from the buffer.
 *---------------------------------------------------------------------*/
void IVAS_TD_RINGBUF_Clear(
    TD_RINGBUF_HANDLE h /* i  : Ring buffer handle */
)
{
    h->read_pos = h->write_pos;
    h->is_full = 0;

lib_rend/ivas_td_ring_buffer.h

deleted100644 → 0
+0 −106
Original line number Diff line number Diff line
/******************************************************************************************************

   (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 IVAS_TD_RING_BUFFER_H
#define IVAS_TD_RING_BUFFER_H

#include "ivas_error.h"
#include <stdint.h>

typedef struct TdRingBuf *TD_RINGBUF_HANDLE;

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Open()
 *
 * Allocate 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 TD_RINGBUF_Open( TD_RINGBUF_HANDLE *ph, uint32_t capacity_per_channel, uint16_t num_channels );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Close()
 *
 * Dellocate TD ring buffer. The given handle will be set to NULL.
 *---------------------------------------------------------------------*/
void TD_RINGBUF_Close( TD_RINGBUF_HANDLE *ph );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Push()
 *
 * Push samples onto the back of the TD ring buffer.
 *---------------------------------------------------------------------*/
void TD_RINGBUF_Push( TD_RINGBUF_HANDLE h, const float *data, uint32_t num_samples_per_channel );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_PushZeros()
 *
 * Push zero samples onto the back of the TD ring buffer.
 *---------------------------------------------------------------------*/
void TD_RINGBUF_PushZeros( TD_RINGBUF_HANDLE h, uint32_t num_samples_per_channel );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Pop()
 *
 * Pop samples from the front of the TD ring buffer.
 *---------------------------------------------------------------------*/
void TD_RINGBUF_Pop( TD_RINGBUF_HANDLE h, float *data, uint32_t num_samples_per_channel );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_IsEmpty()
 *
 * Returns 1 if the ring buffer is empty, or 0 otherwise.
 *---------------------------------------------------------------------*/
int16_t TD_RINGBUF_IsEmpty( TD_RINGBUF_HANDLE h );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_IsFull()
 *
 * Returns 1 if the ring buffer is full, or 0 otherwise.
 *---------------------------------------------------------------------*/
int16_t TD_RINGBUF_IsFull( TD_RINGBUF_HANDLE h );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Size()
 *
 * Returns number of buffered samples per channel.
 *---------------------------------------------------------------------*/
uint32_t TD_RINGBUF_Size( TD_RINGBUF_HANDLE h );

/*---------------------------------------------------------------------*
 * TD_RINGBUF_Clear()
 *
 * Remove all samples from the buffer.
 *---------------------------------------------------------------------*/
void TD_RINGBUF_Clear( TD_RINGBUF_HANDLE h );

#endif /* IVAS_TD_RING_BUFFER_H */
+9 −10
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@
#include "ivas_cnst.h"
#include "ivas_rom_com.h"
#include "ivas_rom_rend.h"
#include "ivas_td_ring_buffer.h"
#include <assert.h>
#include <math.h>
#include <stdbool.h>
@@ -1349,7 +1348,7 @@ static ivas_error alignInputDelay(
        /* buffer has to accomodate maxGlobalDelaySamples + 2 * frameSize */
        tmpSize = maxGlobalDelaySamples;
        tmpSize += 2 * inputAudio.config.numSamplesPerChannel;
        if ( ( error = TD_RINGBUF_Open( &inputBase->delayBuffer,
        if ( ( error = IVAS_TD_RINGBUF_Open( &inputBase->delayBuffer,
                                        tmpSize,
                                        inputAudio.config.numChannels ) ) != IVAS_ERR_OK )
        {
@@ -1359,7 +1358,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 */
        tmpSize = maxGlobalDelaySamples - inputBase->delayNumSamples * cldfb2tdSampleFact;
        TD_RINGBUF_PushZeros( inputBase->delayBuffer,
        IVAS_TD_RINGBUF_PushZeros( inputBase->delayBuffer,
                              tmpSize );

        /* for ISM inputs, ensure the metadata sync delay is updated */
@@ -1371,12 +1370,12 @@ static ivas_error alignInputDelay(
    }

    /* push in the new input data and pop to retrieve a complete input frame */
    TD_RINGBUF_Push( inputBase->delayBuffer,
    IVAS_TD_RINGBUF_Push( inputBase->delayBuffer,
                     inputAudio.data,
                     inputAudio.config.numSamplesPerChannel );
    TD_RINGBUF_Pop( inputBase->delayBuffer,
    IVAS_TD_RINGBUF_Pop( inputBase->delayBuffer,
                    inputBase->inputBuffer.data,
                    flushInputs ? TD_RINGBUF_Size( inputBase->delayBuffer ) : (uint32_t) inputAudio.config.numSamplesPerChannel );
                    flushInputs ? IVAS_TD_RINGBUF_Size( inputBase->delayBuffer ) : (uint32_t) inputAudio.config.numSamplesPerChannel );

    return IVAS_ERR_OK;
}
@@ -1544,7 +1543,7 @@ static void clearInputIsm(
    rendCtx = inputIsm->base.ctx;

    freeInputBaseBufferData( &inputIsm->base.inputBuffer.data );
    TD_RINGBUF_Close( &inputIsm->base.delayBuffer );
    IVAS_TD_RINGBUF_Close( &inputIsm->base.delayBuffer );

    initRendInputBase( &inputIsm->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 );

@@ -2543,7 +2542,7 @@ static void clearInputMc(

    freeMcLfeDelayBuffer( &inputMc->lfeDelayBuffer );
    freeInputBaseBufferData( &inputMc->bufferData );
    TD_RINGBUF_Close( &inputMc->base.delayBuffer );
    IVAS_TD_RINGBUF_Close( &inputMc->base.delayBuffer );

    initRendInputBase( &inputMc->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 );

@@ -2875,7 +2874,7 @@ static void clearInputSba(
    rendCtx = inputSba->base.ctx;

    freeInputBaseBufferData( &inputSba->bufferData );
    TD_RINGBUF_Close( &inputSba->base.delayBuffer );
    IVAS_TD_RINGBUF_Close( &inputSba->base.delayBuffer );

    initRendInputBase( &inputSba->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 );

@@ -2974,7 +2973,7 @@ static void clearInputMasa(
    rendCtx = inputMasa->base.ctx;

    freeInputBaseBufferData( &inputMasa->bufferData );
    TD_RINGBUF_Close( &inputMasa->base.delayBuffer );
    IVAS_TD_RINGBUF_Close( &inputMasa->base.delayBuffer );

    masaPrerendClose( &inputMasa->hMasaPrerend );
    freeMasaExtRenderer( &inputMasa->hMasaExtRend );