LCOV - code coverage report
Current view: top level - lib_isar - isar_splitRend_lcld_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 0 51 0.0 %
Date: 2025-08-23 01:22:27 Functions: 0 3 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 "isar_prot.h"
      36             : #include "ivas_prot_fx.h"
      37             : #ifdef DEBUGGING
      38             : #include "debug.h"
      39             : #endif
      40             : #include "wmc_auto.h"
      41             : 
      42             : /*-------------------------------------------------------------------------
      43             :  * Function isar_splitBinLCLDEncOpen()
      44             :  *
      45             :  *
      46             :  *------------------------------------------------------------------------*/
      47           0 : ivas_error isar_splitBinLCLDEncOpen(
      48             :     ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc,
      49             :     const Word32 iSampleRate,
      50             :     const Word16 iChannels,
      51             :     const Word32 iDataRate,
      52             :     const Word16 iNumBlocks,
      53             :     const Word16 iNumIterations )
      54             : {
      55             :     ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE splitBinLCLDEnc;
      56             :     ivas_error error;
      57             : 
      58           0 :     IF( ( splitBinLCLDEnc = (ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE) malloc( sizeof( ISAR_BIN_HR_SPLIT_LCLD_ENC ) ) ) == NULL )
      59             :     {
      60           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD encoder Module \n" ) );
      61             :     }
      62             : 
      63           0 :     splitBinLCLDEnc->pLcld_enc = NULL; /* place holder for CLDFB encoder handle*/
      64             : 
      65           0 :     splitBinLCLDEnc->iChannels = iChannels;
      66           0 :     IF( ( error = CreateLCLDEncoder( &( splitBinLCLDEnc->psLCLDEncoder ), iSampleRate, iChannels, iDataRate, 1, iNumBlocks, (Word16) CLDFB_NO_COL_MAX / iNumBlocks, 0 ) ) != IVAS_ERR_OK )
      67             :     {
      68           0 :         return error;
      69             :     }
      70             : 
      71           0 :     IF( ( splitBinLCLDEnc->pppfLCLDReal_fx = (Word32 ***) malloc( iChannels * sizeof( Word32 ** ) ) ) == NULL )
      72             :     {
      73           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD encoder Module \n" ) );
      74             :     }
      75           0 :     IF( ( splitBinLCLDEnc->pppfLCLDImag_fx = (Word32 ***) malloc( iChannels * sizeof( Word32 ** ) ) ) == NULL )
      76             :     {
      77           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD encoder Module \n" ) );
      78             :     }
      79             : 
      80           0 :     FOR( Word16 n = 0; n < splitBinLCLDEnc->iChannels; n++ )
      81             :     {
      82           0 :         IF( ( splitBinLCLDEnc->pppfLCLDReal_fx[n] = (Word32 **) malloc( CLDFB_NO_COL_MAX * sizeof( Word32 * ) ) ) == NULL )
      83             :         {
      84           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD encoder Module \n" ) );
      85             :         }
      86           0 :         IF( ( splitBinLCLDEnc->pppfLCLDImag_fx[n] = (Word32 **) malloc( CLDFB_NO_COL_MAX * sizeof( Word32 * ) ) ) == NULL )
      87             :         {
      88           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LCLD encoder Module \n" ) );
      89             :         }
      90             :     }
      91             : 
      92           0 :     splitBinLCLDEnc->iNumIterations = iNumIterations;
      93           0 :     splitBinLCLDEnc->iNumBlocks = iNumBlocks;
      94             : 
      95             : #ifdef CLDFB_DEBUG
      96             :     splitBinLCLDEnc->numFrame = 0;
      97             :     char cldfbFilename[50] = "cldfb_in_ref.qmf";
      98             :     if ( ( splitBinLCLDEnc->cldfbIn = fopen( cldfbFilename, "rb" ) ) == NULL )
      99             :     {
     100             :         fprintf( stderr, "Error: CLDFB bitstream file %s could not be opened\n\n", cldfbFilename );
     101             :         exit( -1 );
     102             :     }
     103             :     int16_t chan, band;
     104             :     fread( &chan, sizeof( int16_t ), 1, splitBinLCLDEnc->cldfbIn );
     105             :     fread( &band, sizeof( int16_t ), 1, splitBinLCLDEnc->cldfbIn );
     106             : #endif
     107             : 
     108           0 :     *hSplitBinLCLDEnc = splitBinLCLDEnc;
     109             : 
     110           0 :     return IVAS_ERR_OK;
     111             : }
     112             : 
     113             : 
     114             : /*-------------------------------------------------------------------------
     115             :  * Function isar_splitBinLCLDEncClose()
     116             :  *
     117             :  *
     118             :  *------------------------------------------------------------------------*/
     119             : 
     120           0 : void isar_splitBinLCLDEncClose(
     121             :     ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc )
     122             : {
     123           0 :     IF( ( *hSplitBinLCLDEnc ) != NULL )
     124             :     {
     125           0 :         DeleteLCLDEncoder( ( *hSplitBinLCLDEnc )->psLCLDEncoder );
     126             : 
     127           0 :         FOR( Word16 n = 0; n < ( *hSplitBinLCLDEnc )->iChannels; n++ )
     128             :         {
     129           0 :             free( ( *hSplitBinLCLDEnc )->pppfLCLDReal_fx[n] );
     130           0 :             free( ( *hSplitBinLCLDEnc )->pppfLCLDImag_fx[n] );
     131             :         }
     132           0 :         free( ( *hSplitBinLCLDEnc )->pppfLCLDReal_fx );
     133           0 :         free( ( *hSplitBinLCLDEnc )->pppfLCLDImag_fx );
     134             : #ifdef CLDFB_DEBUG
     135             :         if ( ( *hSplitBinLCLDEnc )->cldfbIn != NULL )
     136             :         {
     137             :             fclose( ( *hSplitBinLCLDEnc )->cldfbIn );
     138             :         }
     139             : #endif
     140             : 
     141           0 :         free( *hSplitBinLCLDEnc );
     142           0 :         *hSplitBinLCLDEnc = NULL;
     143             :     }
     144             : 
     145           0 :     return;
     146             : }
     147             : 
     148             : /*-------------------------------------------------------------------------
     149             :  * Function isar_splitBinLCLDEncProcess()
     150             :  *
     151             :  *
     152             :  *------------------------------------------------------------------------*/
     153           0 : void isar_splitBinLCLDEncProcess(
     154             :     ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE hSplitBinLCLDEnc,
     155             :     Word32 Cldfb_In_Real_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
     156             :     Word32 Cldfb_In_Imag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
     157             :     const Word32 available_bits,
     158             :     ISAR_SPLIT_REND_BITS_HANDLE pBits,
     159             :     Word16 *q_final )
     160             : {
     161             :     Word32 iBitsWritten, itr, available_bits_itr, rem_itr, available_bits_local;
     162           0 :     push_wmops( "isar_splitBinLCLDEncProcess" );
     163           0 :     assert( hSplitBinLCLDEnc != NULL );
     164           0 :     assert( Cldfb_In_Real_fx != NULL );
     165           0 :     assert( Cldfb_In_Imag_fx != NULL );
     166           0 :     assert( pBits != NULL );
     167             : 
     168           0 :     available_bits_local = available_bits;
     169           0 :     move32();
     170             :     Word16 tmp, tmp_e;
     171             :     /* A conversion is needed for the 3d pointer interface here ........ */
     172           0 :     FOR( itr = 0; itr < hSplitBinLCLDEnc->iNumIterations; itr++ )
     173             :     {
     174             : 
     175           0 :         rem_itr = L_sub( hSplitBinLCLDEnc->iNumIterations, itr );
     176           0 :         tmp = BASOP_Util_Divide3232_Scale( available_bits_local, rem_itr, &tmp_e );
     177           0 :         available_bits_itr = shr( tmp, sub( 15, tmp_e ) ); // Q0
     178             :                                                            // available_bits_itr = available_bits_local / rem_itr;
     179           0 :         FOR( Word32 n = 0; n < hSplitBinLCLDEnc->iChannels; n++ )
     180             :         {
     181           0 :             FOR( Word32 k = 0; k < hSplitBinLCLDEnc->iNumBlocks; k++ )
     182             :             {
     183           0 :                 hSplitBinLCLDEnc->pppfLCLDReal_fx[n][k] = Cldfb_In_Real_fx[n][hSplitBinLCLDEnc->iNumBlocks * itr + k];
     184           0 :                 hSplitBinLCLDEnc->pppfLCLDImag_fx[n][k] = Cldfb_In_Imag_fx[n][hSplitBinLCLDEnc->iNumBlocks * itr + k];
     185             :             }
     186             :         }
     187             : #ifdef CLDFB_DEBUG
     188             :         int16_t readByte = 0;
     189             :         for ( int16_t k = 0; k < hSplitBinLCLDEnc->iNumBlocks; k++ )
     190             :         {
     191             :             for ( int16_t b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ )
     192             :             {
     193             :                 for ( int16_t n = 0; n < hSplitBinLCLDEnc->iChannels; n++ )
     194             :                 {
     195             :                     readByte = fread( &hSplitBinLCLDEnc->pppfLCLDReal[n][k][b], sizeof( float ), 1, hSplitBinLCLDEnc->cldfbIn );
     196             :                     if ( readByte != 1 )
     197             :                         break;
     198             :                     readByte = fread( &hSplitBinLCLDEnc->pppfLCLDReal[n][k][b], sizeof( float ), 1, hSplitBinLCLDEnc->cldfbIn );
     199             :                 }
     200             :             }
     201             :         }
     202             : 
     203             :         if ( readByte == 1 )
     204             :         {
     205             :             printf( "Frame Read = %d\n", ++hSplitBinLCLDEnc->numFrame );
     206             :         }
     207             :         else
     208             :         {
     209             :             printf( "Writing zeroes...\n" );
     210             :             for ( int16_T k = 0; k < hSplitBinLCLDEnc->iNumBlocks; k++ )
     211             :             {
     212             :                 for ( int16_t b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ )
     213             :                 {
     214             :                     for ( int16_t n = 0; n < hSplitBinLCLDEnc->iChannels; n++ )
     215             :                     {
     216             :                         hSplitBinLCLDEnc->pppfLCLDReal[n][k][b] = 0.f;
     217             :                         hSplitBinLCLDEnc->pppfLCLDImag[n][k][b] = 0.f;
     218             :                     }
     219             :                 }
     220             :             }
     221             :         }
     222             : #endif
     223           0 :         EncodeLCLDFrame( hSplitBinLCLDEnc->psLCLDEncoder, hSplitBinLCLDEnc->pppfLCLDReal_fx, hSplitBinLCLDEnc->pppfLCLDImag_fx, &iBitsWritten, available_bits_itr, pBits, q_final );
     224             : 
     225           0 :         available_bits_local = L_sub( available_bits_local, iBitsWritten );
     226             : #ifdef DEBUGGING
     227             :         assert( available_bits_local >= 0 );
     228             : #endif
     229             : 
     230             : #ifdef CLDFB_DEBUG
     231             :         printf( "Bits written = %d\n", iBitsWritten );
     232             : #endif
     233             :     }
     234           0 :     pop_wmops();
     235             : 
     236           0 :     return;
     237             : }

Generated by: LCOV version 1.14