]> git.proxmox.com Git - mirror_qemu.git/blame - audio/mixeng_template.h
audio: error hints need a trailing \n
[mirror_qemu.git] / audio / mixeng_template.h
CommitLineData
85571bc7
FB
1/*
2 * QEMU Mixing engine
1d14ffa9
FB
3 *
4 * Copyright (c) 2004-2005 Vassili Karpov (malc)
5 *
85571bc7
FB
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
24
25/*
26 * Tusen tack till Mike Nordell
27 * dec++'ified by Dscho
28 */
29
1d14ffa9
FB
30#ifndef SIGNED
31#define HALF (IN_MAX >> 1)
32#endif
33
a2885387
RPM
34#define ET glue (ENDIAN_CONVERSION, glue (glue (glue (_, ITYPE), BSIZE), _t))
35#define IN_T glue (glue (ITYPE, BSIZE), _t)
1d14ffa9
FB
36
37#ifdef FLOAT_MIXENG
203cea22 38static inline mixeng_real glue (conv_, ET) (IN_T v)
1d14ffa9
FB
39{
40 IN_T nv = ENDIAN_CONVERT (v);
41
42#ifdef RECIPROCAL
43#ifdef SIGNED
4218fdd7 44 return nv * (2.f / ((mixeng_real)IN_MAX - IN_MIN));
1d14ffa9 45#else
4218fdd7 46 return (nv - HALF) * (2.f / (mixeng_real)IN_MAX);
1d14ffa9
FB
47#endif
48#else /* !RECIPROCAL */
85571bc7 49#ifdef SIGNED
4218fdd7 50 return nv / (((mixeng_real)IN_MAX - IN_MIN) / 2.f);
85571bc7 51#else
4218fdd7 52 return (nv - HALF) / ((mixeng_real)IN_MAX / 2.f);
85571bc7 53#endif
1d14ffa9
FB
54#endif
55}
85571bc7 56
203cea22 57static inline IN_T glue (clip_, ET) (mixeng_real v)
85571bc7 58{
4218fdd7 59 if (v >= 1.f) {
1d14ffa9 60 return IN_MAX;
4218fdd7 61 } else if (v < -1.f) {
1d14ffa9
FB
62 return IN_MIN;
63 }
64
65#ifdef SIGNED
4218fdd7 66 return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f)));
1d14ffa9 67#else
4218fdd7 68 return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF));
1d14ffa9
FB
69#endif
70}
71
72#else /* !FLOAT_MIXENG */
73
74static inline int64_t glue (conv_, ET) (IN_T v)
75{
76 IN_T nv = ENDIAN_CONVERT (v);
85571bc7 77#ifdef SIGNED
1d14ffa9 78 return ((int64_t) nv) << (32 - SHIFT);
85571bc7 79#else
1d14ffa9 80 return ((int64_t) nv - HALF) << (32 - SHIFT);
85571bc7
FB
81#endif
82}
83
1d14ffa9 84static inline IN_T glue (clip_, ET) (int64_t v)
85571bc7 85{
194bdf50 86 if (v >= 0x7fffffffLL) {
85571bc7 87 return IN_MAX;
194bdf50 88 } else if (v < -2147483648LL) {
85571bc7 89 return IN_MIN;
1d14ffa9 90 }
85571bc7
FB
91
92#ifdef SIGNED
1d14ffa9 93 return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT)));
85571bc7 94#else
1d14ffa9 95 return ENDIAN_CONVERT ((IN_T) ((v >> (32 - SHIFT)) + HALF));
85571bc7
FB
96#endif
97}
1d14ffa9 98#endif
85571bc7 99
1d14ffa9 100static void glue (glue (conv_, ET), _to_stereo)
00e07679 101 (struct st_sample *dst, const void *src, int samples)
85571bc7 102{
1ea879e5 103 struct st_sample *out = dst;
85571bc7 104 IN_T *in = (IN_T *) src;
00e07679 105
85571bc7 106 while (samples--) {
00e07679
MW
107 out->l = glue (conv_, ET) (*in++);
108 out->r = glue (conv_, ET) (*in++);
85571bc7
FB
109 out += 1;
110 }
111}
112
1d14ffa9 113static void glue (glue (conv_, ET), _to_mono)
00e07679 114 (struct st_sample *dst, const void *src, int samples)
85571bc7 115{
1ea879e5 116 struct st_sample *out = dst;
85571bc7 117 IN_T *in = (IN_T *) src;
00e07679 118
85571bc7 119 while (samples--) {
00e07679 120 out->l = glue (conv_, ET) (in[0]);
85571bc7
FB
121 out->r = out->l;
122 out += 1;
123 in += 1;
124 }
125}
126
1d14ffa9 127static void glue (glue (clip_, ET), _from_stereo)
1ea879e5 128 (void *dst, const struct st_sample *src, int samples)
85571bc7 129{
1ea879e5 130 const struct st_sample *in = src;
85571bc7
FB
131 IN_T *out = (IN_T *) dst;
132 while (samples--) {
1d14ffa9
FB
133 *out++ = glue (clip_, ET) (in->l);
134 *out++ = glue (clip_, ET) (in->r);
85571bc7
FB
135 in += 1;
136 }
137}
138
1d14ffa9 139static void glue (glue (clip_, ET), _from_mono)
1ea879e5 140 (void *dst, const struct st_sample *src, int samples)
85571bc7 141{
1ea879e5 142 const struct st_sample *in = src;
85571bc7
FB
143 IN_T *out = (IN_T *) dst;
144 while (samples--) {
1d14ffa9 145 *out++ = glue (clip_, ET) (in->l + in->r);
85571bc7
FB
146 in += 1;
147 }
148}
149
1d14ffa9 150#undef ET
85571bc7 151#undef HALF
a2885387 152#undef IN_T