1
2 /*
3 * Diverse Bristol audio routines.
4 * Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 /*
23 * This code should open the midi device (working with ALSA raw midi only for
24 * the moment (9/11/01)), and read data from it. Not sure how it will be read,
25 * either buffers, events, or perhaps just raw data. At some point in the
26 * development this will become a separate thread in the synth code.
27 */
28
29 /*
30 * This should go into a library, is used from various places.
31 */
32 void
bufmerge(register float * src,register float gain1,register float * dst,register float gain2,register int size)33 bufmerge(register float *src, register float gain1, register float *dst,
34 register float gain2, register int size)
35 {
36 float *buf3 = dst;
37
38 for (;size > 0; size-=16)
39 {
40 *dst++ = *buf3++ * gain2 + *src++ * gain1;
41 *dst++ = *buf3++ * gain2 + *src++ * gain1;
42 *dst++ = *buf3++ * gain2 + *src++ * gain1;
43 *dst++ = *buf3++ * gain2 + *src++ * gain1;
44 *dst++ = *buf3++ * gain2 + *src++ * gain1;
45 *dst++ = *buf3++ * gain2 + *src++ * gain1;
46 *dst++ = *buf3++ * gain2 + *src++ * gain1;
47 *dst++ = *buf3++ * gain2 + *src++ * gain1;
48 *dst++ = *buf3++ * gain2 + *src++ * gain1;
49 *dst++ = *buf3++ * gain2 + *src++ * gain1;
50 *dst++ = *buf3++ * gain2 + *src++ * gain1;
51 *dst++ = *buf3++ * gain2 + *src++ * gain1;
52 *dst++ = *buf3++ * gain2 + *src++ * gain1;
53 *dst++ = *buf3++ * gain2 + *src++ * gain1;
54 *dst++ = *buf3++ * gain2 + *src++ * gain1;
55 *dst++ = *buf3++ * gain2 + *src++ * gain1;
56 }
57 /*
58 * Correctly speaking we should check here to make sure that size is zero
59 * and cater for the last 'n' samples however I think we can just take a
60 * minimum count of 16 and take the rest in powers of two.
61 */
62 }
63
64 void
bufadd(register float * buf1,register float add,register int size)65 bufadd(register float *buf1, register float add, register int size)
66 {
67 for (;size > 0; size-=16)
68 {
69 *buf1++ += add;
70 *buf1++ += add;
71 *buf1++ += add;
72 *buf1++ += add;
73 *buf1++ += add;
74 *buf1++ += add;
75 *buf1++ += add;
76 *buf1++ += add;
77 *buf1++ += add;
78 *buf1++ += add;
79 *buf1++ += add;
80 *buf1++ += add;
81 *buf1++ += add;
82 *buf1++ += add;
83 *buf1++ += add;
84 *buf1++ += add;
85 }
86 }
87
88 void
bufset(register float * buf1,register float set,register int size)89 bufset(register float *buf1, register float set, register int size)
90 {
91 for (;size > 0; size-=16)
92 {
93 *buf1++ = set;
94 *buf1++ = set;
95 *buf1++ = set;
96 *buf1++ = set;
97 *buf1++ = set;
98 *buf1++ = set;
99 *buf1++ = set;
100 *buf1++ = set;
101 *buf1++ = set;
102 *buf1++ = set;
103 *buf1++ = set;
104 *buf1++ = set;
105 *buf1++ = set;
106 *buf1++ = set;
107 *buf1++ = set;
108 *buf1++ = set;
109 }
110 }
111
112