root / audio / mixeng_template.h @ afc7df11
History | View | Annotate | Download (3.1 kB)
1 | 85571bc7 | bellard | /*
|
---|---|---|---|
2 | 85571bc7 | bellard | * QEMU Mixing engine
|
3 | 85571bc7 | bellard | *
|
4 | 85571bc7 | bellard | * Copyright (c) 2004 Vassili Karpov (malc)
|
5 | 85571bc7 | bellard | *
|
6 | 85571bc7 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 85571bc7 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 85571bc7 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 85571bc7 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 85571bc7 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 85571bc7 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 85571bc7 | bellard | *
|
13 | 85571bc7 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 85571bc7 | bellard | * all copies or substantial portions of the Software.
|
15 | 85571bc7 | bellard | *
|
16 | 85571bc7 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 85571bc7 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 85571bc7 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 85571bc7 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 85571bc7 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 85571bc7 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 85571bc7 | bellard | * THE SOFTWARE.
|
23 | 85571bc7 | bellard | */
|
24 | 85571bc7 | bellard | |
25 | 85571bc7 | bellard | /*
|
26 | 85571bc7 | bellard | * Tusen tack till Mike Nordell
|
27 | 85571bc7 | bellard | * dec++'ified by Dscho
|
28 | 85571bc7 | bellard | */
|
29 | 85571bc7 | bellard | |
30 | 85571bc7 | bellard | #ifdef SIGNED
|
31 | 85571bc7 | bellard | #define HALFT IN_MAX
|
32 | 85571bc7 | bellard | #define HALF IN_MAX
|
33 | 85571bc7 | bellard | #else
|
34 | 85571bc7 | bellard | #define HALFT ((IN_MAX)>>1) |
35 | 85571bc7 | bellard | #define HALF HALFT
|
36 | 85571bc7 | bellard | #endif
|
37 | 85571bc7 | bellard | |
38 | 85571bc7 | bellard | static int64_t inline glue(conv_,IN_T) (IN_T v) |
39 | 85571bc7 | bellard | { |
40 | 85571bc7 | bellard | #ifdef SIGNED
|
41 | 85571bc7 | bellard | return (INT_MAX*(int64_t)v)/HALF;
|
42 | 85571bc7 | bellard | #else
|
43 | 85571bc7 | bellard | return (INT_MAX*((int64_t)v-HALFT))/HALF;
|
44 | 85571bc7 | bellard | #endif
|
45 | 85571bc7 | bellard | } |
46 | 85571bc7 | bellard | |
47 | 85571bc7 | bellard | static IN_T inline glue(clip_,IN_T) (int64_t v) |
48 | 85571bc7 | bellard | { |
49 | 85571bc7 | bellard | if (v >= INT_MAX)
|
50 | 85571bc7 | bellard | return IN_MAX;
|
51 | 85571bc7 | bellard | else if (v < -INT_MAX) |
52 | 85571bc7 | bellard | return IN_MIN;
|
53 | 85571bc7 | bellard | |
54 | 85571bc7 | bellard | #ifdef SIGNED
|
55 | 85571bc7 | bellard | return (IN_T) (v*HALF/INT_MAX);
|
56 | 85571bc7 | bellard | #else
|
57 | 85571bc7 | bellard | return (IN_T) (v+INT_MAX/2)*HALF/INT_MAX; |
58 | 85571bc7 | bellard | #endif
|
59 | 85571bc7 | bellard | } |
60 | 85571bc7 | bellard | |
61 | 85571bc7 | bellard | static void glue(glue(conv_,IN_T),_to_stereo) (void *dst, const void *src, |
62 | 85571bc7 | bellard | int samples)
|
63 | 85571bc7 | bellard | { |
64 | 85571bc7 | bellard | st_sample_t *out = (st_sample_t *) dst; |
65 | 85571bc7 | bellard | IN_T *in = (IN_T *) src; |
66 | 85571bc7 | bellard | while (samples--) {
|
67 | 85571bc7 | bellard | out->l = glue(conv_,IN_T) (*in++); |
68 | 85571bc7 | bellard | out->r = glue(conv_,IN_T) (*in++); |
69 | 85571bc7 | bellard | out += 1;
|
70 | 85571bc7 | bellard | } |
71 | 85571bc7 | bellard | } |
72 | 85571bc7 | bellard | |
73 | 85571bc7 | bellard | static void glue(glue(conv_,IN_T),_to_mono) (void *dst, const void *src, |
74 | 85571bc7 | bellard | int samples)
|
75 | 85571bc7 | bellard | { |
76 | 85571bc7 | bellard | st_sample_t *out = (st_sample_t *) dst; |
77 | 85571bc7 | bellard | IN_T *in = (IN_T *) src; |
78 | 85571bc7 | bellard | while (samples--) {
|
79 | 85571bc7 | bellard | out->l = glue(conv_,IN_T) (in[0]);
|
80 | 85571bc7 | bellard | out->r = out->l; |
81 | 85571bc7 | bellard | out += 1;
|
82 | 85571bc7 | bellard | in += 1;
|
83 | 85571bc7 | bellard | } |
84 | 85571bc7 | bellard | } |
85 | 85571bc7 | bellard | |
86 | 85571bc7 | bellard | static void glue(glue(clip_,IN_T),_from_stereo) (void *dst, const void *src, |
87 | 85571bc7 | bellard | int samples)
|
88 | 85571bc7 | bellard | { |
89 | 85571bc7 | bellard | st_sample_t *in = (st_sample_t *) src; |
90 | 85571bc7 | bellard | IN_T *out = (IN_T *) dst; |
91 | 85571bc7 | bellard | while (samples--) {
|
92 | 85571bc7 | bellard | *out++ = glue(clip_,IN_T) (in->l); |
93 | 85571bc7 | bellard | *out++ = glue(clip_,IN_T) (in->r); |
94 | 85571bc7 | bellard | in += 1;
|
95 | 85571bc7 | bellard | } |
96 | 85571bc7 | bellard | } |
97 | 85571bc7 | bellard | |
98 | 85571bc7 | bellard | static void glue(glue(clip_,IN_T),_from_mono) (void *dst, const void *src, |
99 | 85571bc7 | bellard | int samples)
|
100 | 85571bc7 | bellard | { |
101 | 85571bc7 | bellard | st_sample_t *in = (st_sample_t *) src; |
102 | 85571bc7 | bellard | IN_T *out = (IN_T *) dst; |
103 | 85571bc7 | bellard | while (samples--) {
|
104 | 85571bc7 | bellard | *out++ = glue(clip_,IN_T) (in->l + in->r); |
105 | 85571bc7 | bellard | in += 1;
|
106 | 85571bc7 | bellard | } |
107 | 85571bc7 | bellard | } |
108 | 85571bc7 | bellard | |
109 | 85571bc7 | bellard | #undef HALF
|
110 | 85571bc7 | bellard | #undef HALFT
|