LCOV - code coverage report
Current view: top level - lib_enc - ivas_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 216 259 83.4 %
Date: 2025-11-01 03:16:20 Functions: 1 1 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 <stdint.h>
      34             : #include <math.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "ivas_cnst.h"
      38             : #include "rom_com.h"
      39             : #include "prot_fx.h"
      40             : #include "ivas_rom_com.h"
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : #include "wmc_auto.h"
      45             : #include "ivas_prot_fx.h"
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * ivas_enc()
      49             :  *
      50             :  * Principal IVAS encoder routine
      51             :  *-------------------------------------------------------------------*/
      52      425288 : ivas_error ivas_enc_fx(
      53             :     Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure                     */
      54             :     const Word16 *data,      /* i  : input signal                                       Q0*/
      55             :     const Word16 n_samples   /* i  : number of input samples            Q0*/
      56             : )
      57             : {
      58             :     Word16 i, n, input_frame, n_samples_chan, nchan_inp /*, scale*/;
      59             :     Word32 input_Fs;
      60             :     IVAS_FORMAT ivas_format;
      61             :     ENCODER_CONFIG_HANDLE hEncoderConfig;
      62             :     BSTR_ENC_HANDLE hMetaData;
      63             :     Word16 nb_bits_metadata[MAX_SCE + 1];
      64             :     Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS];
      65             :     Word32 ivas_total_brate;
      66             :     ivas_error error;
      67      425288 :     error = IVAS_ERR_OK;
      68      425288 :     move32();
      69             : 
      70      425288 :     push_wmops( "ivas_enc" );
      71             : 
      72             :     /*------------------------------------------------------------------*
      73             :      * Initialization - general
      74             :      *-----------------------------------------------------------------*/
      75             : 
      76      425288 :     hEncoderConfig = st_ivas->hEncoderConfig;
      77             : 
      78      425288 :     input_Fs = hEncoderConfig->input_Fs; /* Q0 */
      79      425288 :     ivas_format = hEncoderConfig->ivas_format;
      80      425288 :     nchan_inp = hEncoderConfig->nchan_inp;               /* Q0 */
      81      425288 :     ivas_total_brate = hEncoderConfig->ivas_total_brate; /* Q0 */
      82      425288 :     move32();
      83      425288 :     move32();
      84      425288 :     move16();
      85      425288 :     move32();
      86             : 
      87      425288 :     input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) );
      88      425288 :     IF( NE_16( nchan_inp, 1 ) )
      89             :     {
      90      391672 :         n_samples_chan = extract_l( Mpy_32_32_r( n_samples, one_by_q_level[nchan_inp] ) ); /* Q0 */
      91             :     }
      92             :     ELSE
      93             :     {
      94       33616 :         n_samples_chan = n_samples; /* Q0 */
      95       33616 :         move16();
      96             :     }
      97      425288 :     set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
      98             : 
      99             :     /*----------------------------------------------------------------*
     100             :      * convert 'Word16' input data to 'Word32' in Q11 format
     101             :      *----------------------------------------------------------------*/
     102             : 
     103     8931048 :     FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
     104             :     {
     105     8505760 :         data_fx[n] = st_ivas->p_data_fx[n];
     106     8505760 :         IF( data_fx[n] )
     107             :         {
     108     2565310 :             Scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // Q11
     109             :         }
     110             :     }
     111      425288 :     st_ivas->q_data_fx = Q11;
     112      425288 :     move16();
     113      425288 :     n = 0;
     114      425288 :     move16();
     115     2978898 :     WHILE( LT_16( n, nchan_inp ) )
     116             :     {
     117  2097738250 :         FOR( i = 0; i < n_samples_chan; i++ )
     118             :         {
     119  2095184640 :             data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) );
     120  2095184640 :             move32();
     121             :         }
     122     2553610 :         n = add( n, 1 );
     123             :     }
     124             : 
     125      425288 :     IF( LT_16( n_samples_chan, input_frame ) )
     126             :     {
     127           0 :         FOR( n = 0; n < nchan_inp; n++ )
     128             :         {
     129           0 :             set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) );
     130             :         }
     131             :     }
     132             : 
     133      425288 :     IF( EQ_32( ivas_format, SBA_FORMAT ) )
     134             :     {
     135      123500 :         IF( NE_32( ( error = ivas_sba_enc_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) )
     136             :         {
     137           0 :             return error;
     138             :         }
     139             :     }
     140      301788 :     ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) )
     141             :     {
     142       37000 :         IF( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK )
     143             :         {
     144           0 :             return error;
     145             :         }
     146             :     }
     147             : 
     148             :     /*----------------------------------------------------------------*
     149             :      * HP filtering
     150             :      *----------------------------------------------------------------*/
     151             : 
     152      425288 :     n = getNumChanAnalysis_fx( st_ivas );
     153             : 
     154             :     /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */
     155     2245898 :     FOR( i = 0; i < n; i++ )
     156             :     {
     157     1820610 :         test();
     158     1820610 :         test();
     159     1820610 :         IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) )
     160             :         {
     161      447080 :             hp20_fx_32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs );
     162             :         }
     163     1373530 :         ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) )
     164             :         {
     165     1324680 :             hp20_fx_32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs );
     166             :         }
     167             :     }
     168             : 
     169             :     /*----------------------------------------------------------------*
     170             :      * write IVAS format signaling
     171             :      *----------------------------------------------------------------*/
     172      425288 :     ivas_write_format_fx( st_ivas );
     173             : 
     174             :     /*----------------------------------------------------------------*
     175             :      * Encoding
     176             :      *----------------------------------------------------------------*/
     177      425288 :     test();
     178      425288 :     IF( EQ_32( ivas_format, STEREO_FORMAT ) )
     179             :     {
     180       72486 :         st_ivas->hCPE[0]->element_brate = ivas_total_brate; /* Q0 */
     181       72486 :         move32();
     182       72486 :         IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */, NULL ) ) != IVAS_ERR_OK )
     183             :         {
     184           0 :             return error;
     185             :         }
     186             :     }
     187      352802 :     ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) )
     188             :     {
     189             :         /* select ISM format mode; reconfigure the ISM format encoder */
     190      103826 :         IF( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK )
     191             :         {
     192           0 :             return error;
     193             :         }
     194             : 
     195      103826 :         IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     196             :         {
     197       20720 :             ivas_param_ism_enc_fx( st_ivas, data_fx, input_frame );
     198             : 
     199             :             /* Stereo DMX generation */
     200       20720 :             ivas_param_ism_stereo_dmx_fx( st_ivas, data_fx, input_frame );
     201             : 
     202             :             /* Core coding of Stereo DMX */
     203       20720 :             IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK )
     204             :             {
     205           0 :                 return error;
     206             :             }
     207             :         }
     208       83106 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) )
     209             :         {
     210             :             /* Analysis, decision about bitrates per channel & core coding */
     211       83106 :             IF( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK )
     212             :             {
     213           0 :                 return error;
     214             :             }
     215             :         }
     216             :     }
     217      248976 :     ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) )
     218             :     {
     219             :         /* MASA configuration */
     220      154126 :         IF( EQ_32( ivas_format, MASA_FORMAT ) )
     221             :         {
     222       30626 :             ivas_masa_enc_reconfigure_fx( st_ivas );
     223             :         }
     224             : 
     225             :         /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */
     226             :         /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */
     227      154126 :         IF( st_ivas->nSCE > 0 )
     228             :         {
     229       51371 :             hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData;
     230             :         }
     231             :         ELSE
     232             :         {
     233      102755 :             hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
     234             :         }
     235             : 
     236      154126 :         test();
     237      154126 :         IF( st_ivas->hQMetaData != NULL && EQ_32( ivas_format, MASA_FORMAT ) )
     238             :         {
     239       30626 :             ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */
     240             : 
     241       30626 :             IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK )
     242             :             {
     243           0 :                 return error;
     244             :             }
     245             : 
     246       30626 :             IF( EQ_16( st_ivas->nchan_transport, 2 ) )
     247             :             {
     248       16536 :                 IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode,
     249             :                                                    ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
     250             :                 {
     251           0 :                     return error;
     252             :                 }
     253             :             }
     254             :             ELSE
     255             :             {
     256       14090 :                 IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1,
     257             :                                                    ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
     258             :                 {
     259           0 :                     return error;
     260             :                 }
     261             :             }
     262             :         }
     263      123500 :         ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) )
     264             :         {
     265      123500 :             IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
     266             :             {
     267           0 :                 return error;
     268             :             }
     269             :         }
     270             : 
     271      154126 :         IF( EQ_32( ivas_format, SBA_FORMAT ) )
     272             :         {
     273      123500 :             ivas_sba_getTCs_fx( data_fx, st_ivas, input_frame );
     274             :         }
     275             : 
     276             :         /* core-coding of transport channels */
     277      154126 :         IF( EQ_16( st_ivas->nSCE, 1 ) )
     278             :         {
     279       51371 :             IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     280             :             {
     281           0 :                 return error;
     282             :             }
     283             :         }
     284      102755 :         ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
     285             :         {
     286       51516 :             IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK )
     287             :             {
     288           0 :                 return error;
     289             :             }
     290             :         }
     291       51239 :         ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */
     292             :         {
     293       51239 :             IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     294             :             {
     295           0 :                 return error;
     296             :             }
     297             :         }
     298             :     }
     299       94850 :     ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) )
     300             :     {
     301             :         Word32 *data_separated_object_fx;
     302             :         Word16 q_data_separated_object;
     303             : 
     304             :         Word16 idx_separated_object;
     305             :         Word16 flag_omasa_ener_brate;
     306             : 
     307        9000 :         flag_omasa_ener_brate = 0;
     308        9000 :         move16();
     309             : 
     310             :         /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */
     311        9000 :         IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) )
     312             :         {
     313        2700 :             v_multc_fx( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame );
     314        2700 :             Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); /*  st_ivas->q_data_fx */
     315             :         }
     316             : 
     317             :         /* Estimate TF-tile energy for the input MASA stream */
     318        9000 :         ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx );
     319             : 
     320        9000 :         IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK )
     321             :         {
     322           0 :             return error;
     323             :         }
     324             : 
     325        9000 :         set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
     326        9000 :         idx_separated_object = 0;
     327        9000 :         move16();
     328             : 
     329        9000 :         data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; // Q(st_ivas->q_data_fx)
     330        9000 :         q_data_separated_object = st_ivas->q_data_fx;
     331        9000 :         move16();
     332             : 
     333             :         /* put audio object data in SCE's */
     334        9000 :         IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     335             :         {
     336             :             /* Scaling data_fx */
     337             :             {
     338        5858 :                 Word16 norm_data_in = MAX16B;
     339        5858 :                 move16();
     340       37014 :                 FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ )
     341             :                 {
     342       31156 :                     norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) );
     343             :                 }
     344        5858 :                 IF( LT_16( norm_data_in, 31 ) )
     345             :                 {
     346        5858 :                     norm_data_in = sub( norm_data_in, 7 );    /*guard bit is 4->to handle overflow in cldfbAnalysis*/
     347        5858 :                     norm_data_in = s_min( norm_data_in, 20 ); // limit Q to 31 (11 + norm)
     348       37014 :                     FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ )
     349             :                     {
     350       31156 :                         scale_sig32( data_fx[i], input_frame, norm_data_in ); /*  st_ivas->q_data_fx + norm_data_in */
     351             :                     }
     352        5858 :                     st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in );
     353        5858 :                     move16();
     354             :                 }
     355             :                 ELSE
     356             :                 {
     357           0 :                     st_ivas->q_data_fx = 31;
     358           0 :                     move16();
     359             :                 }
     360             :             }
     361             : 
     362             :             /* Estimate MASA parameters for the objects */
     363        5858 :             ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object );
     364             : 
     365        5858 :             q_data_separated_object = st_ivas->q_data_fx;
     366        5858 :             move16();
     367             :         }
     368             : 
     369             :         /* Encode ISMs transport channels */
     370        9000 :         n = 0;
     371        9000 :         move16();
     372        9000 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
     373             :         {
     374        1862 :             IF( NE_32( ( error = ivas_sce_enc_fx( st_ivas, 0, data_separated_object_fx, q_data_separated_object, input_frame, nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) /* there are no metadata bits in SCE in this mode  */
     375             :             {
     376           0 :                 return error;
     377             :             }
     378             :         }
     379        7138 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     380             :         {
     381        2054 :             IF( NE_32( ( error = ivas_ism_enc_fx( st_ivas, &data_separated_object_fx, q_data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ), IVAS_ERR_OK ) )
     382             :             {
     383           0 :                 return error;
     384             :             }
     385             :         }
     386        5084 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     387             :         {
     388        3142 :             flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); /* Q0 */
     389             : 
     390             :             /* Analysis, decision about bitrates per channel & core coding */
     391        3142 :             IF( NE_32( ( error = ivas_ism_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ), IVAS_ERR_OK ) )
     392             :             {
     393           0 :                 return error;
     394             :             }
     395        3142 :             n = st_ivas->hEncoderConfig->nchan_ism; /* Q0 */
     396        3142 :             move16();
     397             :         }
     398             : 
     399        9000 :         hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
     400             : 
     401        9000 :         IF( st_ivas->nSCE > 0 )
     402             :         {
     403             :             /* update pointer to the buffer of indices (ISM indices were alredy written) */
     404        7058 :             hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot;
     405        7058 :             st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot;
     406             :         }
     407             : 
     408             :         /* Encode MASA parameters and write MASA metadata bitstream */
     409             :         Word16 element_mode;
     410        9000 :         if ( st_ivas->nchan_transport == 2 )
     411             :         {
     412        9000 :             element_mode = st_ivas->hCPE[0]->element_mode;
     413        9000 :             move16();
     414             :         }
     415             :         else
     416             :         {
     417           0 :             element_mode = -1;
     418           0 :             move16();
     419             :         }
     420             : 
     421        9000 :         IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, element_mode,
     422             :                                                   st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ),
     423             :                    IVAS_ERR_OK ) )
     424             :         {
     425           0 :             return error;
     426             :         }
     427             : 
     428             :         /* Configuration of combined-format bit-budget distribution */
     429        9000 :         ivas_set_surplus_brate_enc( st_ivas
     430             : #ifdef DEBUG_MODE_INFO
     431             :                                     ,
     432             :                                     nb_bits_metadata
     433             : #endif
     434             :         );
     435             : 
     436             :         /* Encode MASA transport channels */
     437        9000 :         IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK )
     438             :         {
     439           0 :             return error;
     440             :         }
     441             :     }
     442       85850 :     ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) )
     443             :     {
     444             :         Word16 planar_sba_orig, nchan;
     445       37000 :         planar_sba_orig = hEncoderConfig->sba_planar;
     446       37000 :         move16();
     447             : 
     448             :         /* Analyze objects and determine needed audio signals */
     449       37000 :         ivas_osba_enc_fx( st_ivas->hOSba, st_ivas->hIsmMetaData, data_fx, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar, &st_ivas->q_data_fx );
     450             : 
     451       37000 :         IF( st_ivas->ism_mode == ISM_MODE_NONE )
     452             :         {
     453       14920 :             nchan = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); /* Q0 */
     454             :         }
     455             :         ELSE
     456             :         {
     457       22080 :             nchan = hEncoderConfig->nchan_ism; /* Q0 */
     458       22080 :             move16();
     459             :         }
     460      166040 :         FOR( n = 0; n < nchan; n++ )
     461             :         {
     462      129040 :             scale_sig32( data_fx[n], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // Q(st_ivas->q_data_fx) -> Q11
     463             :         }
     464       37000 :         st_ivas->q_data_fx = Q11;
     465       37000 :         move16();
     466             : 
     467       37000 :         IF( st_ivas->ism_mode == ISM_MODE_NONE )
     468             :         {
     469             :             /*once SBA and ISM are combined into SBA signal then disable planar flag*/
     470       14920 :             hEncoderConfig->sba_planar = 0;
     471       14920 :             move16();
     472       14920 :             IF( EQ_16( st_ivas->nchan_transport, 1 ) )
     473             :             {
     474        6970 :                 hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData;
     475             :             }
     476             :             ELSE
     477             :             {
     478        7950 :                 hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
     479             :             }
     480             : 
     481             :             /* SBA metadata encoding and SBA metadata bitstream writing */
     482       14920 :             IF( ( error = ivas_spar_enc_fx( st_ivas, data_fx, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
     483             :             {
     484           0 :                 return error;
     485             :             }
     486             : 
     487       14920 :             hEncoderConfig->sba_planar = planar_sba_orig; /* Q0 */
     488       14920 :             move16();
     489             :         }
     490             :         ELSE
     491             :         {
     492       22080 :             n = hEncoderConfig->nchan_ism; /* Q0 */
     493       22080 :             move16();
     494       22080 :             hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
     495             : 
     496       22080 :             IF( ( error = ivas_ism_metadata_enc_fx( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
     497             :             {
     498           0 :                 return error;
     499             :             }
     500             : 
     501             :             /* SBA metadata encoding and SBA metadata bitstream writing */
     502       22080 :             IF( ( error = ivas_spar_enc_fx( st_ivas, &data_fx[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
     503             :             {
     504           0 :                 return error;
     505             :             }
     506             : 
     507             :             /* get SBA TCs */
     508       22080 :             ivas_sba_getTCs_fx( &data_fx[n], st_ivas, input_frame );
     509             :         }
     510             : 
     511             :         /* core-coding of transport channels */
     512       37000 :         IF( EQ_16( st_ivas->nSCE, 1 ) )
     513             :         {
     514        6970 :             IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     515             :             {
     516           0 :                 return error;
     517             :             }
     518             :         }
     519       30030 :         ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
     520             :         {
     521        6360 :             IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK )
     522             :             {
     523           0 :                 return error;
     524             :             }
     525             :         }
     526       23670 :         ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */
     527             :         {
     528       23670 :             IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     529             :             {
     530           0 :                 return error;
     531             :             }
     532             :         }
     533             :     }
     534       48850 :     ELSE IF( EQ_32( ivas_format, MC_FORMAT ) )
     535             :     {
     536             :         /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */
     537       48850 :         IF( ( error = ivas_mc_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK )
     538             :         {
     539           0 :             return error;
     540             :         }
     541             : 
     542             :         /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */
     543       48850 :         IF( st_ivas->nSCE > 0 )
     544             :         {
     545       11260 :             hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData;
     546             :         }
     547             :         ELSE
     548             :         {
     549       37590 :             hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
     550             :         }
     551             : 
     552             :         /* LFE low pass filter */
     553       48850 :         ivas_lfe_lpf_enc_apply_fx( st_ivas->hLfeLpf, data_fx[LFE_CHANNEL], input_frame );
     554             : 
     555             :         /* LFE channel encoder */
     556       48850 :         IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
     557             :         {
     558       26130 :             IF( st_ivas->nSCE > 0 )
     559             :             {
     560           0 :                 st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
     561             :             }
     562             :             ELSE
     563             :             {
     564       26130 :                 st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
     565             :             }
     566             : 
     567       26130 :             ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr );
     568             :         }
     569             : 
     570       48850 :         IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
     571             :         {
     572       26130 :             IF( NE_32( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, 0 ) ), IVAS_ERR_OK ) )
     573             :             {
     574           0 :                 return error;
     575             :             }
     576             :         }
     577       22720 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
     578             :         {
     579             :             /* encode MC ParamUpmix parameters and write bitstream */
     580         790 :             ivas_mc_paramupmix_enc_fx( st_ivas, hMetaData, data_fx, input_frame );
     581             : 
     582             :             /* st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; */
     583         790 :             IF( st_ivas->nSCE > 0 )
     584             :             {
     585           0 :                 st_ivas->hLFE->hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
     586             :             }
     587             :             ELSE
     588             :             {
     589         790 :                 st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
     590             :             }
     591             : 
     592         790 :             ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr );
     593             : 
     594         790 :             IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
     595             :             {
     596           0 :                 return error;
     597             :             }
     598             :         }
     599       21930 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
     600             :         {
     601             :             /* encode Parametric MC parameters and write bitstream */
     602       10250 :             ivas_param_mc_enc_fx( st_ivas, hMetaData, data_fx, input_frame );
     603             : 
     604       10250 :             IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
     605             :             {
     606       10140 :                 IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK )
     607             :                 {
     608           0 :                     return error;
     609             :                 }
     610             :             }
     611         110 :             ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
     612             :             {
     613         110 :                 IF( ( error = ivas_mct_enc_fx( st_ivas, data_fx, st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
     614             :                 {
     615           0 :                     return error;
     616             :                 }
     617             :             }
     618             :         }
     619       11680 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
     620             :         {
     621       11680 :             if ( st_ivas->hMcMasa->separateChannelEnabled )
     622             :             {
     623         625 :                 hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */
     624             :             }
     625             : 
     626       89780 :             FOR( i = 0; i < nchan_inp; i++ )
     627             :             {
     628       78100 :                 scale_sig32( data_fx[i], input_frame, sub( Q8, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q8
     629             :             }
     630       11680 :             st_ivas->q_data_fx = Q8;
     631       11680 :             move16();
     632             : 
     633       11680 :             ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx );
     634             : 
     635       89780 :             FOR( i = 0; i < nchan_inp; i++ )
     636             :             {
     637       78100 :                 scale_sig32( data_fx[i], input_frame, sub( Q11, st_ivas->q_data_fx ) ); // st_ivas->q_data_fx -> Q11
     638             :             }
     639       11680 :             st_ivas->q_data_fx = Q11;
     640       11680 :             move16();
     641             : 
     642             :             /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */
     643       70080 :             FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ )
     644             :             {
     645       58400 :                 scale_sig32( st_ivas->hQMetaData->q_direction[0].band_data[i].energy_ratio_fx, MAX_PARAM_SPATIAL_SUBFRAMES, -1 ); // Q31 -> Q30
     646             :             }
     647             : 
     648       11680 :             IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1,
     649             :                                                ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
     650             :             {
     651           0 :                 return error;
     652             :             }
     653             : 
     654       11680 :             IF( st_ivas->hMcMasa->separateChannelEnabled )
     655             :             {
     656         625 :                 IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[2], st_ivas->q_data_fx, input_frame, 0 ) ) != IVAS_ERR_OK )
     657             :                 {
     658           0 :                     return error;
     659             :                 }
     660             : 
     661         625 :                 st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot;
     662             : 
     663         625 :                 IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK )
     664             :                 {
     665           0 :                     return error;
     666             :                 }
     667             :             }
     668             :             ELSE
     669             :             {
     670       11055 :                 IF( EQ_16( st_ivas->nSCE, 1 ) )
     671             :                 {
     672       10635 :                     IF( ( error = ivas_sce_enc_fx( st_ivas, 0, data_fx[0], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
     673             :                     {
     674           0 :                         return error;
     675             :                     }
     676             :                 }
     677         420 :                 ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
     678             :                 {
     679         420 :                     IF( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ) != IVAS_ERR_OK )
     680             :                     {
     681           0 :                         return error;
     682             :                     }
     683             :                 }
     684             :             }
     685             :         }
     686             :     }
     687             : 
     688             :     /*----------------------------------------------------------------*
     689             :      * Common updates
     690             :      *----------------------------------------------------------------*/
     691             : 
     692      425288 :     hEncoderConfig->last_ivas_total_brate = ivas_total_brate;
     693      425288 :     move32();
     694             : 
     695             : #ifdef DEBUG_MODE_INFO
     696             :     {
     697             :         float tmpF = ivas_total_brate / 1000.0f;
     698             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" );
     699             :     }
     700             : #endif
     701             : 
     702      425288 :     pop_wmops();
     703      425288 :     return error;
     704             : }

Generated by: LCOV version 1.14