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