man/hu/mplayer.1 synced with r19052
[mplayer/greg.git] / liba52 / resample_c.c
bloba618ec6e9ecdd8c091655d823a998c57b396cce3
1 // this code is based on a52dec/libao/audio_out_oss.c
3 static inline int16_t convert (int32_t i)
5 if (i > 0x43c07fff)
6 return 32767;
7 else if (i < 0x43bf8000)
8 return -32768;
9 else
10 return i - 0x43c00000;
13 static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
14 int i;
15 int32_t * f = (int32_t *) _f;
16 for (i = 0; i < 256; i++) {
17 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
18 s16[5*i+4] = convert (f[i]);
20 return 5*256;
23 static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
24 int i;
25 int32_t * f = (int32_t *) _f;
26 for (i = 0; i < 256; i++) {
27 s16[i] = convert (f[i]);
29 return 1*256;
32 static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
33 int i;
34 int32_t * f = (int32_t *) _f;
35 for (i = 0; i < 256; i++) {
36 s16[2*i] = convert (f[i]);
37 s16[2*i+1] = convert (f[i+256]);
39 return 2*256;
42 static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
43 int i;
44 int32_t * f = (int32_t *) _f;
45 for (i = 0; i < 256; i++) {
46 s16[5*i] = convert (f[i]);
47 s16[5*i+1] = convert (f[i+512]);
48 s16[5*i+2] = s16[5*i+3] = 0;
49 s16[5*i+4] = convert (f[i+256]);
51 return 5*256;
54 static int a52_resample_2F_2R_to_4_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[4*i] = convert (f[i]);
59 s16[4*i+1] = convert (f[i+256]);
60 s16[4*i+2] = convert (f[i+512]);
61 s16[4*i+3] = convert (f[i+768]);
63 return 4*256;
66 static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
67 int i;
68 int32_t * f = (int32_t *) _f;
69 for (i = 0; i < 256; i++) {
70 s16[5*i] = convert (f[i]);
71 s16[5*i+1] = convert (f[i+512]);
72 s16[5*i+2] = convert (f[i+768]);
73 s16[5*i+3] = convert (f[i+1024]);
74 s16[5*i+4] = convert (f[i+256]);
76 return 5*256;
79 static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
80 int i;
81 int32_t * f = (int32_t *) _f;
82 for (i = 0; i < 256; i++) {
83 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
84 s16[6*i+4] = convert (f[i+256]);
85 s16[6*i+5] = convert (f[i]);
87 return 6*256;
90 static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
91 int i;
92 int32_t * f = (int32_t *) _f;
93 for (i = 0; i < 256; i++) {
94 s16[6*i] = convert (f[i+256]);
95 s16[6*i+1] = convert (f[i+512]);
96 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
97 s16[6*i+5] = convert (f[i]);
99 return 6*256;
102 static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
103 int i;
104 int32_t * f = (int32_t *) _f;
105 for (i = 0; i < 256; i++) {
106 s16[6*i] = convert (f[i+256]);
107 s16[6*i+1] = convert (f[i+768]);
108 s16[6*i+2] = s16[6*i+3] = 0;
109 s16[6*i+4] = convert (f[i+512]);
110 s16[6*i+5] = convert (f[i]);
112 return 6*256;
115 static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
116 int i;
117 int32_t * f = (int32_t *) _f;
118 for (i = 0; i < 256; i++) {
119 s16[6*i] = convert (f[i+256]);
120 s16[6*i+1] = convert (f[i+512]);
121 s16[6*i+2] = convert (f[i+768]);
122 s16[6*i+3] = convert (f[i+1024]);
123 s16[6*i+4] = 0;
124 s16[6*i+5] = convert (f[i]);
126 return 6*256;
129 static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
130 int i;
131 int32_t * f = (int32_t *) _f;
132 for (i = 0; i < 256; i++) {
133 s16[6*i] = convert (f[i+256]);
134 s16[6*i+1] = convert (f[i+768]);
135 s16[6*i+2] = convert (f[i+1024]);
136 s16[6*i+3] = convert (f[i+1280]);
137 s16[6*i+4] = convert (f[i+512]);
138 s16[6*i+5] = convert (f[i]);
140 return 6*256;
144 static void* a52_resample_C(int flags, int ch){
145 switch (flags) {
146 case A52_MONO:
147 if(ch==5) return a52_resample_MONO_to_5_C;
148 if(ch==1) return a52_resample_MONO_to_1_C;
149 break;
150 case A52_CHANNEL:
151 case A52_STEREO:
152 case A52_DOLBY:
153 if(ch==2) return a52_resample_STEREO_to_2_C;
154 break;
155 case A52_3F:
156 if(ch==5) return a52_resample_3F_to_5_C;
157 break;
158 case A52_2F2R:
159 if(ch==4) return a52_resample_2F_2R_to_4_C;
160 break;
161 case A52_3F2R:
162 if(ch==5) return a52_resample_3F_2R_to_5_C;
163 break;
164 case A52_MONO | A52_LFE:
165 if(ch==6) return a52_resample_MONO_LFE_to_6_C;
166 break;
167 case A52_CHANNEL | A52_LFE:
168 case A52_STEREO | A52_LFE:
169 case A52_DOLBY | A52_LFE:
170 if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
171 break;
172 case A52_3F | A52_LFE:
173 if(ch==6) return a52_resample_3F_LFE_to_6_C;
174 break;
175 case A52_2F2R | A52_LFE:
176 if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
177 break;
178 case A52_3F2R | A52_LFE:
179 if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
180 break;
182 return NULL;