author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/multimedia/opieplayer/libmpeg3/audio/exponents.c | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/audio/exponents.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/audio/exponents.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/audio/exponents.c b/core/multimedia/opieplayer/libmpeg3/audio/exponents.c new file mode 100644 index 0000000..deda9b9 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/exponents.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * | ||
3 | *exponents.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 "mpeg3audio.h" | ||
24 | #include "../libmpeg3.h" | ||
25 | #include "../mpeg3protos.h" | ||
26 | #include <stdio.h> | ||
27 | |||
28 | /* Exponent defines */ | ||
29 | #define UNPACK_FBW 1 | ||
30 | #define UNPACK_CPL 2 | ||
31 | #define UNPACK_LFE 4 | ||
32 | |||
33 | static inline int mpeg3audio_ac3_exp_unpack_ch(unsigned int type, | ||
34 | unsigned int expstr, | ||
35 | unsigned int ngrps, | ||
36 | unsigned int initial_exp, | ||
37 | unsigned short exps[], | ||
38 | unsigned short *dest) | ||
39 | { | ||
40 | int i, j; | ||
41 | int exp_acc; | ||
42 | int exp_1, exp_2, exp_3; | ||
43 | |||
44 | if(expstr == MPEG3_EXP_REUSE) | ||
45 | return 0; | ||
46 | |||
47 | /* Handle the initial absolute exponent */ | ||
48 | exp_acc = initial_exp; | ||
49 | j = 0; | ||
50 | |||
51 | /* In the case of a fbw channel then the initial absolute value is | ||
52 | * also an exponent */ | ||
53 | if(type != UNPACK_CPL) | ||
54 | dest[j++] = exp_acc; | ||
55 | |||
56 | /* Loop through the groups and fill the dest array appropriately */ | ||
57 | for(i = 0; i < ngrps; i++) | ||
58 | { | ||
59 | if(exps[i] > 124) | ||
60 | { | ||
61 | fprintf(stderr, "mpeg3audio_ac3_exp_unpack_ch: Invalid exponent %d\n", exps[i]); | ||
62 | return 1; | ||
63 | } | ||
64 | |||
65 | exp_1 = exps[i] / 25; | ||
66 | exp_2 = (exps[i] % 25) / 5; | ||
67 | exp_3 = (exps[i] % 25) % 5; | ||
68 | |||
69 | exp_acc += (exp_1 - 2); | ||
70 | |||
71 | switch(expstr) | ||
72 | { | ||
73 | case MPEG3_EXP_D45: | ||
74 | dest[j++] = exp_acc; | ||
75 | dest[j++] = exp_acc; | ||
76 | case MPEG3_EXP_D25: | ||
77 | dest[j++] = exp_acc; | ||
78 | case MPEG3_EXP_D15: | ||
79 | dest[j++] = exp_acc; | ||
80 | } | ||
81 | |||
82 | exp_acc += (exp_2 - 2); | ||
83 | |||
84 | switch(expstr) | ||
85 | { | ||
86 | case MPEG3_EXP_D45: | ||
87 | dest[j++] = exp_acc; | ||
88 | dest[j++] = exp_acc; | ||
89 | case MPEG3_EXP_D25: | ||
90 | dest[j++] = exp_acc; | ||
91 | case MPEG3_EXP_D15: | ||
92 | dest[j++] = exp_acc; | ||
93 | } | ||
94 | |||
95 | exp_acc += (exp_3 - 2); | ||
96 | |||
97 | switch(expstr) | ||
98 | { | ||
99 | case MPEG3_EXP_D45: | ||
100 | dest[j++] = exp_acc; | ||
101 | dest[j++] = exp_acc; | ||
102 | case MPEG3_EXP_D25: | ||
103 | dest[j++] = exp_acc; | ||
104 | case MPEG3_EXP_D15: | ||
105 | dest[j++] = exp_acc; | ||
106 | } | ||
107 | } | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | int mpeg3audio_ac3_exponent_unpack(mpeg3audio_t *audio, | ||
112 | mpeg3_ac3bsi_t *bsi, | ||
113 | mpeg3_ac3audblk_t *audblk) | ||
114 | { | ||
115 | int i, result = 0; | ||
116 | |||
117 | for(i = 0; i < bsi->nfchans; i++) | ||
118 | result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_FBW, | ||
119 | audblk->chexpstr[i], | ||
120 | audblk->nchgrps[i], | ||
121 | audblk->exps[i][0], | ||
122 | &audblk->exps[i][1], | ||
123 | audblk->fbw_exp[i]); | ||
124 | |||
125 | if(audblk->cplinu && !result) | ||
126 | result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_CPL, | ||
127 | audblk->cplexpstr, | ||
128 | audblk->ncplgrps, | ||
129 | audblk->cplabsexp << 1, | ||
130 | audblk->cplexps, | ||
131 | &audblk->cpl_exp[audblk->cplstrtmant]); | ||
132 | |||
133 | if(bsi->lfeon && !result) | ||
134 | result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_LFE, | ||
135 | audblk->lfeexpstr, | ||
136 | 2, | ||
137 | audblk->lfeexps[0], | ||
138 | &audblk->lfeexps[1], | ||
139 | audblk->lfe_exp); | ||
140 | return result; | ||
141 | } | ||