Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Device / addroutines_71.c
blobf5b8eb2d80ad249ba9dbcd01da496c5e9fec2171
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 *StartPoints
36 ** APTR Unused
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 ( (long) ( (unsigned long) ( offset & 0xffffffffULL ) >> 17) )
65 LONG
66 AddByte71( ADDARGS )
68 BYTE *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;
82 else
84 startpoint = src[ offseti - 1 ] << 8;
87 endpoint = src[ offseti ] << 8;
89 startpoint += (((endpoint - startpoint) * offsetf ) >> 15);
91 if( StopAtZero &&
92 ( ( lastpoint < 0 && startpoint >= 0 ) ||
93 ( lastpoint > 0 && startpoint <= 0 ) ) )
95 break;
98 lastpoint = startpoint;
100 dst[ 0 ] += ScaleLeft * startpoint;
101 dst[ 1 ] += ScaleRight * startpoint;
102 dst += 8;
104 offset += Add;
107 *StartPointLeft = endpoint;
109 *Dst = dst;
110 *Offset = offset;
112 return i;
115 LONG
116 AddBytes71( ADDARGS )
118 BYTE *src = Src;
119 LONG *dst = *Dst;
120 Fixed64 offset = *Offset;
121 int i;
122 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
123 LONG lastpointL, lastpointR;
125 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
127 for( i = 0; i < Samples; i++)
129 if( offseti == FirstOffsetI ) {
130 startpointL = *StartPointLeft;
131 startpointR = *StartPointRight;
133 else
135 startpointL = src[ offseti * 2 + 0 - 2 ] << 8;
136 startpointR = src[ offseti * 2 + 1 - 2 ] << 8;
139 endpointL = src[ offseti * 2 + 0 ] << 8;
140 endpointR = src[ offseti * 2 + 1 ] << 8;
142 startpointL += (((endpointL - startpointL) * offsetf ) >> 15);
143 startpointR += (((endpointR - startpointR) * offsetf ) >> 15);
145 if( StopAtZero &&
146 ( ( lastpointL < 0 && startpointL >= 0 ) ||
147 ( lastpointR < 0 && startpointR >= 0 ) ||
148 ( lastpointL > 0 && startpointL <= 0 ) ||
149 ( lastpointR > 0 && startpointR <= 0 ) ) )
151 break;
154 lastpointL = startpointL;
155 lastpointR = startpointR;
157 dst[ 0 ] += ScaleLeft * startpointL;
158 dst[ 1 ] += ScaleRight * startpointR;
159 dst += 8;
161 offset += Add;
164 *StartPointLeft = endpointL;
165 *StartPointRight = endpointR;
167 *Dst = dst;
168 *Offset = offset;
170 return i;
172 LONG
173 AddWord71( ADDARGS )
175 WORD *src = Src;
176 LONG *dst = *Dst;
177 Fixed64 offset = *Offset;
178 int i;
179 LONG startpoint, endpoint = 0; // Make compiler happy
180 LONG lastpoint;
182 lastpoint = 0; // 0 doesn't affect the StopAtZero code
184 for( i = 0; i < Samples; i++)
186 if( offseti == FirstOffsetI ) {
187 startpoint = *StartPointLeft;
189 else
191 startpoint = src[ offseti - 1 ];
194 endpoint = src[ offseti ];
196 startpoint += (((endpoint - startpoint) * offsetf ) >> 15);
198 if( StopAtZero &&
199 ( ( lastpoint < 0 && startpoint >= 0 ) ||
200 ( lastpoint > 0 && startpoint <= 0 ) ) )
202 break;
205 lastpoint = startpoint;
207 dst[ 0 ] += ScaleLeft * startpoint;
208 dst[ 1 ] += ScaleRight * startpoint;
209 dst += 8;
211 offset += Add;
214 *StartPointLeft = endpoint;
216 *Dst = dst;
217 *Offset = offset;
219 return i;
223 LONG
224 AddWords71( ADDARGS )
226 WORD *src = Src;
227 LONG *dst = *Dst;
228 Fixed64 offset = *Offset;
229 int i;
230 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
231 LONG lastpointL, lastpointR;
233 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
235 for( i = 0; i < Samples; i++)
237 if( offseti == FirstOffsetI ) {
238 startpointL = *StartPointLeft;
239 startpointR = *StartPointRight;
241 else
243 startpointL = src[ offseti * 2 + 0 - 2 ];
244 startpointR = src[ offseti * 2 + 1 - 2 ];
247 endpointL = src[ offseti * 2 + 0 ];
248 endpointR = src[ offseti * 2 + 1 ];
250 startpointL += (((endpointL - startpointL) * offsetf ) >> 15);
251 startpointR += (((endpointR - startpointR) * offsetf ) >> 15);
253 if( StopAtZero &&
254 ( ( lastpointL < 0 && startpointL >= 0 ) ||
255 ( lastpointR < 0 && startpointR >= 0 ) ||
256 ( lastpointL > 0 && startpointL <= 0 ) ||
257 ( lastpointR > 0 && startpointR <= 0 ) ) )
259 break;
262 lastpointL = startpointL;
263 lastpointR = startpointR;
265 dst[ 0 ] += ScaleLeft * startpointL;
266 dst[ 1 ] += ScaleRight * startpointR;
267 dst += 8;
269 offset += Add;
272 *StartPointLeft = endpointL;
273 *StartPointRight = endpointR;
275 *Dst = dst;
276 *Offset = offset;
278 return i;
281 #undef offseti
282 #undef offsetf
284 /*****************************************************************************/
286 #define offseti ( (long) ( offset >> 32 ) )
288 #define offsetf ( offset & 0xffffffffULL )
290 LONG
291 AddLong71( ADDARGS )
293 LONG *src = Src;
294 LONG *dst = *Dst;
295 Fixed64 offset = *Offset;
296 int i;
297 LONG startpoint, endpoint = 0; // Make compiler happy
298 LONG lastpoint;
300 lastpoint = 0; // 0 doesn't affect the StopAtZero code
302 for( i = 0; i < Samples; i++)
304 if( offseti == FirstOffsetI ) {
305 startpoint = *StartPointLeft << 16;
307 else
309 startpoint = src[ offseti - 1 ];
312 endpoint = src[ offseti ];
314 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
316 if( StopAtZero &&
317 ( ( lastpoint < 0 && startpoint >= 0 ) ||
318 ( lastpoint > 0 && startpoint <= 0 ) ) )
320 break;
323 lastpoint = startpoint;
325 dst[ 0 ] += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
326 dst[ 1 ] += (LONG) ( ( (LONGLONG) ScaleRight * startpoint ) >> 16 );
327 dst += 8;
329 offset += Add;
332 *StartPointLeft = endpoint >> 16;
334 *Dst = dst;
335 *Offset = offset;
337 return i;
341 LONG
342 AddLongs71( ADDARGS )
344 LONG *src = Src;
345 LONG *dst = *Dst;
346 Fixed64 offset = *Offset;
347 int i;
348 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
349 LONG lastpointL, lastpointR;
351 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
353 for( i = 0; i < Samples; i++)
355 if( offseti == FirstOffsetI ) {
356 startpointL = *StartPointLeft << 16;
357 startpointR = *StartPointRight << 16;
359 else
361 startpointL = src[ offseti * 2 + 0 - 2 ];
362 startpointR = src[ offseti * 2 + 1 - 2 ];
365 endpointL = src[ offseti * 2 + 0 ];
366 endpointR = src[ offseti * 2 + 1 ];
368 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
369 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
371 if( StopAtZero &&
372 ( ( lastpointL < 0 && startpointL >= 0 ) ||
373 ( lastpointR < 0 && startpointR >= 0 ) ||
374 ( lastpointL > 0 && startpointL <= 0 ) ||
375 ( lastpointR > 0 && startpointR <= 0 ) ) )
377 break;
380 lastpointL = startpointL;
381 lastpointR = startpointR;
383 dst[ 0 ] += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
384 dst[ 1 ] += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
385 dst += 8;
387 offset += Add;
390 *StartPointLeft = endpointL >> 16;
391 *StartPointRight = endpointR >> 16;
393 *Dst = dst;
394 *Offset = offset;
396 return i;
400 LONG
401 Add7171( ADDARGS71 )
403 LONG *src = Src;
404 LONG *dst = *Dst;
405 Fixed64 offset = *Offset;
406 int i;
407 LONG startpointL, startpointR;
408 LONG startpointRL, startpointRR;
409 LONG startpointSL, startpointSR;
410 LONG startpointC, startpointLFE;
411 LONG endpointL = 0, endpointR = 0; // Make compiler happy
412 LONG endpointRL = 0, endpointRR = 0; // Make compiler happy
413 LONG endpointSL = 0, endpointSR = 0; // Make compiler happy
414 LONG endpointC = 0, endpointLFE = 0; // Make compiler happy
415 LONG lastpointL, lastpointR;
416 LONG scale_mono = ( ScaleLeft + ScaleRight ) / 2;
418 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
420 for( i = 0; i < Samples; i++)
422 if( offseti == FirstOffsetI ) {
423 startpointL = StartPoints[ CD_L ] << 16;
424 startpointR = StartPoints[ CD_R ] << 16;
425 startpointRL = StartPoints[ CD_RL ] << 16;
426 startpointRR = StartPoints[ CD_RR ] << 16;
427 startpointSL = StartPoints[ CD_SL ] << 16;
428 startpointSR = StartPoints[ CD_SR ] << 16;
429 startpointC = StartPoints[ CD_C ] << 16;
430 startpointLFE = StartPoints[ CD_LFE ] << 16;
432 else
434 startpointL = src[ offseti * 8 + 0 - 8 ];
435 startpointR = src[ offseti * 8 + 1 - 8 ];
436 startpointRL = src[ offseti * 8 + 2 - 8 ];
437 startpointRR = src[ offseti * 8 + 3 - 8 ];
438 startpointSL = src[ offseti * 8 + 4 - 8 ];
439 startpointSR = src[ offseti * 8 + 5 - 8 ];
440 startpointC = src[ offseti * 8 + 6 - 8 ];
441 startpointLFE = src[ offseti * 8 + 7 - 8 ];
444 endpointL = src[ offseti * 8 + 0 ];
445 endpointR = src[ offseti * 8 + 1 ];
446 endpointRL = src[ offseti * 8 + 2 ];
447 endpointRR = src[ offseti * 8 + 3 ];
448 endpointSL = src[ offseti * 8 + 4 ];
449 endpointSR = src[ offseti * 8 + 5 ];
450 endpointC = src[ offseti * 8 + 6 ];
451 endpointLFE = src[ offseti * 8 + 7 ];
453 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
454 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
455 startpointRL += (LONG) (((LONGLONG) (endpointRL - startpointRL) * offsetf ) >> 32);
456 startpointRR += (LONG) (((LONGLONG) (endpointRR - startpointRR) * offsetf ) >> 32);
457 startpointSL += (LONG) (((LONGLONG) (endpointSL - startpointSL) * offsetf ) >> 32);
458 startpointSR += (LONG) (((LONGLONG) (endpointSR - startpointSR) * offsetf ) >> 32);
459 startpointC += (LONG) (((LONGLONG) (endpointC - startpointC) * offsetf ) >> 32);
460 startpointLFE += (LONG) (((LONGLONG) (endpointLFE - startpointLFE) * offsetf ) >> 32);
462 if( StopAtZero &&
463 ( ( lastpointL < 0 && startpointL >= 0 ) ||
464 ( lastpointR < 0 && startpointR >= 0 ) ||
465 ( lastpointL > 0 && startpointL <= 0 ) ||
466 ( lastpointR > 0 && startpointR <= 0 ) ) )
468 break;
471 lastpointL = startpointL;
472 lastpointR = startpointR;
474 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
475 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
476 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointRL ) >> 16 );
477 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointRR ) >> 16 );
478 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointSL ) >> 16 );
479 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointSR ) >> 16 );
480 *dst++ += (LONG) ( ( (LONGLONG) scale_mono * startpointC ) >> 16 );
481 *dst++ += (LONG) ( ( (LONGLONG) scale_mono * startpointLFE ) >> 16 );
483 offset += Add;
486 StartPoints[ CD_L ] = endpointL >> 16;
487 StartPoints[ CD_R ] = endpointR >> 16;
488 StartPoints[ CD_RL ] = endpointRL >> 16;
489 StartPoints[ CD_RR ] = endpointRR >> 16;
490 StartPoints[ CD_SL ] = endpointSL >> 16;
491 StartPoints[ CD_SR ] = endpointSR >> 16;
492 StartPoints[ CD_C ] = endpointC >> 16;
493 StartPoints[ CD_LFE ] = endpointLFE >> 16;
495 *Dst = dst;
496 *Offset = offset;
498 return i;
501 #undef offseti
502 #undef offsetf
505 /*****************************************************************************/
507 /* Backward mixing code */
509 #define offseti ( (long) ( offset >> 32 ) )
511 #define offsetf ( (long) ( 32768 - ( (unsigned long) ( offset & 0xffffffffULL ) >> 17 ) ) )
513 LONG
514 AddByte71B( ADDARGS )
516 BYTE *src = Src;
517 LONG *dst = *Dst;
518 Fixed64 offset = *Offset;
519 int i;
520 LONG startpoint, endpoint = 0; // Make compiler happy
521 LONG lastpoint;
523 lastpoint = 0; // 0 doesn't affect the StopAtZero code
525 for( i = 0; i < Samples; i++)
527 if( offseti == FirstOffsetI ) {
528 startpoint = *StartPointLeft;
530 else
532 startpoint = src[ offseti + 1 ] << 8;
535 endpoint = src[ offseti ] << 8;
537 startpoint += (((endpoint - startpoint) * offsetf ) >> 15);
539 if( StopAtZero &&
540 ( ( lastpoint < 0 && startpoint >= 0 ) ||
541 ( lastpoint > 0 && startpoint <= 0 ) ) )
543 break;
546 lastpoint = startpoint;
548 dst[ 0 ] += ScaleLeft * startpoint;
549 dst[ 1 ] += ScaleRight * startpoint;
550 dst += 8;
552 offset -= Add;
555 *StartPointLeft = endpoint;
557 *Dst = dst;
558 *Offset = offset;
560 return i;
563 LONG
564 AddBytes71B( ADDARGS )
566 BYTE *src = Src;
567 LONG *dst = *Dst;
568 Fixed64 offset = *Offset;
569 int i;
570 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
571 LONG lastpointL, lastpointR;
573 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
575 for( i = 0; i < Samples; i++)
577 if( offseti == FirstOffsetI ) {
578 startpointL = *StartPointLeft;
579 startpointR = *StartPointRight;
581 else
583 startpointL = src[ offseti * 2 + 0 + 2 ] << 8;
584 startpointR = src[ offseti * 2 + 1 + 2 ] << 8;
587 endpointL = src[ offseti * 2 + 0 ] << 8;
588 endpointR = src[ offseti * 2 + 1 ] << 8;
590 startpointL += (((endpointL - startpointL) * offsetf ) >> 15);
591 startpointR += (((endpointR - startpointR) * offsetf ) >> 15);
593 if( StopAtZero &&
594 ( ( lastpointL < 0 && startpointL >= 0 ) ||
595 ( lastpointR < 0 && startpointR >= 0 ) ||
596 ( lastpointL > 0 && startpointL <= 0 ) ||
597 ( lastpointR > 0 && startpointR <= 0 ) ) )
599 break;
602 lastpointL = startpointL;
603 lastpointR = startpointR;
605 dst[ 0 ] += ScaleLeft * startpointL;
606 dst[ 1 ] += ScaleRight * startpointR;
607 dst += 8;
609 offset -= Add;
612 *StartPointLeft = endpointL;
613 *StartPointRight = endpointR;
615 *Dst = dst;
616 *Offset = offset;
618 return i;
622 LONG
623 AddWord71B( ADDARGS )
625 WORD *src = Src;
626 LONG *dst = *Dst;
627 Fixed64 offset = *Offset;
628 int i;
629 LONG startpoint, endpoint = 0; // Make compiler happy
630 LONG lastpoint;
632 lastpoint = 0; // 0 doesn't affect the StopAtZero code
634 for( i = 0; i < Samples; i++)
636 if( offseti == FirstOffsetI ) {
637 startpoint = *StartPointLeft;
639 else
641 startpoint = src[ offseti + 1 ];
644 endpoint = src[ offseti ];
646 startpoint += (((endpoint - startpoint) * offsetf ) >> 15);
648 if( StopAtZero &&
649 ( ( lastpoint < 0 && startpoint >= 0 ) ||
650 ( lastpoint > 0 && startpoint <= 0 ) ) )
652 break;
655 lastpoint = startpoint;
657 dst[ 0 ] += ScaleLeft * startpoint;
658 dst[ 1 ] += ScaleRight * startpoint;
659 dst += 8;
661 offset -= Add;
664 *StartPointLeft = endpoint;
666 *Dst = dst;
667 *Offset = offset;
669 return i;
673 LONG
674 AddWords71B( ADDARGS )
676 WORD *src = Src;
677 LONG *dst = *Dst;
678 Fixed64 offset = *Offset;
679 int i;
680 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
681 LONG lastpointL, lastpointR;
683 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
685 for( i = 0; i < Samples; i++)
687 if( offseti == FirstOffsetI ) {
688 startpointL = *StartPointLeft;
689 startpointR = *StartPointRight;
691 else
693 startpointL = src[ offseti * 2 + 0 + 2 ];
694 startpointR = src[ offseti * 2 + 1 + 2 ];
697 endpointL = src[ offseti * 2 + 0 ];
698 endpointR = src[ offseti * 2 + 1 ];
700 startpointL += (((endpointL - startpointL) * offsetf ) >> 15);
701 startpointR += (((endpointR - startpointR) * offsetf ) >> 15);
703 if( StopAtZero &&
704 ( ( lastpointL < 0 && startpointL >= 0 ) ||
705 ( lastpointR < 0 && startpointR >= 0 ) ||
706 ( lastpointL > 0 && startpointL <= 0 ) ||
707 ( lastpointR > 0 && startpointR <= 0 ) ) )
709 break;
712 lastpointL = startpointL;
713 lastpointR = startpointR;
715 dst[ 0 ] += ScaleLeft * startpointL;
716 dst[ 1 ] += ScaleRight * startpointR;
717 dst += 8;
719 offset -= Add;
722 *StartPointLeft = endpointL;
723 *StartPointRight = endpointR;
725 *Dst = dst;
726 *Offset = offset;
728 return i;
731 #undef offseti
732 #undef offsetf
734 /*****************************************************************************/
736 #define offseti ( (long) ( offset >> 32 ) )
738 #define offsetf ( (long) ( 32768 - ( (unsigned long) ( offset & 0xffffffffULL ) >> 17 ) ) )
740 LONG
741 AddLong71B( ADDARGS )
743 LONG *src = Src;
744 LONG *dst = *Dst;
745 Fixed64 offset = *Offset;
746 int i;
747 LONG startpoint, endpoint = 0; // Make compiler happy
748 LONG lastpoint;
750 lastpoint = 0; // 0 doesn't affect the StopAtZero code
752 for( i = 0; i < Samples; i++)
754 if( offseti == FirstOffsetI ) {
755 startpoint = *StartPointLeft << 16;
757 else
759 startpoint = src[ offseti + 1 ];
762 endpoint = src[ offseti ];
764 startpoint += (LONG) (((LONGLONG) (endpoint - startpoint) * offsetf ) >> 32);
766 if( StopAtZero &&
767 ( ( lastpoint < 0 && startpoint >= 0 ) ||
768 ( lastpoint > 0 && startpoint <= 0 ) ) )
770 break;
773 lastpoint = startpoint;
775 dst[ 0 ] += (LONG) ( ( (LONGLONG) ScaleLeft * startpoint ) >> 16 );
776 dst[ 1 ] += (LONG) ( ( (LONGLONG) ScaleRight * startpoint ) >> 16 );
777 dst += 8;
779 offset -= Add;
782 *StartPointLeft = endpoint >> 16;
784 *Dst = dst;
785 *Offset = offset;
787 return i;
791 LONG
792 AddLongs71B( ADDARGS )
794 LONG *src = Src;
795 LONG *dst = *Dst;
796 Fixed64 offset = *Offset;
797 int i;
798 LONG startpointL, startpointR, endpointL = 0, endpointR = 0; // Make compiler happy
799 LONG lastpointL, lastpointR;
801 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
803 for( i = 0; i < Samples; i++)
805 if( offseti == FirstOffsetI ) {
806 startpointL = *StartPointLeft << 16;
807 startpointR = *StartPointRight << 16;
809 else
811 startpointL = src[ offseti * 2 + 0 + 2 ];
812 startpointR = src[ offseti * 2 + 1 + 2 ];
815 endpointL = src[ offseti * 2 + 0 ];
816 endpointR = src[ offseti * 2 + 1 ];
818 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
819 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
821 if( StopAtZero &&
822 ( ( lastpointL < 0 && startpointL >= 0 ) ||
823 ( lastpointR < 0 && startpointR >= 0 ) ||
824 ( lastpointL > 0 && startpointL <= 0 ) ||
825 ( lastpointR > 0 && startpointR <= 0 ) ) )
827 break;
830 lastpointL = startpointL;
831 lastpointR = startpointR;
833 dst[ 0 ] += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
834 dst[ 1 ] += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
835 dst += 8;
837 offset -= Add;
840 *StartPointLeft = endpointL >> 16;
841 *StartPointRight = endpointR >> 16;
843 *Dst = dst;
844 *Offset = offset;
846 return i;
850 LONG
851 Add7171B( ADDARGS71 )
853 LONG *src = Src;
854 LONG *dst = *Dst;
855 Fixed64 offset = *Offset;
856 int i;
857 LONG startpointL, startpointR;
858 LONG startpointRL, startpointRR;
859 LONG startpointSL, startpointSR;
860 LONG startpointC, startpointLFE;
861 LONG endpointL = 0, endpointR = 0; // Make compiler happy
862 LONG endpointRL = 0, endpointRR = 0; // Make compiler happy
863 LONG endpointSL = 0, endpointSR = 0; // Make compiler happy
864 LONG endpointC = 0, endpointLFE = 0; // Make compiler happy
865 LONG lastpointL, lastpointR;
866 LONG scale_mono = ( ScaleLeft + ScaleRight ) / 2;
868 lastpointL = lastpointR = 0; // 0 doesn't affect the StopAtZero code
870 for( i = 0; i < Samples; i++)
872 if( offseti == FirstOffsetI ) {
873 startpointL = StartPoints[ CD_L ] << 16;
874 startpointR = StartPoints[ CD_R ] << 16;
875 startpointRL = StartPoints[ CD_RL ] << 16;
876 startpointRR = StartPoints[ CD_RR ] << 16;
877 startpointSL = StartPoints[ CD_SL ] << 16;
878 startpointSR = StartPoints[ CD_SR ] << 16;
879 startpointC = StartPoints[ CD_C ] << 16;
880 startpointLFE = StartPoints[ CD_LFE ] << 16;
882 else
884 startpointL = src[ offseti * 8 + 0 + 8 ];
885 startpointR = src[ offseti * 8 + 1 + 8 ];
886 startpointRL = src[ offseti * 8 + 2 + 8 ];
887 startpointRR = src[ offseti * 8 + 3 + 8 ];
888 startpointSL = src[ offseti * 8 + 4 + 8 ];
889 startpointSR = src[ offseti * 8 + 5 + 8 ];
890 startpointC = src[ offseti * 8 + 6 + 8 ];
891 startpointLFE = src[ offseti * 8 + 7 + 8 ];
894 endpointL = src[ offseti * 8 + 0 ];
895 endpointR = src[ offseti * 8 + 1 ];
896 endpointRL = src[ offseti * 8 + 2 ];
897 endpointRR = src[ offseti * 8 + 3 ];
898 endpointSL = src[ offseti * 8 + 4 ];
899 endpointSR = src[ offseti * 8 + 5 ];
900 endpointC = src[ offseti * 8 + 6 ];
901 endpointLFE = src[ offseti * 8 + 7 ];
903 startpointL += (LONG) (((LONGLONG) (endpointL - startpointL) * offsetf ) >> 32);
904 startpointR += (LONG) (((LONGLONG) (endpointR - startpointR) * offsetf ) >> 32);
905 startpointRL += (LONG) (((LONGLONG) (endpointRL - startpointRL) * offsetf ) >> 32);
906 startpointRR += (LONG) (((LONGLONG) (endpointRR - startpointRR) * offsetf ) >> 32);
907 startpointSL += (LONG) (((LONGLONG) (endpointSL - startpointSL) * offsetf ) >> 32);
908 startpointSR += (LONG) (((LONGLONG) (endpointSR - startpointSR) * offsetf ) >> 32);
909 startpointC += (LONG) (((LONGLONG) (endpointC - startpointC) * offsetf ) >> 32);
910 startpointLFE += (LONG) (((LONGLONG) (endpointLFE - startpointLFE) * offsetf ) >> 32);
912 if( StopAtZero &&
913 ( ( lastpointL < 0 && startpointL >= 0 ) ||
914 ( lastpointR < 0 && startpointR >= 0 ) ||
915 ( lastpointL > 0 && startpointL <= 0 ) ||
916 ( lastpointR > 0 && startpointR <= 0 ) ) )
918 break;
921 lastpointL = startpointL;
922 lastpointR = startpointR;
924 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointL ) >> 16 );
925 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointR ) >> 16 );
926 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointRL ) >> 16 );
927 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointRR ) >> 16 );
928 *dst++ += (LONG) ( ( (LONGLONG) ScaleLeft * startpointSL ) >> 16 );
929 *dst++ += (LONG) ( ( (LONGLONG) ScaleRight * startpointSR ) >> 16 );
930 *dst++ += (LONG) ( ( (LONGLONG) scale_mono * startpointC ) >> 16 );
931 *dst++ += (LONG) ( ( (LONGLONG) scale_mono * startpointLFE ) >> 16 );
933 offset -= Add;
936 StartPoints[ CD_L ] = endpointL >> 16;
937 StartPoints[ CD_R ] = endpointR >> 16;
938 StartPoints[ CD_RL ] = endpointRL >> 16;
939 StartPoints[ CD_RR ] = endpointRR >> 16;
940 StartPoints[ CD_SL ] = endpointSL >> 16;
941 StartPoints[ CD_SR ] = endpointSR >> 16;
942 StartPoints[ CD_C ] = endpointC >> 16;
943 StartPoints[ CD_LFE ] = endpointLFE >> 16;
945 *Dst = dst;
946 *Offset = offset;
948 return i;
951 #undef offseti
952 #undef offsetf