summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/snd_mix_generic.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-11 15:34:30 -0500
committerFranklin Wei <git@fwei.tk>2019-07-19 22:37:40 -0400
commit5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4 (patch)
tree84406e21639529a185556a33e5de7f43cffc277b /apps/plugins/sdl/progs/quake/snd_mix_generic.c
parentb70fecf21ddc21877ec1ae7888d9c18a979e37ad (diff)
downloadrockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.tar.gz
rockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.zip
Quake!
This ports id Software's Quake to run on the SDL plugin runtime. The source code originated from id under the GPLv2 license. I used https://github.com/ahefner/sdlquake as the base of my port. Performance is, unsurprisingly, not on par with what you're probably used to on PC. I average about 10FPS on ipod6g, but it's still playable. Sound works well enough, but in-game music is not supported. I've written ARM assembly routines for the inner sound loop. Make sure you turn the "brightness" all the way down, or colors will look funky. To run, extract Quake's data files to /.rockbox/quake. Have fun! Change-Id: I4285036e967d7f0722802d43cf2096c808ca5799
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}