LCOV - code coverage report
Current view: top level - lib_isar - isar_PredEncoder.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 0 378 0.0 %
Date: 2025-08-23 01:22:27 Functions: 0 7 0.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_fx.h"
      39             : #include "isar_prot.h"
      40             : #include "wmc_auto.h"
      41             : #include "prot_fx.h"
      42             : #include "basop_util.h"
      43             : #include "enh64.h"
      44             : #include "basop32.h"
      45             : 
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * Function activate_bit()
      49             :  *
      50             :  *
      51             :  *-------------------------------------------------------------------*/
      52             : 
      53           0 : static void activate_bit(
      54             :     Word32 *state,
      55             :     const Word32 bit_id )
      56             : {
      57           0 :     ( *state ) = L_or( ( *state ), L_shl( 1, extract_l( bit_id ) ) );
      58             : 
      59           0 :     return;
      60             : }
      61             : 
      62             : /*-------------------------------------------------------------------*
      63             :  * Function deactivate_bit()
      64             :  *
      65             :  *
      66             :  *-------------------------------------------------------------------*/
      67             : 
      68           0 : static void deactivate_bit(
      69             :     Word32 *state,
      70             :     const Word32 bit_id )
      71             : {
      72           0 :     ( *state ) = L_and( ( *state ), ~L_shl( 1, extract_l( bit_id ) ) );
      73             : 
      74           0 :     return;
      75             : }
      76             : 
      77             : 
      78           0 : void UpdatePredictionSubSetId(
      79             :     PredictionEncoder *psPredictionEncoder )
      80             : {
      81           0 :     IF( EQ_32( ++psPredictionEncoder->iSubSetId, psPredictionEncoder->iNumSubSets ) )
      82             :     {
      83           0 :         psPredictionEncoder->iSubSetId = 0;
      84           0 :         move32();
      85             :     }
      86             : 
      87           0 :     return;
      88             : }
      89             : 
      90             : 
      91             : /*-------------------------------------------------------------------*
      92             :  * Function CreatePredictionEncoder()
      93             :  *
      94             :  *
      95             :  *-------------------------------------------------------------------*/
      96             : 
      97           0 : ivas_error CreatePredictionEncoder_fx(
      98             :     PredictionEncoder **psPredictionEncoder_out,
      99             :     const Word32 iChannels,
     100             :     const Word32 iNumBlocks,
     101             :     const Word32 iNumSubSets,
     102             :     const Word32 iMaxNumPredBands )
     103             : {
     104             :     Word32 k, n;
     105           0 :     PredictionEncoder *psPredictionEncoder = NULL;
     106             : 
     107           0 :     IF( ( psPredictionEncoder = (PredictionEncoder *) malloc( sizeof( PredictionEncoder ) ) ) == NULL )
     108             :     {
     109           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     110             :     }
     111             : 
     112           0 :     psPredictionEncoder->iChannels = iChannels;
     113           0 :     move32();
     114           0 :     psPredictionEncoder->iNumBlocks = iNumBlocks;
     115           0 :     move32();
     116           0 :     psPredictionEncoder->iSubSetId = 0;
     117           0 :     move32();
     118           0 :     psPredictionEncoder->iMaxNumPredBands = iMaxNumPredBands;
     119           0 :     move32();
     120           0 :     psPredictionEncoder->iNumSubSets = iNumSubSets;
     121           0 :     move32();
     122           0 :     IF( ( psPredictionEncoder->piPredChanEnable = (Word32 *) malloc( sizeof( Word32 ) * iChannels ) ) == NULL )
     123             :     {
     124           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     125             :     }
     126             : 
     127           0 :     IF( ( psPredictionEncoder->piNumPredBands = (Word32 *) malloc( sizeof( Word32 ) * iChannels ) ) == NULL )
     128             :     {
     129           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     130             :     }
     131           0 :     FOR( n = 0; n < psPredictionEncoder->iChannels; n++ )
     132             :     {
     133           0 :         psPredictionEncoder->piPredChanEnable[n] = 0;
     134           0 :         move32();
     135           0 :         psPredictionEncoder->piNumPredBands[n] = 40; // Will need to be set correctly
     136           0 :         move32();
     137             :     }
     138             : 
     139           0 :     IF( ( psPredictionEncoder->ppiPredBandEnable = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     140             :     {
     141           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     142             :     }
     143           0 :     IF( ( psPredictionEncoder->ppfA1Real_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     144             :     {
     145           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     146             :     }
     147           0 :     IF( ( psPredictionEncoder->ppfA1Imag_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     148             :     {
     149           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     150             :     }
     151           0 :     IF( ( psPredictionEncoder->ppiA1Mag = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     152             :     {
     153           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     154             :     }
     155           0 :     IF( ( psPredictionEncoder->ppiA1Phase = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     156             :     {
     157           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     158             :     }
     159           0 :     IF( ( psPredictionEncoder->pppfInpBufReal_fx = (Word32 ***) malloc( sizeof( Word32 ** ) * iChannels ) ) == NULL )
     160             :     {
     161           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     162             :     }
     163           0 :     IF( ( psPredictionEncoder->pppfInpBufImag_fx = (Word32 ***) malloc( sizeof( Word32 ** ) * iChannels ) ) == NULL )
     164             :     {
     165           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     166             :     }
     167           0 :     IF( ( psPredictionEncoder->ppfInpPrevReal_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     168             :     {
     169           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     170             :     }
     171           0 :     IF( ( psPredictionEncoder->ppfInpPrevImag_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     172             :     {
     173           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     174             :     }
     175           0 :     IF( ( psPredictionEncoder->ppfPredStateReal_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     176             :     {
     177           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     178             :     }
     179           0 :     IF( ( psPredictionEncoder->ppfPredStateImag_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     180             :     {
     181           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     182             :     }
     183           0 :     IF( ( psPredictionEncoder->ppfPredStateRealTmp_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     184             :     {
     185           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     186             :     }
     187           0 :     IF( ( psPredictionEncoder->ppfPredStateImagTmp_fx = (Word32 **) malloc( sizeof( Word32 * ) * iChannels ) ) == NULL )
     188             :     {
     189           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     190             :     }
     191             : 
     192           0 :     FOR( n = 0; n < psPredictionEncoder->iChannels; n++ )
     193             :     {
     194           0 :         IF( ( psPredictionEncoder->ppiPredBandEnable[n] = (Word32 *) malloc( sizeof( Word32 ) * LCLD_BANDS ) ) == NULL )
     195             :         {
     196           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     197             :         }
     198           0 :         IF( ( psPredictionEncoder->ppfA1Real_fx[n] = (Word32 *) malloc( sizeof( Word32 ) * LCLD_BANDS ) ) == NULL )
     199             :         {
     200           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     201             :         }
     202           0 :         IF( ( psPredictionEncoder->ppfA1Imag_fx[n] = (Word32 *) malloc( sizeof( Word32 ) * LCLD_BANDS ) ) == NULL )
     203             :         {
     204           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     205             :         }
     206           0 :         IF( ( psPredictionEncoder->ppiA1Mag[n] = (Word32 *) malloc( sizeof( Word32 ) * LCLD_BANDS ) ) == NULL )
     207             :         {
     208           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     209             :         }
     210           0 :         IF( ( psPredictionEncoder->ppiA1Phase[n] = (Word32 *) malloc( sizeof( Word32 ) * LCLD_BANDS ) ) == NULL )
     211             :         {
     212           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     213             :         }
     214           0 :         IF( ( psPredictionEncoder->pppfInpBufReal_fx[n] = (Word32 **) malloc( sizeof( Word32 * ) * 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           0 :         IF( ( psPredictionEncoder->pppfInpBufImag_fx[n] = (Word32 **) malloc( sizeof( Word32 * ) * LCLD_PRED_WIN_LEN ) ) == NULL )
     219             :         {
     220           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     221             :         }
     222           0 :         FOR( k = 0; k < LCLD_PRED_WIN_LEN; k++ )
     223             :         {
     224           0 :             IF( ( psPredictionEncoder->pppfInpBufReal_fx[n][k] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     225             :             {
     226           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     227             :             }
     228           0 :             IF( ( psPredictionEncoder->pppfInpBufImag_fx[n][k] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     229             :             {
     230           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     231             :             }
     232           0 :             set32_fx( psPredictionEncoder->pppfInpBufReal_fx[n][k], 0, LCLD_BANDS );
     233           0 :             set32_fx( psPredictionEncoder->pppfInpBufImag_fx[n][k], 0, LCLD_BANDS );
     234             :         }
     235           0 :         IF( ( psPredictionEncoder->ppfPredStateReal_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     236             :         {
     237           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     238             :         }
     239           0 :         IF( ( psPredictionEncoder->ppfPredStateImag_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     240             :         {
     241           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     242             :         }
     243           0 :         set32_fx( psPredictionEncoder->ppfPredStateReal_fx[n], 0, LCLD_BANDS );
     244           0 :         set32_fx( psPredictionEncoder->ppfPredStateImag_fx[n], 0, LCLD_BANDS );
     245             : 
     246           0 :         IF( ( psPredictionEncoder->ppfInpPrevReal_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     247             :         {
     248           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     249             :         }
     250           0 :         IF( ( psPredictionEncoder->ppfInpPrevImag_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     251             :         {
     252           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     253             :         }
     254             : 
     255           0 :         set32_fx( psPredictionEncoder->ppfInpPrevReal_fx[n], 0, LCLD_BANDS );
     256           0 :         set32_fx( psPredictionEncoder->ppfInpPrevImag_fx[n], 0, LCLD_BANDS );
     257             : 
     258           0 :         IF( ( psPredictionEncoder->ppfPredStateRealTmp_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     259             :         {
     260           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     261             :         }
     262           0 :         IF( ( psPredictionEncoder->ppfPredStateImagTmp_fx[n] = (Word32 *) malloc( LCLD_BANDS * sizeof( Word32 ) ) ) == NULL )
     263             :         {
     264           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD PredictionEncoder Module \n" ) );
     265             :         }
     266           0 :         set32_fx( psPredictionEncoder->ppfPredStateRealTmp_fx[n], 0, LCLD_BANDS );
     267           0 :         set32_fx( psPredictionEncoder->ppfPredStateImagTmp_fx[n], 0, LCLD_BANDS );
     268           0 :         FOR( k = 0; k < LCLD_BANDS; k++ )
     269             :         {
     270           0 :             psPredictionEncoder->ppiPredBandEnable[n][k] = 0;
     271           0 :             move32();
     272           0 :             psPredictionEncoder->ppfA1Real_fx[n][k] = 0;
     273           0 :             move32();
     274           0 :             psPredictionEncoder->ppfA1Imag_fx[n][k] = 0;
     275           0 :             move32();
     276             :         }
     277             :     }
     278             : 
     279           0 :     *psPredictionEncoder_out = psPredictionEncoder;
     280             : 
     281           0 :     return IVAS_ERR_OK;
     282             : }
     283             : 
     284             : 
     285             : /*-------------------------------------------------------------------*
     286             :  * Function DeletePredictionEncoder()
     287             :  *
     288             :  *
     289             :  *-------------------------------------------------------------------*/
     290             : 
     291           0 : void DeletePredictionEncoder_fx(
     292             :     PredictionEncoder *psPredictionEncoder )
     293             : {
     294             :     Word32 n;
     295           0 :     FOR( n = 0; n < psPredictionEncoder->iChannels; n++ )
     296             :     {
     297             :         Word32 k;
     298           0 :         free( psPredictionEncoder->ppiPredBandEnable[n] );
     299           0 :         free( psPredictionEncoder->ppfA1Real_fx[n] );
     300           0 :         free( psPredictionEncoder->ppfA1Imag_fx[n] );
     301           0 :         free( psPredictionEncoder->ppiA1Mag[n] );
     302           0 :         free( psPredictionEncoder->ppiA1Phase[n] );
     303           0 :         FOR( k = 0; k < LCLD_PRED_WIN_LEN; k++ )
     304             :         {
     305           0 :             free( psPredictionEncoder->pppfInpBufReal_fx[n][k] );
     306           0 :             free( psPredictionEncoder->pppfInpBufImag_fx[n][k] );
     307             :         }
     308           0 :         free( psPredictionEncoder->pppfInpBufReal_fx[n] );
     309           0 :         free( psPredictionEncoder->pppfInpBufImag_fx[n] );
     310           0 :         free( psPredictionEncoder->ppfInpPrevReal_fx[n] );
     311           0 :         free( psPredictionEncoder->ppfInpPrevImag_fx[n] );
     312           0 :         free( psPredictionEncoder->ppfPredStateReal_fx[n] );
     313           0 :         free( psPredictionEncoder->ppfPredStateImag_fx[n] );
     314           0 :         free( psPredictionEncoder->ppfPredStateRealTmp_fx[n] );
     315           0 :         free( psPredictionEncoder->ppfPredStateImagTmp_fx[n] );
     316             :     }
     317           0 :     free( psPredictionEncoder->piPredChanEnable );
     318           0 :     free( psPredictionEncoder->piNumPredBands );
     319           0 :     free( psPredictionEncoder->ppiPredBandEnable );
     320           0 :     free( psPredictionEncoder->ppfA1Real_fx );
     321           0 :     free( psPredictionEncoder->ppfA1Imag_fx );
     322           0 :     free( psPredictionEncoder->ppiA1Mag );
     323           0 :     free( psPredictionEncoder->ppiA1Phase );
     324           0 :     free( psPredictionEncoder->pppfInpBufReal_fx );
     325           0 :     free( psPredictionEncoder->pppfInpBufImag_fx );
     326           0 :     free( psPredictionEncoder->ppfInpPrevReal_fx );
     327           0 :     free( psPredictionEncoder->ppfInpPrevImag_fx );
     328           0 :     free( psPredictionEncoder->ppfPredStateReal_fx );
     329           0 :     free( psPredictionEncoder->ppfPredStateImag_fx );
     330           0 :     free( psPredictionEncoder->ppfPredStateRealTmp_fx );
     331           0 :     free( psPredictionEncoder->ppfPredStateImagTmp_fx );
     332             : 
     333           0 :     free( psPredictionEncoder );
     334             : 
     335           0 :     return;
     336             : }
     337             : 
     338             : 
     339             : /*-------------------------------------------------------------------*
     340             :  * Function ComputePredictors()
     341             :  *
     342             :  *
     343             :  *-------------------------------------------------------------------*/
     344             : 
     345             : 
     346           0 : void ComputePredictors_fx(
     347             :     PredictionEncoder *psPredictionEncoder,
     348             :     Word32 ***pppfReal_fx,  // Q12?
     349             :     Word32 ***pppfImag_fx ) // Q12?
     350             : {
     351             :     Word32 c;
     352           0 :     Word32 b0 = psPredictionEncoder->iSubSetId;
     353           0 :     Word32 bstep = psPredictionEncoder->iNumSubSets;
     354           0 :     Word32 iNumBlocks = psPredictionEncoder->iNumBlocks;
     355             :     /*float ***pppfRealBuf;
     356             :     float ***pppfImagBuf;*/
     357             :     Word32 ***pppfRealBuf_fx;
     358             :     Word32 ***pppfImagBuf_fx;
     359             :     // float pfEstPredBitGain[LCLD_BANDS] = { 0 };
     360           0 :     Word32 pfEstPredBitGain_fx[LCLD_BANDS] = { 0 };
     361             : 
     362           0 :     IF( LT_32( iNumBlocks, LCLD_PRED_WIN_LEN ) )
     363             :     {
     364             :         /*pppfRealBuf = psPredictionEncoder->pppfInpBufReal;
     365             :         pppfImagBuf = psPredictionEncoder->pppfInpBufImag;*/
     366           0 :         pppfRealBuf_fx = psPredictionEncoder->pppfInpBufReal_fx;
     367           0 :         move32();
     368           0 :         pppfImagBuf_fx = psPredictionEncoder->pppfInpBufImag_fx;
     369           0 :         move32();
     370           0 :         FOR( c = 0; c < psPredictionEncoder->iChannels; c++ )
     371             :         {
     372             :             Word32 n;
     373           0 :             FOR( n = 0; n < L_sub( LCLD_PRED_WIN_LEN, iNumBlocks ); n++ )
     374             :             {
     375             :                 /*mvr2r(pppfRealBuf[c][n + iNumBlocks], pppfRealBuf[c][n], LCLD_BANDS);
     376             :                 mvr2r(pppfImagBuf[c][n + iNumBlocks], pppfImagBuf[c][n], LCLD_BANDS);*/
     377           0 :                 mvl2l( pppfRealBuf_fx[c][n + iNumBlocks], pppfRealBuf_fx[c][n], LCLD_BANDS );
     378           0 :                 mvl2l( pppfImagBuf_fx[c][n + iNumBlocks], pppfImagBuf_fx[c][n], LCLD_BANDS );
     379             :             }
     380           0 :             FOR( n = 0; n < iNumBlocks; n++ )
     381             :             {
     382             :                 /*mvr2r(pppfReal[c][n], pppfRealBuf[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS);
     383             :                 mvr2r(pppfImag[c][n], pppfImagBuf[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS);*/
     384           0 :                 mvl2l( pppfReal_fx[c][n], pppfRealBuf_fx[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS );
     385           0 :                 mvl2l( pppfImag_fx[c][n], pppfImagBuf_fx[c][n + LCLD_PRED_WIN_LEN - iNumBlocks], LCLD_BANDS );
     386             :             }
     387             :         }
     388             :     }
     389             :     ELSE
     390             :     {
     391             :         /*pppfRealBuf = pppfReal;
     392             :         pppfImagBuf = pppfImag;*/
     393           0 :         pppfRealBuf_fx = pppfReal_fx;
     394           0 :         move32();
     395           0 :         pppfImagBuf_fx = pppfImag_fx;
     396           0 :         move32();
     397             :     }
     398             : 
     399           0 :     FOR( c = 0; c < psPredictionEncoder->iChannels; c++ )
     400             :     {
     401             :         Word32 b;
     402           0 :         FOR( b = b0; b < psPredictionEncoder->iMaxNumPredBands; b += bstep )
     403             :         {
     404             :             Word32 n;
     405             :             /*float fGain = 0.0;
     406             :             float fBitGain = 0.0;
     407             :             float *pfRxxReal;
     408             :             float *pfRxxImag;
     409             :             float fA1Real;
     410             :             float fA1Imag;*/
     411           0 :             Word32 fGain_fx = 0;
     412           0 :             Word32 fBitGain_fx = 0;
     413             :             Word32 *pfRxxReal_fx;
     414             :             Word32 *pfRxxImag_fx;
     415             :             Word32 fA1Real_fx;
     416             :             Word32 fA1Imag_fx;
     417             :             Word32 L_temp;
     418             :             Word64 W_temp1, W_temp2;
     419             :             Word32 iA1Mag;
     420             :             Word32 iA1Phase;
     421             : 
     422             :             /*pfRxxReal = psPredictionEncoder->pfRxxReal;
     423             :             pfRxxImag = psPredictionEncoder->pfRxxImag;*/
     424           0 :             pfRxxReal_fx = psPredictionEncoder->pfRxxReal_fx;
     425           0 :             move32();
     426           0 :             pfRxxImag_fx = psPredictionEncoder->pfRxxImag_fx;
     427           0 :             move32();
     428             :             /*pfRxxReal[0] = 0.0;
     429             :             pfRxxImag[0] = 0.0;*/
     430           0 :             pfRxxReal_fx[0] = 0;
     431           0 :             move32();
     432           0 :             pfRxxImag_fx[0] = 0;
     433           0 :             move32();
     434           0 :             W_temp1 = 0;
     435           0 :             FOR( n = 0; n < LCLD_PRED_WIN_LEN; n++ )
     436             :             {
     437             :                 // pfRxxReal[0] += (pppfRealBuf[c][n][b] * pppfRealBuf[c][n][b] + pppfImagBuf[c][n][b] * pppfImagBuf[c][n][b]);
     438           0 :                 W_temp1 = W_add( W_temp1, W_add( W_mult0_32_32( pppfRealBuf_fx[c][n][b], pppfRealBuf_fx[c][n][b] ),
     439           0 :                                                  W_mult0_32_32( pppfImagBuf_fx[c][n][b], pppfImagBuf_fx[c][n][b] ) ) ); // Q40
     440             :             }
     441           0 :             Word16 w_norm1 = W_norm( W_temp1 );
     442           0 :             W_temp1 = W_shr( W_temp1, 32 - w_norm1 );
     443           0 :             pfRxxReal_fx[0] = W_extract_l( W_temp1 );
     444             :             /*pfRxxReal[1] = 0.0;
     445             :             pfRxxImag[1] = 0.0;*/
     446           0 :             pfRxxReal_fx[1] = 0;
     447           0 :             move32();
     448           0 :             pfRxxImag_fx[1] = 0;
     449           0 :             move32();
     450           0 :             W_temp1 = 0;
     451           0 :             W_temp2 = 0;
     452           0 :             FOR( n = 1; n < LCLD_PRED_WIN_LEN; n++ )
     453             :             {
     454             :                 /*pfRxxReal[1] += (pppfRealBuf[c][n][b] * pppfRealBuf[c][n - 1][b] + pppfImagBuf[c][n][b] * pppfImagBuf[c][n - 1][b]);
     455             :                 pfRxxImag[1] += (pppfImagBuf[c][n][b] * pppfRealBuf[c][n - 1][b] - pppfRealBuf[c][n][b] * pppfImagBuf[c][n - 1][b]);*/
     456           0 :                 W_temp1 = W_add( W_temp1, W_add( W_mult0_32_32( pppfRealBuf_fx[c][n][b], pppfRealBuf_fx[c][n - 1][b] ),
     457           0 :                                                  W_mult0_32_32( pppfImagBuf_fx[c][n][b], pppfImagBuf_fx[c][n - 1][b] ) ) ); // Q40
     458           0 :                 W_temp2 = W_add( W_temp2, W_sub( W_mult0_32_32( pppfImagBuf_fx[c][n][b], pppfRealBuf_fx[c][n - 1][b] ),
     459           0 :                                                  W_mult0_32_32( pppfRealBuf_fx[c][n][b], pppfImagBuf_fx[c][n - 1][b] ) ) ); // Q40
     460             :             }
     461             : 
     462           0 :             Word16 w_norm2 = W_norm( W_temp1 );
     463           0 :             W_temp1 = W_shr( W_temp1, 32 - w_norm2 );
     464           0 :             pfRxxReal_fx[1] = W_extract_l( W_temp1 );
     465           0 :             Word16 w_norm3 = W_norm( W_temp2 );
     466           0 :             W_temp2 = W_shr( W_temp2, 32 - w_norm3 );
     467           0 :             pfRxxImag_fx[1] = W_extract_l( W_temp2 );
     468           0 :             Word16 final_w_norm = min( w_norm1, min( w_norm2, w_norm3 ) );
     469           0 :             pfRxxReal_fx[0] = L_shr( pfRxxReal_fx[0], w_norm1 - final_w_norm ); // Q8 + final_w_norm
     470           0 :             pfRxxReal_fx[1] = L_shr( pfRxxReal_fx[1], w_norm2 - final_w_norm ); // Q8 + final_w_norm
     471           0 :             pfRxxImag_fx[1] = L_shr( pfRxxImag_fx[1], w_norm3 - final_w_norm ); // Q8 + final_w_norm
     472             :             // if (pfRxxReal[0] > 1e-12f)
     473           0 :             IF( GT_32( pfRxxReal_fx[0], 0 ) )
     474             :             {
     475             :                 /*float fA1Mag;
     476             :                 float fA1Phase;
     477             :                 float fGain2;
     478             :                 float fBitGain2;*/
     479             :                 Word32 fA1Mag_fx;
     480             :                 Word32 fA1Phase_fx;
     481             :                 Word32 fGain2_fx;
     482             :                 Word32 fBitGain2_fx;
     483           0 :                 Word32 iNumBlocksPerPredCoef = L_min( iNumBlocks * psPredictionEncoder->iNumSubSets, LCLD_PRED_WIN_LEN );
     484           0 :                 const Word32 fMagScale_fx32 = 1452576210; // Q28
     485           0 :                 move32();
     486             :                 // const float fInvMagScale = M_PI / (2.0f * (float)(1 << (PRED_QUNAT_FILTER_MAG_BITS)) + 1.0f);
     487           0 :                 const Word16 fInvMagScale_fx = 6055; // Q15
     488           0 :                 move16();
     489             :                 // const float fPhaseScale = (float)(1 << (PRED_QUANT_FILTER_PHASE_BITS - 1)) / M_PI
     490           0 :                 const Word32 fPhaseScale_fx32 = 1367130551; // Q28
     491             :                 // const float fInvPhaseScale = M_PI / (float)(1 << (PRED_QUANT_FILTER_PHASE_BITS - 1));
     492           0 :                 const Word16 fInvPhaseScale_fx = 6434; // Q15
     493           0 :                 move16();
     494             : 
     495             :                 /* Compute filter coefficeints */
     496             :                 // fA1Real = -pfRxxReal[1] / pfRxxReal[0];
     497             :                 Word16 sf_r, sf_i;
     498           0 :                 fA1Real_fx = BASOP_Util_Divide3232_Scale( -pfRxxReal_fx[1], pfRxxReal_fx[0], &sf_r );
     499             :                 // fA1Imag = -pfRxxImag[1] / pfRxxReal[0];
     500           0 :                 fA1Imag_fx = BASOP_Util_Divide3232_Scale( -pfRxxImag_fx[1], pfRxxReal_fx[0], &sf_i );
     501             : 
     502           0 :                 IF( GT_16( sf_r, sf_i ) )
     503             :                 {
     504           0 :                     fA1Imag_fx = L_shr( fA1Imag_fx, sub( sf_r, sf_i ) );
     505           0 :                     sf_i = sf_r;
     506           0 :                     move16();
     507             :                 }
     508           0 :                 ELSE IF( LT_16( sf_r, sf_i ) )
     509             :                 {
     510           0 :                     fA1Real_fx = L_shr( fA1Real_fx, sub( sf_i, sf_r ) );
     511           0 :                     sf_r = sf_i;
     512           0 :                     move16();
     513             :                 }
     514             :                 Word32 L_temp_1;
     515           0 :                 IF( LT_16( sf_r, -7 ) )
     516             :                 {
     517           0 :                     fA1Real_fx = L_shr( fA1Real_fx, sub( -8, sf_r ) );
     518           0 :                     fA1Imag_fx = L_shr( fA1Imag_fx, sub( -8, sf_i ) );
     519           0 :                     sf_r = sf_i = -8;
     520           0 :                     move16();
     521           0 :                     L_temp_1 = MAX_32;
     522           0 :                     move32();
     523             :                 }
     524             :                 ELSE
     525             :                 {
     526           0 :                     L_temp_1 = L_shl( 1, sub( 15, shl( sf_r, 1 ) ) );
     527             :                 }
     528             :                 /* compute these before quant */
     529             :                 /* Compute est coding gain based on quantized filter coefficients */
     530             :                 // fGain = 1.0f / (1.0f - fA1Real * fA1Real - fA1Imag * fA1Imag);
     531           0 :                 L_temp = L_sub( L_sub( L_temp_1, mult_r( extract_l( fA1Real_fx ), extract_l( fA1Real_fx ) ) ), mult_r( extract_l( fA1Imag_fx ), extract_l( fA1Imag_fx ) ) );
     532           0 :                 Word16 exp = norm_l( L_temp );
     533           0 :                 IF( LT_16( exp, 16 ) )
     534             :                 {
     535           0 :                     L_temp = L_shr( L_temp, sub( 16, exp ) );
     536           0 :                     exp = add( sub( 16, exp ), shl( sf_r, 1 ) );
     537             :                 }
     538             :                 else
     539             :                 {
     540           0 :                     exp = shl( sf_r, 1 );
     541             :                 }
     542             :                 // fGain_fx = sub(sub(32767, extract_h(Mpy_32_32(fA1Real_fx, fA1Real_fx))), extract_h(Mpy_32_32(fA1Imag_fx, fA1Imag_fx)));
     543             :                 // fGain_fx = extract_l(L_shl(L_temp, 2*sf_r));
     544           0 :                 fGain_fx = extract_l( L_temp );
     545           0 :                 fGain_fx = max( 1, fGain_fx );
     546           0 :                 fGain_fx = Inv16( extract_l( fGain_fx ), &exp ); // Q15 - exp
     547             :                 // fGain_fx = L_shl(fGain_fx, exp); //Q15
     548             :                 // fBitGain = 0.65f * log2f(fGain) * (float)(iNumBlocksPerPredCoef)-(float)(PRED_QUNAT_FILTER_MAG_BITS + PRED_QUANT_FILTER_PHASE_BITS); // Wrong fix (iNumBlocks-1)
     549             :                 // fBitGain_fx = L_sub(L_mult0(L_shr(L_mult0(21299, L_shr(L_add(BASOP_Util_Log2(fGain_fx), 335544320), 10)), 15), (Word16)iNumBlocksPerPredCoef), 262144); // Wrong fix (iNumBlocks-1) Q15
     550           0 :                 W_temp1 = W_mult0_32_32( L_shr( Mpy_32_32( 1395864371, L_add( BASOP_Util_Log2( fGain_fx ), L_shl( add( 16, exp ), 25 ) ) ), 10 ), iNumBlocksPerPredCoef );
     551           0 :                 Word16 w_norm4 = W_norm( W_temp1 );
     552           0 :                 IF( LT_16( w_norm4, 32 ) )
     553             :                 {
     554           0 :                     W_temp1 = W_shr( W_temp1, 32 - w_norm4 );
     555           0 :                     w_norm4 = sub( 32, w_norm4 );
     556             :                 }
     557             :                 ELSE
     558             :                 {
     559           0 :                     w_norm4 = 0;
     560           0 :                     move16();
     561             :                 }
     562           0 :                 fBitGain_fx = L_sub( W_extract_l( W_temp1 ), L_shr( 262144, w_norm4 ) ); // Wrong fix (iNumBlocks-1) Q15
     563             :                 // fA1Mag = sqrtf(fA1Real * fA1Real + fA1Imag * fA1Imag);
     564           0 :                 fA1Mag_fx = L_add( mult_r( extract_l( fA1Real_fx ), extract_l( fA1Real_fx ) ), mult_r( extract_l( fA1Imag_fx ), extract_l( fA1Imag_fx ) ) ); // Q15 - 2*sf_r
     565             :                 // fA1Mag = fMagScale * asinf(fA1Mag);
     566           0 :                 exp = 0;
     567           0 :                 move16();
     568           0 :                 L_temp = L_sub( L_temp_1, fA1Mag_fx ); // Q15 - 2*sf_r
     569           0 :                 IF( NE_32( L_temp, 0 ) )
     570             :                 {
     571           0 :                     fA1Mag_fx = BASOP_Util_Divide3232_Scale( fA1Mag_fx, L_temp, &exp );
     572             :                 }
     573             :                 ELSE
     574             :                 {
     575           0 :                     fA1Mag_fx = 0;
     576           0 :                     move32();
     577           0 :                     exp = 0;
     578           0 :                     move16();
     579             :                 }
     580           0 :                 fA1Mag_fx = L_shl( fA1Mag_fx, 16 );
     581           0 :                 IF( fA1Mag_fx > 0 )
     582             :                 {
     583           0 :                     fA1Mag_fx = Sqrt32( fA1Mag_fx, &exp );
     584             :                 }
     585             :                 ELSE
     586             :                 {
     587           0 :                     fA1Mag_fx = 0;
     588           0 :                     move32();
     589           0 :                     exp = 0;
     590           0 :                     move16();
     591             :                 }
     592             : 
     593           0 :                 fA1Mag_fx = BASOP_util_atan( L_shr_r_sat( fA1Mag_fx, 6 - exp ) );  // Q14
     594           0 :                 fA1Mag_fx = Mpy_32_16_1( fMagScale_fx32, extract_l( fA1Mag_fx ) ); // Q27
     595             : 
     596             :                 // iA1Mag = (int32_t)(fA1Mag + 0.5f);
     597           0 :                 IF( GE_32( fA1Mag_fx, 0 ) )
     598             :                 {
     599           0 :                     iA1Mag = L_shr( L_add( fA1Mag_fx, 67108864 ), Q27 ); // Q27 -> Q0
     600             :                 }
     601             :                 ELSE
     602             :                 {
     603           0 :                     fA1Mag_fx = L_negate( fA1Mag_fx );
     604           0 :                     iA1Mag = L_shr( L_add( fA1Mag_fx, 67108864 ), Q27 ); // Q27 -> Q0
     605           0 :                     iA1Mag = L_negate( iA1Mag );
     606             :                 }
     607           0 :                 iA1Mag = ( iA1Mag > PRED_QUANT_FILTER_MAG_MIN ) ? iA1Mag : PRED_QUANT_FILTER_MAG_MIN;
     608           0 :                 iA1Mag = ( iA1Mag < PRED_QUANT_FILTER_MAG_MAX ) ? iA1Mag : PRED_QUANT_FILTER_MAG_MAX;
     609             :                 // fA1Mag = sinf(fInvMagScale * (float)iA1Mag);
     610           0 :                 fA1Mag_fx = L_deposit_l( shr( getSinWord16( extract_l( L_shr( L_mult0( extract_l( fInvMagScale_fx ), extract_l( iA1Mag ) ), 2 ) ) ), 1 ) ); // Q14
     611             : 
     612             :                 // fA1Phase = atan2f(fA1Imag, fA1Real);
     613           0 :                 fA1Phase_fx = BASOP_util_atan2( fA1Imag_fx, fA1Real_fx, 0 ); // Q13
     614             :                 // fA1Phase = fPhaseScale * fA1Phase;
     615           0 :                 fA1Phase_fx = Mpy_32_16_1( fPhaseScale_fx32, extract_l( fA1Phase_fx ) ); // Q26
     616             :                 // iA1Phase = (fA1Phase > 0.0f) ? (int32_t)(fA1Phase + 0.5f) : (int32_t)(fA1Phase - 0.5f);
     617             :                 // iA1Phase = (fA1Phase_fx > 0) ? shr(add(fA1Phase_fx, 512), 10) : shr(sub(fA1Phase_fx, 512), 10);
     618           0 :                 IF( GE_32( fA1Phase_fx, 0 ) )
     619             :                 {
     620           0 :                     iA1Phase = L_shr( L_add( fA1Phase_fx, 33554432 ), Q26 ); // Q26 -> Q0
     621             :                 }
     622             :                 ELSE
     623             :                 {
     624           0 :                     fA1Phase_fx = L_negate( fA1Phase_fx );
     625           0 :                     iA1Phase = L_shr( L_add( fA1Phase_fx, 33554432 ), Q26 ); // Q26 -> Q0
     626           0 :                     iA1Phase = L_negate( iA1Phase );
     627             :                 }
     628           0 :                 iA1Phase = ( iA1Phase > PRED_QUANT_FILTER_PHASE_MIN ) ? iA1Phase : PRED_QUANT_FILTER_PHASE_MIN;
     629           0 :                 iA1Phase = ( iA1Phase < PRED_QUANT_FILTER_PHASE_MAX ) ? iA1Phase : PRED_QUANT_FILTER_PHASE_MAX; // Is this the correct way to deal with this? should wrap?
     630             :                 // fA1Phase = fInvPhaseScale * (float)iA1Phase;
     631           0 :                 L_temp = L_mult0( fInvPhaseScale_fx, (Word16) iA1Phase ); // Q15
     632             : 
     633             :                 // fA1Real = fA1Mag * cosf(fA1Phase);
     634           0 :                 fA1Real_fx = L_mult0( extract_l( fA1Mag_fx ), getCosWord16( extract_l( L_shr( L_temp, 2 ) ) ) ); // Q28
     635             :                 // fA1Imag = fA1Mag * sinf(fA1Phase);
     636           0 :                 fA1Imag_fx = L_mult0( extract_l( fA1Mag_fx ), shr( getSinWord16( extract_l( L_shr( L_temp, 2 ) ) ), 1 ) ); // Q28
     637             : 
     638             :                 // fGain2 = 1.0f / (1.0f - fA1Real * fA1Real - fA1Imag * fA1Imag);
     639           0 :                 exp = 0;
     640           0 :                 fGain2_fx = sub( sub( 32767, mult_r( extract_l( L_shr( fA1Real_fx, 13 ) ), extract_l( L_shr( fA1Real_fx, 13 ) ) ) ), mult_r( extract_l( L_shr( fA1Imag_fx, 13 ) ), extract_l( L_shr( fA1Imag_fx, 13 ) ) ) );
     641           0 :                 fGain2_fx = L_max( 1, fGain2_fx );
     642           0 :                 fGain2_fx = Inv16( extract_l( fGain2_fx ), &exp ); // Q15-exp
     643           0 :                 fGain2_fx = L_shl( fGain2_fx, exp );
     644             :                 // fBitGain2 = 0.65f * log2f(fGain) * (float)(iNumBlocksPerPredCoef)-(float)(PRED_QUNAT_FILTER_MAG_BITS + PRED_QUANT_FILTER_PHASE_BITS); // Wrong fix (iNumBlocks-1)
     645             :                 // fBitGain2_fx = L_sub(L_mult0(L_shr(L_mult0(21299, L_shr(L_add(BASOP_Util_Log2(fGain_fx), 335544320), 10)), 15), (Word16)iNumBlocksPerPredCoef), 262144); // Wrong fix (iNumBlocks-1) Q15
     646           0 :                 fBitGain2_fx = L_sub( W_extract_l( W_temp1 ), L_shr( 262144, w_norm4 ) ); // Wrong fix (iNumBlocks-1) Q15
     647             :                 // fGain = (fGain < fGain2) ? fGain : fGain2;
     648           0 :                 fGain_fx = ( fGain_fx < fGain2_fx ) ? fGain_fx : fGain2_fx;
     649             :                 // fBitGain = (fBitGain < fBitGain2) ? fBitGain : fBitGain2;
     650           0 :                 fBitGain_fx = ( fBitGain_fx < fBitGain2_fx ) ? fBitGain_fx : fBitGain2_fx;
     651             :             }
     652             :             ELSE
     653             :             {
     654             :                 /*fA1Real = 0.0f;
     655             :                 fA1Imag = 0.0f;*/
     656           0 :                 fA1Real_fx = 0;
     657           0 :                 move32();
     658           0 :                 fA1Imag_fx = 0;
     659           0 :                 move32();
     660           0 :                 iA1Mag = 0;
     661           0 :                 move32();
     662           0 :                 iA1Phase = 0;
     663           0 :                 move32();
     664             :                 // fGain = -10.0f; // Fix this
     665           0 :                 fGain_fx = -327680; // Fix this
     666           0 :                 move32();
     667             :             }
     668             : 
     669             :             // pfEstPredBitGain[b] = fBitGain;
     670             :             // psPredictionEncoder->ppiPredBandEnable[c][b] = (fBitGain > 0.0f); // Initial prediction enable
     671             :             // psPredictionEncoder->ppfA1Real[c][b] = fA1Real;
     672             :             // psPredictionEncoder->ppfA1Imag[c][b] = fA1Imag;
     673           0 :             pfEstPredBitGain_fx[b] = fBitGain_fx; // Q15
     674           0 :             move32();
     675             :             // printf("\n %d %d %f %f %f ", iA1Mag, iA1Phase, (float)fBitGain_fx / 32768, (float)fA1Real_fx / ONE_IN_Q28, (float)fA1Imag_fx / ONE_IN_Q28);
     676           0 :             psPredictionEncoder->ppiPredBandEnable[c][b] = ( fBitGain_fx > 0 ); // Initial prediction enable
     677           0 :             psPredictionEncoder->ppfA1Real_fx[c][b] = L_shl( fA1Real_fx, Q3 );  // Q31
     678           0 :             psPredictionEncoder->ppfA1Imag_fx[c][b] = L_shl( fA1Imag_fx, Q3 );  // Q31
     679           0 :             psPredictionEncoder->ppiA1Mag[c][b] = iA1Mag;
     680           0 :             move32();
     681           0 :             psPredictionEncoder->ppiA1Phase[c][b] = iA1Phase;
     682           0 :             move32();
     683             :         }
     684             : 
     685             :         {
     686             :             // float fBestCost;
     687             :             Word32 fBestCost_fx;
     688             :             Word32 iPredBands;
     689             :             // float fBitGain;
     690             :             Word32 fBitGain_fx;
     691           0 :             Word32 iPredChanEnable = 0;
     692             : 
     693             :             // fBestCost = 0.0;
     694           0 :             fBestCost_fx = 0;
     695           0 :             move32();
     696           0 :             iPredBands = 0;
     697           0 :             move32();
     698             :             // fBitGain = -7.0;
     699           0 :             fBitGain_fx = -229376; // Q15
     700           0 :             move32();
     701           0 :             FOR( b = b0; b < psPredictionEncoder->iMaxNumPredBands; b += bstep )
     702             :             { // still getting this decision wrong!
     703             :                 // fBitGain -= 1.0;
     704           0 :                 fBitGain_fx = L_sub( fBitGain_fx, 32768 );
     705           0 :                 IF( EQ_32( psPredictionEncoder->ppiPredBandEnable[c][b], 1 ) )
     706             :                 {
     707             :                     // fBitGain += pfEstPredBitGain[b];
     708           0 :                     fBitGain_fx = L_add( fBitGain_fx, pfEstPredBitGain_fx[b] );
     709             :                 }
     710             :                 // if (fBitGain > fBestCost)
     711           0 :                 IF( GT_32( fBitGain_fx, fBestCost_fx ) )
     712             :                 {
     713           0 :                     fBestCost_fx = fBitGain_fx;
     714           0 :                     iPredBands = b;
     715           0 :                     iPredChanEnable = 1;
     716             :                 }
     717             :             }
     718             : 
     719           0 :             IF( EQ_32( iPredChanEnable, 1 ) )
     720             :             {
     721           0 :                 FOR( b = iPredBands + bstep; b < LCLD_BANDS; b += bstep )
     722             :                 {
     723           0 :                     psPredictionEncoder->ppiPredBandEnable[c][b] = 0;
     724             :                 }
     725           0 :                 activate_bit( &psPredictionEncoder->piPredChanEnable[c], psPredictionEncoder->iSubSetId );
     726           0 :                 psPredictionEncoder->piNumPredBands[c] = iPredBands + bstep;
     727             :             }
     728             :             ELSE
     729             :             {
     730           0 :                 FOR( b = b0; b < LCLD_BANDS; b += bstep )
     731             :                 {
     732           0 :                     psPredictionEncoder->ppiPredBandEnable[c][b] = 0;
     733             :                 }
     734           0 :                 deactivate_bit( &psPredictionEncoder->piPredChanEnable[c], psPredictionEncoder->iSubSetId );
     735           0 :                 psPredictionEncoder->piNumPredBands[c] = 0;
     736           0 :                 move32();
     737             :             }
     738             :         }
     739             :     }
     740             : 
     741           0 :     return;
     742             : }
     743             : 
     744             : 
     745             : /*-------------------------------------------------------------------*
     746             :  * Function WritePredictors()
     747             :  *
     748             :  *
     749             :  *-------------------------------------------------------------------*/
     750             : 
     751           0 : Word32 WritePredictors(
     752             :     PredictionEncoder *psPredictionEncoder,
     753             :     ISAR_SPLIT_REND_BITS_HANDLE pBits )
     754             : {
     755           0 :     Word32 iBitsWritten = 0;
     756             :     Word32 c;
     757           0 :     Word32 iNumSubSets = psPredictionEncoder->iNumSubSets;
     758           0 :     Word32 iSubSetId = psPredictionEncoder->iSubSetId;
     759           0 :     Word32 iNumPredBandBits = 6;
     760           0 :     const Word16 iSubSetBits = ( GT_16( LCLD_MAX_NUM_PRED_SUBSETS, 4 ) ? 3 : 2 );
     761           0 :     move32();
     762           0 :     move32();
     763           0 :     move16();
     764             : 
     765             :     /* number of subsets */
     766           0 :     ISAR_SPLIT_REND_BITStream_write_int32( pBits, L_sub( iNumSubSets, 1 ), iSubSetBits ); /* otherwise use default */
     767           0 :     iBitsWritten = L_add( iBitsWritten, iSubSetBits );
     768             : 
     769           0 :     IF( GT_32( iNumSubSets, 1 ) )
     770             :     {
     771             :         /* write current subset */
     772           0 :         ISAR_SPLIT_REND_BITStream_write_int32( pBits, iSubSetId, iSubSetBits );
     773           0 :         iBitsWritten = L_add( iBitsWritten, iSubSetBits );
     774           0 :         iNumPredBandBits = ( GE_32( iNumSubSets, 4 ) ? 4 : 5 );
     775           0 :         move32();
     776             :     }
     777             : 
     778           0 :     FOR( c = 0; c < psPredictionEncoder->iChannels; c++ )
     779             :     {
     780             :         Word32 b;
     781           0 :         Word32 b0 = iSubSetId;
     782           0 :         move32();
     783             : 
     784           0 :         ISAR_SPLIT_REND_BITStream_write_int32( pBits, psPredictionEncoder->piPredChanEnable[c], iNumSubSets );
     785           0 :         iBitsWritten = L_add( iBitsWritten, iNumSubSets );
     786             : 
     787           0 :         IF( get_bit( psPredictionEncoder->piPredChanEnable[c], iSubSetId ) )
     788             :         {
     789           0 :             Word32 iNumPredBands = L_sub( psPredictionEncoder->piNumPredBands[c], b0 ) / iNumSubSets;
     790             : 
     791           0 :             ISAR_SPLIT_REND_BITStream_write_int32( pBits, iNumPredBands, iNumPredBandBits );
     792           0 :             iBitsWritten = L_add( iBitsWritten, iNumPredBandBits );
     793             : 
     794           0 :             FOR( b = b0; b < psPredictionEncoder->piNumPredBands[c]; b += iNumSubSets )
     795             :             {
     796           0 :                 ISAR_SPLIT_REND_BITStream_write_int32( pBits, psPredictionEncoder->ppiPredBandEnable[c][b], 1 );
     797           0 :                 iBitsWritten = L_add( iBitsWritten, 1 );
     798             : 
     799           0 :                 IF( EQ_32( psPredictionEncoder->ppiPredBandEnable[c][b], 1 ) )
     800             :                 {
     801             :                     Word32 iA1Mag;
     802             :                     Word32 iA1Phase;
     803             : 
     804           0 :                     iA1Mag = psPredictionEncoder->ppiA1Mag[c][b];
     805           0 :                     move32();
     806           0 :                     iA1Phase = L_sub( psPredictionEncoder->ppiA1Phase[c][b], PRED_QUANT_FILTER_PHASE_MIN );
     807             : 
     808           0 :                     ISAR_SPLIT_REND_BITStream_write_int32( pBits, iA1Mag, PRED_QUNAT_FILTER_MAG_BITS );
     809           0 :                     iBitsWritten = L_add( iBitsWritten, PRED_QUNAT_FILTER_MAG_BITS );
     810             : 
     811           0 :                     ISAR_SPLIT_REND_BITStream_write_int32( pBits, iA1Phase, PRED_QUANT_FILTER_PHASE_BITS );
     812           0 :                     iBitsWritten = L_add( iBitsWritten, PRED_QUANT_FILTER_PHASE_BITS );
     813             :                 }
     814             :             }
     815             :         }
     816             :     }
     817             : 
     818           0 :     return iBitsWritten;
     819             : }

Generated by: LCOV version 1.14