3696
|
1 /*
|
|
2 * this code is based on a52dec/libao/audio_out_oss.c
|
|
3 * copyright (C) 2001 Arpad Gereoffy
|
|
4 *
|
|
5 * This file is part of a52dec, a free ATSC A-52 stream decoder.
|
|
6 * See http://liba52.sourceforge.net/ for updates.
|
|
7 *
|
|
8 * a52dec is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * a52dec is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
21 */
|
1193
|
22
|
|
23 static inline int16_t convert (int32_t i)
|
|
24 {
|
|
25 if (i > 0x43c07fff)
|
|
26 return 32767;
|
|
27 else if (i < 0x43bf8000)
|
|
28 return -32768;
|
|
29 else
|
|
30 return i - 0x43c00000;
|
|
31 }
|
|
32
|
|
33 static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
|
|
34 int i;
|
|
35 int32_t * f = (int32_t *) _f;
|
|
36 for (i = 0; i < 256; i++) {
|
|
37 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
|
|
38 s16[5*i+4] = convert (f[i]);
|
|
39 }
|
|
40 return 5*256;
|
|
41 }
|
|
42
|
|
43 static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
|
|
44 int i;
|
|
45 int32_t * f = (int32_t *) _f;
|
|
46 for (i = 0; i < 256; i++) {
|
|
47 s16[i] = convert (f[i]);
|
|
48 }
|
|
49 return 1*256;
|
|
50 }
|
|
51
|
|
52 static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
|
|
53 int i;
|
|
54 int32_t * f = (int32_t *) _f;
|
|
55 for (i = 0; i < 256; i++) {
|
|
56 s16[2*i] = convert (f[i]);
|
|
57 s16[2*i+1] = convert (f[i+256]);
|
|
58 }
|
|
59 return 2*256;
|
|
60 }
|
|
61
|
|
62 static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
|
|
63 int i;
|
|
64 int32_t * f = (int32_t *) _f;
|
|
65 for (i = 0; i < 256; i++) {
|
|
66 s16[5*i] = convert (f[i]);
|
|
67 s16[5*i+1] = convert (f[i+512]);
|
|
68 s16[5*i+2] = s16[5*i+3] = 0;
|
|
69 s16[5*i+4] = convert (f[i+256]);
|
|
70 }
|
|
71 return 5*256;
|
|
72 }
|
|
73
|
|
74 static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
|
|
75 int i;
|
|
76 int32_t * f = (int32_t *) _f;
|
|
77 for (i = 0; i < 256; i++) {
|
|
78 s16[4*i] = convert (f[i]);
|
|
79 s16[4*i+1] = convert (f[i+256]);
|
|
80 s16[4*i+2] = convert (f[i+512]);
|
|
81 s16[4*i+3] = convert (f[i+768]);
|
|
82 }
|
|
83 return 4*256;
|
|
84 }
|
|
85
|
|
86 static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
|
|
87 int i;
|
|
88 int32_t * f = (int32_t *) _f;
|
|
89 for (i = 0; i < 256; i++) {
|
|
90 s16[5*i] = convert (f[i]);
|
|
91 s16[5*i+1] = convert (f[i+512]);
|
|
92 s16[5*i+2] = convert (f[i+768]);
|
|
93 s16[5*i+3] = convert (f[i+1024]);
|
|
94 s16[5*i+4] = convert (f[i+256]);
|
|
95 }
|
|
96 return 5*256;
|
|
97 }
|
|
98
|
|
99 static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
|
|
100 int i;
|
|
101 int32_t * f = (int32_t *) _f;
|
|
102 for (i = 0; i < 256; i++) {
|
|
103 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
|
|
104 s16[6*i+4] = convert (f[i+256]);
|
|
105 s16[6*i+5] = convert (f[i]);
|
|
106 }
|
|
107 return 6*256;
|
|
108 }
|
|
109
|
|
110 static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
|
|
111 int i;
|
|
112 int32_t * f = (int32_t *) _f;
|
|
113 for (i = 0; i < 256; i++) {
|
|
114 s16[6*i] = convert (f[i+256]);
|
|
115 s16[6*i+1] = convert (f[i+512]);
|
|
116 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
|
|
117 s16[6*i+5] = convert (f[i]);
|
|
118 }
|
|
119 return 6*256;
|
|
120 }
|
|
121
|
|
122 static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
|
|
123 int i;
|
|
124 int32_t * f = (int32_t *) _f;
|
|
125 for (i = 0; i < 256; i++) {
|
|
126 s16[6*i] = convert (f[i+256]);
|
|
127 s16[6*i+1] = convert (f[i+768]);
|
|
128 s16[6*i+2] = s16[6*i+3] = 0;
|
|
129 s16[6*i+4] = convert (f[i+512]);
|
|
130 s16[6*i+5] = convert (f[i]);
|
|
131 }
|
|
132 return 6*256;
|
|
133 }
|
|
134
|
|
135 static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
|
|
136 int i;
|
|
137 int32_t * f = (int32_t *) _f;
|
|
138 for (i = 0; i < 256; i++) {
|
|
139 s16[6*i] = convert (f[i+256]);
|
|
140 s16[6*i+1] = convert (f[i+512]);
|
|
141 s16[6*i+2] = convert (f[i+768]);
|
|
142 s16[6*i+3] = convert (f[i+1024]);
|
|
143 s16[6*i+4] = 0;
|
|
144 s16[6*i+5] = convert (f[i]);
|
|
145 }
|
|
146 return 6*256;
|
|
147 }
|
|
148
|
|
149 static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
|
|
150 int i;
|
|
151 int32_t * f = (int32_t *) _f;
|
|
152 for (i = 0; i < 256; i++) {
|
|
153 s16[6*i] = convert (f[i+256]);
|
|
154 s16[6*i+1] = convert (f[i+768]);
|
|
155 s16[6*i+2] = convert (f[i+1024]);
|
|
156 s16[6*i+3] = convert (f[i+1280]);
|
|
157 s16[6*i+4] = convert (f[i+512]);
|
|
158 s16[6*i+5] = convert (f[i]);
|
|
159 }
|
|
160 return 6*256;
|
|
161 }
|
|
162
|
|
163
|
|
164 static void* a52_resample_C(int flags, int ch){
|
|
165 switch (flags) {
|
|
166 case A52_MONO:
|
|
167 if(ch==5) return a52_resample_MONO_to_5_C;
|
|
168 if(ch==1) return a52_resample_MONO_to_1_C;
|
|
169 break;
|
|
170 case A52_CHANNEL:
|
|
171 case A52_STEREO:
|
|
172 case A52_DOLBY:
|
|
173 if(ch==2) return a52_resample_STEREO_to_2_C;
|
|
174 break;
|
|
175 case A52_3F:
|
|
176 if(ch==5) return a52_resample_3F_to_5_C;
|
|
177 break;
|
|
178 case A52_2F2R:
|
|
179 if(ch==4) return a52_resample_2F_2R_to_4_C;
|
|
180 break;
|
|
181 case A52_3F2R:
|
|
182 if(ch==5) return a52_resample_3F_2R_to_5_C;
|
|
183 break;
|
|
184 case A52_MONO | A52_LFE:
|
|
185 if(ch==6) return a52_resample_MONO_LFE_to_6_C;
|
|
186 break;
|
|
187 case A52_CHANNEL | A52_LFE:
|
|
188 case A52_STEREO | A52_LFE:
|
|
189 case A52_DOLBY | A52_LFE:
|
|
190 if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
|
|
191 break;
|
|
192 case A52_3F | A52_LFE:
|
|
193 if(ch==6) return a52_resample_3F_LFE_to_6_C;
|
|
194 break;
|
|
195 case A52_2F2R | A52_LFE:
|
|
196 if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
|
|
197 break;
|
|
198 case A52_3F2R | A52_LFE:
|
|
199 if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
|
|
200 break;
|
|
201 }
|
|
202 return NULL;
|
|
203 }
|