summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/snd_mix_generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/quake/snd_mix_generic.c')
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix_generic.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/snd_mix_generic.c b/apps/plugins/sdl/progs/quake/snd_mix_generic.c
new file mode 100644
index 0000000000..2c4b67b77c
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/snd_mix_generic.c
@@ -0,0 +1,69 @@
1/* This file is included from snd_mix.c */
2
3#include "SDL.h"
4
5// allow standalone compilation
6#ifndef QUAKE_SOUND
7extern short *paintbuffer;
8#define INLINE
9#else
10#define INLINE static inline
11#endif
12
13// C version
14static inline short CLAMPADD(short a, short b)
15{
16 int val = (int)a + (int)b;
17 if (val > 32767)
18 {
19 //rb->splashf(HZ, "saturate");
20 return 32767;
21 }
22 else if (val < -32768)
23 {
24 //rb->splashf(HZ, "saturate");
25 return -32768;
26 }
27 else
28 return val;
29}
30
31// if not ARMv5
32#ifndef __ARM_ARCH__5TEJ__
33void SND_PaintChannelFrom8 (int true_lvol, int true_rvol, signed char *sfx, int count)
34{
35 //return;
36 //LOGF("mix8\n");
37 int data;
38 int i;
39
40 // we have 8-bit sound in sfx[], which we want to scale to
41 // 16bit and take the volume into account
42 for (i=0 ; i<count ; i++)
43 {
44 // We could use the QADD16 instruction on ARMv6+
45 // or just 32-bit QADD with pre-shifted arguments
46 data = sfx[i];
47 paintbuffer[2*i+0] = CLAMPADD(paintbuffer[2*i+0], data * true_lvol); // need saturation
48 paintbuffer[2*i+1] = CLAMPADD(paintbuffer[2*i+1], data * true_rvol);
49 }
50}
51#endif
52
53void SND_PaintChannelFrom16 (int true_lvol, int true_rvol, signed short *sfx, int count)
54{
55 //return;
56 //LOGF("mix16\n");
57 int data;
58 int left, right;
59 int i;
60
61 for (i=0 ; i<count ; i+=2)
62 {
63 data = sfx[i];
64 left = ((int)data * true_lvol) >> 8;
65 right = ((int)data * true_rvol) >> 8;
66 paintbuffer[2*i+0] = CLAMPADD(paintbuffer[2*i+0], left); // need saturation
67 paintbuffer[2*i+1] = CLAMPADD(paintbuffer[2*i+1], right);
68 }
69}