Makefile: remove outdated vf_halfpack entry
[mplayer/kovensky.git] / liba52 / resample_c.c
blob58deed6aab105e2ce53f283e6960a4918ee44e1d
1 /*
2 * resample_c.c
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)
27 if (i > 0x43c07fff)
28 return 32767;
29 else if (i < 0x43bf8000)
30 return -32768;
31 else
32 return i - 0x43c00000;
35 static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
36 int i;
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]);
42 return 5*256;
45 static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
46 int i;
47 int32_t * f = (int32_t *) _f;
48 for (i = 0; i < 256; i++) {
49 s16[i] = convert (f[i]);
51 return 1*256;
54 static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
55 int i;
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]);
61 return 2*256;
64 static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
65 int i;
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]);
73 return 5*256;
76 static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
77 int i;
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]);
85 return 4*256;
88 static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
89 int i;
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]);
98 return 5*256;
101 static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
102 int i;
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]);
109 return 6*256;
112 static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
113 int i;
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]);
121 return 6*256;
124 static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
125 int i;
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]);
134 return 6*256;
137 static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
138 int i;
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]);
145 s16[6*i+4] = 0;
146 s16[6*i+5] = convert (f[i]);
148 return 6*256;
151 static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
152 int i;
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]);
162 return 6*256;
166 static void* a52_resample_C(int flags, int ch){
167 switch (flags) {
168 case A52_MONO:
169 if(ch==5) return a52_resample_MONO_to_5_C;
170 if(ch==1) return a52_resample_MONO_to_1_C;
171 break;
172 case A52_CHANNEL:
173 case A52_STEREO:
174 case A52_DOLBY:
175 if(ch==2) return a52_resample_STEREO_to_2_C;
176 break;
177 case A52_3F:
178 if(ch==5) return a52_resample_3F_to_5_C;
179 break;
180 case A52_2F2R:
181 if(ch==4) return a52_resample_2F_2R_to_4_C;
182 break;
183 case A52_3F2R:
184 if(ch==5) return a52_resample_3F_2R_to_5_C;
185 break;
186 case A52_MONO | A52_LFE:
187 if(ch==6) return a52_resample_MONO_LFE_to_6_C;
188 break;
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;
193 break;
194 case A52_3F | A52_LFE:
195 if(ch==6) return a52_resample_3F_LFE_to_6_C;
196 break;
197 case A52_2F2R | A52_LFE:
198 if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
199 break;
200 case A52_3F2R | A52_LFE:
201 if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
202 break;
204 return NULL;