Commit faa2953f authored by Jan Kiene's avatar Jan Kiene
Browse files

align with parallel port for later MR

parent d871f859
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
#ifndef IVAS_PROT_REND_H
#define IVAS_PROT_REND_H

#include "typedef.h"
#include <stdint.h>
#include "options.h"
#include "ivas_error.h"
@@ -1601,8 +1600,8 @@ void ivas_rend_closeCldfbRend(

ivas_error ivas_TD_RINGBUF_Open(
    TD_RINGBUF_HANDLE *ph,                                      /* i/o: Ring buffer handle                     */
    const UWord16 capacity_per_channel,                        /* i  : Number of samples stored per channel   */
    const UWord16 num_channels                                 /* i  : Number of channels                     */
    const Word16 capacity_per_channel,                          /* i  : Number of samples stored per channel   */
    const Word16 num_channels                                   /* i  : Number of channels                     */
);

void ivas_TD_RINGBUF_Close( 
@@ -1612,24 +1611,23 @@ void ivas_TD_RINGBUF_Close(
void ivas_TD_RINGBUF_Push( 
    TD_RINGBUF_HANDLE h,                                        /* i/o: Ring buffer handle                       */
    const Word32 *data,                                          /* i  : Input data                               */
    const UWord16 num_samples_per_channel                      /* i  : Number of samples per channel to store   */
    const Word16 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 UWord16 num_samples_per_channel                      /* i  : Number of zeros per channel to store    */
    const Word16 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                      */
    Word32 *data,                                                /* i  : Output data                             */
    const UWord16 num_samples_per_channel                      /* i  : Number of samples per channel to retrieve*/
    const Word16 num_samples_per_channel                      /* i  : Number of samples per channel to retrieve*/
);
#endif

uint16_t ivas_TD_RINGBUF_Size(
Word16 ivas_TD_RINGBUF_Size(
    const TD_RINGBUF_HANDLE h                                   /* i  : Ring buffer handle                      */
);

/* clang-format on */

#endif /* IVAS_PROT_REND_H */
+56 −84
Original line number Diff line number Diff line
@@ -30,14 +30,13 @@

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

#include "basop32.h"
#include "move.h"
#include "typedef.h"
#include <assert.h>
#include <stdlib.h>
#include "ivas_error_utils.h"
#include "ivas_prot_rend_fx.h"
#include "options.h"
#include "wmc_auto.h"
#include "prot_fx.h"


/*-----------------------------------------------------------------------*
@@ -50,7 +49,7 @@
 * Returns total number of buffered samples (including number of channels)
 *---------------------------------------------------------------------*/

static UWord32 ivas_td_ringbuf_total_size(
static Word32 ivas_td_ringbuf_total_size(
    TD_RINGBUF_HANDLE h )
{
    IF( h->is_full )
@@ -58,7 +57,7 @@ static UWord32 ivas_td_ringbuf_total_size(
        return h->capacity;
    }

    IF( h->read_pos <= h->write_pos )
    IF( LE_32( h->read_pos, h->write_pos ) )
    {
        return L_sub( h->write_pos, h->read_pos );
    }
@@ -69,21 +68,13 @@ static UWord32 ivas_td_ringbuf_total_size(

static Word16 ivas_td_ringbuf_has_space_for_num_samples(
    TD_RINGBUF_HANDLE h,
    const UWord32 num_samples )
    const Word32 num_samples )
{
    // float was : return (Word16) ( ivas_td_ringbuf_total_size( h ) + num_samples <= h->capacity );
    Word16 has_space;
    UWord32 total_size_after;

    move16();
    has_space = 0;

    total_size_after = L_add( ivas_td_ringbuf_total_size( h ), num_samples );
    IF( LE_32( total_size_after, h->capacity ) )
    if ( LE_32( L_add( ivas_td_ringbuf_total_size( h ), num_samples ), h->capacity ) )
    {
        has_space = 1;
        return 1;
    }
    return has_space;
    return 0;
}


@@ -101,44 +92,41 @@ static Word16 ivas_td_ringbuf_has_space_for_num_samples(

ivas_error ivas_TD_RINGBUF_Open(
    TD_RINGBUF_HANDLE *ph,             /* i/o: Ring buffer handle                     */
    const UWord16 capacity_per_channel, /* i  : Number of samples stored per channel   */
    const UWord16 num_channels          /* i  : Number of channels                     */
    const Word16 capacity_per_channel, /* i  : Number of samples stored per channel   */
    const Word16 num_channels          /* i  : Number of channels                     */
)
{
    TD_RINGBUF_HANDLE h;
    UWord32 capacity;
    Word32 capacity;

    capacity = L_mult0( capacity_per_channel, num_channels ); // Q0 x Q0 -> Q0
    capacity = L_mult0( capacity_per_channel, num_channels );
    move32();

    h = malloc( sizeof( TD_RINGBUF_DATA ) );
    IF( h == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for TD ring buffer\n" );
    }

    move32();
    h->data = NULL;
    move32();
    h->capacity = 0;
    move16();
    h->num_channels = num_channels;
    move32();
    h->num_channels = num_channels;
    move16();
    h->write_pos = 0;
    move32();
    h->read_pos = 0;
    move16();
    h->is_full = 0;
    move32();
    h->is_full = 0;
    move16();
    *ph = h;

    h->data = malloc( capacity * sizeof( Word32 ) );
    IF( h->data == NULL )
    if ( h->data == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to allocate memory for TD ring buffer\n" );
    }

    move32();
    h->capacity = capacity;
    move32();

    return IVAS_ERR_OK;
}
@@ -161,8 +149,6 @@ void ivas_TD_RINGBUF_Close(
    {
        return;
    }

    move32();
    h = *ph;

    IF( h == NULL )
@@ -177,7 +163,6 @@ void ivas_TD_RINGBUF_Close(

    free( h );
    *ph = NULL;
    move32();

    return;
}
@@ -193,39 +178,34 @@ void ivas_TD_RINGBUF_Close(
void ivas_TD_RINGBUF_Push(
    TD_RINGBUF_HANDLE h,                 /* i/o: Ring buffer handle                       */
    const Word32 *data,                  /* i  : Input data                               */
    const UWord16 num_samples_per_channel /* i  : Number of samples per channel to store   */
    const Word16 num_samples_per_channel /* i  : Number of samples per channel to store   */
)
{
    UWord16 c, s;
    Word32 s;
    Word16 c;

    assert( ivas_td_ringbuf_has_space_for_num_samples( h, L_mult0( 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 )
    {
        FOR( c = 0; c < h->num_channels; ++c )
        {
            UWord32 shift_val;

            /* pointer is advance by c * num_samples_per_channel + s */
            shift_val = L_mult0( c, num_samples_per_channel );
            shift_val = L_add( s, shift_val );

            h->data[h->write_pos] = data[L_add( L_mult0( c, num_samples_per_channel ), s )];
            move32();
            h->data[h->write_pos] = *( data + shift_val );
            ++h->write_pos;

            IF( EQ_32( h->write_pos, h->capacity ) )
            if ( EQ_32( h->write_pos, h->capacity ) )
            {
                move32();
                h->write_pos = 0;
                move32();
            }
        }
    }

    IF( EQ_32( h->read_pos, h->write_pos ) )
    if ( EQ_32( h->read_pos, h->write_pos ) )
    {
        move32();
        h->is_full = 1;
        move16();
    }

    return;
@@ -240,13 +220,14 @@ void ivas_TD_RINGBUF_Push(

void ivas_TD_RINGBUF_PushZeros(
    TD_RINGBUF_HANDLE h,                 /* i/o: Ring buffer handle                   */
    const UWord16 num_samples_per_channel /* i  : Number of zeros per channel to store */
    const Word16 num_samples_per_channel /* i  : Number of zeros per channel to store */
)
{
    UWord16 c, s;
    Word32 s;
    Word16 c;

    assert( ivas_td_ringbuf_has_space_for_num_samples( h, L_mult0( num_samples_per_channel, h->num_channels ) ) );
    IF( EQ_16( num_samples_per_channel, 0 ) )
    assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) );
    if ( !num_samples_per_channel )
    {
        return;
    }
@@ -255,22 +236,22 @@ void ivas_TD_RINGBUF_PushZeros(
    {
        FOR( c = 0; c < h->num_channels; ++c )
        {
            h->data[h->write_pos] = 0.f;
            move32();
            h->data[h->write_pos] = 0;
            ++h->write_pos;

            IF( EQ_32( h->write_pos, h->capacity ) )
            if ( EQ_32( h->write_pos, h->capacity ) )
            {
                move32();
                h->write_pos = 0;
                move32();
            }
        }
    }

    IF( EQ_32( h->read_pos, h->write_pos ) )
    if ( EQ_32( h->read_pos, h->write_pos ) )
    {
        move32();
        h->is_full = 1;
        move16();
    }

    return;
@@ -286,40 +267,34 @@ void ivas_TD_RINGBUF_PushZeros(
void ivas_TD_RINGBUF_Pop(
    TD_RINGBUF_HANDLE h,                 /* i/o: Ring buffer handle                           */
    Word32 *data,                        /* i  : Output data                                  */
    const UWord16 num_samples_per_channel /* i  : Number of samples per channel to retrieve    */
    const Word16 num_samples_per_channel /* i  : Number of samples per channel to retrieve    */
)
{
    UWord16 c, s;
    Word32 requested_samples;
    Word32 s;
    Word16 c;

    requested_samples = L_mult0( num_samples_per_channel, h->num_channels );
    assert( GE_32( ivas_td_ringbuf_total_size( h ), requested_samples ) );
    assert( ivas_td_ringbuf_total_size( h ) >= num_samples_per_channel * h->num_channels );

    FOR( s = 0; s < num_samples_per_channel; ++s )
    {
        FOR( c = 0; c < h->num_channels; ++c )
        {
            UWord32 shift_val;

            /* pointer is advanced by c * num_samples_per_channel + s */
            shift_val = L_mult0( c, num_samples_per_channel );
            shift_val = L_add( s, shift_val );

            *( data + shift_val ) = h->data[h->read_pos];
            data[L_add( L_mult0( c, num_samples_per_channel ), s )] = h->data[h->read_pos];
            move32();
            ++h->read_pos;

            IF( EQ_32( h->write_pos, h->capacity ) )
            IF( EQ_32( h->read_pos, h->capacity ) )
            {
                h->read_pos = 0;
                move32();
                h->write_pos = 0;
            }
        }
    }

    IF( NE_16( h->is_full, 0 ) )
    if ( h->is_full )
    {
        move16();
        h->is_full = 0;
        move16();
    }

    return;
@@ -332,12 +307,9 @@ void ivas_TD_RINGBUF_Pop(
 * Returns number of buffered samples per channel.
 *---------------------------------------------------------------------*/

UWord16 ivas_TD_RINGBUF_Size(
Word16 ivas_TD_RINGBUF_Size(
    const TD_RINGBUF_HANDLE h /* i  : Ring buffer handle */
)
{
    UWord16 size;

    size = div_l( ivas_td_ringbuf_total_size( h ), h->num_channels );
    return size;
    return extract_l( ar_div( ivas_td_ringbuf_total_size( h ), L_deposit_l( h->num_channels ) ) );
}