3 * uncouple.c Copyright (C) Aaron Holtzman - May 1999
5 * This file is part of libmpeg3
7 * libmpeg3 is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * libmpeg3 is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "../bitstream.h"
24 #include "mpeg3audio.h"
26 static unsigned char mpeg3_first_bit_lut
[256] =
28 0, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5,
29 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
30 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
31 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
32 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
33 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
34 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
35 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
36 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
46 /* Converts an unsigned exponent in the range of 0-24 and a 16 bit mantissa
47 * to an IEEE single precision floating point value */
48 static inline void mpeg3audio_ac3_convert_to_float(unsigned short exp
,
49 unsigned short mantissa
,
56 /* If the mantissa is zero we can simply return zero */
63 /* Exponent is offset by 127 in IEEE format minus the shift to
64 * align the mantissa to 1.f (subtracted in the final result) */
67 /* Take care of the one asymmetric negative number */
68 if(mantissa
== 0x8000)
71 /* Extract the sign bit, invert the mantissa if it's negative, and
72 shift out the sign bit */
76 num
= 0x80000000 + (exponent
<< 23);
84 /* Find the index of the most significant one bit */
85 i
= mpeg3_first_bit_lut
[mantissa
>> 8];
88 i
= mpeg3_first_bit_lut
[mantissa
& 0xff] + 8;
90 *dest
= num
- (i
<< 23) + (mantissa
<< (7 + i
));
95 int mpeg3audio_ac3_uncouple(mpeg3audio_t
*audio
,
97 mpeg3_ac3audblk_t
*audblk
,
98 mpeg3_stream_coeffs_t
*coeffs
)
102 for(i
= 0; i
< bsi
->nfchans
; i
++)
104 for(j
= 0; j
< audblk
->endmant
[i
]; j
++)
105 mpeg3audio_ac3_convert_to_float(audblk
->fbw_exp
[i
][j
],
106 audblk
->chmant
[i
][j
],
107 (u_int32_t
*)&coeffs
->fbw
[i
][j
]);
112 for(i
= 0; i
< bsi
->nfchans
; i
++)
114 if(audblk
->chincpl
[i
])
116 mpeg3audio_ac3_uncouple_channel(audio
,
127 /* There are always 7 mantissas for lfe */
128 for(j
= 0; j
< 7 ; j
++)
129 mpeg3audio_ac3_convert_to_float(audblk
->lfe_exp
[j
],
131 (u_int32_t
*)&coeffs
->lfe
[j
]);