Commit ae50cf1e authored by vaclav's avatar vaclav
Browse files

- tuning for 24.4 kbps 1-Obj

- introduce file ivas_omasa_com.c
- editorial improvements (formatting, 'const', comments)
parent cb723a90
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@
    <ClCompile Include="..\lib_com\ivas_mdct_core_com.c" />
    <ClCompile Include="..\lib_com\ivas_mdct_imdct.c" />
    <ClCompile Include="..\lib_com\ivas_mdft_imdft.c" />
    <ClCompile Include="..\lib_com\ivas_omasa_com.c" />
    <ClCompile Include="..\lib_com\ivas_pca_tools.c" />
    <ClCompile Include="..\lib_com\ivas_qmetadata_com.c" />
    <ClCompile Include="..\lib_com\ivas_qspherical_com.c" />
+3 −0
Original line number Diff line number Diff line
@@ -463,6 +463,9 @@
    <ClCompile Include="..\lib_com\ivas_mdct_imdct.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\ivas_omasa_com.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\lib_com\basop_proto_func.h">
+8 −3
Original line number Diff line number Diff line
@@ -316,6 +316,11 @@ typedef enum
#define ISM_MEDIUM_IMP                          2
#define ISM_HIGH_IMP                            3

#ifdef OMASA_BRATE
#define BRATE_ISM_INACTIVE                      2450 /* CoreCoder bitrate in ISM no meta / inactive frames */
#define BITS_ISM_INACTIVE                       ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
#endif

#define ISM_AZIMUTH_NBITS                       7
#define ISM_AZIMUTH_MIN                         -180.0f
#define ISM_AZIMUTH_MAX                         180.0f
@@ -352,7 +357,7 @@ typedef enum
    ,
    ISM_MASA_MODE_PARAM,                       /* parametric ISM mode for combined MASA ISM format          */
    ISM_MASA_MODE_ONE_OBJ,                     /* MASA ISM mode when one object is encoded separarately     */
    ISM_MASA_MODE_DISC
    ISM_MASA_MODE_DISC                         /* MASA ISM mode when all objects are encoded separarately   */
#endif
} ISM_MODE;

+8 −126
Original line number Diff line number Diff line
@@ -50,8 +50,10 @@

#define FRMS_PER_SECOND ( 1000000000 / FRAME_SIZE_NS )

#ifndef OMASA_BRATE
#define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISm inactive frames */
#define BITS_ISM_INACTIVE  ( BRATE_ISM_INACTIVE / FRMS_PER_SECOND )
#endif

#define BETA_ISM_LOW_IMP    0.6f
#define BETA_ISM_MEDIUM_IMP 0.8f
@@ -115,7 +117,6 @@ ivas_error ivas_ism_config(
    int16_t n_ISms;
    ivas_error error;


    error = IVAS_ERR_OK;
#ifdef MASA_AND_OBJECTS
    if ( combined_format_flag == 1 )
@@ -425,11 +426,13 @@ void ivas_ism_reset_metadata(
    return;
}


/*-------------------------------------------------------------------*
 * ivas_ism_reset_metadata_API()
 *
 * Reset ISm metadata parameters
 *-------------------------------------------------------------------*/

void ivas_ism_reset_metadata_API(
    ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle     */
)
@@ -440,6 +443,7 @@ void ivas_ism_reset_metadata_API(
    return;
}


/*-------------------------------------------------------------------*
 * ism_quant_meta()
 *
@@ -582,7 +586,9 @@ ISM_MODE ivas_ism_mode_select(

    return ism_mode;
}
#ifdef MASA_AND_OBJECTS


#ifdef MASA_AND_OBJECTS // VE2Nokia: move this function to the new file ivas_omasa_com.c (?)
/*---------------------------------------------------------------
 * ivas_omasa_ism_mode_select()
 *
@@ -677,128 +683,4 @@ ISM_MODE ivas_omasa_ism_mode_select(

    return ism_mode;
}


#ifdef OMASA_BRATE
/*---------------------------------------------------------------
 * ivas_interformat_brate()
 *
 * Bit-budget distribution in case of combined-format coding
 * ---------------------------------------------------------------*/

#define GAMMA_ISM_LOW_IMP    0.8f
#define GAMMA_ISM_LOW_IMP2   0.9f
#define GAMMA_ISM_MEDIUM_IMP 1.2f
#define GAMMA_ISM_HIGH_IMP   1.4f
#define GAMMA_ISM_HIGH_IMP2  1.35f

/*! r: adjusted bitrate */
int32_t ivas_interformat_brate(
    const ISM_MODE ism_mode,     /* i  : ISM mode               */
    const int32_t element_brate, /* i  : element bitrate        */
    const int16_t ism_imp        /* i  : ISM importance flag    */
)
{
    int32_t element_brate_out;
    int16_t nBits, limit_low, limit_high;

    nBits = (int16_t) ( element_brate / FRAMES_PER_SEC );

    if ( ism_imp == ISM_INACTIVE_IMP )
    {
        nBits = BITS_ISM_INACTIVE;
    }
    else if ( ism_imp == ISM_LOW_IMP )
    {
        if ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */
        {
            nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 );
        }
        else
        {
            nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
        }
    }
    else if ( ism_imp == ISM_MEDIUM_IMP )
    {
        nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
    }
    else /* ISM_HIGH_IMP */
    {
        if ( ism_mode == ISM_MASA_MODE_ONE_OBJ )
        {
            nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 );
        }
        else
        {
            nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP );
        }
    }

    limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
    if ( ism_imp == ISM_INACTIVE_IMP )
    {
        limit_low = BITS_ISM_INACTIVE;
    }
    else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT )
    {
        limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC;
    }

    limit_high = IVAS_512k / FRAMES_PER_SEC;
    if ( element_brate < SCE_CORE_16k_LOW_LIMIT )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRMS_PER_SECOND;
    }

    nBits = check_bounds_s( nBits, limit_low, limit_high );

    element_brate_out = nBits * FRAMES_PER_SEC;

    return element_brate_out;
}


/*---------------------------------------------------------------
 * ivas_combined_format_brate_sanity()
 *
 * Sanity check in combined format coding
 * ---------------------------------------------------------------*/

void ivas_combined_format_brate_sanity(
    const int32_t element_brate, /* i  : element bitrate                */
    const int16_t core,          /* i  : core                           */
    int32_t *core_brate,         /* i/o: core bitrate                   */
    int16_t *diff_nBits          /* o  : number of differential bits    */
)
{
    int16_t limit_high, nBits;

    /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by
    low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget
    for ACELP core-coding @12.8 kHz is too high */

    if ( element_brate < ACELP_12k8_HIGH_LIMIT )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
        nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC );

        *diff_nBits = nBits - limit_high;
        if ( *diff_nBits > 0 )
        {
            if ( core == TCX_20_CORE || core == TCX_10_CORE )
            {
                *diff_nBits = 0;
            }
            else /* ACELP core */
            {
                *core_brate -= ( *diff_nBits * FRAMES_PER_SEC );
            }
        }
    }

    return;
}

#endif
#endif
+182 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022 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 <stdlib.h>
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "prot.h"
#ifdef DEBUGGING
#include "debug.h"
#endif


#ifdef OMASA_BRATE
/*---------------------------------------------------------------
 * Local constants
 * ---------------------------------------------------------------*/


#define GAMMA_ISM_LOW_IMP    0.8f
#define GAMMA_ISM_MEDIUM_IMP 1.2f
#define GAMMA_ISM_HIGH_IMP   1.4f

#define GAMMA_ISM_LOW_IMP2    0.9f
#define GAMMA_ISM_MEDIUM_IMP2 1.2f
#define GAMMA_ISM_HIGH_IMP2   1.35f


/*---------------------------------------------------------------
 * ivas_interformat_brate()
 *
 * Bit-budget distribution in case of combined-format coding
 * ---------------------------------------------------------------*/

/*! r: adjusted bitrate */
int32_t ivas_interformat_brate(
    const ISM_MODE ism_mode,     /* i  : ISM mode               */
    const int32_t element_brate, /* i  : element bitrate        */
    const int16_t ism_imp        /* i  : ISM importance flag    */
)
{
    int32_t element_brate_out;
    int16_t nBits, limit_low, limit_high;

    nBits = (int16_t) ( element_brate / FRAMES_PER_SEC );


    if ( ism_imp == ISM_INACTIVE_IMP )
    {
        nBits = BITS_ISM_INACTIVE;
    }
    else
    {
        if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ||
             ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */
        )
        {
            if ( ism_imp == ISM_LOW_IMP )
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 );
            }
            else if ( ism_imp == ISM_MEDIUM_IMP )
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP2 );
            }
            else /* ISM_HIGH_IMP */
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 );
            }
        }
        else
        {
            if ( ism_imp == ISM_LOW_IMP )
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
            }
            else if ( ism_imp == ISM_MEDIUM_IMP )
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
            }
            else /* ISM_HIGH_IMP */
            {
                nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP );
            }
        }
    }

    limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
    if ( ism_imp == ISM_INACTIVE_IMP )
    {
        limit_low = BITS_ISM_INACTIVE;
    }
    else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT )
    {
        limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC;
    }

    limit_high = IVAS_512k / FRAMES_PER_SEC;
    if ( element_brate < SCE_CORE_16k_LOW_LIMIT )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
    }

    nBits = check_bounds_s( nBits, limit_low, limit_high );

    element_brate_out = nBits * FRAMES_PER_SEC;

    return element_brate_out;
}


/*---------------------------------------------------------------
 * ivas_combined_format_brate_sanity()
 *
 * Sanity check in combined format coding
 * ---------------------------------------------------------------*/

void ivas_combined_format_brate_sanity(
    const int32_t element_brate, /* i  : element bitrate                */
    const int16_t core,          /* i  : core                           */
    int32_t *core_brate,         /* i/o: core bitrate                   */
    int16_t *diff_nBits          /* o  : number of differential bits    */
)
{
    int16_t limit_high, nBits;

    /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by
    low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget
    for ACELP core-coding @12.8 kHz is too high */

    if ( element_brate < ACELP_12k8_HIGH_LIMIT )
    {
        limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
        nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC );

        *diff_nBits = nBits - limit_high;
        if ( *diff_nBits > 0 )
        {
            if ( core == TCX_20_CORE || core == TCX_10_CORE )
            {
                *diff_nBits = 0;
            }
            else /* ACELP core */
            {
                *core_brate -= ( *diff_nBits * FRAMES_PER_SEC );
            }
        }
    }

    return;
}

#endif
Loading