Commit 08776d37 authored by sagnowski's avatar sagnowski
Browse files

Store CLDFB content used for SR in a ring buffer

parent 0746d664
Loading
Loading
Loading
Loading
Loading
+227 −0
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.

*******************************************************************************************************/

#include "cldfb_ring_buffer.h"
#include "cnst.h"
#include "prot.h"
#include "ivas_error_utils.h"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef FIX_1119_SPLIT_RENDERING_VOIP

struct CldfbRingBuffer {
    float* real;
    float* imag;
    uint32_t capacity;
    uint32_t write_pos;
    uint32_t read_pos;
    int16_t is_full;
};

ivas_error CLDFB_RB_Open( CLDFB_RING_BUFFER_HANDLE *ph, int16_t capacity_columns )
{
    CLDFB_RING_BUFFER_HANDLE h;
    int32_t capacity;
    capacity = capacity_columns * CLDFB_NO_CHANNELS_MAX;

    if ( ( h = malloc( sizeof( struct CldfbRingBuffer ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for CLDFB ring buffer\n" );
    }
    h->real = NULL;
    h->imag = NULL;
    h->capacity = 0;
    h->write_pos = 0;
    h->read_pos = 0;
    h->is_full = 0;
    *ph = h;

    if ( ( h->real = malloc( capacity * sizeof( float ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for CLDFB ring buffer\n" );
    }
    if ( ( h->imag = malloc( capacity * sizeof( float ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for CLDFB ring buffer\n" );
    }
    h->capacity = capacity;

    return IVAS_ERR_OK;
}

void CLDFB_RB_Close( CLDFB_RING_BUFFER_HANDLE *ph )
{
    CLDFB_RING_BUFFER_HANDLE h;

    if ( ph == NULL )
    {
        return;
    }
    h = *ph;

    if ( h == NULL )
    {
        return;
    }

    if ( h->real != NULL )
    {
        free( h->real );
    }
    if ( h->imag != NULL )
    {
        free( h->imag );
    }

    free( h );
    *ph = NULL;

    return;
}

void CLDFB_RB_Push( CLDFB_RING_BUFFER_HANDLE h, const float* real, const float* imag, uint16_t num_bands )
{
    assert( num_bands <= CLDFB_NO_CHANNELS_MAX );
    assert( !CLDFB_RB_IsFull( h ) );

    mvr2r( real, &h->real[h->write_pos], (int16_t) num_bands );
    mvr2r( imag, &h->imag[h->write_pos], (int16_t) num_bands );

    h->write_pos += CLDFB_NO_CHANNELS_MAX;
    if ( h->write_pos == h->capacity )
    {
        h->write_pos = 0;
    }

    if ( h->read_pos == h->write_pos )
    {
        h->is_full = 1;
    }

    return;
}

void CLDFB_RB_Pop( CLDFB_RING_BUFFER_HANDLE h, float* real, float* imag, uint16_t num_bands )
{
    CLDFB_RB_Front( h, real, imag, num_bands );

    h->read_pos += CLDFB_NO_CHANNELS_MAX;
    if ( h->read_pos == h->capacity )
    {
        h->read_pos = 0;
    }

    if ( h->is_full )
    {
        h->is_full = 0;
    }
}

void CLDFB_RB_Front( CLDFB_RING_BUFFER_HANDLE h, float* real, float* imag, uint16_t num_bands )
{
    assert( num_bands <= CLDFB_NO_CHANNELS_MAX );
    assert( !CLDFB_RB_IsEmpty( h ) );

    mvr2r( &h->real[h->read_pos], real, (int16_t) num_bands );
    mvr2r( &h->imag[h->read_pos], imag, (int16_t) num_bands );

    return;
}

static uint32_t rb_num_floats( CLDFB_RING_BUFFER_HANDLE h )
{
    uint16_t ret;

    if ( CLDFB_RB_IsFull( h ) )
    {
        return h->capacity;
    }

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

    return ret;
}

int16_t CLDFB_RB_GetNthLastPushed( CLDFB_RING_BUFFER_HANDLE h, float** p_real, float** p_imag, uint16_t n )
{
    uint32_t offset;
    offset = ( n + 1 ) * CLDFB_NO_CHANNELS_MAX;

    /* Trying to access column that was already popped, error */
    if ( rb_num_floats( h ) < offset )
    {
        *p_real = NULL;
        *p_imag = NULL;
        return -1;
    }

    if ( offset <= h->write_pos )
    {
        *p_real = &h->real[h->write_pos - offset];
        *p_imag = &h->imag[h->write_pos - offset];
    }
    else
    {
        /* wrap around */
        *p_real = &h->real[h->write_pos + h->capacity - offset];
        *p_imag = &h->imag[h->write_pos + h->capacity - offset];
    }

    return 0;
}

int16_t CLDFB_RB_IsEmpty( CLDFB_RING_BUFFER_HANDLE h )
{
    return (int16_t) ( h->read_pos == h->write_pos && !h->is_full );
}

int16_t CLDFB_RB_IsFull( CLDFB_RING_BUFFER_HANDLE h )
{
    return h->is_full;
}

uint16_t CLDFB_RB_Size( CLDFB_RING_BUFFER_HANDLE h )
{
    return rb_num_floats( h ) / CLDFB_NO_CHANNELS_MAX;
}

#endif
+66 −0
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 CLDFB_RING_BUFFER_H
#define CLDFB_RING_BUFFER_H

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

#ifdef FIX_1119_SPLIT_RENDERING_VOIP

typedef struct CldfbRingBuffer* CLDFB_RING_BUFFER_HANDLE;

ivas_error CLDFB_RB_Open( CLDFB_RING_BUFFER_HANDLE *ph, int16_t capacity_columns );

void CLDFB_RB_Close( CLDFB_RING_BUFFER_HANDLE *ph );

void CLDFB_RB_Push( CLDFB_RING_BUFFER_HANDLE h, const float* real, const float* imag, uint16_t num_bands );

void CLDFB_RB_Pop( CLDFB_RING_BUFFER_HANDLE h, float* real, float* imag, uint16_t num_bands );

void CLDFB_RB_Front( CLDFB_RING_BUFFER_HANDLE h, float* real, float* imag, uint16_t num_bands );

/**
 * Get pointers into the last nth pushed CLDFB column.
 * TODO: describe n more precisely
 */
int16_t CLDFB_RB_GetNthLastPushed( CLDFB_RING_BUFFER_HANDLE h, float** p_real, float** p_imag, uint16_t n );

int16_t CLDFB_RB_IsEmpty( CLDFB_RING_BUFFER_HANDLE h );

int16_t CLDFB_RB_IsFull( CLDFB_RING_BUFFER_HANDLE h );

uint16_t CLDFB_RB_Size( CLDFB_RING_BUFFER_HANDLE h );

#endif /* FIX_1119_SPLIT_RENDERING_VOIP */
#endif
+9 −0
Original line number Diff line number Diff line
@@ -2328,8 +2328,17 @@ void ivas_dirac_dec_render_sf(
                {
                    for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
                    {
#ifdef FIX_1119_SPLIT_RENDERING_VOIP
                        CLDFB_RB_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],
                            hSpatParamRendCom->num_freq_bands
                        );
#else
                        mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands );
                        mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands );
#endif
                    }
                }
            }
+9 −0
Original line number Diff line number Diff line
@@ -1820,8 +1820,17 @@ void ivas_param_mc_dec_render(
                    {
                        for ( ch = 0; ch < nchan_out_cldfb; ch++ )
                        {
#ifdef FIX_1119_SPLIT_RENDERING_VOIP
                            CLDFB_RB_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],
                                hParamMC->num_freq_bands
                            );
#else
                            mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hParamMC->num_freq_bands );
                            mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hParamMC->num_freq_bands );
#endif
                        }
                    }
                }
+9 −0
Original line number Diff line number Diff line
@@ -790,8 +790,17 @@ static void ivas_mc_paramupmix_dec_sf(
                {
                    for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
                    {
#ifdef FIX_1119_SPLIT_RENDERING_VOIP
                        CLDFB_RB_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],
                            maxBand
                        );
#else
                        mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
                        mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
#endif
                    }
                }
            }
Loading