summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/snd_mix.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/quake/snd_mix.c')
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/snd_mix.c b/apps/plugins/sdl/progs/quake/snd_mix.c
new file mode 100644
index 0000000000..3f254552b9
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/snd_mix.c
@@ -0,0 +1,132 @@
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// snd_mix.c -- portable code to mix sounds for snd_dma.c
21
22#include "quakedef.h"
23
24#define DWORD unsigned long
25
26// why not write straight to SHM buffer?!?
27//portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
28int16_t *paintbuffer; // stereo interleaved samples
29
30/*
31===============================================================================
32
33CHANNEL MIXING
34
35===============================================================================
36*/
37
38// in snd_mix_*
39
40void SND_PaintChannelFrom8 (int true_lvol, int true_rvol, signed char *sfx, int count);
41void SND_PaintChannelFrom16 (int true_lvol, int true_rvol, signed short *sfx, int count);
42
43void S_PaintChannels(int endtime)
44{
45 int i;
46 int end;
47 channel_t *ch;
48 sfxcache_t *sc;
49 int ltime, count;
50
51 paintbuffer = shm->buffer;
52
53 //while (paintedtime < endtime)
54 //{
55 // if paintbuffer is smaller than DMA buffer
56
57 end = endtime;
58 //if (endtime - paintedtime > PAINTBUFFER_SIZE)
59 //end = paintedtime + PAINTBUFFER_SIZE;
60
61 // clear the paint buffer
62 memset(paintbuffer, 0, (end - paintedtime) * sizeof(int16_t));
63
64 // 0-255
65 int volume_fp = volume.value * 255;
66
67 // paint in the channels.
68 ch = channels;
69 for (i=0; i<total_channels ; i++, ch++)
70 {
71 if (!ch->sfx)
72 continue;
73 if (!ch->leftvol && !ch->rightvol)
74 continue;
75 sc = S_LoadSound (ch->sfx); // sound fx cache
76 if (!sc)
77 continue;
78
79 ltime = paintedtime;
80
81 while (ltime < end)
82 { // paint up to end of sound channel, or end of buffer, whichever is greatest
83 if (ch->end < end)
84 count = ch->end - ltime;
85 else
86 count = end - ltime;
87
88 //if(count == 1)
89 // rb->splashf(HZ, "Potential problem");
90
91 if (count > 0)
92 {
93 int true_lvol, true_rvol;
94 true_lvol = (volume_fp * ch->leftvol) / 256;
95 true_rvol = (volume_fp * ch->rightvol) / 256;
96
97 if (sc->width == 1)
98 {
99 signed char *sfx = (char*)sc->data + ch->pos;
100 SND_PaintChannelFrom8(true_lvol, true_rvol, sfx, count);
101 }
102 else
103 {
104 signed short *sfx = (short*)sc->data + ch->pos;
105 SND_PaintChannelFrom16(true_lvol, true_rvol, sfx, count);
106 }
107
108 ch->pos += count;
109 ltime += count;
110 }
111
112 // if at end of loop, restart
113 if (ltime >= ch->end)
114 {
115 if (sc->loopstart >= 0)
116 {
117 ch->pos = sc->loopstart;
118 ch->end = ltime + sc->length - ch->pos;
119 }
120 else
121 { // channel just stopped
122 ch->sfx = NULL;
123 break;
124 }
125 }
126 }
127 }
128
129 // transfer out according to DMA format
130 //S_TransferPaintBuffer(end);
131 paintedtime = end;
132}