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