1 // this code is based on a52dec/libao/audio_out_oss.c
3 static inline int16_t convert (int32_t i
)
7 else if (i
< 0x43bf8000)
10 return i
- 0x43c00000;
13 static int a52_resample_MONO_to_5_C(float * _f
, int16_t * s16
){
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
]);
23 static int a52_resample_MONO_to_1_C(float * _f
, int16_t * s16
){
25 int32_t * f
= (int32_t *) _f
;
26 for (i
= 0; i
< 256; i
++) {
27 s16
[i
] = convert (f
[i
]);
32 static int a52_resample_STEREO_to_2_C(float * _f
, int16_t * s16
){
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]);
42 static int a52_resample_3F_to_5_C(float * _f
, int16_t * s16
){
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]);
54 static int a52_resample_2F_2R_to_4_C(float * _f
, int16_t * s16
){
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]);
66 static int a52_resample_3F_2R_to_5_C(float * _f
, int16_t * s16
){
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]);
79 static int a52_resample_MONO_LFE_to_6_C(float * _f
, int16_t * s16
){
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
]);
90 static int a52_resample_STEREO_LFE_to_6_C(float * _f
, int16_t * s16
){
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
]);
102 static int a52_resample_3F_LFE_to_6_C(float * _f
, int16_t * s16
){
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
]);
115 static int a52_resample_2F_2R_LFE_to_6_C(float * _f
, int16_t * s16
){
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]);
124 s16
[6*i
+5] = convert (f
[i
]);
129 static int a52_resample_3F_2R_LFE_to_6_C(float * _f
, int16_t * s16
){
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
]);
144 static void* a52_resample_C(int flags
, int ch
){
147 if(ch
==5) return a52_resample_MONO_to_5_C
;
148 if(ch
==1) return a52_resample_MONO_to_1_C
;
153 if(ch
==2) return a52_resample_STEREO_to_2_C
;
156 if(ch
==5) return a52_resample_3F_to_5_C
;
159 if(ch
==4) return a52_resample_2F_2R_to_4_C
;
162 if(ch
==5) return a52_resample_3F_2R_to_5_C
;
164 case A52_MONO
| A52_LFE
:
165 if(ch
==6) return a52_resample_MONO_LFE_to_6_C
;
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
;
172 case A52_3F
| A52_LFE
:
173 if(ch
==6) return a52_resample_3F_LFE_to_6_C
;
175 case A52_2F2R
| A52_LFE
:
176 if(ch
==6) return a52_resample_2F_2R_LFE_to_6_C
;
178 case A52_3F2R
| A52_LFE
:
179 if(ch
==6) return a52_resample_3F_2R_LFE_to_6_C
;