| 1 | // some code for sample mixing |
| 2 | // (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas |
| 3 | |
| 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 | |
| 14 | void 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 | |
| 31 | void 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 | |
| 45 | void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count) |
| 46 | { |
| 47 | while (count--) |
| 48 | { |
| 49 | *dest_buf++ += *mp3_buf++ >> 1; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count) |
| 54 | { |
| 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 | } |
| 62 | } |
| 63 | |
| 64 | void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count) |
| 65 | { |
| 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 | } |
| 73 | } |
| 74 | |