final src and Makefile adjustments for PSP release
[picodrive.git] / Pico / sound / mix.c
CommitLineData
8b99ab90 1// some code for sample mixing
2// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas
3
4f265db7 4#define MAXOUT (+32767)
5#define MINOUT (-32768)
6
7/* limitter */
8#define Limit(val, max,min) { \
9 if ( val > max ) val = max; \
10 else if ( val < min ) val = min; \
11}
12
13
4f265db7 14void mix_32_to_16l_stereo(short *dest, int *src, int count)
15{
16 int l, r;
17
18 for (; count > 0; count--)
19 {
20 l = r = *dest;
21 l += *src++;
22 r += *src++;
23 Limit( l, MAXOUT, MINOUT );
24 Limit( r, MAXOUT, MINOUT );
25 *dest++ = l;
26 *dest++ = r;
27 }
28}
29
30
31void mix_32_to_16_mono(short *dest, int *src, int count)
32{
33 int l;
34
35 for (; count > 0; count--)
36 {
37 l = *dest;
38 l += *src++;
39 Limit( l, MAXOUT, MINOUT );
40 *dest++ = l;
41 }
42}
43
44
cea65903 45void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
46{
4b167c12 47 while (count--)
48 {
49 *dest_buf++ += *mp3_buf++ >> 1;
50 }
cea65903 51}
52
53void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
54{
4b167c12 55 count >>= 1;
56 while (count--)
57 {
58 *dest_buf++ += *mp3_buf++ >> 1;
59 *dest_buf++ += *mp3_buf++ >> 1;
60 mp3_buf += 1*2;
61 }
cea65903 62}
63
64void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
65{
4b167c12 66 count >>= 1;
67 while (count--)
68 {
69 *dest_buf++ += *mp3_buf++ >> 1;
70 *dest_buf++ += *mp3_buf++ >> 1;
71 mp3_buf += 3*2;
72 }
cea65903 73}
74