3 * Copyright (C) 2001 Árpád Gereöffy
5 * This file is part of a52dec, a free ATSC A-52 stream decoder.
6 * See http://liba52.sourceforge.net/ for updates.
8 * File added for use with MPlayer and not part of original a52dec.
10 * a52dec is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * a52dec is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 static inline int16_t convert (int32_t i
)
29 else if (i
< 0x43bf8000)
32 return i
- 0x43c00000;
35 static int a52_resample_MONO_to_5_C(float * _f
, int16_t * s16
){
37 int32_t * f
= (int32_t *) _f
;
38 for (i
= 0; i
< 256; i
++) {
39 s16
[5*i
] = s16
[5*i
+1] = s16
[5*i
+2] = s16
[5*i
+3] = 0;
40 s16
[5*i
+4] = convert (f
[i
]);
45 static int a52_resample_MONO_to_1_C(float * _f
, int16_t * s16
){
47 int32_t * f
= (int32_t *) _f
;
48 for (i
= 0; i
< 256; i
++) {
49 s16
[i
] = convert (f
[i
]);
54 static int a52_resample_STEREO_to_2_C(float * _f
, int16_t * s16
){
56 int32_t * f
= (int32_t *) _f
;
57 for (i
= 0; i
< 256; i
++) {
58 s16
[2*i
] = convert (f
[i
]);
59 s16
[2*i
+1] = convert (f
[i
+256]);
64 static int a52_resample_3F_to_5_C(float * _f
, int16_t * s16
){
66 int32_t * f
= (int32_t *) _f
;
67 for (i
= 0; i
< 256; i
++) {
68 s16
[5*i
] = convert (f
[i
]);
69 s16
[5*i
+1] = convert (f
[i
+512]);
70 s16
[5*i
+2] = s16
[5*i
+3] = 0;
71 s16
[5*i
+4] = convert (f
[i
+256]);
76 static int a52_resample_2F_2R_to_4_C(float * _f
, int16_t * s16
){
78 int32_t * f
= (int32_t *) _f
;
79 for (i
= 0; i
< 256; i
++) {
80 s16
[4*i
] = convert (f
[i
]);
81 s16
[4*i
+1] = convert (f
[i
+256]);
82 s16
[4*i
+2] = convert (f
[i
+512]);
83 s16
[4*i
+3] = convert (f
[i
+768]);
88 static int a52_resample_3F_2R_to_5_C(float * _f
, int16_t * s16
){
90 int32_t * f
= (int32_t *) _f
;
91 for (i
= 0; i
< 256; i
++) {
92 s16
[5*i
] = convert (f
[i
]);
93 s16
[5*i
+1] = convert (f
[i
+512]);
94 s16
[5*i
+2] = convert (f
[i
+768]);
95 s16
[5*i
+3] = convert (f
[i
+1024]);
96 s16
[5*i
+4] = convert (f
[i
+256]);
101 static int a52_resample_MONO_LFE_to_6_C(float * _f
, int16_t * s16
){
103 int32_t * f
= (int32_t *) _f
;
104 for (i
= 0; i
< 256; i
++) {
105 s16
[6*i
] = s16
[6*i
+1] = s16
[6*i
+2] = s16
[6*i
+3] = 0;
106 s16
[6*i
+4] = convert (f
[i
+256]);
107 s16
[6*i
+5] = convert (f
[i
]);
112 static int a52_resample_STEREO_LFE_to_6_C(float * _f
, int16_t * s16
){
114 int32_t * f
= (int32_t *) _f
;
115 for (i
= 0; i
< 256; i
++) {
116 s16
[6*i
] = convert (f
[i
+256]);
117 s16
[6*i
+1] = convert (f
[i
+512]);
118 s16
[6*i
+2] = s16
[6*i
+3] = s16
[6*i
+4] = 0;
119 s16
[6*i
+5] = convert (f
[i
]);
124 static int a52_resample_3F_LFE_to_6_C(float * _f
, int16_t * s16
){
126 int32_t * f
= (int32_t *) _f
;
127 for (i
= 0; i
< 256; i
++) {
128 s16
[6*i
] = convert (f
[i
+256]);
129 s16
[6*i
+1] = convert (f
[i
+768]);
130 s16
[6*i
+2] = s16
[6*i
+3] = 0;
131 s16
[6*i
+4] = convert (f
[i
+512]);
132 s16
[6*i
+5] = convert (f
[i
]);
137 static int a52_resample_2F_2R_LFE_to_6_C(float * _f
, int16_t * s16
){
139 int32_t * f
= (int32_t *) _f
;
140 for (i
= 0; i
< 256; i
++) {
141 s16
[6*i
] = convert (f
[i
+256]);
142 s16
[6*i
+1] = convert (f
[i
+512]);
143 s16
[6*i
+2] = convert (f
[i
+768]);
144 s16
[6*i
+3] = convert (f
[i
+1024]);
146 s16
[6*i
+5] = convert (f
[i
]);
151 static int a52_resample_3F_2R_LFE_to_6_C(float * _f
, int16_t * s16
){
153 int32_t * f
= (int32_t *) _f
;
154 for (i
= 0; i
< 256; i
++) {
155 s16
[6*i
] = convert (f
[i
+256]);
156 s16
[6*i
+1] = convert (f
[i
+768]);
157 s16
[6*i
+2] = convert (f
[i
+1024]);
158 s16
[6*i
+3] = convert (f
[i
+1280]);
159 s16
[6*i
+4] = convert (f
[i
+512]);
160 s16
[6*i
+5] = convert (f
[i
]);
166 static void* a52_resample_C(int flags
, int ch
){
169 if(ch
==5) return a52_resample_MONO_to_5_C
;
170 if(ch
==1) return a52_resample_MONO_to_1_C
;
175 if(ch
==2) return a52_resample_STEREO_to_2_C
;
178 if(ch
==5) return a52_resample_3F_to_5_C
;
181 if(ch
==4) return a52_resample_2F_2R_to_4_C
;
184 if(ch
==5) return a52_resample_3F_2R_to_5_C
;
186 case A52_MONO
| A52_LFE
:
187 if(ch
==6) return a52_resample_MONO_LFE_to_6_C
;
189 case A52_CHANNEL
| A52_LFE
:
190 case A52_STEREO
| A52_LFE
:
191 case A52_DOLBY
| A52_LFE
:
192 if(ch
==6) return a52_resample_STEREO_LFE_to_6_C
;
194 case A52_3F
| A52_LFE
:
195 if(ch
==6) return a52_resample_3F_LFE_to_6_C
;
197 case A52_2F2R
| A52_LFE
:
198 if(ch
==6) return a52_resample_2F_2R_LFE_to_6_C
;
200 case A52_3F2R
| A52_LFE
:
201 if(ch
==6) return a52_resample_3F_2R_LFE_to_6_C
;