revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / AHI / Device / addroutines_lofi.c
blob1e7db4ef6e23eb92ac2ef9c3ec23f2023285f588
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 "addroutines.h"
25 /******************************************************************************
26 ** Add-Routines ***************************************************************
27 ******************************************************************************/
29 /* Forward mixing code */
31 #define offseti ( (long) ( offset >> 32 ) )
33 LONG
34 AddLofiByteMono( ADDARGS )
36 BYTE *src = Src;
37 WORD *dst = *Dst;
38 Fixed64 offset = *Offset;
39 int i;
40 LONG lastpoint, sample;
42 lastpoint = 0; // 0 doesn't affect the StopAtZero code
44 for( i = 0; i < Samples; i++)
46 sample = src[ offseti ] << 8;
48 if( StopAtZero &&
49 ( ( lastpoint < 0 && sample >= 0 ) ||
50 ( lastpoint > 0 && sample <= 0 ) ) )
52 break;
55 lastpoint = sample;
57 *dst++ += ( ScaleLeft * sample ) >> 16;
59 offset += Add;
62 *Dst = dst;
63 *Offset = offset;
65 return i;
69 LONG
70 AddLofiByteStereo( ADDARGS )
72 BYTE *src = Src;
73 WORD *dst = *Dst;
74 Fixed64 offset = *Offset;
75 int i;
76 LONG lastpoint, sample;
78 lastpoint = 0; // 0 doesn't affect the StopAtZero code
80 for( i = 0; i < Samples; i++)
82 sample = src[ offseti ] << 8;
84 if( StopAtZero &&
85 ( ( lastpoint < 0 && sample >= 0 ) ||
86 ( lastpoint > 0 && sample <= 0 ) ) )
88 break;
91 lastpoint = sample;
93 *dst++ += ( ScaleLeft * sample ) >> 16;
94 *dst++ += ( ScaleRight * sample ) >> 16;
96 offset += Add;
99 *Dst = dst;
100 *Offset = offset;
102 return i;
106 LONG
107 AddLofiBytesMono( ADDARGS )
109 BYTE *src = Src;
110 WORD *dst = *Dst;
111 Fixed64 offset = *Offset;
112 int i;
113 LONG lastpointL, lastpointR, sampleL, sampleR;
115 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
117 for( i = 0; i < Samples; i++)
119 sampleL = src[ offseti * 2 + 0 ] << 8;
120 sampleR = src[ offseti * 2 + 1 ] << 8;
122 if( StopAtZero &&
123 ( ( lastpointL < 0 && sampleL >= 0 ) ||
124 ( lastpointR < 0 && sampleR >= 0 ) ||
125 ( lastpointL > 0 && sampleL <= 0 ) ||
126 ( lastpointR > 0 && sampleR <= 0 ) ) )
128 break;
131 lastpointL = sampleL;
132 lastpointR = sampleR;
134 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
136 offset += Add;
139 *Dst = dst;
140 *Offset = offset;
142 return i;
146 LONG
147 AddLofiBytesStereo( ADDARGS )
149 BYTE *src = Src;
150 WORD *dst = *Dst;
151 Fixed64 offset = *Offset;
152 int i;
153 LONG lastpointL, lastpointR, sampleL, sampleR;
155 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
157 for( i = 0; i < Samples; i++)
159 sampleL = src[ offseti * 2 + 0 ] << 8;
160 sampleR = src[ offseti * 2 + 1 ] << 8;
162 if( StopAtZero &&
163 ( ( lastpointL < 0 && sampleL >= 0 ) ||
164 ( lastpointR < 0 && sampleR >= 0 ) ||
165 ( lastpointL > 0 && sampleL <= 0 ) ||
166 ( lastpointR > 0 && sampleR <= 0 ) ) )
168 break;
171 lastpointL = sampleL;
172 lastpointR = sampleR;
174 *dst++ += ( ScaleLeft * sampleL ) >> 16;
175 *dst++ += ( ScaleRight * sampleR ) >> 16;
177 offset += Add;
180 *Dst = dst;
181 *Offset = offset;
183 return i;
187 LONG
188 AddLofiWordMono( ADDARGS )
190 WORD *src = Src;
191 WORD *dst = *Dst;
192 Fixed64 offset = *Offset;
193 int i;
194 LONG lastpoint, sample;
196 lastpoint = 0; // 0 doesn't affect the StopAtZero code
198 for( i = 0; i < Samples; i++)
200 sample = src[ offseti ];
202 if( StopAtZero &&
203 ( ( lastpoint < 0 && sample >= 0 ) ||
204 ( lastpoint > 0 && sample <= 0 ) ) )
206 break;
209 lastpoint = sample;
211 *dst++ += ( ScaleLeft * sample ) >> 16;
213 offset += Add;
216 *Dst = dst;
217 *Offset = offset;
219 return i;
223 LONG
224 AddLofiWordStereo( ADDARGS )
226 WORD *src = Src;
227 WORD *dst = *Dst;
228 Fixed64 offset = *Offset;
229 int i;
230 LONG lastpoint, sample;
232 lastpoint = 0; // 0 doesn't affect the StopAtZero code
234 for( i = 0; i < Samples; i++)
236 sample = src[ offseti ];
238 if( StopAtZero &&
239 ( ( lastpoint < 0 && sample >= 0 ) ||
240 ( lastpoint > 0 && sample <= 0 ) ) )
242 break;
245 lastpoint = sample;
247 *dst++ += ( ScaleLeft * sample ) >> 16;
248 *dst++ += ( ScaleRight * sample ) >> 16;
250 offset += Add;
253 *Dst = dst;
254 *Offset = offset;
256 return i;
259 LONG
260 AddLofiWordsMono( ADDARGS )
262 WORD *src = Src;
263 WORD *dst = *Dst;
264 Fixed64 offset = *Offset;
265 int i;
266 LONG lastpointL, lastpointR, sampleL, sampleR;
268 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
270 for( i = 0; i < Samples; i++)
272 sampleL = src[ offseti * 2 + 0 ];
273 sampleR = src[ offseti * 2 + 1 ];
275 if( StopAtZero &&
276 ( ( lastpointL < 0 && sampleL >= 0 ) ||
277 ( lastpointR < 0 && sampleR >= 0 ) ||
278 ( lastpointL > 0 && sampleL <= 0 ) ||
279 ( lastpointR > 0 && sampleR <= 0 ) ) )
281 break;
284 lastpointL = sampleL;
285 lastpointR = sampleR;
287 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
289 offset += Add;
292 *Dst = dst;
293 *Offset = offset;
295 return i;
299 LONG
300 AddLofiWordsStereo( ADDARGS )
302 WORD *src = Src;
303 WORD *dst = *Dst;
304 Fixed64 offset = *Offset;
305 int i;
306 LONG lastpointL, lastpointR, sampleL, sampleR;
308 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
310 for( i = 0; i < Samples; i++)
312 sampleL = src[ offseti * 2 + 0 ];
313 sampleR = src[ offseti * 2 + 1 ];
315 if( StopAtZero &&
316 ( ( lastpointL < 0 && sampleL >= 0 ) ||
317 ( lastpointR < 0 && sampleR >= 0 ) ||
318 ( lastpointL > 0 && sampleL <= 0 ) ||
319 ( lastpointR > 0 && sampleR <= 0 ) ) )
321 break;
324 lastpointL = sampleL;
325 lastpointR = sampleR;
327 *dst++ += ( ScaleLeft * sampleL ) >> 16;
328 *dst++ += ( ScaleRight * sampleR ) >> 16;
330 offset += Add;
333 *Dst = dst;
334 *Offset = offset;
336 return i;
339 /*****************************************************************************/
341 /* Backward mixing code */
343 LONG
344 AddLofiByteMonoB( ADDARGS )
346 BYTE *src = Src;
347 WORD *dst = *Dst;
348 Fixed64 offset = *Offset;
349 int i;
350 LONG lastpoint, sample;
352 lastpoint = 0; // 0 doesn't affect the StopAtZero code
354 for( i = 0; i < Samples; i++)
356 sample = src[ offseti ] << 8;
358 if( StopAtZero &&
359 ( ( lastpoint < 0 && sample >= 0 ) ||
360 ( lastpoint > 0 && sample <= 0 ) ) )
362 break;
365 lastpoint = sample;
367 *dst++ += ( ScaleLeft * sample ) >> 16;
369 offset -= Add;
372 *Dst = dst;
373 *Offset = offset;
375 return i;
379 LONG
380 AddLofiByteStereoB( ADDARGS )
382 BYTE *src = Src;
383 WORD *dst = *Dst;
384 Fixed64 offset = *Offset;
385 int i;
386 LONG lastpoint, sample;
388 lastpoint = 0; // 0 doesn't affect the StopAtZero code
390 for( i = 0; i < Samples; i++)
392 sample = src[ offseti ] << 8;
394 if( StopAtZero &&
395 ( ( lastpoint < 0 && sample >= 0 ) ||
396 ( lastpoint > 0 && sample <= 0 ) ) )
398 break;
401 lastpoint = sample;
403 *dst++ += ( ScaleLeft * sample ) >> 16;
404 *dst++ += ( ScaleRight * sample ) >> 16;
406 offset -= Add;
409 *Dst = dst;
410 *Offset = offset;
412 return i;
416 LONG
417 AddLofiBytesMonoB( ADDARGS )
419 BYTE *src = Src;
420 WORD *dst = *Dst;
421 Fixed64 offset = *Offset;
422 int i;
423 LONG lastpointL, lastpointR, sampleL, sampleR;
425 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
427 for( i = 0; i < Samples; i++)
429 sampleL = src[ offseti * 2 + 0 ] << 8;
430 sampleR = src[ offseti * 2 + 1 ] << 8;
432 if( StopAtZero &&
433 ( ( lastpointL < 0 && sampleL >= 0 ) ||
434 ( lastpointR < 0 && sampleR >= 0 ) ||
435 ( lastpointL > 0 && sampleL <= 0 ) ||
436 ( lastpointR > 0 && sampleR <= 0 ) ) )
438 break;
441 lastpointL = sampleL;
442 lastpointR = sampleR;
444 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
446 offset -= Add;
449 *Dst = dst;
450 *Offset = offset;
452 return i;
456 LONG
457 AddLofiBytesStereoB( ADDARGS )
459 BYTE *src = Src;
460 WORD *dst = *Dst;
461 Fixed64 offset = *Offset;
462 int i;
463 LONG lastpointL, lastpointR, sampleL, sampleR;
465 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
467 for( i = 0; i < Samples; i++)
469 sampleL = src[ offseti * 2 + 0 ] << 8;
470 sampleR = src[ offseti * 2 + 1 ] << 8;
472 if( StopAtZero &&
473 ( ( lastpointL < 0 && sampleL >= 0 ) ||
474 ( lastpointR < 0 && sampleR >= 0 ) ||
475 ( lastpointL > 0 && sampleL <= 0 ) ||
476 ( lastpointR > 0 && sampleR <= 0 ) ) )
478 break;
481 lastpointL = sampleL;
482 lastpointR = sampleR;
484 *dst++ += ( ScaleLeft * sampleL ) >> 16;
485 *dst++ += ( ScaleRight * sampleR ) >> 16;
487 offset -= Add;
490 *Dst = dst;
491 *Offset = offset;
493 return i;
497 LONG
498 AddLofiWordMonoB( ADDARGS )
500 WORD *src = Src;
501 WORD *dst = *Dst;
502 Fixed64 offset = *Offset;
503 int i;
504 LONG lastpoint, sample;
506 lastpoint = 0; // 0 doesn't affect the StopAtZero code
508 for( i = 0; i < Samples; i++)
510 sample = src[ offseti ];
512 if( StopAtZero &&
513 ( ( lastpoint < 0 && sample >= 0 ) ||
514 ( lastpoint > 0 && sample <= 0 ) ) )
516 break;
519 lastpoint = sample;
521 *dst++ += ( ScaleLeft * sample ) >> 16;
523 offset -= Add;
526 *Dst = dst;
527 *Offset = offset;
529 return i;
533 LONG
534 AddLofiWordStereoB( ADDARGS )
536 WORD *src = Src;
537 WORD *dst = *Dst;
538 Fixed64 offset = *Offset;
539 int i;
540 LONG lastpoint, sample;
542 lastpoint = 0; // 0 doesn't affect the StopAtZero code
544 for( i = 0; i < Samples; i++)
546 sample = src[ offseti ];
548 if( StopAtZero &&
549 ( ( lastpoint < 0 && sample >= 0 ) ||
550 ( lastpoint > 0 && sample <= 0 ) ) )
552 break;
555 lastpoint = sample;
557 *dst++ += ( ScaleLeft * sample ) >> 16;
558 *dst++ += ( ScaleRight * sample ) >> 16;
560 offset -= Add;
563 *Dst = dst;
564 *Offset = offset;
566 return i;
570 LONG
571 AddLofiWordsMonoB( ADDARGS )
573 WORD *src = Src;
574 WORD *dst = *Dst;
575 Fixed64 offset = *Offset;
576 int i;
577 LONG lastpointL, lastpointR, sampleL, sampleR;
579 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
581 for( i = 0; i < Samples; i++)
583 sampleL = src[ offseti * 2 + 0 ];
584 sampleR = src[ offseti * 2 + 1 ];
586 if( StopAtZero &&
587 ( ( lastpointL < 0 && sampleL >= 0 ) ||
588 ( lastpointR < 0 && sampleR >= 0 ) ||
589 ( lastpointL > 0 && sampleL <= 0 ) ||
590 ( lastpointR > 0 && sampleR <= 0 ) ) )
592 break;
595 lastpointL = sampleL;
596 lastpointR = sampleR;
598 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
600 offset -= Add;
603 *Dst = dst;
604 *Offset = offset;
606 return i;
610 LONG
611 AddLofiWordsStereoB( ADDARGS )
613 WORD *src = Src;
614 WORD *dst = *Dst;
615 Fixed64 offset = *Offset;
616 int i;
617 LONG lastpointL, lastpointR, sampleL, sampleR;
619 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
621 for( i = 0; i < Samples; i++)
623 sampleL = src[ offseti * 2 + 0 ];
624 sampleR = src[ offseti * 2 + 1 ];
626 if( StopAtZero &&
627 ( ( lastpointL < 0 && sampleL >= 0 ) ||
628 ( lastpointR < 0 && sampleR >= 0 ) ||
629 ( lastpointL > 0 && sampleL <= 0 ) ||
630 ( lastpointR > 0 && sampleR <= 0 ) ) )
632 break;
635 lastpointL = sampleL;
636 lastpointR = sampleR;
638 *dst++ += ( ScaleLeft * sampleL ) >> 16;
639 *dst++ += ( ScaleRight * sampleR ) >> 16;
641 offset -= Add;
644 *Dst = dst;
645 *Offset = offset;
647 return i;
650 /*****************************************************************************/