LCOV - code coverage report
Current view: top level - lib_isar - isar_PredEncoder.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 226 257 87.9 %
Date: 2025-11-01 05:07:43 Functions: 7 7 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 "options.h"
      35             : #include <math.h>
      36             : #include "isar_lcld_prot.h"
      37             : #include "isar_rom_lcld_tables.h"
      38             : #include "prot.h"
      39             : #include "isar_prot.h"
      40             : #include "wmc_auto.h"
      41             : 
      42             : 
      43             : /*-------------------------------------------------------------------*
      44             :  * Function activate_bit()
      45             :  *
      46             :  *
      47             :  *-------------------------------------------------------------------*/
      48             : 
      49      133430 : static void activate_bit(
      50             :     int32_t *state,
      51             :     const int32_t bit_id )
      52             : {
      53      133430 :     ( *state ) |= ( 1 << bit_id );
      54             : 
      55      133430 :     return;
      56             : }
      57             : 
      58             : 
      59             : /*-------------------------------------------------------------------*
      60             :  * Function deactivate_bit()
      61             :  *
      62             :  *
      63             :  *-------------------------------------------------------------------*/
      64             : 
      65      133024 : static void deactivate_bit(
      66             :     int32_t *state,
      67             :     const int32_t bit_id )
      68             : {
      69      133024 :     ( *state ) &= ( ~( 1 << bit_id ) );
      70             : 
      71      133024 :     return;
      72             : }
      73             : 
      74             : 
      75             : /*-------------------------------------------------------------------*
      76             :  * Function UpdatePredictionSubSetId()
      77             :  *
      78             :  *
      79             :  *-------------------------------------------------------------------*/
      80             : 
      81      133227 : void UpdatePredictionSubSetId(
      82             :     PredictionEncoder *psPredictionEncoder )
      83             : {
      84      133227 :     if ( ++psPredictionEncoder->iSubSetId == psPredictionEncoder->iNumSubSets )
      85             :     {
      86      128196 :         psPredictionEncoder->iSubSetId = 0;
      87             :     }
      88             : 
      89      133227 :     return;
      90             : }
      91             : 
      92             : 
      93             : /*-------------------------------------------------------------------*
      94             :  * Function CreatePredictionEncoder()
      95             :  *
      96             :  *
      97             :  *-------------------------------------------------------------------*/
      98             : 
      99         664 : ivas_error CreatePredictionEncoder(
     100             :     PredictionEncoder **psPredictionEncoder_out,
     101             :     const int32_t iChannels,
     102             :     const int32_t iNumBlocks,
     103             :     const int32_t iNumSubSets,
     104             :     const int32_t iMaxNumPredBands )
     105             : {
     106             :     int32_t k, n;
     107         664 :     PredictionEncoder *psPredictionEncoder = NULL;
     108             : 
     109         664 :     if ( ( psPredictionEncoder = (PredictionEncoder *) malloc( sizeof( PredictionEncoder ) ) ) == NULL )
     110             :     {
     111           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     112             :     }
     113             : 
     114         664 :     psPredictionEncoder->iChannels = iChannels;
     115         664 :     psPredictionEncoder->iNumBlocks = iNumBlocks;
     116         664 :     psPredictionEncoder->iSubSetId = 0;
     117         664 :     psPredictionEncoder->iMaxNumPredBands = iMaxNumPredBands;
     118         664 :     psPredictionEncoder->iNumSubSets = iNumSubSets;
     119             : 
     120         664 :     if ( ( psPredictionEncoder->piPredChanEnable = (int32_t *) malloc( sizeof( int32_t ) * iChannels ) ) == NULL )
     121             :     {
     122           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     123             :     }
     124             : 
     125         664 :     if ( ( psPredictionEncoder->piNumPredBands = (int32_t *) malloc( sizeof( int32_t ) * iChannels ) ) == NULL )
     126             :     {
     127           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     128             :     }
     129        1992 :     for ( n = 0; n < psPredictionEncoder->iChannels; n++ )
     130             :     {
     131        1328 :         psPredictionEncoder->piPredChanEnable[n] = 0;
     132        1328 :         psPredictionEncoder->piNumPredBands[n] = 40;
     133             :     }
     134             : 
     135         664 :     if ( ( psPredictionEncoder->ppiPredBandEnable = (int32_t **) malloc( sizeof( int32_t * ) * iChannels ) ) == NULL )
     136             :     {
     137           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     138             :     }
     139         664 :     if ( ( psPredictionEncoder->ppfA1Real = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     140             :     {
     141           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     142             :     }
     143         664 :     if ( ( psPredictionEncoder->ppfA1Imag = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     144             :     {
     145           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     146             :     }
     147         664 :     if ( ( psPredictionEncoder->ppiA1Mag = (int32_t **) malloc( sizeof( int32_t * ) * iChannels ) ) == NULL )
     148             :     {
     149           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     150             :     }
     151         664 :     if ( ( psPredictionEncoder->ppiA1Phase = (int32_t **) malloc( sizeof( int32_t * ) * iChannels ) ) == NULL )
     152             :     {
     153           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     154             :     }
     155         664 :     if ( ( psPredictionEncoder->pppfInpBufReal = (float ***) malloc( sizeof( float ** ) * iChannels ) ) == NULL )
     156             :     {
     157           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     158             :     }
     159         664 :     if ( ( psPredictionEncoder->pppfInpBufImag = (float ***) malloc( sizeof( float ** ) * iChannels ) ) == NULL )
     160             :     {
     161           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     162             :     }
     163         664 :     if ( ( psPredictionEncoder->ppfInpPrevReal = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     164             :     {
     165           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     166             :     }
     167         664 :     if ( ( psPredictionEncoder->ppfInpPrevImag = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     168             :     {
     169           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     170             :     }
     171         664 :     if ( ( psPredictionEncoder->ppfPredStateReal = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     172             :     {
     173           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     174             :     }
     175         664 :     if ( ( psPredictionEncoder->ppfPredStateImag = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     176             :     {
     177           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     178             :     }
     179         664 :     if ( ( psPredictionEncoder->ppfPredStateRealTmp = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     180             :     {
     181           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     182             :     }
     183         664 :     if ( ( psPredictionEncoder->ppfPredStateImagTmp = (float **) malloc( sizeof( float * ) * iChannels ) ) == NULL )
     184             :     {
     185           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     186             :     }
     187             : 
     188        1992 :     for ( n = 0; n < psPredictionEncoder->iChannels; n++ )
     189             :     {
     190        1328 :         if ( ( psPredictionEncoder->ppiPredBandEnable[n] = (int32_t *) malloc( sizeof( int32_t ) * LCLD_BANDS ) ) == NULL )
     191             :         {
     192           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     193             :         }
     194        1328 :         if ( ( psPredictionEncoder->ppfA1Real[n] = (float *) malloc( sizeof( float ) * LCLD_BANDS ) ) == NULL )
     195             :         {
     196           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     197             :         }
     198        1328 :         if ( ( psPredictionEncoder->ppfA1Imag[n] = (float *) malloc( sizeof( float ) * LCLD_BANDS ) ) == NULL )
     199             :         {
     200           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     201             :         }
     202        1328 :         if ( ( psPredictionEncoder->ppiA1Mag[n] = (int32_t *) malloc( sizeof( int32_t ) * LCLD_BANDS ) ) == NULL )
     203             :         {
     204           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     205             :         }
     206        1328 :         if ( ( psPredictionEncoder->ppiA1Phase[n] = (int32_t *) malloc( sizeof( int32_t ) * LCLD_BANDS ) ) == NULL )
     207             :         {
     208           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     209             :         }
     210        1328 :         if ( ( psPredictionEncoder->pppfInpBufReal[n] = (float **) malloc( sizeof( float * ) * LCLD_PRED_WIN_LEN ) ) == NULL )
     211             :         {
     212           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     213             :         }
     214        1328 :         if ( ( psPredictionEncoder->pppfInpBufImag[n] = (float **) malloc( sizeof( float * ) * LCLD_PRED_WIN_LEN ) ) == NULL )
     215             :         {
     216           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     217             :         }
     218       22576 :         for ( k = 0; k < LCLD_PRED_WIN_LEN; k++ )
     219             :         {
     220       21248 :             if ( ( psPredictionEncoder->pppfInpBufReal[n][k] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     221             :             {
     222           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     223             :             }
     224       21248 :             if ( ( psPredictionEncoder->pppfInpBufImag[n][k] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     225             :             {
     226           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     227             :             }
     228       21248 :             set_zero( psPredictionEncoder->pppfInpBufReal[n][k], LCLD_BANDS );
     229       21248 :             set_zero( psPredictionEncoder->pppfInpBufImag[n][k], LCLD_BANDS );
     230             :         }
     231        1328 :         if ( ( psPredictionEncoder->ppfPredStateReal[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     232             :         {
     233           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     234             :         }
     235        1328 :         if ( ( psPredictionEncoder->ppfPredStateImag[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     236             :         {
     237           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     238             :         }
     239        1328 :         set_zero( psPredictionEncoder->ppfPredStateReal[n], LCLD_BANDS );
     240        1328 :         set_zero( psPredictionEncoder->ppfPredStateImag[n], LCLD_BANDS );
     241             : 
     242        1328 :         if ( ( psPredictionEncoder->ppfInpPrevReal[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     243             :         {
     244           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     245             :         }
     246        1328 :         if ( ( psPredictionEncoder->ppfInpPrevImag[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     247             :         {
     248           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     249             :         }
     250             : 
     251        1328 :         set_zero( psPredictionEncoder->ppfInpPrevReal[n], LCLD_BANDS );
     252        1328 :         set_zero( psPredictionEncoder->ppfInpPrevImag[n], LCLD_BANDS );
     253             : 
     254        1328 :         if ( ( psPredictionEncoder->ppfPredStateRealTmp[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     255             :         {
     256           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     257             :         }
     258        1328 :         if ( ( psPredictionEncoder->ppfPredStateImagTmp[n] = (float *) malloc( LCLD_BANDS * sizeof( float ) ) ) == NULL )
     259             :         {
     260           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     261             :         }
     262        1328 :         set_zero( psPredictionEncoder->ppfPredStateRealTmp[n], LCLD_BANDS );
     263        1328 :         set_zero( psPredictionEncoder->ppfPredStateImagTmp[n], LCLD_BANDS );
     264       81008 :         for ( k = 0; k < LCLD_BANDS; k++ )
     265             :         {
     266       79680 :             psPredictionEncoder->ppiPredBandEnable[n][k] = 0;
     267       79680 :             psPredictionEncoder->ppfA1Real[n][k] = 0.0f;
     268       79680 :             psPredictionEncoder->ppfA1Imag[n][k] = 0.0f;
     269             :         }
     270             :     }
     271             : 
     272         664 :     *psPredictionEncoder_out = psPredictionEncoder;
     273             : 
     274         664 :     return IVAS_ERR_OK;
     275             : }
     276             : 
     277             : 
     278             : /*-------------------------------------------------------------------*
     279             :  * Function DeletePredictionEncoder()
     280             :  *
     281             :  *
     282             :  *-------------------------------------------------------------------*/
     283             : 
     284         664 : void DeletePredictionEncoder(
     285             :     PredictionEncoder *psPredictionEncoder )
     286             : {
     287             :     int32_t n;
     288        1992 :     for ( n = 0; n < psPredictionEncoder->iChannels; n++ )
     289             :     {
     290             :         int32_t k;
     291        1328 :         free( psPredictionEncoder->ppiPredBandEnable[n] );
     292        1328 :         free( psPredictionEncoder->ppfA1Real[n] );
     293        1328 :         free( psPredictionEncoder->ppfA1Imag[n] );
     294        1328 :         free( psPredictionEncoder->ppiA1Mag[n] );
     295        1328 :         free( psPredictionEncoder->ppiA1Phase[n] );
     296       22576 :         for ( k = 0; k < LCLD_PRED_WIN_LEN; k++ )
     297             :         {
     298       21248 :             free( psPredictionEncoder->pppfInpBufReal[n][k] );
     299       21248 :             free( psPredictionEncoder->pppfInpBufImag[n][k] );
     300             :         }
     301        1328 :         free( psPredictionEncoder->pppfInpBufReal[n] );
     302        1328 :         free( psPredictionEncoder->pppfInpBufImag[n] );
     303        1328 :         free( psPredictionEncoder->ppfInpPrevReal[n] );
     304        1328 :         free( psPredictionEncoder->ppfInpPrevImag[n] );
     305        1328 :         free( psPredictionEncoder->ppfPredStateReal[n] );
     306        1328 :         free( psPredictionEncoder->ppfPredStateImag[n] );
     307        1328 :         free( psPredictionEncoder->ppfPredStateRealTmp[n] );
     308        1328 :         free( psPredictionEncoder->ppfPredStateImagTmp[n] );
     309             :     }
     310         664 :     free( psPredictionEncoder->piPredChanEnable );
     311         664 :     free( psPredictionEncoder->piNumPredBands );
     312         664 :     free( psPredictionEncoder->ppiPredBandEnable );
     313         664 :     free( psPredictionEncoder->ppfA1Real );
     314         664 :     free( psPredictionEncoder->ppfA1Imag );
     315         664 :     free( psPredictionEncoder->ppiA1Mag );
     316         664 :     free( psPredictionEncoder->ppiA1Phase );
     317         664 :     free( psPredictionEncoder->pppfInpBufReal );
     318         664 :     free( psPredictionEncoder->pppfInpBufImag );
     319         664 :     free( psPredictionEncoder->ppfInpPrevReal );
     320         664 :     free( psPredictionEncoder->ppfInpPrevImag );
     321         664 :     free( psPredictionEncoder->ppfPredStateReal );
     322         664 :     free( psPredictionEncoder->ppfPredStateImag );
     323         664 :     free( psPredictionEncoder->ppfPredStateRealTmp );
     324         664 :     free( psPredictionEncoder->ppfPredStateImagTmp );
     325             : 
     326             : 
     327         664 :     free( psPredictionEncoder );
     328             : 
     329         664 :     return;
     330             : }
     331             : 
     332             : 
     333             : /*-------------------------------------------------------------------*
     334             :  * Function ComputePredictors()
     335             :  *
     336             :  *
     337             :  *-------------------------------------------------------------------*/
     338             : 
     339      133227 : void ComputePredictors(
     340             :     PredictionEncoder *psPredictionEncoder,
     341             :     float ***pppfReal,
     342             :     float ***pppfImag )
     343             : {
     344             :     int32_t c;
     345             : 
     346      133227 :     int32_t b0 = psPredictionEncoder->iSubSetId;
     347      133227 :     int32_t bstep = psPredictionEncoder->iNumSubSets;
     348      133227 :     int32_t iNumBlocks = psPredictionEncoder->iNumBlocks;
     349             :     float ***pppfRealBuf;
     350             :     float ***pppfImagBuf;
     351      133227 :     float pfEstPredBitGain[LCLD_BANDS] = { 0 };
     352             : 
     353      133227 :     if ( iNumBlocks < LCLD_PRED_WIN_LEN )
     354             :     {
     355        8049 :         pppfRealBuf = psPredictionEncoder->pppfInpBufReal;
     356        8049 :         pppfImagBuf = psPredictionEncoder->pppfInpBufImag;
     357       24147 :         for ( c = 0; c < psPredictionEncoder->iChannels; c++ )
     358             :         {
     359             :             int32_t n;
     360      177082 :             for ( n = 0; n < LCLD_PRED_WIN_LEN - iNumBlocks; n++ )
     361             :             {
     362      160984 :                 mvr2r( pppfRealBuf[c][n + iNumBlocks], pppfRealBuf[c][n], LCLD_BANDS );
     363      160984 :                 mvr2r( pppfImagBuf[c][n + iNumBlocks], pppfImagBuf[c][n], LCLD_BANDS );
     364             :             }
     365      112682 :             for ( n = 0; n < iNumBlocks; n++ )
     366             :             {
     367       96584 :                 mvr2r( pppfReal[c][n], pppfRealBuf[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS );
     368       96584 :                 mvr2r( pppfImag[c][n], pppfImagBuf[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS );
     369             :             }
     370             :         }
     371             :     }
     372             :     else
     373             :     {
     374      125178 :         pppfRealBuf = pppfReal;
     375      125178 :         pppfImagBuf = pppfImag;
     376             :     }
     377             : 
     378      399681 :     for ( c = 0; c < psPredictionEncoder->iChannels; c++ )
     379             :     {
     380             :         int32_t b;
     381    13086080 :         for ( b = b0; b < psPredictionEncoder->iMaxNumPredBands; b += bstep )
     382             :         {
     383             :             int32_t n;
     384    12819626 :             float fGain = 0.0;
     385    12819626 :             float fBitGain = 0.0;
     386             :             float *pfRxxReal;
     387             :             float *pfRxxImag;
     388             :             float fA1Real;
     389             :             float fA1Imag;
     390             :             int32_t iA1Mag;
     391             :             int32_t iA1Phase;
     392             : 
     393    12819626 :             pfRxxReal = psPredictionEncoder->pfRxxReal;
     394    12819626 :             pfRxxImag = psPredictionEncoder->pfRxxImag;
     395             : 
     396    12819626 :             pfRxxReal[0] = 0.0;
     397    12819626 :             pfRxxImag[0] = 0.0;
     398   217933642 :             for ( n = 0; n < LCLD_PRED_WIN_LEN; n++ )
     399             :             {
     400   205114016 :                 pfRxxReal[0] += ( pppfRealBuf[c][n][b] * pppfRealBuf[c][n][b] + pppfImagBuf[c][n][b] * pppfImagBuf[c][n][b] );
     401             :             }
     402             : 
     403    12819626 :             pfRxxReal[1] = 0.0;
     404    12819626 :             pfRxxImag[1] = 0.0;
     405   205114016 :             for ( n = 1; n < LCLD_PRED_WIN_LEN; n++ )
     406             :             {
     407   192294390 :                 pfRxxReal[1] += ( pppfRealBuf[c][n][b] * pppfRealBuf[c][n - 1][b] + pppfImagBuf[c][n][b] * pppfImagBuf[c][n - 1][b] );
     408   192294390 :                 pfRxxImag[1] += ( pppfImagBuf[c][n][b] * pppfRealBuf[c][n - 1][b] - pppfRealBuf[c][n][b] * pppfImagBuf[c][n - 1][b] );
     409             :             }
     410             : 
     411    12819626 :             if ( pfRxxReal[0] > 1e-12f )
     412             :             {
     413             :                 float fA1Mag;
     414             :                 float fA1Phase;
     415             :                 float fGain2;
     416             :                 float fBitGain2;
     417    12819314 :                 int32_t iNumBlocksPerPredCoef = min( iNumBlocks * psPredictionEncoder->iNumSubSets, LCLD_PRED_WIN_LEN );
     418             : 
     419    12819314 :                 const float fMagScale = ( 2.0f * (float) ( 1 << ( PRED_QUNAT_FILTER_MAG_BITS ) ) + 1.0f ) / M_PI;
     420    12819314 :                 const float fInvMagScale = M_PI / ( 2.0f * (float) ( 1 << ( PRED_QUNAT_FILTER_MAG_BITS ) ) + 1.0f );
     421    12819314 :                 const float fPhaseScale = (float) ( 1 << ( PRED_QUANT_FILTER_PHASE_BITS - 1 ) ) / M_PI;
     422    12819314 :                 const float fInvPhaseScale = M_PI / (float) ( 1 << ( PRED_QUANT_FILTER_PHASE_BITS - 1 ) );
     423             : 
     424             :                 /* Compute filter coefficeints */
     425    12819314 :                 fA1Real = -pfRxxReal[1] / pfRxxReal[0];
     426    12819314 :                 fA1Imag = -pfRxxImag[1] / pfRxxReal[0];
     427             : 
     428             :                 /* compute these before quant */
     429             :                 /* Compute est coding gain based on quantized filter coefficients */
     430    12819314 :                 fGain = 1.0f / ( 1.0f - fA1Real * fA1Real - fA1Imag * fA1Imag );
     431    12819314 :                 fBitGain = 0.65f * log2f( fGain ) * (float) ( iNumBlocksPerPredCoef ) - (float) ( PRED_QUNAT_FILTER_MAG_BITS + PRED_QUANT_FILTER_PHASE_BITS );
     432    12819314 :                 fA1Mag = sqrtf( fA1Real * fA1Real + fA1Imag * fA1Imag );
     433    12819314 :                 fA1Mag = fMagScale * asinf( fA1Mag );
     434    12819314 :                 iA1Mag = (int32_t) ( fA1Mag + 0.5f );
     435    12819314 :                 iA1Mag = ( iA1Mag > PRED_QUANT_FILTER_MAG_MIN ) ? iA1Mag : PRED_QUANT_FILTER_MAG_MIN;
     436    12819314 :                 iA1Mag = ( iA1Mag < PRED_QUANT_FILTER_MAG_MAX ) ? iA1Mag : PRED_QUANT_FILTER_MAG_MAX;
     437    12819314 :                 fA1Mag = sinf( fInvMagScale * (float) iA1Mag );
     438             : 
     439    12819314 :                 fA1Phase = atan2f( fA1Imag, fA1Real );
     440    12819314 :                 fA1Phase = fPhaseScale * fA1Phase;
     441    12819314 :                 iA1Phase = ( fA1Phase > 0.0f ) ? (int32_t) ( fA1Phase + 0.5f ) : (int32_t) ( fA1Phase - 0.5f );
     442    12819314 :                 iA1Phase = ( iA1Phase > PRED_QUANT_FILTER_PHASE_MIN ) ? iA1Phase : PRED_QUANT_FILTER_PHASE_MIN;
     443    12819314 :                 iA1Phase = ( iA1Phase < PRED_QUANT_FILTER_PHASE_MAX ) ? iA1Phase : PRED_QUANT_FILTER_PHASE_MAX;
     444    12819314 :                 fA1Phase = fInvPhaseScale * (float) iA1Phase;
     445             : 
     446    12819314 :                 fA1Real = fA1Mag * cosf( fA1Phase );
     447    12819314 :                 fA1Imag = fA1Mag * sinf( fA1Phase );
     448             : 
     449    12819314 :                 fGain2 = 1.0f / ( 1.0f - fA1Real * fA1Real - fA1Imag * fA1Imag );
     450    12819314 :                 fBitGain2 = 0.65f * log2f( fGain ) * (float) ( iNumBlocksPerPredCoef ) - (float) ( PRED_QUNAT_FILTER_MAG_BITS + PRED_QUANT_FILTER_PHASE_BITS );
     451    12819314 :                 fGain = ( fGain < fGain2 ) ? fGain : fGain2;
     452    12819314 :                 fBitGain = ( fBitGain < fBitGain2 ) ? fBitGain : fBitGain2;
     453             :             }
     454             :             else
     455             :             {
     456         312 :                 fA1Real = 0.0f;
     457         312 :                 fA1Imag = 0.0f;
     458         312 :                 iA1Mag = 0;
     459         312 :                 iA1Phase = 0;
     460         312 :                 fGain = -10.0f;
     461             :             }
     462             : 
     463    12819626 :             pfEstPredBitGain[b] = fBitGain;
     464    12819626 :             psPredictionEncoder->ppiPredBandEnable[c][b] = ( fBitGain > 0.0f );
     465    12819626 :             psPredictionEncoder->ppfA1Real[c][b] = fA1Real;
     466    12819626 :             psPredictionEncoder->ppfA1Imag[c][b] = fA1Imag;
     467    12819626 :             psPredictionEncoder->ppiA1Mag[c][b] = iA1Mag;
     468    12819626 :             psPredictionEncoder->ppiA1Phase[c][b] = iA1Phase;
     469             :         }
     470             : 
     471             :         {
     472             :             float fBestCost;
     473             :             int32_t iPredBands;
     474             :             float fBitGain;
     475      266454 :             int32_t iPredChanEnable = 0;
     476             : 
     477      266454 :             fBestCost = 0.0;
     478      266454 :             iPredBands = 0;
     479      266454 :             fBitGain = -7.0;
     480    13086080 :             for ( b = b0; b < psPredictionEncoder->iMaxNumPredBands; b += bstep )
     481             :             {
     482    12819626 :                 fBitGain -= 1.0;
     483    12819626 :                 if ( psPredictionEncoder->ppiPredBandEnable[c][b] == 1 )
     484             :                 {
     485     2255717 :                     fBitGain += pfEstPredBitGain[b];
     486             :                 }
     487    12819626 :                 if ( fBitGain > fBestCost )
     488             :                 {
     489      430399 :                     fBestCost = fBitGain;
     490      430399 :                     iPredBands = b;
     491      430399 :                     iPredChanEnable = 1;
     492             :                 }
     493             :             }
     494             : 
     495      266454 :             if ( iPredChanEnable == 1 )
     496             :             {
     497     6365089 :                 for ( b = iPredBands + bstep; b < LCLD_BANDS; b += bstep )
     498             :                 {
     499     6231659 :                     psPredictionEncoder->ppiPredBandEnable[c][b] = 0;
     500             :                 }
     501      133430 :                 activate_bit( &psPredictionEncoder->piPredChanEnable[c], psPredictionEncoder->iSubSetId );
     502      133430 :                 psPredictionEncoder->piNumPredBands[c] = iPredBands + bstep;
     503             :             }
     504             :             else
     505             :             {
     506     7669879 :                 for ( b = b0; b < LCLD_BANDS; b += bstep )
     507             :                 {
     508     7536855 :                     psPredictionEncoder->ppiPredBandEnable[c][b] = 0;
     509             :                 }
     510      133024 :                 deactivate_bit( &psPredictionEncoder->piPredChanEnable[c], psPredictionEncoder->iSubSetId );
     511      133024 :                 psPredictionEncoder->piNumPredBands[c] = 0;
     512             :             }
     513             :         }
     514             :     }
     515             : 
     516      133227 :     return;
     517             : }
     518             : 
     519             : 
     520             : /*-------------------------------------------------------------------*
     521             :  * Function ApplyForwardPredictors()
     522             :  *
     523             :  *
     524             :  *-------------------------------------------------------------------*/
     525             : 
     526             : /*-------------------------------------------------------------------*
     527             :  * Function WritePredictors()
     528             :  *
     529             :  *
     530             :  *-------------------------------------------------------------------*/
     531             : 
     532      133227 : int32_t WritePredictors(
     533             :     PredictionEncoder *psPredictionEncoder,
     534             :     ISAR_SPLIT_REND_BITS_HANDLE pBits )
     535             : {
     536      133227 :     int32_t iBitsWritten = 0;
     537             :     int32_t c;
     538      133227 :     int32_t iNumSubSets = psPredictionEncoder->iNumSubSets;
     539      133227 :     int32_t iSubSetId = psPredictionEncoder->iSubSetId;
     540      133227 :     int32_t iNumPredBandBits = 6;
     541      133227 :     const int16_t iSubSetBits = ( LCLD_MAX_NUM_PRED_SUBSETS > 4 ? 3 : 2 );
     542             : 
     543             :     /* number of subsets */
     544      133227 :     ISAR_SPLIT_REND_BITStream_write_int32( pBits, iNumSubSets - 1, iSubSetBits ); /* otherwise use default */
     545      133227 :     iBitsWritten += iSubSetBits;
     546             : 
     547      133227 :     if ( iNumSubSets > 1 )
     548             :     {
     549             :         /* write current subset */
     550        8049 :         ISAR_SPLIT_REND_BITStream_write_int32( pBits, iSubSetId, iSubSetBits );
     551        8049 :         iBitsWritten += iSubSetBits;
     552        8049 :         iNumPredBandBits = ( iNumSubSets >= 4 ? 4 : 5 );
     553             :     }
     554             : 
     555      399681 :     for ( c = 0; c < psPredictionEncoder->iChannels; c++ )
     556             :     {
     557             :         int32_t b;
     558      266454 :         int32_t b0 = iSubSetId;
     559             : 
     560      266454 :         ISAR_SPLIT_REND_BITStream_write_int32( pBits, psPredictionEncoder->piPredChanEnable[c], iNumSubSets );
     561      266454 :         iBitsWritten += iNumSubSets;
     562             : 
     563      266454 :         if ( get_bit( psPredictionEncoder->piPredChanEnable[c], iSubSetId ) )
     564             :         {
     565      133430 :             int32_t iNumPredBands = ( psPredictionEncoder->piNumPredBands[c] - b0 ) / iNumSubSets;
     566             : 
     567      133430 :             ISAR_SPLIT_REND_BITStream_write_int32( pBits, iNumPredBands, iNumPredBandBits );
     568      133430 :             iBitsWritten += iNumPredBandBits;
     569             : 
     570     1748466 :             for ( b = b0; b < psPredictionEncoder->piNumPredBands[c]; b += iNumSubSets )
     571             :             {
     572     1615036 :                 ISAR_SPLIT_REND_BITStream_write_int32( pBits, psPredictionEncoder->ppiPredBandEnable[c][b], 1 );
     573     1615036 :                 iBitsWritten += 1;
     574             : 
     575     1615036 :                 if ( psPredictionEncoder->ppiPredBandEnable[c][b] == 1 )
     576             :                 {
     577             :                     int32_t iA1Mag;
     578             :                     int32_t iA1Phase;
     579             : 
     580      732637 :                     iA1Mag = psPredictionEncoder->ppiA1Mag[c][b];
     581      732637 :                     iA1Phase = psPredictionEncoder->ppiA1Phase[c][b] - PRED_QUANT_FILTER_PHASE_MIN;
     582             : 
     583      732637 :                     ISAR_SPLIT_REND_BITStream_write_int32( pBits, iA1Mag, PRED_QUNAT_FILTER_MAG_BITS );
     584      732637 :                     iBitsWritten += PRED_QUNAT_FILTER_MAG_BITS;
     585             : 
     586      732637 :                     ISAR_SPLIT_REND_BITStream_write_int32( pBits, iA1Phase, PRED_QUANT_FILTER_PHASE_BITS );
     587      732637 :                     iBitsWritten += PRED_QUANT_FILTER_PHASE_BITS;
     588             :                 }
     589             :             }
     590             :         }
     591             :     }
     592             : 
     593      133227 :     return iBitsWritten;
     594             : }

Generated by: LCOV version 1.14