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,
23 #include "addroutines.h"
25 /******************************************************************************
26 ** Add-Routines ***************************************************************
27 ******************************************************************************/
29 /* Forward mixing code */
31 #define offseti ( (long) ( offset >> 32 ) )
34 AddLofiByteMono( ADDARGS
)
38 Fixed64 offset
= *Offset
;
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;
49 ( ( lastpoint
< 0 && sample
>= 0 ) ||
50 ( lastpoint
> 0 && sample
<= 0 ) ) )
57 *dst
++ += ( ScaleLeft
* sample
) >> 16;
70 AddLofiByteStereo( ADDARGS
)
74 Fixed64 offset
= *Offset
;
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;
85 ( ( lastpoint
< 0 && sample
>= 0 ) ||
86 ( lastpoint
> 0 && sample
<= 0 ) ) )
93 *dst
++ += ( ScaleLeft
* sample
) >> 16;
94 *dst
++ += ( ScaleRight
* sample
) >> 16;
107 AddLofiBytesMono( ADDARGS
)
111 Fixed64 offset
= *Offset
;
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;
123 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
124 ( lastpointR
< 0 && sampleR
>= 0 ) ||
125 ( lastpointL
> 0 && sampleL
<= 0 ) ||
126 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
131 lastpointL
= sampleL
;
132 lastpointR
= sampleR
;
134 *dst
++ += ( ScaleLeft
* sampleL
+ ScaleRight
* sampleR
) >> 16;
147 AddLofiBytesStereo( ADDARGS
)
151 Fixed64 offset
= *Offset
;
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;
163 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
164 ( lastpointR
< 0 && sampleR
>= 0 ) ||
165 ( lastpointL
> 0 && sampleL
<= 0 ) ||
166 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
171 lastpointL
= sampleL
;
172 lastpointR
= sampleR
;
174 *dst
++ += ( ScaleLeft
* sampleL
) >> 16;
175 *dst
++ += ( ScaleRight
* sampleR
) >> 16;
188 AddLofiWordMono( ADDARGS
)
192 Fixed64 offset
= *Offset
;
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
];
203 ( ( lastpoint
< 0 && sample
>= 0 ) ||
204 ( lastpoint
> 0 && sample
<= 0 ) ) )
211 *dst
++ += ( ScaleLeft
* sample
) >> 16;
224 AddLofiWordStereo( ADDARGS
)
228 Fixed64 offset
= *Offset
;
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
];
239 ( ( lastpoint
< 0 && sample
>= 0 ) ||
240 ( lastpoint
> 0 && sample
<= 0 ) ) )
247 *dst
++ += ( ScaleLeft
* sample
) >> 16;
248 *dst
++ += ( ScaleRight
* sample
) >> 16;
260 AddLofiWordsMono( ADDARGS
)
264 Fixed64 offset
= *Offset
;
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 ];
276 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
277 ( lastpointR
< 0 && sampleR
>= 0 ) ||
278 ( lastpointL
> 0 && sampleL
<= 0 ) ||
279 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
284 lastpointL
= sampleL
;
285 lastpointR
= sampleR
;
287 *dst
++ += ( ScaleLeft
* sampleL
+ ScaleRight
* sampleR
) >> 16;
300 AddLofiWordsStereo( ADDARGS
)
304 Fixed64 offset
= *Offset
;
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 ];
316 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
317 ( lastpointR
< 0 && sampleR
>= 0 ) ||
318 ( lastpointL
> 0 && sampleL
<= 0 ) ||
319 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
324 lastpointL
= sampleL
;
325 lastpointR
= sampleR
;
327 *dst
++ += ( ScaleLeft
* sampleL
) >> 16;
328 *dst
++ += ( ScaleRight
* sampleR
) >> 16;
339 /*****************************************************************************/
341 /* Backward mixing code */
344 AddLofiByteMonoB( ADDARGS
)
348 Fixed64 offset
= *Offset
;
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;
359 ( ( lastpoint
< 0 && sample
>= 0 ) ||
360 ( lastpoint
> 0 && sample
<= 0 ) ) )
367 *dst
++ += ( ScaleLeft
* sample
) >> 16;
380 AddLofiByteStereoB( ADDARGS
)
384 Fixed64 offset
= *Offset
;
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;
395 ( ( lastpoint
< 0 && sample
>= 0 ) ||
396 ( lastpoint
> 0 && sample
<= 0 ) ) )
403 *dst
++ += ( ScaleLeft
* sample
) >> 16;
404 *dst
++ += ( ScaleRight
* sample
) >> 16;
417 AddLofiBytesMonoB( ADDARGS
)
421 Fixed64 offset
= *Offset
;
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;
433 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
434 ( lastpointR
< 0 && sampleR
>= 0 ) ||
435 ( lastpointL
> 0 && sampleL
<= 0 ) ||
436 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
441 lastpointL
= sampleL
;
442 lastpointR
= sampleR
;
444 *dst
++ += ( ScaleLeft
* sampleL
+ ScaleRight
* sampleR
) >> 16;
457 AddLofiBytesStereoB( ADDARGS
)
461 Fixed64 offset
= *Offset
;
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;
473 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
474 ( lastpointR
< 0 && sampleR
>= 0 ) ||
475 ( lastpointL
> 0 && sampleL
<= 0 ) ||
476 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
481 lastpointL
= sampleL
;
482 lastpointR
= sampleR
;
484 *dst
++ += ( ScaleLeft
* sampleL
) >> 16;
485 *dst
++ += ( ScaleRight
* sampleR
) >> 16;
498 AddLofiWordMonoB( ADDARGS
)
502 Fixed64 offset
= *Offset
;
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
];
513 ( ( lastpoint
< 0 && sample
>= 0 ) ||
514 ( lastpoint
> 0 && sample
<= 0 ) ) )
521 *dst
++ += ( ScaleLeft
* sample
) >> 16;
534 AddLofiWordStereoB( ADDARGS
)
538 Fixed64 offset
= *Offset
;
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
];
549 ( ( lastpoint
< 0 && sample
>= 0 ) ||
550 ( lastpoint
> 0 && sample
<= 0 ) ) )
557 *dst
++ += ( ScaleLeft
* sample
) >> 16;
558 *dst
++ += ( ScaleRight
* sample
) >> 16;
571 AddLofiWordsMonoB( ADDARGS
)
575 Fixed64 offset
= *Offset
;
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 ];
587 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
588 ( lastpointR
< 0 && sampleR
>= 0 ) ||
589 ( lastpointL
> 0 && sampleL
<= 0 ) ||
590 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
595 lastpointL
= sampleL
;
596 lastpointR
= sampleR
;
598 *dst
++ += ( ScaleLeft
* sampleL
+ ScaleRight
* sampleR
) >> 16;
611 AddLofiWordsStereoB( ADDARGS
)
615 Fixed64 offset
= *Offset
;
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 ];
627 ( ( lastpointL
< 0 && sampleL
>= 0 ) ||
628 ( lastpointR
< 0 && sampleR
>= 0 ) ||
629 ( lastpointL
> 0 && sampleL
<= 0 ) ||
630 ( lastpointR
> 0 && sampleR
<= 0 ) ) )
635 lastpointL
= sampleL
;
636 lastpointR
= sampleR
;
638 *dst
++ += ( ScaleLeft
* sampleL
) >> 16;
639 *dst
++ += ( ScaleRight
* sampleR
) >> 16;
650 /*****************************************************************************/