4 * Copyright (c) 2004 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
34 #define HALFT ((IN_MAX)>>1)
38 static int64_t inline glue(conv_,IN_T) (IN_T v)
41 return (INT_MAX*(int64_t)v)/HALF;
43 return (INT_MAX*((int64_t)v-HALFT))/HALF;
47 static IN_T inline glue(clip_,IN_T) (int64_t v)
51 else if (v < -INT_MAX)
55 return (IN_T) (v*HALF/INT_MAX);
57 return (IN_T) (v+INT_MAX/2)*HALF/INT_MAX;
61 static void glue(glue(conv_,IN_T),_to_stereo) (void *dst, const void *src,
64 st_sample_t *out = (st_sample_t *) dst;
65 IN_T *in = (IN_T *) src;
67 out->l = glue(conv_,IN_T) (*in++);
68 out->r = glue(conv_,IN_T) (*in++);
73 static void glue(glue(conv_,IN_T),_to_mono) (void *dst, const void *src,
76 st_sample_t *out = (st_sample_t *) dst;
77 IN_T *in = (IN_T *) src;
79 out->l = glue(conv_,IN_T) (in[0]);
86 static void glue(glue(clip_,IN_T),_from_stereo) (void *dst, const void *src,
89 st_sample_t *in = (st_sample_t *) src;
90 IN_T *out = (IN_T *) dst;
92 *out++ = glue(clip_,IN_T) (in->l);
93 *out++ = glue(clip_,IN_T) (in->r);
98 static void glue(glue(clip_,IN_T),_from_mono) (void *dst, const void *src,
101 st_sample_t *in = (st_sample_t *) src;
102 IN_T *out = (IN_T *) dst;
104 *out++ = glue(clip_,IN_T) (in->l + in->r);