summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspeex/stereo.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2024-05-08 10:36:38 -0400
committerSolomon Peachy <pizza@shaftnet.org>2024-06-20 07:08:35 -0400
commit547b6a570dbad844e79b4ba5eb934f043bab6318 (patch)
tree0cbdb670d73a2544d33985166c5abfa69e20a590 /lib/rbcodec/codecs/libspeex/stereo.c
parent8ef20383b1e5025f7724e750832de6e28e50680d (diff)
downloadrockbox-547b6a570dbad844e79b4ba5eb934f043bab6318.tar.gz
rockbox-547b6a570dbad844e79b4ba5eb934f043bab6318.zip
codecs: Update libspeex from 1.2beta3 to 1.2rc1
This is a relatively minor bump, but it's the first step towards bringing this current. Change-Id: Iab6c9b0c77f0ba705280434ea74b513364719499
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/stereo.c')
-rw-r--r--lib/rbcodec/codecs/libspeex/stereo.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/rbcodec/codecs/libspeex/stereo.c b/lib/rbcodec/codecs/libspeex/stereo.c
index 0aca1050fa..e995cde093 100644
--- a/lib/rbcodec/codecs/libspeex/stereo.c
+++ b/lib/rbcodec/codecs/libspeex/stereo.c
@@ -1,21 +1,21 @@
1/* Copyright (C) 2002 Jean-Marc Valin 1/* Copyright (C) 2002 Jean-Marc Valin
2 File: stereo.c 2 File: stereo.c
3 3
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions 5 modification, are permitted provided that the following conditions
6 are met: 6 are met:
7 7
8 - Redistributions of source code must retain the above copyright 8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer. 9 notice, this list of conditions and the following disclaimer.
10 10
11 - Redistributions in binary form must reproduce the above copyright 11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the 12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution. 13 documentation and/or other materials provided with the distribution.
14 14
15 - Neither the name of the Xiph.org Foundation nor the names of its 15 - Neither the name of the Xiph.org Foundation nor the names of its
16 contributors may be used to endorse or promote products derived from 16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission. 17 this software without specific prior written permission.
18 18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -71,11 +71,11 @@ static const spx_word16_t balance_bounds[31] = {18, 23, 30, 38, 49, 63, 81, 104
71#ifdef FIXED_POINT 71#ifdef FIXED_POINT
72#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_reset((SpeexStereoState*)s); } while (0); 72#define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_reset((SpeexStereoState*)s); } while (0);
73#else 73#else
74#define COMPATIBILITY_HACK(s) 74#define COMPATIBILITY_HACK(s)
75#endif 75#endif
76 76
77static SpeexStereoState global_stereo_state; 77static SpeexStereoState global_stereo_state;
78SpeexStereoState *speex_stereo_state_init() 78EXPORT SpeexStereoState *speex_stereo_state_init()
79{ 79{
80 /* SpeexStereoState *stereo = speex_alloc(sizeof(SpeexStereoState)); */ 80 /* SpeexStereoState *stereo = speex_alloc(sizeof(SpeexStereoState)); */
81 SpeexStereoState *stereo = &global_stereo_state; 81 SpeexStereoState *stereo = &global_stereo_state;
@@ -83,7 +83,7 @@ SpeexStereoState *speex_stereo_state_init()
83 return stereo; 83 return stereo;
84} 84}
85 85
86void speex_stereo_state_reset(SpeexStereoState *_stereo) 86EXPORT void speex_stereo_state_reset(SpeexStereoState *_stereo)
87{ 87{
88 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo; 88 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo;
89#ifdef FIXED_POINT 89#ifdef FIXED_POINT
@@ -100,10 +100,10 @@ void speex_stereo_state_reset(SpeexStereoState *_stereo)
100 stereo->smooth_right = 1.f; 100 stereo->smooth_right = 1.f;
101 stereo->reserved1 = 0; 101 stereo->reserved1 = 0;
102 stereo->reserved2 = 0; 102 stereo->reserved2 = 0;
103#endif 103#endif
104} 104}
105 105
106void speex_stereo_state_destroy(SpeexStereoState *stereo) 106EXPORT void speex_stereo_state_destroy(SpeexStereoState *stereo)
107{ 107{
108 (void)stereo; 108 (void)stereo;
109 /* speex_free(stereo); */ 109 /* speex_free(stereo); */
@@ -111,7 +111,7 @@ void speex_stereo_state_destroy(SpeexStereoState *stereo)
111 111
112#ifndef SPEEX_DISABLE_ENCODER 112#ifndef SPEEX_DISABLE_ENCODER
113#ifndef DISABLE_FLOAT_API 113#ifndef DISABLE_FLOAT_API
114void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) 114EXPORT void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
115{ 115{
116 int i, tmp; 116 int i, tmp;
117 float e_left=0, e_right=0, e_tot=0; 117 float e_left=0, e_right=0, e_tot=0;
@@ -129,7 +129,7 @@ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
129 /*Quantization*/ 129 /*Quantization*/
130 speex_bits_pack(bits, 14, 5); 130 speex_bits_pack(bits, 14, 5);
131 speex_bits_pack(bits, SPEEX_INBAND_STEREO, 4); 131 speex_bits_pack(bits, SPEEX_INBAND_STEREO, 4);
132 132
133 balance=4*log(balance); 133 balance=4*log(balance);
134 134
135 /*Pack sign*/ 135 /*Pack sign*/
@@ -140,16 +140,16 @@ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
140 balance=floor(.5+fabs(balance)); 140 balance=floor(.5+fabs(balance));
141 if (balance>30) 141 if (balance>30)
142 balance=31; 142 balance=31;
143 143
144 speex_bits_pack(bits, (int)balance, 5); 144 speex_bits_pack(bits, (int)balance, 5);
145 145
146 /* FIXME: this is a hack */ 146 /* FIXME: this is a hack */
147 tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 4); 147 tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 4);
148 speex_bits_pack(bits, tmp, 2); 148 speex_bits_pack(bits, tmp, 2);
149} 149}
150#endif /* #ifndef DISABLE_FLOAT_API */ 150#endif /* #ifndef DISABLE_FLOAT_API */
151 151
152void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits) 152EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
153{ 153{
154 int i, tmp; 154 int i, tmp;
155 spx_word32_t e_left=0, e_right=0, e_tot=0; 155 spx_word32_t e_left=0, e_right=0, e_tot=0;
@@ -159,7 +159,7 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
159#ifdef FIXED_POINT 159#ifdef FIXED_POINT
160 int shift; 160 int shift;
161#endif 161#endif
162 162
163 /* In band marker */ 163 /* In band marker */
164 speex_bits_pack(bits, 14, 5); 164 speex_bits_pack(bits, 14, 5);
165 /* Stereo marker */ 165 /* Stereo marker */
@@ -204,9 +204,9 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
204 if (balance_id>30) 204 if (balance_id>30)
205 balance_id=31; 205 balance_id=31;
206#endif 206#endif
207 207
208 speex_bits_pack(bits, balance_id, 5); 208 speex_bits_pack(bits, balance_id, 5);
209 209
210 /* "coherence" quantisation */ 210 /* "coherence" quantisation */
211#ifdef FIXED_POINT 211#ifdef FIXED_POINT
212 shift = spx_ilog2(e_tot); 212 shift = spx_ilog2(e_tot);
@@ -217,7 +217,7 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
217#else 217#else
218 e_ratio = e_tot/(1.+e_left+e_right); 218 e_ratio = e_tot/(1.+e_left+e_right);
219#endif 219#endif
220 220
221 tmp=scal_quant(EXTRACT16(e_ratio), e_ratio_quant_bounds, 4); 221 tmp=scal_quant(EXTRACT16(e_ratio), e_ratio_quant_bounds, 4);
222 /*fprintf (stderr, "%d %d %d %d\n", largest, smallest, balance_id, e_ratio);*/ 222 /*fprintf (stderr, "%d %d %d %d\n", largest, smallest, balance_id, e_ratio);*/
223 speex_bits_pack(bits, tmp, 2); 223 speex_bits_pack(bits, tmp, 2);
@@ -225,18 +225,18 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
225#endif /* SPEEX_DISABLE_ENCODER */ 225#endif /* SPEEX_DISABLE_ENCODER */
226 226
227#ifndef DISABLE_FLOAT_API 227#ifndef DISABLE_FLOAT_API
228void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo) 228EXPORT void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo)
229{ 229{
230 int i; 230 int i;
231 spx_word32_t balance; 231 spx_word32_t balance;
232 spx_word16_t e_left, e_right, e_ratio; 232 spx_word16_t e_left, e_right, e_ratio;
233 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo; 233 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo;
234 234
235 COMPATIBILITY_HACK(stereo); 235 COMPATIBILITY_HACK(stereo);
236 236
237 balance=stereo->balance; 237 balance=stereo->balance;
238 e_ratio=stereo->e_ratio; 238 e_ratio=stereo->e_ratio;
239 239
240 /* These two are Q14, with max value just below 2. */ 240 /* These two are Q14, with max value just below 2. */
241 e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance)))); 241 e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance))));
242 e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8); 242 e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8);
@@ -252,7 +252,7 @@ void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo)
252} 252}
253#endif /* #ifndef DISABLE_FLOAT_API */ 253#endif /* #ifndef DISABLE_FLOAT_API */
254 254
255void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState *_stereo) 255EXPORT void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState *_stereo)
256{ 256{
257 int i; 257 int i;
258 spx_word32_t balance; 258 spx_word32_t balance;
@@ -260,10 +260,10 @@ void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState
260 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo; 260 RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo;
261 261
262 /* COMPATIBILITY_HACK(stereo); */ 262 /* COMPATIBILITY_HACK(stereo); */
263 263
264 balance=stereo->balance; 264 balance=stereo->balance;
265 e_ratio=stereo->e_ratio; 265 e_ratio=stereo->e_ratio;
266 266
267 /* These two are Q14, with max value just below 2. */ 267 /* These two are Q14, with max value just below 2. */
268 e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance)))); 268 e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance))));
269 e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8); 269 e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8);
@@ -278,7 +278,7 @@ void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState
278 } 278 }
279} 279}
280 280
281int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data) 281EXPORT int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data)
282{ 282{
283 (void)state; 283 (void)state;
284 RealSpeexStereoState *stereo; 284 RealSpeexStereoState *stereo;
@@ -286,7 +286,7 @@ int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data)
286 int tmp; 286 int tmp;
287 287
288 stereo = (RealSpeexStereoState*)data; 288 stereo = (RealSpeexStereoState*)data;
289 289
290 /* COMPATIBILITY_HACK(stereo); */ 290 /* COMPATIBILITY_HACK(stereo); */
291 291
292 if (speex_bits_unpack_unsigned(bits, 1)) 292 if (speex_bits_unpack_unsigned(bits, 1))