/src/qemu/audio/mixeng_template.h
Line | Count | Source |
1 | | /* |
2 | | * QEMU Mixing engine |
3 | | * |
4 | | * Copyright (c) 2004-2005 Vassili Karpov (malc) |
5 | | * |
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 | | |
30 | | #ifndef SIGNED |
31 | 224M | #define BIAS ((IN_T)1 << (SHIFT - 1)) |
32 | | #endif |
33 | | |
34 | | #define ET glue (ENDIAN_CONVERSION, glue (glue (glue (_, ITYPE), BSIZE), _t)) |
35 | 1.80G | #define IN_T glue (glue (ITYPE, BSIZE), _t) |
36 | | |
37 | | #ifdef FLOAT_MIXENG |
38 | | static inline mixeng_real glue (conv_, ET) (IN_T v) |
39 | | { |
40 | | IN_T nv = ENDIAN_CONVERT (v); |
41 | | |
42 | | #ifdef RECIPROCAL |
43 | | #ifdef SIGNED |
44 | | return nv * (2.f / ((mixeng_real)IN_MAX - IN_MIN)); |
45 | | #else |
46 | | return ((mixeng_real)nv - BIAS) * (1.f / BIAS); |
47 | | #endif |
48 | | #else /* !RECIPROCAL */ |
49 | | #ifdef SIGNED |
50 | | return nv / (((mixeng_real)IN_MAX - IN_MIN) / 2.f); |
51 | | #else |
52 | | return ((mixeng_real)nv - BIAS) / BIAS; |
53 | | #endif |
54 | | #endif |
55 | | } |
56 | | |
57 | | static inline IN_T glue (clip_, ET) (mixeng_real v) |
58 | | { |
59 | | if (v >= 1.f) { |
60 | | return IN_MAX; |
61 | | } else if (v < -1.f) { |
62 | | return IN_MIN; |
63 | | } |
64 | | |
65 | | #ifdef SIGNED |
66 | | return ENDIAN_CONVERT((IN_T)(v * (((mixeng_real)IN_MAX - IN_MIN) / 2.f))); |
67 | | #else |
68 | | return ENDIAN_CONVERT(MIN((int64_t)(v * BIAS) + BIAS, IN_MAX)); |
69 | | #endif |
70 | | } |
71 | | |
72 | | #else /* !FLOAT_MIXENG */ |
73 | | |
74 | | static inline int64_t glue (conv_, ET) (IN_T v) |
75 | 1.78G | { |
76 | 1.78G | IN_T nv = ENDIAN_CONVERT (v); |
77 | | #ifdef SIGNED |
78 | 1.56G | return ((int64_t) nv) << (32 - SHIFT); |
79 | | #else |
80 | 224M | return ((int64_t) nv - BIAS) << (32 - SHIFT); |
81 | | #endif |
82 | 1.78G | } mixeng.c:conv_natural_uint8_t Line | Count | Source | 75 | 221M | { | 76 | 221M | IN_T nv = ENDIAN_CONVERT (v); | 77 | | #ifdef SIGNED | 78 | | return ((int64_t) nv) << (32 - SHIFT); | 79 | | #else | 80 | 221M | return ((int64_t) nv - BIAS) << (32 - SHIFT); | 81 | 221M | #endif | 82 | 221M | } |
mixeng.c:conv_natural_uint16_t Line | Count | Source | 75 | 3.08M | { | 76 | 3.08M | IN_T nv = ENDIAN_CONVERT (v); | 77 | | #ifdef SIGNED | 78 | | return ((int64_t) nv) << (32 - SHIFT); | 79 | | #else | 80 | 3.08M | return ((int64_t) nv - BIAS) << (32 - SHIFT); | 81 | 3.08M | #endif | 82 | 3.08M | } |
Unexecuted instantiation: mixeng.c:conv_natural_uint32_t Unexecuted instantiation: mixeng.c:conv_swap_uint16_t Unexecuted instantiation: mixeng.c:conv_swap_uint32_t mixeng.c:conv_natural_int8_t Line | Count | Source | 75 | 85.6M | { | 76 | 85.6M | IN_T nv = ENDIAN_CONVERT (v); | 77 | 85.6M | #ifdef SIGNED | 78 | 85.6M | return ((int64_t) nv) << (32 - SHIFT); | 79 | | #else | 80 | | return ((int64_t) nv - BIAS) << (32 - SHIFT); | 81 | | #endif | 82 | 85.6M | } |
mixeng.c:conv_natural_int16_t Line | Count | Source | 75 | 1.40G | { | 76 | 1.40G | IN_T nv = ENDIAN_CONVERT (v); | 77 | 1.40G | #ifdef SIGNED | 78 | 1.40G | return ((int64_t) nv) << (32 - SHIFT); | 79 | | #else | 80 | | return ((int64_t) nv - BIAS) << (32 - SHIFT); | 81 | | #endif | 82 | 1.40G | } |
Unexecuted instantiation: mixeng.c:conv_natural_int32_t mixeng.c:conv_swap_int16_t Line | Count | Source | 75 | 75.0M | { | 76 | 75.0M | IN_T nv = ENDIAN_CONVERT (v); | 77 | 75.0M | #ifdef SIGNED | 78 | 75.0M | return ((int64_t) nv) << (32 - SHIFT); | 79 | | #else | 80 | | return ((int64_t) nv - BIAS) << (32 - SHIFT); | 81 | | #endif | 82 | 75.0M | } |
Unexecuted instantiation: mixeng.c:conv_swap_int32_t |
83 | | |
84 | | static inline IN_T glue (clip_, ET) (int64_t v) |
85 | 1.60G | { |
86 | 1.60G | if (v >= 0x7fffffffLL) { |
87 | 15.2M | return IN_MAX; |
88 | 1.58G | } else if (v < -2147483648LL) { |
89 | 100M | return IN_MIN; |
90 | 100M | } |
91 | | |
92 | | #ifdef SIGNED |
93 | 1.45G | return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT))); |
94 | | #else |
95 | 29.3M | return ENDIAN_CONVERT((IN_T)((v >> (32 - SHIFT)) + BIAS)); |
96 | | #endif |
97 | 1.60G | } mixeng.c:clip_natural_uint8_t Line | Count | Source | 85 | 29.3M | { | 86 | 29.3M | if (v >= 0x7fffffffLL) { | 87 | 0 | return IN_MAX; | 88 | 29.3M | } else if (v < -2147483648LL) { | 89 | 0 | return IN_MIN; | 90 | 0 | } | 91 | | | 92 | | #ifdef SIGNED | 93 | | return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT))); | 94 | | #else | 95 | 29.3M | return ENDIAN_CONVERT((IN_T)((v >> (32 - SHIFT)) + BIAS)); | 96 | 29.3M | #endif | 97 | 29.3M | } |
Unexecuted instantiation: mixeng.c:clip_natural_uint16_t Unexecuted instantiation: mixeng.c:clip_natural_uint32_t Unexecuted instantiation: mixeng.c:clip_swap_uint16_t Unexecuted instantiation: mixeng.c:clip_swap_uint32_t Unexecuted instantiation: mixeng.c:clip_natural_int8_t mixeng.c:clip_natural_int16_t Line | Count | Source | 85 | 1.57G | { | 86 | 1.57G | if (v >= 0x7fffffffLL) { | 87 | 15.2M | return IN_MAX; | 88 | 1.55G | } else if (v < -2147483648LL) { | 89 | 100M | return IN_MIN; | 90 | 100M | } | 91 | | | 92 | 1.45G | #ifdef SIGNED | 93 | 1.45G | return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT))); | 94 | | #else | 95 | | return ENDIAN_CONVERT((IN_T)((v >> (32 - SHIFT)) + BIAS)); | 96 | | #endif | 97 | 1.57G | } |
Unexecuted instantiation: mixeng.c:clip_natural_int32_t Unexecuted instantiation: mixeng.c:clip_swap_int16_t Unexecuted instantiation: mixeng.c:clip_swap_int32_t |
98 | | #endif |
99 | | |
100 | | static void glue (glue (conv_, ET), _to_stereo) |
101 | | (struct st_sample *dst, const void *src, int samples) |
102 | 11.0M | { |
103 | 11.0M | struct st_sample *out = dst; |
104 | 11.0M | IN_T *in = (IN_T *) src; |
105 | | |
106 | 809M | while (samples--) { |
107 | 798M | out->l = glue (conv_, ET) (*in++); |
108 | 798M | out->r = glue (conv_, ET) (*in++); |
109 | 798M | out += 1; |
110 | 798M | } |
111 | 11.0M | } mixeng.c:conv_natural_uint8_t_to_stereo Line | Count | Source | 102 | 1.01M | { | 103 | 1.01M | struct st_sample *out = dst; | 104 | 1.01M | IN_T *in = (IN_T *) src; | 105 | | | 106 | 58.3M | while (samples--) { | 107 | 57.3M | out->l = glue (conv_, ET) (*in++); | 108 | 57.3M | out->r = glue (conv_, ET) (*in++); | 109 | 57.3M | out += 1; | 110 | 57.3M | } | 111 | 1.01M | } |
mixeng.c:conv_natural_uint16_t_to_stereo Line | Count | Source | 102 | 4.75k | { | 103 | 4.75k | struct st_sample *out = dst; | 104 | 4.75k | IN_T *in = (IN_T *) src; | 105 | | | 106 | 346k | while (samples--) { | 107 | 341k | out->l = glue (conv_, ET) (*in++); | 108 | 341k | out->r = glue (conv_, ET) (*in++); | 109 | 341k | out += 1; | 110 | 341k | } | 111 | 4.75k | } |
Unexecuted instantiation: mixeng.c:conv_natural_uint32_t_to_stereo Unexecuted instantiation: mixeng.c:conv_swap_uint16_t_to_stereo Unexecuted instantiation: mixeng.c:conv_swap_uint32_t_to_stereo mixeng.c:conv_natural_int8_t_to_stereo Line | Count | Source | 102 | 195k | { | 103 | 195k | struct st_sample *out = dst; | 104 | 195k | IN_T *in = (IN_T *) src; | 105 | | | 106 | 11.1M | while (samples--) { | 107 | 10.9M | out->l = glue (conv_, ET) (*in++); | 108 | 10.9M | out->r = glue (conv_, ET) (*in++); | 109 | 10.9M | out += 1; | 110 | 10.9M | } | 111 | 195k | } |
mixeng.c:conv_natural_int16_t_to_stereo Line | Count | Source | 102 | 8.88M | { | 103 | 8.88M | struct st_sample *out = dst; | 104 | 8.88M | IN_T *in = (IN_T *) src; | 105 | | | 106 | 701M | while (samples--) { | 107 | 692M | out->l = glue (conv_, ET) (*in++); | 108 | 692M | out->r = glue (conv_, ET) (*in++); | 109 | 692M | out += 1; | 110 | 692M | } | 111 | 8.88M | } |
Unexecuted instantiation: mixeng.c:conv_natural_int32_t_to_stereo mixeng.c:conv_swap_int16_t_to_stereo Line | Count | Source | 102 | 921k | { | 103 | 921k | struct st_sample *out = dst; | 104 | 921k | IN_T *in = (IN_T *) src; | 105 | | | 106 | 38.2M | while (samples--) { | 107 | 37.2M | out->l = glue (conv_, ET) (*in++); | 108 | 37.2M | out->r = glue (conv_, ET) (*in++); | 109 | 37.2M | out += 1; | 110 | 37.2M | } | 111 | 921k | } |
Unexecuted instantiation: mixeng.c:conv_swap_int32_t_to_stereo |
112 | | |
113 | | static void glue (glue (conv_, ET), _to_mono) |
114 | | (struct st_sample *dst, const void *src, int samples) |
115 | 5.65M | { |
116 | 5.65M | struct st_sample *out = dst; |
117 | 5.65M | IN_T *in = (IN_T *) src; |
118 | | |
119 | 194M | while (samples--) { |
120 | 188M | out->l = glue (conv_, ET) (in[0]); |
121 | 188M | out->r = out->l; |
122 | 188M | out += 1; |
123 | 188M | in += 1; |
124 | 188M | } |
125 | 5.65M | } mixeng.c:conv_natural_uint8_t_to_mono Line | Count | Source | 115 | 2.90M | { | 116 | 2.90M | struct st_sample *out = dst; | 117 | 2.90M | IN_T *in = (IN_T *) src; | 118 | | | 119 | 109M | while (samples--) { | 120 | 106M | out->l = glue (conv_, ET) (in[0]); | 121 | 106M | out->r = out->l; | 122 | 106M | out += 1; | 123 | 106M | in += 1; | 124 | 106M | } | 125 | 2.90M | } |
mixeng.c:conv_natural_uint16_t_to_mono Line | Count | Source | 115 | 18.2k | { | 116 | 18.2k | struct st_sample *out = dst; | 117 | 18.2k | IN_T *in = (IN_T *) src; | 118 | | | 119 | 2.42M | while (samples--) { | 120 | 2.40M | out->l = glue (conv_, ET) (in[0]); | 121 | 2.40M | out->r = out->l; | 122 | 2.40M | out += 1; | 123 | 2.40M | in += 1; | 124 | 2.40M | } | 125 | 18.2k | } |
Unexecuted instantiation: mixeng.c:conv_natural_uint32_t_to_mono Unexecuted instantiation: mixeng.c:conv_swap_uint16_t_to_mono Unexecuted instantiation: mixeng.c:conv_swap_uint32_t_to_mono mixeng.c:conv_natural_int8_t_to_mono Line | Count | Source | 115 | 1.92M | { | 116 | 1.92M | struct st_sample *out = dst; | 117 | 1.92M | IN_T *in = (IN_T *) src; | 118 | | | 119 | 65.6M | while (samples--) { | 120 | 63.7M | out->l = glue (conv_, ET) (in[0]); | 121 | 63.7M | out->r = out->l; | 122 | 63.7M | out += 1; | 123 | 63.7M | in += 1; | 124 | 63.7M | } | 125 | 1.92M | } |
mixeng.c:conv_natural_int16_t_to_mono Line | Count | Source | 115 | 754k | { | 116 | 754k | struct st_sample *out = dst; | 117 | 754k | IN_T *in = (IN_T *) src; | 118 | | | 119 | 15.9M | while (samples--) { | 120 | 15.1M | out->l = glue (conv_, ET) (in[0]); | 121 | 15.1M | out->r = out->l; | 122 | 15.1M | out += 1; | 123 | 15.1M | in += 1; | 124 | 15.1M | } | 125 | 754k | } |
Unexecuted instantiation: mixeng.c:conv_natural_int32_t_to_mono mixeng.c:conv_swap_int16_t_to_mono Line | Count | Source | 115 | 45.6k | { | 116 | 45.6k | struct st_sample *out = dst; | 117 | 45.6k | IN_T *in = (IN_T *) src; | 118 | | | 119 | 484k | while (samples--) { | 120 | 438k | out->l = glue (conv_, ET) (in[0]); | 121 | 438k | out->r = out->l; | 122 | 438k | out += 1; | 123 | 438k | in += 1; | 124 | 438k | } | 125 | 45.6k | } |
Unexecuted instantiation: mixeng.c:conv_swap_int32_t_to_mono |
126 | | |
127 | | static void glue (glue (clip_, ET), _from_stereo) |
128 | | (void *dst, const struct st_sample *src, int samples) |
129 | 3.59M | { |
130 | 3.59M | const struct st_sample *in = src; |
131 | 3.59M | IN_T *out = (IN_T *) dst; |
132 | 804M | while (samples--) { |
133 | 800M | *out++ = glue (clip_, ET) (in->l); |
134 | 800M | *out++ = glue (clip_, ET) (in->r); |
135 | 800M | in += 1; |
136 | 800M | } |
137 | 3.59M | } mixeng.c:clip_natural_uint8_t_from_stereo Line | Count | Source | 129 | 144k | { | 130 | 144k | const struct st_sample *in = src; | 131 | 144k | IN_T *out = (IN_T *) dst; | 132 | 14.7M | while (samples--) { | 133 | 14.5M | *out++ = glue (clip_, ET) (in->l); | 134 | 14.5M | *out++ = glue (clip_, ET) (in->r); | 135 | 14.5M | in += 1; | 136 | 14.5M | } | 137 | 144k | } |
Unexecuted instantiation: mixeng.c:clip_natural_uint16_t_from_stereo Unexecuted instantiation: mixeng.c:clip_natural_uint32_t_from_stereo Unexecuted instantiation: mixeng.c:clip_swap_uint16_t_from_stereo Unexecuted instantiation: mixeng.c:clip_swap_uint32_t_from_stereo Unexecuted instantiation: mixeng.c:clip_natural_int8_t_from_stereo mixeng.c:clip_natural_int16_t_from_stereo Line | Count | Source | 129 | 3.45M | { | 130 | 3.45M | const struct st_sample *in = src; | 131 | 3.45M | IN_T *out = (IN_T *) dst; | 132 | 789M | while (samples--) { | 133 | 786M | *out++ = glue (clip_, ET) (in->l); | 134 | 786M | *out++ = glue (clip_, ET) (in->r); | 135 | 786M | in += 1; | 136 | 786M | } | 137 | 3.45M | } |
Unexecuted instantiation: mixeng.c:clip_natural_int32_t_from_stereo Unexecuted instantiation: mixeng.c:clip_swap_int16_t_from_stereo Unexecuted instantiation: mixeng.c:clip_swap_int32_t_from_stereo |
138 | | |
139 | | static void glue (glue (clip_, ET), _from_mono) |
140 | | (void *dst, const struct st_sample *src, int samples) |
141 | 17.1k | { |
142 | 17.1k | const struct st_sample *in = src; |
143 | 17.1k | IN_T *out = (IN_T *) dst; |
144 | 229k | while (samples--) { |
145 | 211k | *out++ = glue (clip_, ET) (in->l + in->r); |
146 | 211k | in += 1; |
147 | 211k | } |
148 | 17.1k | } mixeng.c:clip_natural_uint8_t_from_mono Line | Count | Source | 141 | 13.1k | { | 142 | 13.1k | const struct st_sample *in = src; | 143 | 13.1k | IN_T *out = (IN_T *) dst; | 144 | 200k | while (samples--) { | 145 | 187k | *out++ = glue (clip_, ET) (in->l + in->r); | 146 | 187k | in += 1; | 147 | 187k | } | 148 | 13.1k | } |
Unexecuted instantiation: mixeng.c:clip_natural_uint16_t_from_mono Unexecuted instantiation: mixeng.c:clip_natural_uint32_t_from_mono Unexecuted instantiation: mixeng.c:clip_swap_uint16_t_from_mono Unexecuted instantiation: mixeng.c:clip_swap_uint32_t_from_mono Unexecuted instantiation: mixeng.c:clip_natural_int8_t_from_mono mixeng.c:clip_natural_int16_t_from_mono Line | Count | Source | 141 | 3.97k | { | 142 | 3.97k | const struct st_sample *in = src; | 143 | 3.97k | IN_T *out = (IN_T *) dst; | 144 | 28.7k | while (samples--) { | 145 | 24.7k | *out++ = glue (clip_, ET) (in->l + in->r); | 146 | 24.7k | in += 1; | 147 | 24.7k | } | 148 | 3.97k | } |
Unexecuted instantiation: mixeng.c:clip_natural_int32_t_from_mono Unexecuted instantiation: mixeng.c:clip_swap_int16_t_from_mono Unexecuted instantiation: mixeng.c:clip_swap_int32_t_from_mono |
149 | | |
150 | | #undef ET |
151 | | #undef BIAS |
152 | | #undef IN_T |