1 /*-
2 * Copyright (c) 2005 Boris Mikhaylov
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <math.h>
25 #include <stdlib.h>
26 #include <memory.h>
27
28 #include "bs2b.h"
29
30 #ifndef M_PI
31 #define M_PI 3.14159265358979323846
32 #endif
33
int16swap(uint16_t * x)34 static void int16swap( uint16_t *x )
35 {
36 *x = ( *x >> 8 ) | ( *x << 8 );
37 }
38
int24swap(bs2b_uint24_t * x)39 static void int24swap( bs2b_uint24_t *x )
40 {
41 uint8_t x1;
42
43 x1 = x->octet0;
44 x->octet0 = x->octet2;
45 x->octet2 = x1;
46 }
47
int32swap(uint32_t * x)48 static void int32swap( uint32_t *x )
49 {
50 *x = ( *x >> 24 ) | ( ( *x >> 8 ) & 0xff00 ) |
51 ( ( *x << 8 ) & ( ( uint32_t )0xff << 16 ) ) | ( *x << 24 );
52 }
53
int64swap(uint32_t * x)54 static void int64swap( uint32_t *x )
55 {
56 uint32_t x1;
57
58 x1 = *x;
59 *x = x[ 1 ];
60 x[ 1 ] = x1;
61
62 int32swap( x );
63 int32swap( x + 1 );
64 }
65
int242double(bs2b_int24_t * in)66 static double int242double( bs2b_int24_t *in )
67 {
68 int32_t out =
69 #ifdef WORDS_BIGENDIAN
70 ( ( uint32_t )in->octet2 ) |
71 ( ( uint32_t )in->octet1 << 8 ) |
72 ( ( uint32_t )in->octet0 << 16 ) |
73 ( ( in->octet0 < 0 ? ( uint32_t )-1 : 0 ) << 24 );
74 #else
75 ( ( uint32_t )in->octet0 ) |
76 ( ( uint32_t )in->octet1 << 8 ) |
77 ( ( uint32_t )in->octet2 << 16 ) |
78 ( ( in->octet2 < 0 ? ( uint32_t )-1 : 0 ) << 24 );
79 #endif /* WORDS_BIGENDIAN */
80
81 return ( double )out;
82 } /* int242double() */
83
uint242double(bs2b_uint24_t * in)84 static double uint242double( bs2b_uint24_t *in )
85 {
86 uint32_t out =
87 #ifdef WORDS_BIGENDIAN
88 ( ( uint32_t )in->octet2 ) |
89 ( ( uint32_t )in->octet1 << 8 ) |
90 ( ( uint32_t )in->octet0 << 16 );
91 #else
92 ( ( uint32_t )in->octet0 ) |
93 ( ( uint32_t )in->octet1 << 8 ) |
94 ( ( uint32_t )in->octet2 << 16 );
95 #endif /* WORDS_BIGENDIAN */
96
97 return ( double )out;
98 } /* uint242double() */
99
double2int24(double in,bs2b_int24_t * out)100 static void double2int24( double in, bs2b_int24_t *out )
101 {
102 uint32_t i = ( uint32_t )in;
103
104 #ifdef WORDS_BIGENDIAN
105 out->octet2 = i & 0xff;
106 out->octet1 = ( i >> 8 ) & 0xff;
107 out->octet0 = ( i >> 16 ) & 0xff;
108 #else
109 out->octet0 = i & 0xff;
110 out->octet1 = ( i >> 8 ) & 0xff;
111 out->octet2 = ( i >> 16 ) & 0xff;
112 #endif /* WORDS_BIGENDIAN */
113 } /* double2int24() */
114
double2uint24(double in,bs2b_uint24_t * out)115 static void double2uint24( double in, bs2b_uint24_t *out )
116 {
117 uint32_t i = ( uint32_t )in;
118
119 #ifdef WORDS_BIGENDIAN
120 out->octet2 = i & 0xff;
121 out->octet1 = ( i >> 8 ) & 0xff;
122 out->octet0 = ( i >> 16 ) & 0xff;
123 #else
124 out->octet0 = i & 0xff;
125 out->octet1 = ( i >> 8 ) & 0xff;
126 out->octet2 = ( i >> 16 ) & 0xff;
127 #endif /* WORDS_BIGENDIAN */
128 } /* double2uint24() */
129
130 /* Set up bs2b data. */
init(t_bs2bdp bs2bdp)131 static void init( t_bs2bdp bs2bdp )
132 {
133 double Fc_lo; /* Lowpass filter cut frequency (Hz) */
134 double Fc_hi; /* Highboost filter cut frequency (Hz) */
135 double G_lo; /* Lowpass filter gain (multiplier) */
136 double G_hi; /* Highboost filter gain (multiplier) */
137 double GB_lo; /* Lowpass filter gain (dB) */
138 double GB_hi; /* Highboost filter gain (dB) ( 0 dB is highs ) */
139 double level; /* Feeding level (dB) ( level = GB_lo - GB_hi ) */
140 double x;
141
142 if( ( bs2bdp->srate > BS2B_MAXSRATE ) || ( bs2bdp->srate < BS2B_MINSRATE ) )
143 bs2bdp->srate = BS2B_DEFAULT_SRATE;
144
145 Fc_lo = bs2bdp->level & 0xffff;
146 level = ( bs2bdp->level & 0xffff0000 ) >> 16;
147
148 if( ( Fc_lo > BS2B_MAXFCUT ) || ( Fc_lo < BS2B_MINFCUT ) ||
149 ( level > BS2B_MAXFEED ) || ( level < BS2B_MINFEED ) )
150 {
151 bs2bdp->level = BS2B_DEFAULT_CLEVEL;
152 Fc_lo = bs2bdp->level & 0xffff;
153 level = ( bs2bdp->level & 0xffff0000 ) >> 16;
154 }
155
156 level /= 10.0;
157
158 GB_lo = level * -5.0 / 6.0 - 3.0;
159 GB_hi = level / 6.0 - 3.0;
160
161 G_lo = pow( 10, GB_lo / 20.0 );
162 G_hi = 1.0 - pow( 10, GB_hi / 20.0 );
163 Fc_hi = Fc_lo * pow( 2.0, ( GB_lo - 20.0 * log10( G_hi ) ) / 12.0 );
164
165 /* $fc = $Fc / $s;
166 * $d = 1 / 2 / pi / $fc;
167 * $x = exp(-1 / $d);
168 */
169
170 x = exp( -2.0 * M_PI * Fc_lo / bs2bdp->srate );
171 bs2bdp->b1_lo = x;
172 bs2bdp->a0_lo = G_lo * ( 1.0 - x );
173
174 x = exp( -2.0 * M_PI * Fc_hi / bs2bdp->srate );
175 bs2bdp->b1_hi = x;
176 bs2bdp->a0_hi = 1.0 - G_hi * ( 1.0 - x );
177 bs2bdp->a1_hi = -x;
178
179 bs2bdp->gain = 1.0 / ( 1.0 - G_hi + G_lo );
180 } /* init() */
181
182 /* Single pole IIR filter.
183 * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
184 */
185
186 /* Lowpass filter */
187 #define lo_filter( in, out_1 ) \
188 ( bs2bdp->a0_lo * in + bs2bdp->b1_lo * out_1 )
189
190 /* Highboost filter */
191 #define hi_filter( in, in_1, out_1 ) \
192 ( bs2bdp->a0_hi * in + bs2bdp->a1_hi * in_1 + bs2bdp->b1_hi * out_1 )
193
cross_feed_d(t_bs2bdp bs2bdp,double * sample)194 static void cross_feed_d( t_bs2bdp bs2bdp, double *sample )
195 {
196 /* Lowpass filter */
197 bs2bdp->lfs.lo[ 0 ] = lo_filter( sample[ 0 ], bs2bdp->lfs.lo[ 0 ] );
198 bs2bdp->lfs.lo[ 1 ] = lo_filter( sample[ 1 ], bs2bdp->lfs.lo[ 1 ] );
199
200 /* Highboost filter */
201 bs2bdp->lfs.hi[ 0 ] =
202 hi_filter( sample[ 0 ], bs2bdp->lfs.asis[ 0 ], bs2bdp->lfs.hi[ 0 ] );
203 bs2bdp->lfs.hi[ 1 ] =
204 hi_filter( sample[ 1 ], bs2bdp->lfs.asis[ 1 ], bs2bdp->lfs.hi[ 1 ] );
205 bs2bdp->lfs.asis[ 0 ] = sample[ 0 ];
206 bs2bdp->lfs.asis[ 1 ] = sample[ 1 ];
207
208 /* Crossfeed */
209 sample[ 0 ] = bs2bdp->lfs.hi[ 0 ] + bs2bdp->lfs.lo[ 1 ];
210 sample[ 1 ] = bs2bdp->lfs.hi[ 1 ] + bs2bdp->lfs.lo[ 0 ];
211
212 /* Bass boost cause allpass attenuation */
213 sample[ 0 ] *= bs2bdp->gain;
214 sample[ 1 ] *= bs2bdp->gain;
215 } /* cross_feed_d() */
216
217 /* Exported functions.
218 * See descriptions in "bs2b.h"
219 */
220
bs2b_open(void)221 t_bs2bdp bs2b_open( void )
222 {
223 t_bs2bdp bs2bdp = NULL;
224
225 if( NULL != ( bs2bdp = malloc( sizeof( t_bs2bd ) ) ) )
226 {
227 memset( bs2bdp, 0, sizeof( t_bs2bd ) );
228 bs2b_set_srate( bs2bdp, BS2B_DEFAULT_SRATE );
229 }
230
231 return bs2bdp;
232 } /* bs2b_open() */
233
bs2b_close(t_bs2bdp bs2bdp)234 void bs2b_close( t_bs2bdp bs2bdp )
235 {
236 free( bs2bdp );
237 } /* bs2b_close() */
238
bs2b_set_level(t_bs2bdp bs2bdp,uint32_t level)239 void bs2b_set_level( t_bs2bdp bs2bdp, uint32_t level )
240 {
241 if( NULL == bs2bdp ) return;
242
243 if( level == bs2bdp->level ) return;
244
245 bs2bdp->level = level;
246 init( bs2bdp );
247 } /* bs2b_set_level() */
248
bs2b_get_level(t_bs2bdp bs2bdp)249 uint32_t bs2b_get_level( t_bs2bdp bs2bdp )
250 {
251 return bs2bdp->level;
252 } /* bs2b_get_level() */
253
bs2b_set_level_fcut(t_bs2bdp bs2bdp,int fcut)254 void bs2b_set_level_fcut( t_bs2bdp bs2bdp, int fcut )
255 {
256 uint32_t level;
257
258 if( NULL == bs2bdp ) return;
259
260 level = bs2bdp->level;
261 level &= 0xffff0000;
262 level |= ( uint32_t )fcut;
263 bs2b_set_level( bs2bdp, level );
264 } /* bs2b_set_level_fcut() */
265
bs2b_get_level_fcut(t_bs2bdp bs2bdp)266 int bs2b_get_level_fcut( t_bs2bdp bs2bdp )
267 {
268 return( ( int )( bs2bdp->level & 0xffff ) );
269 } /* bs2b_get_level_fcut() */
270
bs2b_set_level_feed(t_bs2bdp bs2bdp,int feed)271 void bs2b_set_level_feed( t_bs2bdp bs2bdp, int feed )
272 {
273 uint32_t level;
274
275 if( NULL == bs2bdp ) return;
276
277 level = bs2bdp->level;
278 level &= ( uint32_t )0xffff;
279 level |= ( uint32_t )feed << 16;
280 bs2b_set_level( bs2bdp, level );
281 } /* bs2b_set_level_feed() */
282
bs2b_get_level_feed(t_bs2bdp bs2bdp)283 int bs2b_get_level_feed( t_bs2bdp bs2bdp )
284 {
285 return( ( int )( ( bs2bdp->level & 0xffff0000 ) >> 16 ) );
286 } /* bs2b_get_level_feed() */
287
bs2b_get_level_delay(t_bs2bdp bs2bdp)288 int bs2b_get_level_delay( t_bs2bdp bs2bdp )
289 {
290 int fcut;
291
292 fcut = bs2bdp->level & 0xffff; /* get cut frequency */
293
294 if( ( fcut > BS2B_MAXFCUT ) || ( fcut < BS2B_MINFCUT ) )
295 return 0;
296
297 return bs2b_level_delay( fcut );
298 } /* bs2b_get_level_delay() */
299
bs2b_set_srate(t_bs2bdp bs2bdp,uint32_t srate)300 void bs2b_set_srate( t_bs2bdp bs2bdp, uint32_t srate )
301 {
302 if( NULL == bs2bdp ) return;
303
304 if( srate == bs2bdp->srate ) return;
305
306 bs2bdp->srate = srate;
307 init( bs2bdp );
308 bs2b_clear( bs2bdp );
309 } /* bs2b_set_srate() */
310
bs2b_get_srate(t_bs2bdp bs2bdp)311 uint32_t bs2b_get_srate( t_bs2bdp bs2bdp )
312 {
313 return bs2bdp->srate;
314 } /* bs2b_get_srate() */
315
bs2b_clear(t_bs2bdp bs2bdp)316 void bs2b_clear( t_bs2bdp bs2bdp )
317 {
318 if( NULL == bs2bdp ) return;
319 memset( &bs2bdp->lfs, 0, sizeof( bs2bdp->lfs ) );
320 } /* bs2b_clear() */
321
bs2b_is_clear(t_bs2bdp bs2bdp)322 int bs2b_is_clear( t_bs2bdp bs2bdp )
323 {
324 int loopv = sizeof( bs2bdp->lfs );
325
326 while( loopv )
327 {
328 if( ( ( char * )&bs2bdp->lfs )[ --loopv ] != 0 )
329 return 0;
330 }
331
332 return 1;
333 } /* bs2b_is_clear() */
334
bs2b_runtime_version(void)335 char const *bs2b_runtime_version( void )
336 {
337 return BS2B_VERSION_STR;
338 } /* bs2b_runtime_version() */
339
bs2b_runtime_version_int(void)340 uint32_t bs2b_runtime_version_int( void )
341 {
342 return BS2B_VERSION_INT;
343 } /* bs2b_runtime_version_int() */
344
bs2b_cross_feed_d(t_bs2bdp bs2bdp,double * sample,int n)345 void bs2b_cross_feed_d( t_bs2bdp bs2bdp, double *sample, int n )
346 {
347 if( n > 0 )
348 {
349 while( n-- )
350 {
351 cross_feed_d( bs2bdp, sample );
352
353 /* Clipping of overloaded samples */
354 if( sample[ 0 ] > 1.0 ) sample[ 0 ] = 1.0;
355 if( sample[ 0 ] < -1.0 ) sample[ 0 ] = -1.0;
356 if( sample[ 1 ] > 1.0 ) sample[ 1 ] = 1.0;
357 if( sample[ 1 ] < -1.0 ) sample[ 1 ] = -1.0;
358
359 sample += 2;
360 } /* while */
361 } /* if */
362 } /* bs2b_cross_feed_d() */
363
bs2b_cross_feed_dbe(t_bs2bdp bs2bdp,double * sample,int n)364 void bs2b_cross_feed_dbe( t_bs2bdp bs2bdp, double *sample, int n )
365 {
366 if( n > 0 )
367 {
368 while( n-- )
369 {
370 #ifndef WORDS_BIGENDIAN
371 int64swap( ( uint32_t * )sample );
372 int64swap( ( uint32_t * )( sample + 1 ) );
373 #endif
374
375 cross_feed_d( bs2bdp, sample );
376
377 /* Clipping of overloaded samples */
378 if( sample[ 0 ] > 1.0 ) sample[ 0 ] = 1.0;
379 if( sample[ 0 ] < -1.0 ) sample[ 0 ] = -1.0;
380 if( sample[ 1 ] > 1.0 ) sample[ 1 ] = 1.0;
381 if( sample[ 1 ] < -1.0 ) sample[ 1 ] = -1.0;
382
383 #ifndef WORDS_BIGENDIAN
384 int64swap( ( uint32_t * )sample );
385 int64swap( ( uint32_t * )( sample + 1 ) );
386 #endif
387
388 sample += 2;
389 } /* while */
390 } /* if */
391 } /* bs2b_cross_feed_dbe() */
392
bs2b_cross_feed_dle(t_bs2bdp bs2bdp,double * sample,int n)393 void bs2b_cross_feed_dle( t_bs2bdp bs2bdp, double *sample, int n )
394 {
395 if( n > 0 )
396 {
397 while( n-- )
398 {
399 #ifdef WORDS_BIGENDIAN
400 int64swap( ( uint32_t * )sample );
401 int64swap( ( uint32_t * )( sample + 1 ) );
402 #endif
403
404 cross_feed_d( bs2bdp, sample );
405
406 /* Clipping of overloaded samples */
407 if( sample[ 0 ] > 1.0 ) sample[ 0 ] = 1.0;
408 if( sample[ 0 ] < -1.0 ) sample[ 0 ] = -1.0;
409 if( sample[ 1 ] > 1.0 ) sample[ 1 ] = 1.0;
410 if( sample[ 1 ] < -1.0 ) sample[ 1 ] = -1.0;
411
412 #ifdef WORDS_BIGENDIAN
413 int64swap( ( uint32_t * )sample );
414 int64swap( ( uint32_t * )( sample + 1 ) );
415 #endif
416
417 sample += 2;
418 } /* while */
419 } /* if */
420 } /* bs2b_cross_feed_dle() */
421
bs2b_cross_feed_f(t_bs2bdp bs2bdp,float * sample,int n)422 void bs2b_cross_feed_f( t_bs2bdp bs2bdp, float *sample, int n )
423 {
424 double sample_d[ 2 ];
425
426 if( n > 0 )
427 {
428 while( n-- )
429 {
430 sample_d[ 0 ] = ( double )sample[ 0 ];
431 sample_d[ 1 ] = ( double )sample[ 1 ];
432
433 cross_feed_d( bs2bdp, sample_d );
434
435 /* Clipping of overloaded samples */
436 if( sample_d[ 0 ] > 1.0 ) sample_d[ 0 ] = 1.0;
437 if( sample_d[ 0 ] < -1.0 ) sample_d[ 0 ] = -1.0;
438 if( sample_d[ 1 ] > 1.0 ) sample_d[ 1 ] = 1.0;
439 if( sample_d[ 1 ] < -1.0 ) sample_d[ 1 ] = -1.0;
440
441 sample[ 0 ] = ( float )sample_d[ 0 ];
442 sample[ 1 ] = ( float )sample_d[ 1 ];
443
444 sample += 2;
445 } /* while */
446 } /* if */
447 } /* bs2b_cross_feed_f() */
448
bs2b_cross_feed_fbe(t_bs2bdp bs2bdp,float * sample,int n)449 void bs2b_cross_feed_fbe( t_bs2bdp bs2bdp, float *sample, int n )
450 {
451 double sample_d[ 2 ];
452
453 if( n > 0 )
454 {
455 while( n-- )
456 {
457 #ifndef WORDS_BIGENDIAN
458 int32swap( ( uint32_t * )sample );
459 int32swap( ( uint32_t * )( sample + 1 ) );
460 #endif
461
462 sample_d[ 0 ] = ( double )sample[ 0 ];
463 sample_d[ 1 ] = ( double )sample[ 1 ];
464
465 cross_feed_d( bs2bdp, sample_d );
466
467 /* Clipping of overloaded samples */
468 if( sample_d[ 0 ] > 1.0 ) sample_d[ 0 ] = 1.0;
469 if( sample_d[ 0 ] < -1.0 ) sample_d[ 0 ] = -1.0;
470 if( sample_d[ 1 ] > 1.0 ) sample_d[ 1 ] = 1.0;
471 if( sample_d[ 1 ] < -1.0 ) sample_d[ 1 ] = -1.0;
472
473 sample[ 0 ] = ( float )sample_d[ 0 ];
474 sample[ 1 ] = ( float )sample_d[ 1 ];
475
476 #ifndef WORDS_BIGENDIAN
477 int32swap( ( uint32_t * )sample );
478 int32swap( ( uint32_t * )( sample + 1 ) );
479 #endif
480
481 sample += 2;
482 } /* while */
483 } /* if */
484 } /* bs2b_cross_feed_fbe() */
485
bs2b_cross_feed_fle(t_bs2bdp bs2bdp,float * sample,int n)486 void bs2b_cross_feed_fle( t_bs2bdp bs2bdp, float *sample, int n )
487 {
488 double sample_d[ 2 ];
489
490 if( n > 0 )
491 {
492 while( n-- )
493 {
494 #ifdef WORDS_BIGENDIAN
495 int32swap( ( uint32_t * )sample );
496 int32swap( ( uint32_t * )( sample + 1 ) );
497 #endif
498
499 sample_d[ 0 ] = ( double )sample[ 0 ];
500 sample_d[ 1 ] = ( double )sample[ 1 ];
501
502 cross_feed_d( bs2bdp, sample_d );
503
504 /* Clipping of overloaded samples */
505 if( sample_d[ 0 ] > 1.0 ) sample_d[ 0 ] = 1.0;
506 if( sample_d[ 0 ] < -1.0 ) sample_d[ 0 ] = -1.0;
507 if( sample_d[ 1 ] > 1.0 ) sample_d[ 1 ] = 1.0;
508 if( sample_d[ 1 ] < -1.0 ) sample_d[ 1 ] = -1.0;
509
510 sample[ 0 ] = ( float )sample_d[ 0 ];
511 sample[ 1 ] = ( float )sample_d[ 1 ];
512
513 #ifdef WORDS_BIGENDIAN
514 int32swap( ( uint32_t * )sample );
515 int32swap( ( uint32_t * )( sample + 1 ) );
516 #endif
517
518 sample += 2;
519 } /* while */
520 } /* if */
521 } /* bs2b_cross_feed_fle() */
522
523 #define MAX_INT32_VALUE 2147483647.0
524 #define MIN_INT32_VALUE -2147483648.0
525 #define MAX_INT24_VALUE 8388607.0
526 #define MIN_INT24_VALUE -8388608.0
527 #define MAX_INT16_VALUE 32767.0
528 #define MIN_INT16_VALUE -32768.0
529 #define MAX_INT8_VALUE 127.0
530 #define MIN_INT8_VALUE -128.0
531
bs2b_cross_feed_s32(t_bs2bdp bs2bdp,int32_t * sample,int n)532 void bs2b_cross_feed_s32( t_bs2bdp bs2bdp, int32_t *sample, int n )
533 {
534 double sample_d[ 2 ];
535
536 if( n > 0 )
537 {
538 while( n-- )
539 {
540 sample_d[ 0 ] = ( double )sample[ 0 ];
541 sample_d[ 1 ] = ( double )sample[ 1 ];
542
543 cross_feed_d( bs2bdp, sample_d );
544
545 /* Clipping of overloaded samples */
546 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
547 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
548 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
549 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
550
551 sample[ 0 ] = ( int32_t )sample_d[ 0 ];
552 sample[ 1 ] = ( int32_t )sample_d[ 1 ];
553
554 sample += 2;
555 } /* while */
556 } /* if */
557 } /* bs2b_cross_feed_s32() */
558
bs2b_cross_feed_u32(t_bs2bdp bs2bdp,uint32_t * sample,int n)559 void bs2b_cross_feed_u32( t_bs2bdp bs2bdp, uint32_t *sample, int n )
560 {
561 double sample_d[ 2 ];
562
563 if( n > 0 )
564 {
565 while( n-- )
566 {
567 sample_d[ 0 ] = ( double )( ( int32_t )( sample[ 0 ] ^ 0x80000000 ) );
568 sample_d[ 1 ] = ( double )( ( int32_t )( sample[ 1 ] ^ 0x80000000 ) );
569
570 cross_feed_d( bs2bdp, sample_d );
571
572 /* Clipping of overloaded samples */
573 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
574 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
575 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
576 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
577
578 sample[ 0 ] = ( ( uint32_t )sample_d[ 0 ] ) ^ 0x80000000;
579 sample[ 1 ] = ( ( uint32_t )sample_d[ 1 ] ) ^ 0x80000000;
580
581 sample += 2;
582 } /* while */
583 } /* if */
584 } /* bs2b_cross_feed_u32() */
585
bs2b_cross_feed_s32be(t_bs2bdp bs2bdp,int32_t * sample,int n)586 void bs2b_cross_feed_s32be( t_bs2bdp bs2bdp, int32_t *sample, int n )
587 {
588 double sample_d[ 2 ];
589
590 if( n > 0 )
591 {
592 while( n-- )
593 {
594 #ifndef WORDS_BIGENDIAN
595 int32swap( ( uint32_t * )sample );
596 int32swap( ( uint32_t * )( sample + 1 ) );
597 #endif
598
599 sample_d[ 0 ] = ( double )sample[ 0 ];
600 sample_d[ 1 ] = ( double )sample[ 1 ];
601
602 cross_feed_d( bs2bdp, sample_d );
603
604 /* Clipping of overloaded samples */
605 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
606 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
607 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
608 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
609
610 sample[ 0 ] = ( int32_t )sample_d[ 0 ];
611 sample[ 1 ] = ( int32_t )sample_d[ 1 ];
612
613 #ifndef WORDS_BIGENDIAN
614 int32swap( ( uint32_t * )sample );
615 int32swap( ( uint32_t * )( sample + 1 ) );
616 #endif
617
618 sample += 2;
619 } /* while */
620 } /* if */
621 } /* bs2b_cross_feed_s32be() */
622
bs2b_cross_feed_u32be(t_bs2bdp bs2bdp,uint32_t * sample,int n)623 void bs2b_cross_feed_u32be( t_bs2bdp bs2bdp, uint32_t *sample, int n )
624 {
625 double sample_d[ 2 ];
626
627 if( n > 0 )
628 {
629 while( n-- )
630 {
631 #ifndef WORDS_BIGENDIAN
632 int32swap( sample );
633 int32swap( sample + 1 );
634 #endif
635
636 sample_d[ 0 ] = ( double )( ( int32_t )( sample[ 0 ] ^ 0x80000000 ) );
637 sample_d[ 1 ] = ( double )( ( int32_t )( sample[ 1 ] ^ 0x80000000 ) );
638
639 cross_feed_d( bs2bdp, sample_d );
640
641 /* Clipping of overloaded samples */
642 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
643 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
644 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
645 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
646
647 sample[ 0 ] = ( ( uint32_t )sample_d[ 0 ] ) ^ 0x80000000;
648 sample[ 1 ] = ( ( uint32_t )sample_d[ 1 ] ) ^ 0x80000000;
649
650 #ifndef WORDS_BIGENDIAN
651 int32swap( sample );
652 int32swap( sample + 1 );
653 #endif
654
655 sample += 2;
656 } /* while */
657 } /* if */
658 } /* bs2b_cross_feed_u32be() */
659
bs2b_cross_feed_s32le(t_bs2bdp bs2bdp,int32_t * sample,int n)660 void bs2b_cross_feed_s32le( t_bs2bdp bs2bdp, int32_t *sample, int n )
661 {
662 double sample_d[ 2 ];
663
664 if( n > 0 )
665 {
666 while( n-- )
667 {
668 #ifdef WORDS_BIGENDIAN
669 int32swap( sample );
670 int32swap( sample + 1 );
671 #endif
672
673 sample_d[ 0 ] = ( double )sample[ 0 ];
674 sample_d[ 1 ] = ( double )sample[ 1 ];
675
676 cross_feed_d( bs2bdp, sample_d );
677
678 /* Clipping of overloaded samples */
679 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
680 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
681 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
682 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
683
684 sample[ 0 ] = ( int32_t )sample_d[ 0 ];
685 sample[ 1 ] = ( int32_t )sample_d[ 1 ];
686
687 #ifdef WORDS_BIGENDIAN
688 int32swap( sample );
689 int32swap( sample + 1 );
690 #endif
691
692 sample += 2;
693 } /* while */
694 } /* if */
695 } /* bs2b_cross_feed_s32le() */
696
bs2b_cross_feed_u32le(t_bs2bdp bs2bdp,uint32_t * sample,int n)697 void bs2b_cross_feed_u32le( t_bs2bdp bs2bdp, uint32_t *sample, int n )
698 {
699 double sample_d[ 2 ];
700
701 if( n > 0 )
702 {
703 while( n-- )
704 {
705 #ifdef WORDS_BIGENDIAN
706 int32swap( sample );
707 int32swap( sample + 1 );
708 #endif
709
710 sample_d[ 0 ] = ( double )( ( int32_t )( sample[ 0 ] ^ 0x80000000 ) );
711 sample_d[ 1 ] = ( double )( ( int32_t )( sample[ 1 ] ^ 0x80000000 ) );
712
713 cross_feed_d( bs2bdp, sample_d );
714
715 /* Clipping of overloaded samples */
716 if( sample_d[ 0 ] > MAX_INT32_VALUE ) sample_d[ 0 ] = MAX_INT32_VALUE;
717 if( sample_d[ 0 ] < MIN_INT32_VALUE ) sample_d[ 0 ] = MIN_INT32_VALUE;
718 if( sample_d[ 1 ] > MAX_INT32_VALUE ) sample_d[ 1 ] = MAX_INT32_VALUE;
719 if( sample_d[ 1 ] < MIN_INT32_VALUE ) sample_d[ 1 ] = MIN_INT32_VALUE;
720
721 sample[ 0 ] = ( ( uint32_t )sample_d[ 0 ] ) ^ 0x80000000;
722 sample[ 1 ] = ( ( uint32_t )sample_d[ 1 ] ) ^ 0x80000000;
723
724 #ifdef WORDS_BIGENDIAN
725 int32swap( sample );
726 int32swap( sample + 1 );
727 #endif
728
729 sample += 2;
730 } /* while */
731 } /* if */
732 } /* bs2b_cross_feed_u32le() */
733
bs2b_cross_feed_s16(t_bs2bdp bs2bdp,int16_t * sample,int n)734 void bs2b_cross_feed_s16( t_bs2bdp bs2bdp, int16_t *sample, int n )
735 {
736 double sample_d[ 2 ];
737
738 if( n > 0 )
739 {
740 while( n-- )
741 {
742 sample_d[ 0 ] = ( double )sample[ 0 ];
743 sample_d[ 1 ] = ( double )sample[ 1 ];
744
745 cross_feed_d( bs2bdp, sample_d );
746
747 /* Clipping of overloaded samples */
748 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
749 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
750 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
751 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
752
753 sample[ 0 ] = ( int16_t )sample_d[ 0 ];
754 sample[ 1 ] = ( int16_t )sample_d[ 1 ];
755
756 sample += 2;
757 } /* while */
758 } /* if */
759 } /* bs2b_cross_feed_s16() */
760
bs2b_cross_feed_u16(t_bs2bdp bs2bdp,uint16_t * sample,int n)761 void bs2b_cross_feed_u16( t_bs2bdp bs2bdp, uint16_t *sample, int n )
762 {
763 double sample_d[ 2 ];
764
765 if( n > 0 )
766 {
767 while( n-- )
768 {
769 sample_d[ 0 ] = ( double )( ( int16_t )( sample[ 0 ] ^ 0x8000 ) );
770 sample_d[ 1 ] = ( double )( ( int16_t )( sample[ 1 ] ^ 0x8000 ) );
771
772 cross_feed_d( bs2bdp, sample_d );
773
774 /* Clipping of overloaded samples */
775 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
776 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
777 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
778 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
779
780 sample[ 0 ] = ( ( uint16_t )sample_d[ 0 ] ) ^ 0x8000;
781 sample[ 1 ] = ( ( uint16_t )sample_d[ 1 ] ) ^ 0x8000;
782
783 sample += 2;
784 } /* while */
785 } /* if */
786 } /* bs2b_cross_feed_u16() */
787
bs2b_cross_feed_s16be(t_bs2bdp bs2bdp,int16_t * sample,int n)788 void bs2b_cross_feed_s16be( t_bs2bdp bs2bdp, int16_t *sample, int n )
789 {
790 double sample_d[ 2 ];
791
792 if( n > 0 )
793 {
794 while( n-- )
795 {
796 #ifndef WORDS_BIGENDIAN
797 int16swap( ( uint16_t * )sample );
798 int16swap( ( uint16_t * )( sample + 1 ) );
799 #endif
800
801 sample_d[ 0 ] = ( double )sample[ 0 ];
802 sample_d[ 1 ] = ( double )sample[ 1 ];
803
804 cross_feed_d( bs2bdp, sample_d );
805
806 /* Clipping of overloaded samples */
807 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
808 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
809 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
810 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
811
812 sample[ 0 ] = ( int16_t )sample_d[ 0 ];
813 sample[ 1 ] = ( int16_t )sample_d[ 1 ];
814
815 #ifndef WORDS_BIGENDIAN
816 int16swap( ( uint16_t * )sample );
817 int16swap( ( uint16_t * )( sample + 1 ) );
818 #endif
819
820 sample += 2;
821 } /* while */
822 } /* if */
823 } /* bs2b_cross_feed_s16be() */
824
bs2b_cross_feed_u16be(t_bs2bdp bs2bdp,uint16_t * sample,int n)825 void bs2b_cross_feed_u16be( t_bs2bdp bs2bdp, uint16_t *sample, int n )
826 {
827 double sample_d[ 2 ];
828
829 if( n > 0 )
830 {
831 while( n-- )
832 {
833 #ifndef WORDS_BIGENDIAN
834 int16swap( sample );
835 int16swap( sample + 1 );
836 #endif
837
838 sample_d[ 0 ] = ( double )( ( int16_t )( sample[ 0 ] ^ 0x8000 ) );
839 sample_d[ 1 ] = ( double )( ( int16_t )( sample[ 1 ] ^ 0x8000 ) );
840
841 cross_feed_d( bs2bdp, sample_d );
842
843 /* Clipping of overloaded samples */
844 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
845 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
846 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
847 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
848
849 sample[ 0 ] = ( ( uint16_t )sample_d[ 0 ] ) ^ 0x8000;
850 sample[ 1 ] = ( ( uint16_t )sample_d[ 1 ] ) ^ 0x8000;
851
852 #ifndef WORDS_BIGENDIAN
853 int16swap( sample );
854 int16swap( sample + 1 );
855 #endif
856
857 sample += 2;
858 } /* while */
859 } /* if */
860 } /* bs2b_cross_feed_u16be() */
861
bs2b_cross_feed_s16le(t_bs2bdp bs2bdp,int16_t * sample,int n)862 void bs2b_cross_feed_s16le( t_bs2bdp bs2bdp, int16_t *sample, int n )
863 {
864 double sample_d[ 2 ];
865
866 if( n > 0 )
867 {
868 while( n-- )
869 {
870 #ifdef WORDS_BIGENDIAN
871 int16swap( sample );
872 int16swap( sample + 1 );
873 #endif
874
875 sample_d[ 0 ] = ( double )sample[ 0 ];
876 sample_d[ 1 ] = ( double )sample[ 1 ];
877
878 cross_feed_d( bs2bdp, sample_d );
879
880 /* Clipping of overloaded samples */
881 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
882 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
883 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
884 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
885
886 sample[ 0 ] = ( int16_t )sample_d[ 0 ];
887 sample[ 1 ] = ( int16_t )sample_d[ 1 ];
888
889 #ifdef WORDS_BIGENDIAN
890 int16swap( sample );
891 int16swap( sample + 1 );
892 #endif
893
894 sample += 2;
895 } /* while */
896 } /* if */
897 } /* bs2b_cross_feed_s16le() */
898
bs2b_cross_feed_u16le(t_bs2bdp bs2bdp,uint16_t * sample,int n)899 void bs2b_cross_feed_u16le( t_bs2bdp bs2bdp, uint16_t *sample, int n )
900 {
901 double sample_d[ 2 ];
902
903 if( n > 0 )
904 {
905 while( n-- )
906 {
907 #ifdef WORDS_BIGENDIAN
908 int16swap( sample );
909 int16swap( sample + 1 );
910 #endif
911
912 sample_d[ 0 ] = ( double )( ( int16_t )( sample[ 0 ] ^ 0x8000 ) );
913 sample_d[ 1 ] = ( double )( ( int16_t )( sample[ 1 ] ^ 0x8000 ) );
914
915 cross_feed_d( bs2bdp, sample_d );
916
917 /* Clipping of overloaded samples */
918 if( sample_d[ 0 ] > MAX_INT16_VALUE ) sample_d[ 0 ] = MAX_INT16_VALUE;
919 if( sample_d[ 0 ] < MIN_INT16_VALUE ) sample_d[ 0 ] = MIN_INT16_VALUE;
920 if( sample_d[ 1 ] > MAX_INT16_VALUE ) sample_d[ 1 ] = MAX_INT16_VALUE;
921 if( sample_d[ 1 ] < MIN_INT16_VALUE ) sample_d[ 1 ] = MIN_INT16_VALUE;
922
923 sample[ 0 ] = ( ( uint16_t )sample_d[ 0 ] ) ^ 0x8000;
924 sample[ 1 ] = ( ( uint16_t )sample_d[ 1 ] ) ^ 0x8000;
925
926 #ifdef WORDS_BIGENDIAN
927 int16swap( sample );
928 int16swap( sample + 1 );
929 #endif
930
931 sample += 2;
932 } /* while */
933 } /* if */
934 } /* bs2b_cross_feed_u16le() */
935
bs2b_cross_feed_s8(t_bs2bdp bs2bdp,int8_t * sample,int n)936 void bs2b_cross_feed_s8( t_bs2bdp bs2bdp, int8_t *sample, int n )
937 {
938 double sample_d[ 2 ];
939
940 if( n > 0 )
941 {
942 while( n-- )
943 {
944 sample_d[ 0 ] = ( double )sample[ 0 ];
945 sample_d[ 1 ] = ( double )sample[ 1 ];
946
947 cross_feed_d( bs2bdp, sample_d );
948
949 /* Clipping of overloaded samples */
950 if( sample_d[ 0 ] > MAX_INT8_VALUE ) sample_d[ 0 ] = MAX_INT8_VALUE;
951 if( sample_d[ 0 ] < MIN_INT8_VALUE ) sample_d[ 0 ] = MIN_INT8_VALUE;
952 if( sample_d[ 1 ] > MAX_INT8_VALUE ) sample_d[ 1 ] = MAX_INT8_VALUE;
953 if( sample_d[ 1 ] < MIN_INT8_VALUE ) sample_d[ 1 ] = MIN_INT8_VALUE;
954
955 sample[ 0 ] = ( int8_t )sample_d[ 0 ];
956 sample[ 1 ] = ( int8_t )sample_d[ 1 ];
957
958 sample += 2;
959 } /* while */
960 } /* if */
961 } /* bs2b_cross_feed_s8() */
962
bs2b_cross_feed_u8(t_bs2bdp bs2bdp,uint8_t * sample,int n)963 void bs2b_cross_feed_u8( t_bs2bdp bs2bdp, uint8_t *sample, int n )
964 {
965 double sample_d[ 2 ];
966
967 if( n > 0 )
968 {
969 while( n-- )
970 {
971 sample_d[ 0 ] = ( double )( ( int8_t )( sample[ 0 ] ^ 0x80 ) );
972 sample_d[ 1 ] = ( double )( ( int8_t )( sample[ 1 ] ^ 0x80 ) );
973
974 cross_feed_d( bs2bdp, sample_d );
975
976 /* Clipping of overloaded samples */
977 if( sample_d[ 0 ] > MAX_INT8_VALUE ) sample_d[ 0 ] = MAX_INT8_VALUE;
978 if( sample_d[ 0 ] < MIN_INT8_VALUE ) sample_d[ 0 ] = MIN_INT8_VALUE;
979 if( sample_d[ 1 ] > MAX_INT8_VALUE ) sample_d[ 1 ] = MAX_INT8_VALUE;
980 if( sample_d[ 1 ] < MIN_INT8_VALUE ) sample_d[ 1 ] = MIN_INT8_VALUE;
981
982 sample[ 0 ] = ( ( uint8_t )sample_d[ 0 ] ) ^ 0x80;
983 sample[ 1 ] = ( ( uint8_t )sample_d[ 1 ] ) ^ 0x80;
984
985 sample += 2;
986 } /* while */
987 } /* if */
988 } /* bs2b_cross_feed_u8() */
989
bs2b_cross_feed_s24(t_bs2bdp bs2bdp,bs2b_int24_t * sample,int n)990 void bs2b_cross_feed_s24( t_bs2bdp bs2bdp, bs2b_int24_t *sample, int n )
991 {
992 double sample_d[ 2 ];
993
994 if( n > 0 )
995 {
996 while( n-- )
997 {
998 sample_d[ 0 ] = int242double( sample );
999 sample_d[ 1 ] = int242double( sample + 1 );
1000
1001 cross_feed_d( bs2bdp, sample_d );
1002
1003 /* Clipping of overloaded samples */
1004 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1005 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1006 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1007 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1008
1009 double2int24( sample_d[ 0 ], sample );
1010 double2int24( sample_d[ 1 ], sample + 1 );
1011
1012 sample += 2;
1013 } /* while */
1014 } /* if */
1015 } /* bs2b_cross_feed_s24() */
1016
bs2b_cross_feed_u24(t_bs2bdp bs2bdp,bs2b_uint24_t * sample,int n)1017 void bs2b_cross_feed_u24( t_bs2bdp bs2bdp, bs2b_uint24_t *sample, int n )
1018 {
1019 double sample_d[ 2 ];
1020
1021 if( n > 0 )
1022 {
1023 while( n-- )
1024 {
1025 sample_d[ 0 ] = uint242double( sample ) - MAX_INT24_VALUE - 1.0;
1026 sample_d[ 1 ] = uint242double( sample + 1 ) - MAX_INT24_VALUE - 1.0;
1027
1028 cross_feed_d( bs2bdp, sample_d );
1029
1030 /* Clipping of overloaded samples */
1031 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1032 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1033 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1034 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1035
1036 double2uint24( sample_d[ 0 ] + MAX_INT24_VALUE + 1.0 , sample );
1037 double2uint24( sample_d[ 1 ] + MAX_INT24_VALUE + 1.0 , sample + 1 );
1038
1039 sample += 2;
1040 } /* while */
1041 } /* if */
1042 } /* bs2b_cross_feed_u24() */
1043
bs2b_cross_feed_s24be(t_bs2bdp bs2bdp,bs2b_int24_t * sample,int n)1044 void bs2b_cross_feed_s24be( t_bs2bdp bs2bdp, bs2b_int24_t *sample, int n )
1045 {
1046 double sample_d[ 2 ];
1047
1048 if( n > 0 )
1049 {
1050 while( n-- )
1051 {
1052 #ifndef WORDS_BIGENDIAN
1053 int24swap( ( bs2b_uint24_t * )sample );
1054 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1055 #endif
1056
1057 sample_d[ 0 ] = int242double( sample );
1058 sample_d[ 1 ] = int242double( sample + 1 );
1059
1060 cross_feed_d( bs2bdp, sample_d );
1061
1062 /* Clipping of overloaded samples */
1063 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1064 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1065 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1066 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1067
1068 double2int24( sample_d[ 0 ], sample );
1069 double2int24( sample_d[ 1 ], sample + 1 );
1070
1071 #ifndef WORDS_BIGENDIAN
1072 int24swap( ( bs2b_uint24_t * )sample );
1073 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1074 #endif
1075
1076 sample += 2;
1077 } /* while */
1078 } /* if */
1079 } /* bs2b_cross_feed_s24be() */
1080
bs2b_cross_feed_u24be(t_bs2bdp bs2bdp,bs2b_uint24_t * sample,int n)1081 void bs2b_cross_feed_u24be( t_bs2bdp bs2bdp, bs2b_uint24_t *sample, int n )
1082 {
1083 double sample_d[ 2 ];
1084
1085 if( n > 0 )
1086 {
1087 while( n-- )
1088 {
1089 #ifndef WORDS_BIGENDIAN
1090 int24swap( ( bs2b_uint24_t * )sample );
1091 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1092 #endif
1093
1094 sample_d[ 0 ] = uint242double( sample ) - MAX_INT24_VALUE - 1.0;
1095 sample_d[ 1 ] = uint242double( sample + 1 ) - MAX_INT24_VALUE - 1.0;
1096
1097 cross_feed_d( bs2bdp, sample_d );
1098
1099 /* Clipping of overloaded samples */
1100 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1101 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1102 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1103 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1104
1105 double2uint24( sample_d[ 0 ] + MAX_INT24_VALUE + 1.0 , sample );
1106 double2uint24( sample_d[ 1 ] + MAX_INT24_VALUE + 1.0 , sample + 1 );
1107
1108 #ifndef WORDS_BIGENDIAN
1109 int24swap( ( bs2b_uint24_t * )sample );
1110 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1111 #endif
1112
1113 sample += 2;
1114 } /* while */
1115 } /* if */
1116 } /* bs2b_cross_feed_u24be() */
1117
bs2b_cross_feed_s24le(t_bs2bdp bs2bdp,bs2b_int24_t * sample,int n)1118 void bs2b_cross_feed_s24le( t_bs2bdp bs2bdp, bs2b_int24_t *sample, int n )
1119 {
1120 double sample_d[ 2 ];
1121
1122 if( n > 0 )
1123 {
1124 while( n-- )
1125 {
1126 #ifdef WORDS_BIGENDIAN
1127 int24swap( ( bs2b_uint24_t * )sample );
1128 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1129 #endif
1130
1131 sample_d[ 0 ] = int242double( sample );
1132 sample_d[ 1 ] = int242double( sample + 1 );
1133
1134 cross_feed_d( bs2bdp, sample_d );
1135
1136 /* Clipping of overloaded samples */
1137 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1138 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1139 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1140 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1141
1142 double2int24( sample_d[ 0 ], sample );
1143 double2int24( sample_d[ 1 ], sample + 1 );
1144
1145 #ifdef WORDS_BIGENDIAN
1146 int24swap( ( bs2b_uint24_t * )sample );
1147 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1148 #endif
1149
1150 sample += 2;
1151 } /* while */
1152 } /* if */
1153 } /* bs2b_cross_feed_s24le() */
1154
bs2b_cross_feed_u24le(t_bs2bdp bs2bdp,bs2b_uint24_t * sample,int n)1155 void bs2b_cross_feed_u24le( t_bs2bdp bs2bdp, bs2b_uint24_t *sample, int n )
1156 {
1157 double sample_d[ 2 ];
1158
1159 if( n > 0 )
1160 {
1161 while( n-- )
1162 {
1163 #ifdef WORDS_BIGENDIAN
1164 int24swap( ( bs2b_uint24_t * )sample );
1165 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1166 #endif
1167
1168 sample_d[ 0 ] = uint242double( sample ) - MAX_INT24_VALUE - 1.0;
1169 sample_d[ 1 ] = uint242double( sample + 1 ) - MAX_INT24_VALUE - 1.0;
1170
1171 cross_feed_d( bs2bdp, sample_d );
1172
1173 /* Clipping of overloaded samples */
1174 if( sample_d[ 0 ] > MAX_INT24_VALUE ) sample_d[ 0 ] = MAX_INT24_VALUE;
1175 if( sample_d[ 0 ] < MIN_INT24_VALUE ) sample_d[ 0 ] = MIN_INT24_VALUE;
1176 if( sample_d[ 1 ] > MAX_INT24_VALUE ) sample_d[ 1 ] = MAX_INT24_VALUE;
1177 if( sample_d[ 1 ] < MIN_INT24_VALUE ) sample_d[ 1 ] = MIN_INT24_VALUE;
1178
1179 double2uint24( sample_d[ 0 ] + MAX_INT24_VALUE + 1.0 , sample );
1180 double2uint24( sample_d[ 1 ] + MAX_INT24_VALUE + 1.0 , sample + 1 );
1181
1182 #ifdef WORDS_BIGENDIAN
1183 int24swap( ( bs2b_uint24_t * )sample );
1184 int24swap( ( bs2b_uint24_t * )( sample + 1 ) );
1185 #endif
1186
1187 sample += 2;
1188 } /* while */
1189 } /* if */
1190 } /* bs2b_cross_feed_u24le() */
1191