drc: support ms ABI
[picodrive.git] / pico / sound / mix.c
CommitLineData
cff531af 1/*
2 * some code for sample mixing
3 * (C) notaz, 2006,2007
4 *
5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
7 */
8b99ab90 8
4f265db7 9#define MAXOUT (+32767)
10#define MINOUT (-32768)
11
12/* limitter */
13#define Limit(val, max,min) { \
14 if ( val > max ) val = max; \
15 else if ( val < min ) val = min; \
16}
17
18
4f265db7 19void mix_32_to_16l_stereo(short *dest, int *src, int count)
20{
21 int l, r;
22
23 for (; count > 0; count--)
24 {
25 l = r = *dest;
26 l += *src++;
27 r += *src++;
28 Limit( l, MAXOUT, MINOUT );
29 Limit( r, MAXOUT, MINOUT );
30 *dest++ = l;
31 *dest++ = r;
32 }
33}
34
35
36void mix_32_to_16_mono(short *dest, int *src, int count)
37{
38 int l;
39
40 for (; count > 0; count--)
41 {
42 l = *dest;
43 l += *src++;
44 Limit( l, MAXOUT, MINOUT );
45 *dest++ = l;
46 }
47}
48
49
cea65903 50void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
51{
4b167c12 52 while (count--)
53 {
54 *dest_buf++ += *mp3_buf++ >> 1;
55 }
cea65903 56}
57
58void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
59{
4b167c12 60 count >>= 1;
61 while (count--)
62 {
63 *dest_buf++ += *mp3_buf++ >> 1;
64 *dest_buf++ += *mp3_buf++ >> 1;
65 mp3_buf += 1*2;
66 }
cea65903 67}
68
69void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
70{
4b167c12 71 count >>= 1;
72 while (count--)
73 {
74 *dest_buf++ += *mp3_buf++ >> 1;
75 *dest_buf++ += *mp3_buf++ >> 1;
76 mp3_buf += 3*2;
77 }
cea65903 78}
79