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)
34 #define ET glue (ENDIAN_CONVERSION, glue (_, IN_T))
37 static mixeng_real inline glue (conv_, ET) (IN_T v)
39 IN_T nv = ENDIAN_CONVERT (v);
43 return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN));
45 return (nv - HALF) * (1.f / (mixeng_real) IN_MAX);
47 #else /* !RECIPROCAL */
49 return nv / (mixeng_real) (IN_MAX - IN_MIN);
51 return (nv - HALF) / (mixeng_real) IN_MAX;
56 static IN_T inline glue (clip_, ET) (mixeng_real v)
66 return ENDIAN_CONVERT ((IN_T) (v * (IN_MAX - IN_MIN)));
68 return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
72 #else /* !FLOAT_MIXENG */
74 static inline int64_t glue (conv_, ET) (IN_T v)
76 IN_T nv = ENDIAN_CONVERT (v);
78 return ((int64_t) nv) << (32 - SHIFT);
80 return ((int64_t) nv - HALF) << (32 - SHIFT);
84 static inline IN_T glue (clip_, ET) (int64_t v)
86 if (v >= 0x7f000000) {
89 else if (v < -2147483648LL) {
94 return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT)));
96 return ENDIAN_CONVERT ((IN_T) ((v >> (32 - SHIFT)) + HALF));
101 static void glue (glue (conv_, ET), _to_stereo)
102 (struct st_sample *dst, const void *src, int samples)
104 struct st_sample *out = dst;
105 IN_T *in = (IN_T *) src;
108 out->l = glue (conv_, ET) (*in++);
109 out->r = glue (conv_, ET) (*in++);
114 static void glue (glue (conv_, ET), _to_mono)
115 (struct st_sample *dst, const void *src, int samples)
117 struct st_sample *out = dst;
118 IN_T *in = (IN_T *) src;
121 out->l = glue (conv_, ET) (in[0]);
128 static void glue (glue (clip_, ET), _from_stereo)
129 (void *dst, const struct st_sample *src, int samples)
131 const struct st_sample *in = src;
132 IN_T *out = (IN_T *) dst;
134 *out++ = glue (clip_, ET) (in->l);
135 *out++ = glue (clip_, ET) (in->r);
140 static void glue (glue (clip_, ET), _from_mono)
141 (void *dst, const struct st_sample *src, int samples)
143 const struct st_sample *in = src;
144 IN_T *out = (IN_T *) dst;
146 *out++ = glue (clip_, ET) (in->l + in->r);