Commit 8b4bd143 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

addition of lib isar, not compiling yet

parent e86f14b5
Loading
Loading
Loading
Loading

apps/isar_post_rend.c

0 → 100644
+1253 −0

File added.

Preview size limit exceeded, changes collapsed.

+72 −40
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@
#define IVAS_MAX_PARAM_SPATIAL_SUBFRAMES 4
#define IVAS_ROOM_ABS_COEFF              6

/* Maximum buffer length (per channel) in samples */
#define MAX_BUFFER_LENGTH_PER_CHANNEL ( L_FRAME48k )

/* Frame size required when rendering to binaural */
#define BINAURAL_RENDERING_FRAME_SIZE_MS 5

/*----------------------------------------------------------------------------------*
 * Common API enum for output audio configurations
 *----------------------------------------------------------------------------------*/
@@ -200,9 +206,10 @@ typedef struct _IVAS_JBM_TRACE_DATA
 * Split rendering API constants, structures, and enums
 *----------------------------------------------------------------------------------*/

#define IVAS_MAX_SPLIT_REND_BITRATE                   768000
#define IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES ( ( ( (int32_t) IVAS_MAX_SPLIT_REND_BITRATE / IVAS_NUM_FRAMES_PER_SEC ) + 7 ) >> 3 )
#define IVAS_SPLIT_REND_ADDITIONAL_BYTES_TO_READ      1
#define ISAR_MAX_SPLIT_REND_BITRATE                   768000
#define ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES ( ( ( (int32_t) ISAR_MAX_SPLIT_REND_BITRATE / IVAS_NUM_FRAMES_PER_SEC ) + 7 ) >> 3 )
#define ISAR_SPLIT_REND_ADDITIONAL_BYTES_TO_READ      1
#define SPLIT_REND_BITS_BUFF_SIZE                     ( ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES + ISAR_SPLIT_REND_ADDITIONAL_BYTES_TO_READ )

typedef enum
{
@@ -214,47 +221,51 @@ typedef enum
    YAW_ROLL,
    PITCH_ROLL

} IVAS_SPLIT_REND_ROT_AXIS;
} ISAR_SPLIT_REND_ROT_AXIS;

typedef enum
{
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE_NONE,
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB,
    ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE,
    ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB,

} IVAS_SPLIT_REND_POSE_CORRECTION_MODE;
} ISAR_SPLIT_REND_POSE_CORRECTION_MODE;

typedef enum
{
    IVAS_SPLIT_REND_CODEC_LCLD,
    IVAS_SPLIT_REND_CODEC_LC3PLUS,
    IVAS_SPLIT_REND_CODEC_DEFAULT, /* Will use LCLD for CLDFB rendering paths and LC3plus for TD rendering paths */
    IVAS_SPLIT_REND_CODEC_NONE
    ISAR_SPLIT_REND_CODEC_LCLD,
    ISAR_SPLIT_REND_CODEC_LC3PLUS,
    ISAR_SPLIT_REND_CODEC_DEFAULT, /* Will use LCLD for CLDFB rendering paths and LC3plus for TD rendering paths */
    ISAR_SPLIT_REND_CODEC_NONE

} IVAS_SPLIT_REND_CODEC;
} ISAR_SPLIT_REND_CODEC;

typedef enum
{
    IVAS_SPLIT_REND_RENDERER_SELECTION_CREND,
    IVAS_SPLIT_REND_RENDERER_SELECTION_FASTCONV,
    IVAS_SPLIT_REND_RENDERER_SELECTION_PARAMBIN,
    IVAS_SPLIT_REND_RENDERER_SELECTION_TDREND,
    IVAS_SPLIT_REND_RENDERER_SELECTION_DEFAULT,
    ISAR_SPLIT_REND_RENDERER_SELECTION_CREND,
    ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV,
    ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN,
    ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND,
    ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT,

} IVAS_SPLIT_REND_RENDERER_SELECTION;
} ISAR_SPLIT_REND_RENDERER_SELECTION;

typedef struct _IVAS_SPLIT_REND_BITS_DATA
typedef struct _ISAR_SPLIT_REND_BITS_DATA
{
    uint8_t *bits_buf;
    int32_t buf_len; /*size of bits_buf in bytes. This field should be set by allocator of bits_buf*/
    int32_t bits_written;
    int32_t bits_read;
    int16_t codec_frame_size_ms;
    IVAS_SPLIT_REND_CODEC codec;
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE pose_correction;
    ISAR_SPLIT_REND_CODEC codec;
    ISAR_SPLIT_REND_POSE_CORRECTION_MODE pose_correction;
#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS
    int16_t isar_frame_size_ms;
    int16_t lc3plus_highres;
#endif

} IVAS_SPLIT_REND_BITS_DATA, *IVAS_SPLIT_REND_BITS_HANDLE;
} ISAR_SPLIT_REND_BITS_DATA, *ISAR_SPLIT_REND_BITS_HANDLE;

typedef struct _IVAS_SPLIT_REND_CONFIG
typedef struct _ISAR_SPLIT_REND_CONFIG
{
    int32_t splitRendBitRate; /*Bit rate for split rendering mode, if "pcm_out" is set then "splitRendBitRate" is used as a limit for MD bitrate */
    int16_t hq_mode;          /*High quality 3DOF mode with additional side information. Requires more pre-renditions. */
@@ -266,12 +277,18 @@ typedef struct _IVAS_SPLIT_REND_CONFIG
                              3 - (3dof correction. By default YAW, PITCH and ROLL correction)
                              */
    int16_t codec_delay_ms;   /*PLACEHOLDER (currently being ignored) : look ahead delay of the codec that is used to code BIN signal output of pre-renderer*/
#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS
    int16_t isar_frame_size_ms; /* ISAR bit stream frame size in milliseconds */
#endif
    int16_t codec_frame_size_ms; /* Codec frame size in milliseconds, only relevant with LC3plus */
    IVAS_SPLIT_REND_POSE_CORRECTION_MODE poseCorrectionMode;
    IVAS_SPLIT_REND_CODEC codec;
    IVAS_SPLIT_REND_RENDERER_SELECTION rendererSelection;
    ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrectionMode;
    ISAR_SPLIT_REND_CODEC codec;
    ISAR_SPLIT_REND_RENDERER_SELECTION rendererSelection;
#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS
    int16_t lc3plus_highres;
#endif

} IVAS_SPLIT_REND_CONFIG_DATA;
} ISAR_SPLIT_REND_CONFIG_DATA, *ISAR_SPLIT_REND_CONFIG_HANDLE;
#endif

/*----------------------------------------------------------------------------------*
@@ -314,10 +331,25 @@ typedef struct _IVAS_RENDER_CONFIG
#endif
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcoustics;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    IVAS_SPLIT_REND_CONFIG_DATA split_rend_config;
    ISAR_SPLIT_REND_CONFIG_DATA split_rend_config;
#endif
    float directivity[IVAS_MAX_NUM_OBJECTS * 3];

} IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE;

typedef struct
{
    int16_t numSamplesPerChannel;
    int16_t numChannels;
#ifdef SPLIT_REND_WITH_HEAD_ROT
    int16_t is_cldfb;
#endif
} IVAS_REND_AudioBufferConfig;

typedef struct
{
    IVAS_REND_AudioBufferConfig config;
    float *data;
} IVAS_REND_AudioBuffer;

#endif /* COMMON_API_TYPES_H */

lib_isar/isar_MSPred.c

0 → 100644
+470 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2023 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 "options.h"
#include <stdint.h>
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include "isar_lcld_prot.h"
#include "isar_prot.h"
#include "wmc_auto.h"


/*-------------------------------------------------------------------*
 * Function _round()
 *
 *
 *-------------------------------------------------------------------*/

static int32_t _round(
    float val )
{
    return ( val > 0.0f ? (int32_t) ( val + 0.5f ) : (int32_t) ( val - 0.5f ) );
}


/*-------------------------------------------------------------------*
 * Function quantPhase()
 *
 *
 *-------------------------------------------------------------------*/

int32_t quantPhase(
    float phase )
{
    int32_t phaseQ;

    phaseQ = _round( phase * PHASE_QUANT_FACTOR );
    if ( phaseQ == PHASE_MAX_VAL )
    {
        phaseQ = PHASE_MIN_VAL;
    }
    return phaseQ;
}


/*-------------------------------------------------------------------*
 * Function cplxmult_lcld()
 *
 *
 *-------------------------------------------------------------------*/

void cplxmult_lcld(
    float *pr1,
    float *pi1,
    const float r2,
    const float i2 )
{
    float r1 = *pr1, i1 = *pi1;

    *pr1 = r1 * r2 - i1 * i2;
    *pi1 = r1 * i2 + i1 * r2;

    return;
}


/*-------------------------------------------------------------------*
 * Function requantPhase()
 *
 *
 *-------------------------------------------------------------------*/

int32_t requantPhase(
    int32_t phaseQ )
{

    if ( phaseQ >= PHASE_MAX_VAL )
    {
        phaseQ += PHASE_MAX_VAL;
        phaseQ %= ( 2 * PHASE_MAX_VAL );
        phaseQ -= PHASE_MAX_VAL;
    }
    else if ( phaseQ < PHASE_MIN_VAL )
    {
        phaseQ -= PHASE_MAX_VAL;
        phaseQ %= ( 2 * PHASE_MAX_VAL );
        phaseQ += PHASE_MAX_VAL;
        if ( phaseQ == PHASE_MAX_VAL )
        {
            phaseQ = PHASE_MIN_VAL;
        }
    }

    return phaseQ;
}


/*-------------------------------------------------------------------*
 * Function quantPred()
 *
 *
 *-------------------------------------------------------------------*/

int32_t quantPred(
    const float pred )
{
    int32_t predQ = _round( pred * PRED_QUANT_FACTOR );
    predQ = predQ > PRED_MAX_VAL ? PRED_MAX_VAL : predQ;
    predQ = predQ < PRED_MIN_VAL ? PRED_MIN_VAL : predQ;

    return predQ;
}


/*-------------------------------------------------------------------*
 * Function dequantPhase()
 *
 *
 *-------------------------------------------------------------------*/

float dequantPhase(
    const int32_t phaseQ )
{
    return (float) phaseQ / PHASE_QUANT_FACTOR;
}


/*-------------------------------------------------------------------*
 * Function dequantPred()
 *
 *
 *-------------------------------------------------------------------*/

float dequantPred( int32_t predQ )
{
    return (float) predQ / PRED_QUANT_FACTOR;
}


/*-------------------------------------------------------------------*
 * Function PrepEncode()
 *
 *
 *-------------------------------------------------------------------*/

int32_t PrepEncode(
    int32_t *piQuant,
    const int32_t *piMSFlags,
    const int32_t numBands )
{
    int32_t b, numMSBands = 0;

    for ( b = 0; b < numBands; b++ )
    {
        if ( piMSFlags[b] )
        {
            piQuant[numMSBands++] = piQuant[b];
        }
    }

    for ( b = numMSBands; b < numBands; b++ )
    {
        piQuant[b] = 0;
    }

    return numMSBands;
}


/*-------------------------------------------------------------------*
 * Function EncodePhase()
 *
 *
 *-------------------------------------------------------------------*/

void EncodePhase(
    int32_t *phaseQuant,
    const int32_t numMSBands,
    const int32_t diffDim )
{
    int32_t b;

    if ( diffDim > 0 )
    {
        int32_t tmp1, tmp2;
        tmp1 = phaseQuant[0];
        for ( b = 1; b < numMSBands; b++ )
        {
            tmp2 = phaseQuant[b];
            phaseQuant[b] -= tmp1;
            tmp1 = tmp2;
        }
    }

    if ( diffDim > 1 )
    {
        int32_t tmp1, tmp2;
        tmp1 = phaseQuant[1];
        for ( b = 2; b < numMSBands; b++ )
        {
            tmp2 = phaseQuant[b];
            phaseQuant[b] -= tmp1;
            tmp1 = tmp2;
        }
    }
    for ( b = 1; b < numMSBands; b++ )
    {
        phaseQuant[b] = requantPhase( phaseQuant[b] );
    }

    return;
}


/*-------------------------------------------------------------------*
 * Function DecodePhase()
 *
 *
 *-------------------------------------------------------------------*/

void DecodePhase(
    int32_t *phaseQuant,
    const int32_t numMSBands,
    const int32_t diffDim )
{
    int32_t b;

    if ( diffDim > 1 )
    {
        for ( b = 2; b < numMSBands; b++ )
        {
            phaseQuant[b] += phaseQuant[b - 1];
        }
    }

    if ( diffDim > 0 )
    {
        for ( b = 1; b < numMSBands; b++ )
        {
            phaseQuant[b] += phaseQuant[b - 1];
        }
    }

    for ( b = 1; b < numMSBands; b++ )
    {
        phaseQuant[b] = requantPhase( phaseQuant[b] );
    }

    return;
}


/*-------------------------------------------------------------------*
 * Function EncodePredCoef()
 *
 *
 *-------------------------------------------------------------------*/

int32_t EncodePredCoef(
    int32_t *predQuant,
    const int32_t numMSBands )
{
    int32_t b, tmp1, tmp2;

    tmp1 = predQuant[0];
    for ( b = 1; b < numMSBands; b++ )
    {
        tmp2 = predQuant[b];
        predQuant[b] -= tmp1;
        tmp1 = tmp2;
    }

    return numMSBands;
}


/*-------------------------------------------------------------------*
 * Function DecodePredCoef()
 *
 *
 *-------------------------------------------------------------------*/

void DecodePredCoef(
    int32_t *phaseQuant,
    const int32_t numMSBands )
{
    int32_t b;

    for ( b = 1; b < numMSBands; b++ )
    {
        phaseQuant[b] += phaseQuant[b - 1];
    }

    return;
}


/*-------------------------------------------------------------------*
 * Function CountMSBits()
 *
 *
 *-------------------------------------------------------------------*/

int32_t CountMSBits(
    int32_t iNumBands,
    const int32_t iMSMode,
    const int32_t *piMSFlags,
    const int32_t *piLRPhaseDiff,
    const int32_t *piMSPredCoef )
{
    int32_t iBitsWritten = 0;
    int32_t b;
    int32_t anyNonZero;
    int32_t iNumMSBands = 0;
    int32_t piPhaseCopy[MAX_BANDS_48];
    int32_t piPredCopy[MAX_BANDS_48];

    for ( b = 0; b < MAX_BANDS_48; b++ )
    {
        piPhaseCopy[b] = 0;
        piPredCopy[b] = 0;
    }

    iBitsWritten += 2; /* iMSMode */
    for ( b = 0; b < iNumBands; b++ )
    {
        iNumMSBands += ( piMSFlags[b] != 0 );
    }

    if ( iNumMSBands == 0 )
    {
        return iBitsWritten;
    }

    if ( iNumMSBands < iNumBands )
    {
        iBitsWritten += iNumBands; /* piMSFlags */
    }

    if ( iMSMode < 3 )
    {
        return iBitsWritten;
    }

    /* prepare arrays for coding evaluation */
    for ( b = 0; b < iNumBands; b++ )
    {
        piPhaseCopy[b] = piLRPhaseDiff[b];
        piPredCopy[b] = piMSPredCoef[b];
    }

    /* Differential Coding of Phase Data*/
    PrepEncode( piPhaseCopy, piMSFlags, iNumBands );
    PrepEncode( piPredCopy, piMSFlags, iNumBands );
    EncodePhase( piPhaseCopy, iNumMSBands, PHASE_DIFF_DIM );
    EncodePredCoef( piPredCopy, iNumMSBands );

    iBitsWritten += 1; /* iMSPredAll */
    anyNonZero = 0;    /* phase */
    for ( b = 0; b < iNumMSBands; b++ )
    {
        if ( piPhaseCopy[b] != 0 )
        {
            anyNonZero = 1;
            break;
        }
    }
    iBitsWritten++; /*anyNonZero Phase*/
    if ( anyNonZero )
    {
        iBitsWritten += PHASE_BAND0_BITS;
        for ( b = 1; b < iNumMSBands; b++ )
        {
            int32_t tabIdx = piPhaseCopy[b] - ENV_DELTA_MIN;
            iBitsWritten += c_aaiRMSEnvHuffEnc[tabIdx][0];
        }
    }
    anyNonZero = 0; /* prediction */
    for ( b = 0; b < iNumMSBands; b++ )
    {
        if ( piPredCopy[b] != 0 )
        {
            anyNonZero = 1;
            break;
        }
    }

    iBitsWritten++; /* any nonZero Pred */
    if ( anyNonZero )
    {
        iBitsWritten += PRED_BAND0_BITS;
        for ( b = 1; b < iNumMSBands; b++ )
        {
            int32_t tabIdx = piPredCopy[b] - ENV_DELTA_MIN;
            iBitsWritten += c_aaiRMSEnvHuffEnc[tabIdx][0];
        }
    }

    return iBitsWritten;
}


#ifdef DEBUG_WRITE_MS_PRED
void writeMSPred(
    int32_t *phaseQuant,
    int32_t *predQuant,
    int32_t MSMode,
    int32_t numMSBands,
    int32_t numBands,
    void *fid,
    int32_t *piMsFlags )
{
    int32_t b;

    fid = (FILE *) fid;
    fprintf( fid, "%d %d", MSMode, numMSBands );
    for ( b = 0; b < numMSBands; b++ )
    {
        fprintf( fid, " %d", phaseQuant[b] );
    }
    for ( b = numMSBands; b < numBands; b++ )
    {
        fprintf( fid, " %d", 0 );
    }
    for ( b = 0; b < numMSBands; b++ )
    {
        fprintf( fid, " %d", predQuant[b] );
    }
    for ( b = numMSBands; b < numBands; b++ )
    {
        fprintf( fid, " %d", 0 );
    }
    for ( b = 0; b < numBands; b++ )
    {
        fprintf( fid, " %d", piMsFlags[b] );
    }
    fprintf( fid, "\n" );

    return;
}
#endif
#endif
+57 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2023 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 <stdint.h>
#include "options.h"
#ifdef SPLIT_REND_WITH_HEAD_ROT
#include <math.h>
#include "prot.h"
#include "isar_lcld_prot.h"
#include "wmc_auto.h"


/*------------------------------------------------------------------------------------------*
 * Function DeleteNoiseGen()
 *
 *
 *------------------------------------------------------------------------------------------*/

void DeleteNoiseGen( NoiseGen *psNoiseGen )
{
    free( psNoiseGen->pfNoiseBuffer );
    free( psNoiseGen );

    return;
}

extern float GetNoise( NoiseGen *psNoiseGen );
#endif
+252 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading