grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / AHI / Device / addroutines_32bit.c
blobd3c367a0074d1e60856e8a6cc379da16bda9b853
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 typedef long long LONGLONG;
27 /******************************************************************************
28 ** Add-Routines ***************************************************************
29 ******************************************************************************/
32 ** LONG Samples
33 ** LONG ScaleLeft
34 ** LONG ScaleRight
35 ** LONG *StartPointLeft
36 ** LONG *StartPointRight
37 ** void *Src
38 ** void **Dst
39 ** LONG FirstOffsetI
40 ** Fixed64 *Offset
41 ** Fixed64 Add
42 ** BOOL StopAtZero
47 Notes:
49 The fraction offset is divided by two in order to make sure that the
50 calculation of linearsample fits a LONG (0 =< offsetf <= 32767).
52 The routines could be faster, of course. One idea is to split the for loop
53 into two loops in order to eliminate the FirstOffsetI test in the second loop.
55 */
57 /*****************************************************************************/
59 /* Forward mixing code */
61 #define offseti ( (long) ( offset >> 32 ) )
63 #define offsetf ( offset & 0xffffffffULL )
65 LONG
66 AddLongMono( ADDARGS )
68 LONG *src = Src;
69 LONG *dst = *Dst;
70 Fixed64 offset = *Offset;
71 int i;
72 LONG startpoint, endpoint = 0; // Make compiler happy
73 LONG lastpoint;
75 lastpoint = 0; // 0 doesn't affect the StopAtZero code
77 for( i = 0; i < Samples; i++)
79 if( offseti == FirstOffsetI ) {
80 startpoint = *StartPointLeft << 16;
82 else
84 startpoint = src[ offseti - 1 ];
87 endpoint = src[ offseti ];
89 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
91 if( StopAtZero &&
92 ( ( lastpoint < 0 && startpoint >= 0 ) ||
93 ( lastpoint > 0 && startpoint <= 0 ) ) )
95 break;
98 lastpoint = startpoint;
100 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
102 offset += Add;
105 *StartPointLeft = endpoint >> 16;
107 *Dst = dst;
108 *Offset = offset;
110 return i;
114 LONG
115 AddLongStereo( ADDARGS )
117 LONG *src = Src;
118 LONG *dst = *Dst;
119 Fixed64 offset = *Offset;
120 int i;
121 LONG startpoint, endpoint = 0; // Make compiler happy
122 LONG lastpoint;
124 lastpoint = 0; // 0 doesn't affect the StopAtZero code
126 for( i = 0; i < Samples; i++)
128 if( offseti == FirstOffsetI ) {
129 startpoint = *StartPointLeft << 16;
131 else
133 startpoint = src[ offseti - 1 ];
136 endpoint = src[ offseti ];
138 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
140 if( StopAtZero &&
141 ( ( lastpoint < 0 && startpoint >= 0 ) ||
142 ( lastpoint > 0 && startpoint <= 0 ) ) )
144 break;
147 lastpoint = startpoint;
149 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
150 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpoint ) >> 16 );
152 offset += Add;
155 *StartPointLeft = endpoint >> 16;
157 *Dst = dst;
158 *Offset = offset;
160 return i;
163 LONG
164 AddLongsMono( ADDARGS )
166 LONG *src = Src;
167 LONG *dst = *Dst;
168 Fixed64 offset = *Offset;
169 int i;
170 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
171 LONG lastpointL, lastpointR;
173 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
175 for( i = 0; i < Samples; i++)
177 if( offseti == FirstOffsetI ) {
178 startpointL = *StartPointLeft << 16;
179 startpointR = *StartPointRight << 16;
181 else
183 startpointL = src[ offseti * 2 + 0 - 2 ];
184 startpointR = src[ offseti * 2 + 1 - 2 ];
187 endpointL = src[ offseti * 2 + 0 ];
188 endpointR = src[ offseti * 2 + 1 ];
190 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
191 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
193 if( StopAtZero &&
194 ( ( lastpointL < 0 && startpointL >= 0 ) ||
195 ( lastpointR < 0 && startpointR >= 0 ) ||
196 ( lastpointL > 0 && startpointL <= 0 ) ||
197 ( lastpointR > 0 && startpointR <= 0 ) ) )
199 break;
202 lastpointL = startpointL;
203 lastpointR = startpointR;
205 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 )
206 + (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
208 offset += Add;
211 *StartPointLeft = endpointL >> 16;
212 *StartPointRight = endpointR >> 16;
214 *Dst = dst;
215 *Offset = offset;
217 return i;
221 LONG
222 AddLongsStereo( ADDARGS )
224 LONG *src = Src;
225 LONG *dst = *Dst;
226 Fixed64 offset = *Offset;
227 int i;
228 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
229 LONG lastpointL, lastpointR;
231 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
233 for( i = 0; i < Samples; i++)
235 if( offseti == FirstOffsetI ) {
236 startpointL = *StartPointLeft << 16;
237 startpointR = *StartPointRight << 16;
239 else
241 startpointL = src[ offseti * 2 + 0 - 2 ];
242 startpointR = src[ offseti * 2 + 1 - 2 ];
245 endpointL = src[ offseti * 2 + 0 ];
246 endpointR = src[ offseti * 2 + 1 ];
248 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
249 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
251 if( StopAtZero &&
252 ( ( lastpointL < 0 && startpointL >= 0 ) ||
253 ( lastpointR < 0 && startpointR >= 0 ) ||
254 ( lastpointL > 0 && startpointL <= 0 ) ||
255 ( lastpointR > 0 && startpointR <= 0 ) ) )
257 break;
260 lastpointL = startpointL;
261 lastpointR = startpointR;
263 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
264 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
266 offset += Add;
269 *StartPointLeft = endpointL >> 16;
270 *StartPointRight = endpointR >> 16;
272 *Dst = dst;
273 *Offset = offset;
275 return i;
279 LONG
280 Add71Mono( ADDARGS )
282 LONG *src = Src;
283 LONG *dst = *Dst;
284 Fixed64 offset = *Offset;
285 int i;
286 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
287 LONG lastpointL, lastpointR;
289 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
291 for( i = 0; i < Samples; i++)
293 if( offseti == FirstOffsetI ) {
294 startpointL = *StartPointLeft << 16;
295 startpointR = *StartPointRight << 16;
297 else
299 startpointL = src[ offseti * 8 + 0 - 8 ];
300 startpointR = src[ offseti * 8 + 1 - 8 ];
303 endpointL = src[ offseti * 8 + 0 ];
304 endpointR = src[ offseti * 8 + 1 ];
306 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
307 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
309 if( StopAtZero &&
310 ( ( lastpointL < 0 && startpointL >= 0 ) ||
311 ( lastpointR < 0 && startpointR >= 0 ) ||
312 ( lastpointL > 0 && startpointL <= 0 ) ||
313 ( lastpointR > 0 && startpointR <= 0 ) ) )
315 break;
318 lastpointL = startpointL;
319 lastpointR = startpointR;
321 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 )
322 + (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
324 offset += Add;
327 *StartPointLeft = endpointL >> 16;
328 *StartPointRight = endpointR >> 16;
330 *Dst = dst;
331 *Offset = offset;
333 return i;
337 LONG
338 Add71Stereo( ADDARGS )
340 LONG *src = Src;
341 LONG *dst = *Dst;
342 Fixed64 offset = *Offset;
343 int i;
344 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
345 LONG lastpointL, lastpointR;
347 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
349 for( i = 0; i < Samples; i++)
351 if( offseti == FirstOffsetI ) {
352 startpointL = *StartPointLeft << 16;
353 startpointR = *StartPointRight << 16;
355 else
357 startpointL = src[ offseti * 8 + 0 - 8 ];
358 startpointR = src[ offseti * 8 + 1 - 8 ];
361 endpointL = src[ offseti * 8 + 0 ];
362 endpointR = src[ offseti * 8 + 1 ];
364 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
365 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
367 if( StopAtZero &&
368 ( ( lastpointL < 0 && startpointL >= 0 ) ||
369 ( lastpointR < 0 && startpointR >= 0 ) ||
370 ( lastpointL > 0 && startpointL <= 0 ) ||
371 ( lastpointR > 0 && startpointR <= 0 ) ) )
373 break;
376 lastpointL = startpointL;
377 lastpointR = startpointR;
379 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
380 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
382 offset += Add;
385 *StartPointLeft = endpointL >> 16;
386 *StartPointRight = endpointR >> 16;
388 *Dst = dst;
389 *Offset = offset;
391 return i;
394 /*****************************************************************************/
396 /* Lofi mixing code */
398 LONG
399 AddLofiLongMono( ADDARGS )
401 LONG *src = Src;
402 WORD *dst = *Dst;
403 Fixed64 offset = *Offset;
404 int i;
405 LONG lastpoint, sample;
407 lastpoint = 0; // 0 doesn't affect the StopAtZero code
409 for( i = 0; i < Samples; i++)
411 sample = src[ offseti ] >> 16;
413 if( StopAtZero &&
414 ( ( lastpoint < 0 && sample >= 0 ) ||
415 ( lastpoint > 0 && sample <= 0 ) ) )
417 break;
420 lastpoint = sample;
422 *dst++ += ( ScaleLeft * sample ) >> 16;
424 offset += Add;
427 *Dst = dst;
428 *Offset = offset;
430 return i;
434 LONG
435 AddLofiLongStereo( ADDARGS )
437 LONG *src = Src;
438 WORD *dst = *Dst;
439 Fixed64 offset = *Offset;
440 int i;
441 LONG lastpoint, sample;
443 lastpoint = 0; // 0 doesn't affect the StopAtZero code
445 for( i = 0; i < Samples; i++)
447 sample = src[ offseti ] >> 16;;
449 if( StopAtZero &&
450 ( ( lastpoint < 0 && sample >= 0 ) ||
451 ( lastpoint > 0 && sample <= 0 ) ) )
453 break;
456 lastpoint = sample;
458 *dst++ += ( ScaleLeft * sample ) >> 16;
459 *dst++ += ( ScaleRight * sample ) >> 16;
461 offset += Add;
464 *Dst = dst;
465 *Offset = offset;
467 return i;
470 LONG
471 AddLofiLongsMono( ADDARGS )
473 LONG *src = Src;
474 WORD *dst = *Dst;
475 Fixed64 offset = *Offset;
476 int i;
477 LONG lastpointL, lastpointR, sampleL, sampleR;
479 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
481 for( i = 0; i < Samples; i++)
483 sampleL = src[ offseti * 2 + 0 ] >> 16;;
484 sampleR = src[ offseti * 2 + 1 ] >> 16;;
486 if( StopAtZero &&
487 ( ( lastpointL < 0 && sampleL >= 0 ) ||
488 ( lastpointR < 0 && sampleR >= 0 ) ||
489 ( lastpointL > 0 && sampleL <= 0 ) ||
490 ( lastpointR > 0 && sampleR <= 0 ) ) )
492 break;
495 lastpointL = sampleL;
496 lastpointR = sampleR;
498 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
500 offset += Add;
503 *Dst = dst;
504 *Offset = offset;
506 return i;
510 LONG
511 AddLofiLongsStereo( ADDARGS )
513 LONG *src = Src;
514 WORD *dst = *Dst;
515 Fixed64 offset = *Offset;
516 int i;
517 LONG lastpointL, lastpointR, sampleL, sampleR;
519 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
521 for( i = 0; i < Samples; i++)
523 sampleL = src[ offseti * 2 + 0 ] >> 16;;
524 sampleR = src[ offseti * 2 + 1 ] >> 16;;
526 if( StopAtZero &&
527 ( ( lastpointL < 0 && sampleL >= 0 ) ||
528 ( lastpointR < 0 && sampleR >= 0 ) ||
529 ( lastpointL > 0 && sampleL <= 0 ) ||
530 ( lastpointR > 0 && sampleR <= 0 ) ) )
532 break;
535 lastpointL = sampleL;
536 lastpointR = sampleR;
538 *dst++ += ( ScaleLeft * sampleL ) >> 16;
539 *dst++ += ( ScaleRight * sampleR ) >> 16;
541 offset += Add;
544 *Dst = dst;
545 *Offset = offset;
547 return i;
552 #undef offsetf
554 /*****************************************************************************/
556 /* Backward mixing code */
558 #define offsetf ( (long) ( 32768 - ( (unsigned long) ( offset & 0xffffffffULL ) >> 17 ) ) )
560 LONG
561 AddLongMonoB( ADDARGS )
563 LONG *src = Src;
564 LONG *dst = *Dst;
565 Fixed64 offset = *Offset;
566 int i;
567 LONG startpoint, endpoint = 0; // Make compiler happy
568 LONG lastpoint;
570 lastpoint = 0; // 0 doesn't affect the StopAtZero code
572 for( i = 0; i < Samples; i++)
574 if( offseti == FirstOffsetI ) {
575 startpoint = *StartPointLeft << 16;
577 else
579 startpoint = src[ offseti + 1 ];
582 endpoint = src[ offseti ];
584 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
586 if( StopAtZero &&
587 ( ( lastpoint < 0 && startpoint >= 0 ) ||
588 ( lastpoint > 0 && startpoint <= 0 ) ) )
590 break;
593 lastpoint = startpoint;
595 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
597 offset -= Add;
600 *StartPointLeft = endpoint >> 16;
602 *Dst = dst;
603 *Offset = offset;
605 return i;
609 LONG
610 AddLongStereoB( ADDARGS )
612 LONG *src = Src;
613 LONG *dst = *Dst;
614 Fixed64 offset = *Offset;
615 int i;
616 LONG startpoint, endpoint = 0; // Make compiler happy
617 LONG lastpoint;
619 lastpoint = 0; // 0 doesn't affect the StopAtZero code
621 for( i = 0; i < Samples; i++)
623 if( offseti == FirstOffsetI ) {
624 startpoint = *StartPointLeft << 16;
626 else
628 startpoint = src[ offseti + 1 ];
631 endpoint = src[ offseti ];
633 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
635 if( StopAtZero &&
636 ( ( lastpoint < 0 && startpoint >= 0 ) ||
637 ( lastpoint > 0 && startpoint <= 0 ) ) )
639 break;
642 lastpoint = startpoint;
644 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
645 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpoint ) >> 16 );
647 offset -= Add;
650 *StartPointLeft = endpoint >> 16;
652 *Dst = dst;
653 *Offset = offset;
655 return i;
659 LONG
660 AddLongsMonoB( ADDARGS )
662 LONG *src = Src;
663 LONG *dst = *Dst;
664 Fixed64 offset = *Offset;
665 int i;
666 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
667 LONG lastpointL, lastpointR;
669 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
671 for( i = 0; i < Samples; i++)
673 if( offseti == FirstOffsetI ) {
674 startpointL = *StartPointLeft << 16;
675 startpointR = *StartPointRight << 16;
677 else
679 startpointL = src[ offseti * 2 + 0 + 2 ];
680 startpointR = src[ offseti * 2 + 1 + 2 ];
683 endpointL = src[ offseti * 2 + 0 ];
684 endpointR = src[ offseti * 2 + 1 ];
686 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
687 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
689 if( StopAtZero &&
690 ( ( lastpointL < 0 && startpointL >= 0 ) ||
691 ( lastpointR < 0 && startpointR >= 0 ) ||
692 ( lastpointL > 0 && startpointL <= 0 ) ||
693 ( lastpointR > 0 && startpointR <= 0 ) ) )
695 break;
698 lastpointL = startpointL;
699 lastpointR = startpointR;
701 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 ) +
702 (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
704 offset -= Add;
707 *StartPointLeft = endpointL >> 16;
708 *StartPointRight = endpointR >> 16;
710 *Dst = dst;
711 *Offset = offset;
713 return i;
717 LONG
718 AddLongsStereoB( ADDARGS )
720 LONG *src = Src;
721 LONG *dst = *Dst;
722 Fixed64 offset = *Offset;
723 int i;
724 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
725 LONG lastpointL, lastpointR;
727 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
729 for( i = 0; i < Samples; i++)
731 if( offseti == FirstOffsetI ) {
732 startpointL = *StartPointLeft << 16;
733 startpointR = *StartPointRight << 16;
735 else
737 startpointL = src[ offseti * 2 + 0 + 2 ];
738 startpointR = src[ offseti * 2 + 1 + 2 ];
741 endpointL = src[ offseti * 2 + 0 ];
742 endpointR = src[ offseti * 2 + 1 ];
744 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
745 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
747 if( StopAtZero &&
748 ( ( lastpointL < 0 && startpointL >= 0 ) ||
749 ( lastpointR < 0 && startpointR >= 0 ) ||
750 ( lastpointL > 0 && startpointL <= 0 ) ||
751 ( lastpointR > 0 && startpointR <= 0 ) ) )
753 break;
756 lastpointL = startpointL;
757 lastpointR = startpointR;
759 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
760 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
762 offset -= Add;
765 *StartPointLeft = endpointL >> 16;
766 *StartPointRight = endpointR >> 16;
768 *Dst = dst;
769 *Offset = offset;
771 return i;
775 LONG
776 Add71MonoB( ADDARGS )
778 LONG *src = Src;
779 LONG *dst = *Dst;
780 Fixed64 offset = *Offset;
781 int i;
782 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
783 LONG lastpointL, lastpointR;
785 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
787 for( i = 0; i < Samples; i++)
789 if( offseti == FirstOffsetI ) {
790 startpointL = *StartPointLeft << 16;
791 startpointR = *StartPointRight << 16;
793 else
795 startpointL = src[ offseti * 8 + 0 + 8 ];
796 startpointR = src[ offseti * 8 + 1 + 8 ];
799 endpointL = src[ offseti * 8 + 0 ];
800 endpointR = src[ offseti * 8 + 1 ];
802 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
803 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
805 if( StopAtZero &&
806 ( ( lastpointL < 0 && startpointL >= 0 ) ||
807 ( lastpointR < 0 && startpointR >= 0 ) ||
808 ( lastpointL > 0 && startpointL <= 0 ) ||
809 ( lastpointR > 0 && startpointR <= 0 ) ) )
811 break;
814 lastpointL = startpointL;
815 lastpointR = startpointR;
817 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 ) +
818 (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
820 offset -= Add;
823 *StartPointLeft = endpointL >> 16;
824 *StartPointRight = endpointR >> 16;
826 *Dst = dst;
827 *Offset = offset;
829 return i;
833 LONG
834 Add71StereoB( ADDARGS )
836 LONG *src = Src;
837 LONG *dst = *Dst;
838 Fixed64 offset = *Offset;
839 int i;
840 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
841 LONG lastpointL, lastpointR;
843 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
845 for( i = 0; i < Samples; i++)
847 if( offseti == FirstOffsetI ) {
848 startpointL = *StartPointLeft << 16;
849 startpointR = *StartPointRight << 16;
851 else
853 startpointL = src[ offseti * 8 + 0 + 8 ];
854 startpointR = src[ offseti * 8 + 1 + 8 ];
857 endpointL = src[ offseti * 8 + 0 ];
858 endpointR = src[ offseti * 8 + 1 ];
860 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
861 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
863 if( StopAtZero &&
864 ( ( lastpointL < 0 && startpointL >= 0 ) ||
865 ( lastpointR < 0 && startpointR >= 0 ) ||
866 ( lastpointL > 0 && startpointL <= 0 ) ||
867 ( lastpointR > 0 && startpointR <= 0 ) ) )
869 break;
872 lastpointL = startpointL;
873 lastpointR = startpointR;
875 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
876 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
878 offset -= Add;
881 *StartPointLeft = endpointL >> 16;
882 *StartPointRight = endpointR >> 16;
884 *Dst = dst;
885 *Offset = offset;
887 return i;
891 /*****************************************************************************/
893 /* Lofi mixing code */
895 LONG
896 AddLofiLongMonoB( ADDARGS )
898 LONG *src = Src;
899 WORD *dst = *Dst;
900 Fixed64 offset = *Offset;
901 int i;
902 LONG lastpoint, sample;
904 lastpoint = 0; // 0 doesn't affect the StopAtZero code
906 for( i = 0; i < Samples; i++)
908 sample = src[ offseti ] >> 16;;
910 if( StopAtZero &&
911 ( ( lastpoint < 0 && sample >= 0 ) ||
912 ( lastpoint > 0 && sample <= 0 ) ) )
914 break;
917 lastpoint = sample;
919 *dst++ += ( ScaleLeft * sample ) >> 16;
921 offset -= Add;
924 *Dst = dst;
925 *Offset = offset;
927 return i;
931 LONG
932 AddLofiLongStereoB( ADDARGS )
934 LONG *src = Src;
935 WORD *dst = *Dst;
936 Fixed64 offset = *Offset;
937 int i;
938 LONG lastpoint, sample;
940 lastpoint = 0; // 0 doesn't affect the StopAtZero code
942 for( i = 0; i < Samples; i++)
944 sample = src[ offseti ] >> 16;;
946 if( StopAtZero &&
947 ( ( lastpoint < 0 && sample >= 0 ) ||
948 ( lastpoint > 0 && sample <= 0 ) ) )
950 break;
953 lastpoint = sample;
955 *dst++ += ( ScaleLeft * sample ) >> 16;
956 *dst++ += ( ScaleRight * sample ) >> 16;
958 offset -= Add;
961 *Dst = dst;
962 *Offset = offset;
964 return i;
968 LONG
969 AddLofiLongsMonoB( ADDARGS )
971 LONG *src = Src;
972 WORD *dst = *Dst;
973 Fixed64 offset = *Offset;
974 int i;
975 LONG lastpointL, lastpointR, sampleL, sampleR;
977 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
979 for( i = 0; i < Samples; i++)
981 sampleL = src[ offseti * 2 + 0 ] >> 16;;
982 sampleR = src[ offseti * 2 + 1 ] >> 16;;
984 if( StopAtZero &&
985 ( ( lastpointL < 0 && sampleL >= 0 ) ||
986 ( lastpointR < 0 && sampleR >= 0 ) ||
987 ( lastpointL > 0 && sampleL <= 0 ) ||
988 ( lastpointR > 0 && sampleR <= 0 ) ) )
990 break;
993 lastpointL = sampleL;
994 lastpointR = sampleR;
996 *dst++ += ( ScaleLeft * sampleL + ScaleRight * sampleR ) >> 16;
998 offset -= Add;
1001 *Dst = dst;
1002 *Offset = offset;
1004 return i;
1008 LONG
1009 AddLofiLongsStereoB( ADDARGS )
1011 LONG *src = Src;
1012 WORD *dst = *Dst;
1013 Fixed64 offset = *Offset;
1014 int i;
1015 LONG lastpointL, lastpointR, sampleL, sampleR;
1017 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
1019 for( i = 0; i < Samples; i++)
1021 sampleL = src[ offseti * 2 + 0 ] >> 16;;
1022 sampleR = src[ offseti * 2 + 1 ] >> 16;;
1024 if( StopAtZero &&
1025 ( ( lastpointL < 0 && sampleL >= 0 ) ||
1026 ( lastpointR < 0 && sampleR >= 0 ) ||
1027 ( lastpointL > 0 && sampleL <= 0 ) ||
1028 ( lastpointR > 0 && sampleR <= 0 ) ) )
1030 break;
1033 lastpointL = sampleL;
1034 lastpointR = sampleR;
1036 *dst++ += ( ScaleLeft * sampleL ) >> 16;
1037 *dst++ += ( ScaleRight * sampleR ) >> 16;
1039 offset -= Add;
1042 *Dst = dst;
1043 *Offset = offset;
1045 return i;
1049 #undef offseti
1050 #undef offsetf
1052 /*****************************************************************************/