4 * Copyright (c) 2004-2005 Vassili Karpov (malc)
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * Tusen tack till Mike Nordell
27 * dec++'ified by Dscho
31 #define HALF (IN_MAX >> 1)
38 #define VOL(a, b) ((a) * (b))
40 #define VOL(a, b) ((a) * (b)) >> 32
44 #define ET glue (ENDIAN_CONVERSION, glue (_, IN_T))
47 static real_t
inline glue (conv_
, ET
) (IN_T v
)
49 IN_T nv
= ENDIAN_CONVERT (v
);
53 return nv
* (1.f
/ (real_t
) (IN_MAX
- IN_MIN
));
55 return (nv
- HALF
) * (1.f
/ (real_t
) IN_MAX
);
57 #else /* !RECIPROCAL */
59 return nv
/ (real_t
) (IN_MAX
- IN_MIN
);
61 return (nv
- HALF
) / (real_t
) IN_MAX
;
66 static IN_T
inline glue (clip_
, ET
) (real_t v
)
76 return ENDIAN_CONVERT ((IN_T
) (v
* (IN_MAX
- IN_MIN
)));
78 return ENDIAN_CONVERT ((IN_T
) ((v
* IN_MAX
) + HALF
));
82 #else /* !FLOAT_MIXENG */
84 static inline int64_t glue (conv_
, ET
) (IN_T v
)
86 IN_T nv
= ENDIAN_CONVERT (v
);
88 return ((int64_t) nv
) << (32 - SHIFT
);
90 return ((int64_t) nv
- HALF
) << (32 - SHIFT
);
94 static inline IN_T
glue (clip_
, ET
) (int64_t v
)
96 if (v
>= 0x7f000000) {
99 else if (v
< -2147483648LL) {
104 return ENDIAN_CONVERT ((IN_T
) (v
>> (32 - SHIFT
)));
106 return ENDIAN_CONVERT ((IN_T
) ((v
>> (32 - SHIFT
)) + HALF
));
111 static void glue (glue (conv_
, ET
), _to_stereo
)
112 (st_sample_t
*dst
, const void *src
, int samples
, volume_t
*vol
)
114 st_sample_t
*out
= dst
;
115 IN_T
*in
= (IN_T
*) src
;
118 mixeng_clear (dst
, samples
);
125 out
->l
= VOL (glue (conv_
, ET
) (*in
++), vol
->l
);
126 out
->r
= VOL (glue (conv_
, ET
) (*in
++), vol
->r
);
131 static void glue (glue (conv_
, ET
), _to_mono
)
132 (st_sample_t
*dst
, const void *src
, int samples
, volume_t
*vol
)
134 st_sample_t
*out
= dst
;
135 IN_T
*in
= (IN_T
*) src
;
138 mixeng_clear (dst
, samples
);
145 out
->l
= VOL (glue (conv_
, ET
) (in
[0]), vol
->l
);
152 static void glue (glue (clip_
, ET
), _from_stereo
)
153 (void *dst
, const st_sample_t
*src
, int samples
)
155 const st_sample_t
*in
= src
;
156 IN_T
*out
= (IN_T
*) dst
;
158 *out
++ = glue (clip_
, ET
) (in
->l
);
159 *out
++ = glue (clip_
, ET
) (in
->r
);
164 static void glue (glue (clip_
, ET
), _from_mono
)
165 (void *dst
, const st_sample_t
*src
, int samples
)
167 const st_sample_t
*in
= src
;
168 IN_T
*out
= (IN_T
*) dst
;
170 *out
++ = glue (clip_
, ET
) (in
->l
+ in
->r
);