w.i.p - correctly remap ColorModel_TrueColor images.
[AROS.git] / workbench / devs / AHI / Device / dspechofuncs.c
blobaaceecfcd1200fd54bec3597326ffdf250005395
1 /*
2 AHI - Hardware independent audio subsystem
3 Copyright (C) 1996-2005 Martin Blom <martin@blom.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
18 MA 02139, USA.
21 #include <config.h>
23 #include "ahi_def.h"
24 #include "dspecho.h"
25 #include "dspechofuncs.h"
27 /**************
28 * Inputs: ahiede_Delay, ahiede_Feedback, ahiede_Mix, ahiede_Cross
30 * Delay = ahide_Delay
31 * MixN = 1-ahide_Mix
32 * MixD = ahide_Mix
33 * FeedbackDO = ahide_Feedback*ahide_Cross
34 * FeedbackDS = ahide_Feedback*(1-ahide_Cross)
35 * FeedbackNO = (1-ahide_Feedback)*ahide_Cross
36 * FeedbackNS = (1-ahide_Feedback)*(1-ahide_Cross)
38 * |\
39 * left in ->---+----------+---------------------| >---->(+)----> left out
40 * | | MixN |/ ^
41 * FeedbackNO \¯/ \¯/ FeedbackNS |
42 * v v |
43 * | | |
44 * | v |¯¯¯| |\ |
45 * | +--->(+)-->| T |----+-------| >------+
46 * | | ^ |___| | MixD |/
47 * | | | Delay |
48 * | | | |
49 * | | | /| |
50 * | | +-----< |-----+
51 * | | FeedbackDS \| |
52 * | | |
53 * | | /| |
54 * (+)<--(-----------< |-----+
55 * | | \| FeedbackDO
56 * | |
57 * | |
58 * | |
59 * | | /| FeedbackDO
60 * | (+)<---------< |-----+
61 * | | \| |
62 * | | |
63 * | | FeedbackDS /| |
64 * | | +-----< |-----+
65 * | | | \| |
66 * | | | |
67 * | | v |¯¯¯| | |\
68 * +----(--->(+)-->| T |----+-------| >------+
69 * | ^ |___| MixD |/ |
70 * | | Delay |
71 * ^ ^ |
72 * FeedbackNO /_\ /_\ FeedbackNS |
73 * | | |\ v
74 * right in ->-------+-----+---------------------| >---->(+)----> right out
75 * MixN |/
79 void
80 EchoMono16( LONG loops,
81 struct Echo *es,
82 void **buffer,
83 void **srcptr,
84 void **dstptr)
86 WORD *buf;
87 WORD *src, *dst;
88 LONG sample, delaysample;
90 buf = *buffer;
91 src = *srcptr;
92 dst = *dstptr;
94 while(loops > 0)
96 sample = *buf;
97 delaysample = *src++;
99 *buf++ = ( es->ahiecho_MixN * sample + es->ahiecho_MixD * delaysample ) >> 16;
101 sample = es->ahiecho_FeedbackNS * sample +
102 es->ahiecho_FeedbackDS * (delaysample + 1);
104 *dst++ = sample >> 16;
106 loops--;
109 *buffer = buf;
110 *srcptr = src;
111 *dstptr = dst;
115 void
116 EchoStereo16( LONG loops,
117 struct Echo *es,
118 void **buffer,
119 void **srcptr,
120 void **dstptr)
122 WORD *buf;
123 WORD *src, *dst;
124 LONG sample, sampleL, sampleR, delaysampleL, delaysampleR;
126 buf = *buffer;
127 src = *srcptr;
128 dst = *dstptr;
130 while(loops > 0)
132 sampleL = *buf;
133 delaysampleL = *src++;
135 *buf++ = ( es->ahiecho_MixN * sampleL + es->ahiecho_MixD * delaysampleL ) >> 16;
137 sampleR = *buf;
138 delaysampleR = *src++;
140 *buf++ = ( es->ahiecho_MixN * sampleR + es->ahiecho_MixD * delaysampleR ) >> 16;
142 sample = es->ahiecho_FeedbackDS * (delaysampleL + 1) +
143 es->ahiecho_FeedbackDO * (delaysampleR + 1) +
144 es->ahiecho_FeedbackNS * sampleL +
145 es->ahiecho_FeedbackNO * sampleR;
147 *dst++ = sample >> 16;
149 sample = es->ahiecho_FeedbackDO * (delaysampleL + 1) +
150 es->ahiecho_FeedbackDS * (delaysampleR + 1) +
151 es->ahiecho_FeedbackNO * sampleL +
152 es->ahiecho_FeedbackNS * sampleR;
154 *dst++ = sample >> 16;
156 loops--;
159 *buffer = buf;
160 *srcptr = src;
161 *dstptr = dst;
165 void
166 EchoMono32 ( LONG loops,
167 struct Echo *es,
168 void **buffer,
169 void **srcptr,
170 void **dstptr)
172 LONG *buf;
173 WORD *src, *dst;
174 LONG sample, delaysample;
176 buf = *buffer;
177 src = *srcptr;
178 dst = *dstptr;
180 while(loops > 0)
182 sample = *buf >> 16;
183 delaysample = *src++;
185 *buf++ = es->ahiecho_MixN * sample + es->ahiecho_MixD * delaysample;
187 sample = es->ahiecho_FeedbackNS * sample +
188 es->ahiecho_FeedbackDS * (delaysample + 1);
190 *dst++ = sample >> 16;
192 loops--;
195 *buffer = buf;
196 *srcptr = src;
197 *dstptr = dst;
201 void
202 EchoStereo32 ( LONG loops,
203 struct Echo *es,
204 void **buffer,
205 void **srcptr,
206 void **dstptr)
208 LONG *buf;
209 WORD *src, *dst;
210 LONG sample, sampleL, sampleR, delaysampleL, delaysampleR;
212 buf = *buffer;
213 src = *srcptr;
214 dst = *dstptr;
216 while(loops > 0)
218 sampleL = *buf >> 16;
219 delaysampleL = *src++;
221 *buf++ = es->ahiecho_MixN * sampleL + es->ahiecho_MixD * delaysampleL;
223 sampleR = *buf >> 16;
224 delaysampleR = *src++;
226 *buf++ = es->ahiecho_MixN * sampleR + es->ahiecho_MixD * delaysampleR;
228 sample = es->ahiecho_FeedbackDS * (delaysampleL + 1) +
229 es->ahiecho_FeedbackDO * (delaysampleR + 1) +
230 es->ahiecho_FeedbackNS * sampleL +
231 es->ahiecho_FeedbackNO * sampleR;
233 *dst++ = sample >> 16;
235 sample = es->ahiecho_FeedbackDO * (delaysampleL + 1) +
236 es->ahiecho_FeedbackDS * (delaysampleR + 1) +
237 es->ahiecho_FeedbackNO * sampleL +
238 es->ahiecho_FeedbackNS * sampleR;
240 *dst++ = sample >> 16;
242 loops--;
245 *buffer = buf;
246 *srcptr = src;
247 *dstptr = dst;
251 void
252 EchoMulti32 ( LONG loops,
253 struct Echo *es,
254 void **buffer,
255 void **srcptr,
256 void **dstptr)
258 LONG *buf;
259 WORD *src, *dst;
260 LONG sample, sampleL, sampleR, delaysampleL, delaysampleR;
262 buf = *buffer;
263 src = *srcptr;
264 dst = *dstptr;
266 while(loops > 0)
268 sampleL = *buf >> 16;
269 delaysampleL = *src++;
271 *buf++ = es->ahiecho_MixN * sampleL + es->ahiecho_MixD * delaysampleL;
273 sampleR = *buf >> 16;
274 delaysampleR = *src++;
276 *buf++ = es->ahiecho_MixN * sampleR + es->ahiecho_MixD * delaysampleR;
278 sample = es->ahiecho_FeedbackDS * (delaysampleL + 1) +
279 es->ahiecho_FeedbackDO * (delaysampleR + 1) +
280 es->ahiecho_FeedbackNS * sampleL +
281 es->ahiecho_FeedbackNO * sampleR;
283 *dst++ = sample >> 16;
285 sample = es->ahiecho_FeedbackDO * (delaysampleL + 1) +
286 es->ahiecho_FeedbackDS * (delaysampleR + 1) +
287 es->ahiecho_FeedbackNO * sampleL +
288 es->ahiecho_FeedbackNS * sampleR;
290 *dst++ = sample >> 16;
292 // Skip unused channels
293 buf += 6;
294 src += 6;
295 dst += 6;
297 loops--;
300 *buffer = buf;
301 *srcptr = src;
302 *dstptr = dst;