LCOV - code coverage report
Current view: top level - lib_enc - ivas_sba_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 99 107 92.5 %
Date: 2025-05-03 01:55:50 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include <math.h>
      36             : #include "options.h"
      37             : #include "cnst.h"
      38             : #include "ivas_cnst.h"
      39             : #include "rom_com.h"
      40             : #include "prot_fx.h"
      41             : #include "ivas_prot_fx.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "wmc_auto.h"
      44             : #include "ivas_prot_fx.h"
      45             : 
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * ivas_sba_getTCs()
      49             :  *
      50             :  * Get TCs from Ambisonics signal in ACN
      51             :  *-------------------------------------------------------------------*/
      52      138810 : void ivas_sba_getTCs_fx(
      53             :     Word32 *sba_data[],      /* i  : SBA signals Q11              */
      54             :     Encoder_Struct *st_ivas, /* i/o: Encoder struct               */
      55             :     const Word16 input_frame /* i  : frame length                 */
      56             : )
      57             : {
      58      138810 :     IF( st_ivas->hEncoderConfig->sba_planar )
      59             :     {
      60       10250 :         ivas_sba_zero_vert_comp_fx( sba_data, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar, input_frame );
      61             :     }
      62             : 
      63      138810 :     st_ivas->nchan_transport = ivas_get_sba_num_TCs_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
      64      138810 :     move16();
      65             : 
      66      138810 :     IF( GE_16( st_ivas->nchan_transport, 3 ) )
      67             :     {
      68             :         /*convert WYZX downmix to WYXZ*/
      69       66549 :         Word16 i = 0;
      70       66549 :         move16();
      71             :         Word32 temp;
      72    54465589 :         FOR( i = 0; i < input_frame; i++ )
      73             :         {
      74    54399040 :             temp = sba_data[2][i];
      75    54399040 :             sba_data[2][i] = sba_data[3][i];
      76    54399040 :             sba_data[3][i] = temp;
      77    54399040 :             move32();
      78    54399040 :             move32();
      79    54399040 :             move32();
      80             :         }
      81             :     }
      82             : 
      83             : 
      84      138810 :     return;
      85             : }
      86             : 
      87             : /*-------------------------------------------------------------------*
      88             :  * ivas_sba_enc_reconfigure_fx()
      89             :  *
      90             :  * Reconfigure IVAS SBA encoder
      91             :  *-------------------------------------------------------------------*/
      92             : 
      93      122500 : ivas_error ivas_sba_enc_reconfigure_fx(
      94             :     Encoder_Struct *st_ivas /* i/o: IVAS encoder structure      */
      95             : )
      96             : {
      97             :     Word16 n, nSCE_old, nCPE_old, nchan_transport_old;
      98             :     Word32 ivas_total_brate;
      99             :     ivas_error error;
     100             :     ENCODER_CONFIG_HANDLE hEncoderConfig;
     101             : 
     102      122500 :     error = IVAS_ERR_OK;
     103      122500 :     move32();
     104      122500 :     hEncoderConfig = st_ivas->hEncoderConfig;
     105      122500 :     ivas_total_brate = hEncoderConfig->ivas_total_brate;
     106      122500 :     move32();
     107             : 
     108      122500 :     IF( NE_32( ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) )
     109             :     {
     110        1020 :         DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC;
     111             :         SPAR_ENC_HANDLE hSpar;
     112             :         Word16 analysis_order_old;
     113             :         Word16 spar_reconfig_flag;
     114             :         Word16 nbands_old;
     115             :         Word16 ndir_old;
     116             : 
     117        1020 :         spar_reconfig_flag = 0;
     118        1020 :         nchan_transport_old = st_ivas->nchan_transport;
     119        1020 :         nCPE_old = st_ivas->nCPE;
     120        1020 :         nSCE_old = st_ivas->nSCE;
     121        1020 :         move16();
     122        1020 :         move16();
     123        1020 :         move16();
     124        1020 :         move16();
     125             : 
     126        1020 :         st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order );
     127        1020 :         move16();
     128        1020 :         analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order );
     129             : 
     130        1020 :         nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands;
     131        1020 :         move16();
     132        1020 :         ndir_old = st_ivas->hQMetaData->no_directions;
     133        1020 :         move16();
     134             : 
     135        1020 :         IF( NE_16( analysis_order_old, st_ivas->sba_analysis_order ) )
     136             :         {
     137             :             Word16 i, n_old;
     138             :             Word32 **old_mem_hp20_in_fx;
     139             : 
     140         241 :             n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) );
     141         241 :             n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) );
     142             : 
     143         241 :             IF( GT_16( n, n_old ) )
     144             :             {
     145             :                 /* save old mem_hp_20 pointer */
     146         124 :                 old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx;
     147         124 :                 st_ivas->mem_hp20_in_fx = NULL;
     148             : 
     149         124 :                 IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL )
     150             :                 {
     151           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     152             :                 }
     153             : 
     154         620 :                 FOR( i = 0; i < n_old; i++ )
     155             :                 {
     156         496 :                     st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i];
     157         496 :                     old_mem_hp20_in_fx[i] = NULL;
     158             :                 }
     159             :                 /* create additional hp20 memories */
     160        1479 :                 FOR( ; i < n; i++ )
     161             :                 {
     162        1355 :                     IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL )
     163             :                     {
     164           0 :                         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     165             :                     }
     166             : 
     167        1355 :                     set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 );
     168             :                 }
     169             : 
     170         124 :                 free( old_mem_hp20_in_fx );
     171         124 :                 old_mem_hp20_in_fx = NULL;
     172             :             }
     173         117 :             ELSE IF( LT_16( n, n_old ) )
     174             :             {
     175             :                 /* save old mem_hp_20 pointer */
     176         117 :                 old_mem_hp20_in_fx = st_ivas->mem_hp20_in_fx;
     177         117 :                 st_ivas->mem_hp20_in_fx = NULL;
     178             : 
     179         117 :                 IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL )
     180             :                 {
     181           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
     182             :                 }
     183             : 
     184         585 :                 FOR( i = 0; i < n; i++ )
     185             :                 {
     186         468 :                     st_ivas->mem_hp20_in_fx[i] = old_mem_hp20_in_fx[i];
     187         468 :                     old_mem_hp20_in_fx[i] = NULL;
     188             :                 }
     189             :                 /* remove superfluous hp20 memories */
     190        1395 :                 FOR( ; i < n_old; i++ )
     191             :                 {
     192        1278 :                     free( old_mem_hp20_in_fx[i] );
     193        1278 :                     old_mem_hp20_in_fx[i] = NULL;
     194             :                 }
     195             : 
     196         117 :                 free( old_mem_hp20_in_fx );
     197         117 :                 old_mem_hp20_in_fx = NULL;
     198             :             }
     199             :         }
     200             : 
     201        1020 :         ivas_spar_config_fx( ivas_total_brate, s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 );
     202             : 
     203        1020 :         hSpar = st_ivas->hSpar;
     204             : 
     205        1020 :         IF( EQ_16( st_ivas->nchan_transport, 1 ) )
     206             :         {
     207         372 :             hEncoderConfig->element_mode_init = IVAS_SCE;
     208             :         }
     209             :         ELSE
     210             :         {
     211         648 :             hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
     212             :         }
     213        1020 :         move16();
     214             : 
     215        1020 :         test();
     216        1020 :         test();
     217        1020 :         test();
     218        1020 :         test();
     219        1020 :         IF( NE_16( nchan_transport_old, st_ivas->nchan_transport ) || ( LT_32( ivas_total_brate, IVAS_512k ) && GE_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) || ( GE_32( ivas_total_brate, IVAS_512k ) && LT_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) )
     220             :         {
     221             :             /* FB mixer handle */
     222         815 :             IF( hDirAC->hFbMixer != NULL )
     223             :             {
     224           0 :                 ivas_FB_mixer_close_fx( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 );
     225           0 :                 hDirAC->hFbMixer = NULL;
     226             :             }
     227         815 :             spar_reconfig_flag = 1;
     228         815 :             move16();
     229         815 :             ivas_spar_enc_close_fx( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag );
     230             : 
     231         815 :             IF( ( error = ivas_spar_enc_open_fx( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK )
     232             :             {
     233           0 :                 return error;
     234             :             }
     235             :         }
     236             : 
     237        1020 :         st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag;
     238        1020 :         move16();
     239             : 
     240        1020 :         IF( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
     241             :         {
     242           0 :             return error;
     243             :         }
     244             : 
     245        1020 :         test();
     246        1020 :         IF( NE_16( st_ivas->hQMetaData->q_direction->cfg.nbands, nbands_old ) || NE_16( st_ivas->hQMetaData->no_directions, ndir_old ) )
     247             :         {
     248             :             Word16 dir, j, i;
     249         522 :             IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction;
     250        1130 :             FOR( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ )
     251             :             {
     252        3774 :                 FOR( j = 0; j < q_direction[dir].cfg.nbands; j++ )
     253             :                 {
     254       15830 :                     FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
     255             :                     {
     256       12664 :                         q_direction[dir].band_data[j].energy_ratio_index[i] = 0;
     257       12664 :                         q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0;
     258       12664 :                         move16();
     259       12664 :                         move16();
     260             :                     }
     261             :                 }
     262             :             }
     263             :         }
     264        1020 :         hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band;
     265        1020 :         move16();
     266             : 
     267             :         /*-----------------------------------------------------------------*
     268             :          * Allocate, initialize, and configure SCE/CPE/MCT handles
     269             :          *-----------------------------------------------------------------*/
     270             : 
     271        1020 :         IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK )
     272             :         {
     273           0 :             return error;
     274             :         }
     275             :     }
     276             : 
     277      122500 :     return error;
     278             : }

Generated by: LCOV version 1.14