summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/audio/uncouple.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmpeg3/audio/uncouple.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c b/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c
new file mode 100644
index 0000000..d87a078
--- a/dev/null
+++ b/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c
@@ -0,0 +1,135 @@
1/*
2 *
3 *uncouple.c Copyright (C) Aaron Holtzman - May 1999
4 *
5 * This file is part of libmpeg3
6 *
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)
10 * any later version.
11 *
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.
16 *
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.
20 *
21 */
22
23#include "../bitstream.h"
24#include "mpeg3audio.h"
25
26static unsigned char mpeg3_first_bit_lut[256] =
27{
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
44};
45
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 */
48static inline void mpeg3audio_ac3_convert_to_float(unsigned short exp,
49 unsigned short mantissa,
50 unsigned MPEG3_INT32 *dest)
51{
52 int num;
53 short exponent;
54 int i;
55
56/* If the mantissa is zero we can simply return zero */
57 if(mantissa == 0)
58 {
59 *dest = 0;
60 return;
61 }
62
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) */
65 exponent = 127 - exp;
66
67/* Take care of the one asymmetric negative number */
68 if(mantissa == 0x8000)
69 mantissa++;
70
71/* Extract the sign bit, invert the mantissa if it's negative, and
72 shift out the sign bit */
73 if(mantissa & 0x8000)
74 {
75 mantissa *= -1;
76 num = 0x80000000 + (exponent << 23);
77 }
78 else
79 {
80 mantissa *= 1;
81 num = exponent << 23;
82 }
83
84/* Find the index of the most significant one bit */
85 i = mpeg3_first_bit_lut[mantissa >> 8];
86
87 if(i == 0)
88 i = mpeg3_first_bit_lut[mantissa & 0xff] + 8;
89
90 *dest = num - (i << 23) + (mantissa << (7 + i));
91 return;
92}
93
94
95int mpeg3audio_ac3_uncouple(mpeg3audio_t *audio,
96 mpeg3_ac3bsi_t *bsi,
97 mpeg3_ac3audblk_t *audblk,
98 mpeg3_stream_coeffs_t *coeffs)
99{
100 int i, j;
101
102 for(i = 0; i < bsi->nfchans; i++)
103 {
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 (unsigned MPEG3_INT32*)&coeffs->fbw[i][j]);
108 }
109
110 if(audblk->cplinu)
111 {
112 for(i = 0; i < bsi->nfchans; i++)
113 {
114 if(audblk->chincpl[i])
115 {
116 mpeg3audio_ac3_uncouple_channel(audio,
117 coeffs,
118 audblk,
119 i);
120 }
121 }
122
123 }
124
125 if(bsi->lfeon)
126 {
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],
130 audblk->lfemant[j],
131 (unsigned MPEG3_INT32*)&coeffs->lfe[j]);
132
133 }
134 return 0;
135}