summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/duke3d/Game/src
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/duke3d/Game/src')
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c18
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.h7
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c633
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c140
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/game.c5
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/global.c12
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/global.h2
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/sounds.c100
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/util_lib.h3
9 files changed, 467 insertions, 453 deletions
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c
index 9a47f0e247..7567d7314b 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c
@@ -39,6 +39,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39#include <conio.h> 39#include <conio.h>
40#endif 40#endif
41 41
42#include "../global.h"
43
42#include "util.h" 44#include "util.h"
43#include "dpmi.h" 45#include "dpmi.h"
44#include "usrhooks.h" 46#include "usrhooks.h"
@@ -120,7 +122,8 @@ static int MV_FooMemory;
120static int MV_BufferDescriptor; 122static int MV_BufferDescriptor;
121static int MV_BufferEmpty[ NumberOfBuffers ]; 123static int MV_BufferEmpty[ NumberOfBuffers ];
122char *MV_MixBuffer[ NumberOfBuffers + 1 ]; 124char *MV_MixBuffer[ NumberOfBuffers + 1 ];
123double *MV_FooBuffer = NULL; 125/* fixed-point */
126long *MV_FooBuffer = NULL;
124 127
125static VoiceNode *MV_Voices = NULL; 128static VoiceNode *MV_Voices = NULL;
126 129
@@ -134,7 +137,7 @@ static void ( *MV_CallBackFunc )( unsigned long ) = NULL;
134static void ( *MV_RecordFunc )( char *ptr, int length ) = NULL; 137static void ( *MV_RecordFunc )( char *ptr, int length ) = NULL;
135static void ( *MV_MixFunction )( VoiceNode *voice); 138static void ( *MV_MixFunction )( VoiceNode *voice);
136 139
137int MV_MaxVolume = 63; 140const int MV_MaxVolume = 63;
138 141
139int *MV_GLast, *MV_GPos, *MV_GVal; 142int *MV_GLast, *MV_GPos, *MV_GVal;
140 143
@@ -144,8 +147,8 @@ char *MV_MixDestination;
144short *MV_LeftVolume; 147short *MV_LeftVolume;
145short *MV_RightVolume; 148short *MV_RightVolume;
146#else 149#else
147int MV_LeftVolume; 150int MV_LeftVolume, MV_LeftScale;
148int MV_RightVolume; 151int MV_RightVolume, MV_RightScale;
149#endif 152#endif
150int MV_SampleSize = 1; 153int MV_SampleSize = 1;
151int MV_RightChannelOffset; 154int MV_RightChannelOffset;
@@ -317,6 +320,9 @@ static void MV_Mix( VoiceNode *voice )
317 MV_MixDestination += 8; 320 MV_MixDestination += 8;
318 } 321 }
319 322
323 MV_LeftScale = (MV_LeftVolume << FRACBITS) / MV_MaxVolume;
324 MV_RightScale = (MV_RightVolume << FRACBITS) / MV_MaxVolume;
325
320 // Add this voice to the mix 326 // Add this voice to the mix
321 while( length > 0 ) 327 while( length > 0 )
322 { 328 {
@@ -459,7 +465,7 @@ void MV_ServiceVoc
459 } 465 }
460 466
461 { 467 {
462 ClearBuffer_DW( MV_FooBuffer, 0, sizeof(double) / 4 * MV_BufferSize / MV_SampleSize * MV_Channels); 468 ClearBuffer_DW( MV_FooBuffer, 0, sizeof(long) / 4 * MV_BufferSize / MV_SampleSize * MV_Channels);
463 MV_BufferEmpty[ MV_MixPage ] = TRUE; 469 MV_BufferEmpty[ MV_MixPage ] = TRUE;
464 } 470 }
465 471
@@ -3109,7 +3115,7 @@ int MV_Init
3109 MV_SetVolume( MV_MaxTotalVolume ); 3115 MV_SetVolume( MV_MaxTotalVolume );
3110 3116
3111 3117
3112 MV_FooMemory = sizeof(double) * MixBufferSize * numchannels + 1024; 3118 MV_FooMemory = sizeof(long) * MixBufferSize * numchannels + 1024;
3113 status = USRHOOKS_GetMem( ( void ** )&ptr, MV_FooMemory); 3119 status = USRHOOKS_GetMem( ( void ** )&ptr, MV_FooMemory);
3114 if ( status != USRHOOKS_Ok ) 3120 if ( status != USRHOOKS_Ok )
3115 { 3121 {
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.h b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.h
index 6e6dd8e684..5f0d055732 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.h
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.h
@@ -31,12 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31#ifndef __MULTIVOC_H 31#ifndef __MULTIVOC_H
32#define __MULTIVOC_H 32#define __MULTIVOC_H
33 33
34//#include <windows.h>
35#include <SDL.h> 34#include <SDL.h>
36 35
37// forward declare 36/* must 8 or less, otherwise sound will clip */
38//struct SDL_mutex; 37#define FRACBITS 8
39
40 38
41#define MV_MinVoiceHandle 1 39#define MV_MinVoiceHandle 1
42 40
@@ -124,7 +122,6 @@ int MV_Shutdown( void );
124void MV_UnlockMemory( void ); 122void MV_UnlockMemory( void );
125int MV_LockMemory( void ); 123int MV_LockMemory( void );
126 124
127//CRITICAL_SECTION reverbCS;
128SDL_mutex* reverbMutex; 125SDL_mutex* reverbMutex;
129 126
130#endif 127#endif
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c
index ea5c0e47bb..61485a1ca0 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c
@@ -1,14 +1,16 @@
1#include "multivoc.h" 1#include "multivoc.h"
2 2
3#include "fixedpoint.h"
4
3#include "../global.h" /* for readLE16 */ 5#include "../global.h" /* for readLE16 */
4 6
5extern char *MV_MixDestination; 7extern char *MV_MixDestination;
6extern uint32_t MV_MixPosition; 8extern uint32_t MV_MixPosition;
7extern int *MV_GLast, *MV_GPos, *MV_GVal; 9extern int *MV_GLast, *MV_GPos, *MV_GVal;
8 10
9extern int MV_LeftVolume; 11extern int MV_LeftVolume, MV_LeftScale;
10extern int MV_RightVolume; 12extern int MV_RightVolume, MV_RightScale;
11extern int MV_MaxVolume; 13extern const int MV_MaxVolume;
12 14
13// extern unsigned char *MV_HarshClipTable; 15// extern unsigned char *MV_HarshClipTable;
14 16
@@ -27,457 +29,470 @@ extern int g_CV_CubicInterpolation;
27 29
28int MV_cubic(int position) 30int MV_cubic(int position)
29{ 31{
30 int xd, fa; 32 int xd, fa;
31 xd = (position >> 1) & 0x7FFF; 33 xd = (position >> 1) & 0x7FFF;
32 34
33 fa = gval(3) - 3*gval(2) + 3*gval(1) - gval0; 35 fa = gval(3) - 3*gval(2) + 3*gval(1) - gval0;
34 fa *= (xd - (2<<15)) / 6; 36 fa *= (xd - (2<<15)) / 6;
35 fa >>= 15; 37 fa >>= 15;
36 fa += gval(2) - gval(1) - gval(1) + gval0; 38 fa += gval(2) - gval(1) - gval(1) + gval0;
37 fa *= (xd - (1<<15)) >> 1; 39 fa *= (xd - (1<<15)) >> 1;
38 fa >>= 15; 40 fa >>= 15;
39 fa += gval(1) - gval0; 41 fa += gval(1) - gval0;
40 fa *= xd; 42 fa *= xd;
41 fa >>= 15; 43 fa >>= 15;
42 fa += gval0; 44 fa += gval0;
43 return fa; 45 return fa;
44} 46}
45 47
46/* 48/*
47static int MV_cubic8(const unsigned char *src, int position, int rate) 49 static int MV_cubic8(const unsigned char *src, int position, int rate)
48{ 50 {
49 int temp, hpos = position >> 16; 51 int temp, hpos = position >> 16;
50 52
51 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos; 53 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos;
52 54
53 temp = hpos; 55 temp = hpos;
54 56
55 while (hpos > *MV_GLast) 57 while (hpos > *MV_GLast)
56 { 58 {
57 gval0 = ((int)src[temp++] - 0x80) << 8; 59 gval0 = ((int)src[temp++] - 0x80) << 8;
58 *MV_GPos = (*MV_GPos + 1) & 3; 60 *MV_GPos = (*MV_GPos + 1) & 3;
59 (*MV_GLast)++; 61 (*MV_GLast)++;
60 } 62 }
61 63
62 return do_cubic ? (MV_cubic(position) >> 8) + 0x80 : (gval(3) >> 8) + 0x80; 64 return do_cubic ? (MV_cubic(position) >> 8) + 0x80 : (gval(3) >> 8) + 0x80;
63} 65 }
64*/ 66*/
65 67
66static int MV_cubic16(const short *src, int position, int rate) 68static int MV_cubic16(const short *src, int position, int rate)
67{ 69{
68 int temp, hpos = position >> 16; 70 int temp, hpos = position >> 16;
69 71
70 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos; 72 if (abs(hpos - *MV_GLast) > 3)
73 *MV_GLast = hpos;
71 74
72 temp = hpos; 75 temp = hpos;
73 76
74 while (hpos > *MV_GLast) 77 while (hpos > *MV_GLast)
75 { 78 {
76 /* readLE16 returns unsigned short, but it won't be casted 79 /* readLE16 returns unsigned short, but it won't be casted
77 * implicitly, since gval0 is of type int. */ 80 * implicitly, since gval0 is of type int. */
78 gval0 = (short) readLE16(src + temp++); 81 gval0 = (short) readLE16(src + temp);
82 temp++;
79 83
80 *MV_GPos = (*MV_GPos + 1) & 3; 84 *MV_GPos = (*MV_GPos + 1) & 3;
81 (*MV_GLast)++; 85 (*MV_GLast)++;
82 } 86 }
83 87
84 return do_cubic ? MV_cubic(position) : gval(3); 88 return do_cubic ? MV_cubic(position) : gval(3);
85} 89}
86 90
87static int MV_cubic8to16(const unsigned char *src, int position, int rate) 91static int MV_cubic8to16(const unsigned char *src, int position, int rate)
88{ 92{
89 int temp, hpos = position >> 16; 93 int temp, hpos = position >> 16;
90 94
91 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos; 95 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos;
92 96
93 temp = hpos; 97 temp = hpos;
94 98
95 while (hpos > *MV_GLast) 99 while (hpos > *MV_GLast)
96 { 100 {
97 gval0 = ((int)src[temp++] - 0x80) << 8; 101 gval0 = ((int)src[temp++] - 0x80) << 8;
98 *MV_GPos = (*MV_GPos + 1) & 3; 102 *MV_GPos = (*MV_GPos + 1) & 3;
99 (*MV_GLast)++; 103 (*MV_GLast)++;
100 } 104 }
101 105
102 return do_cubic ? MV_cubic(position) : gval(3); 106 return do_cubic ? MV_cubic(position) : gval(3);
103} 107}
104 108
105/* 109/*
106static int MV_cubic16to8(const short *src, int position, int rate) 110 static int MV_cubic16to8(const short *src, int position, int rate)
107{ 111 {
108 int temp, hpos = position >> 16; 112 int temp, hpos = position >> 16;
109 113
110 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos; 114 if (abs(hpos - *MV_GLast) > 3) *MV_GLast = hpos;
111 115
112 temp = hpos; 116 temp = hpos;
113 117
114 while (hpos > *MV_GLast) 118 while (hpos > *MV_GLast)
115 { 119 {
116 gval0 = src[temp++]; 120 gval0 = src[temp++];
117 *MV_GPos = (*MV_GPos + 1) & 3; 121 *MV_GPos = (*MV_GPos + 1) & 3;
118 (*MV_GLast)++; 122 (*MV_GLast)++;
119 } 123 }
120 124
121 return do_cubic ? (MV_cubic(position) >> 8) + 0x80 : (gval(3) >> 8) + 0x80; 125 return do_cubic ? (MV_cubic(position) >> 8) + 0x80 : (gval(3) >> 8) + 0x80;
122} 126 }
123*/ 127*/
124 128
129/*
125void MV_Mix8BitMono( uint32_t position, uint32_t rate, 130void MV_Mix8BitMono( uint32_t position, uint32_t rate,
126 const char *start, uint32_t length ) 131 const char *start, uint32_t length )
127{ 132{
128 const unsigned char *src; 133 const unsigned char *src;
129 unsigned char *dest; 134 unsigned char *dest;
130 unsigned int i; 135 unsigned int i;
131 136
132 src = (const unsigned char *)start; 137 src = (const unsigned char *)start;
133 dest = (unsigned char *)MV_MixDestination; 138 dest = (unsigned char *)MV_MixDestination;
134 139
135 for (i = 0; i < length; i++) { 140 for (i = 0; i < length; i++) {
136 int s = MV_cubic8to16(src, position, rate); 141 int s = MV_cubic8to16(src, position, rate);
137 int d = (*dest - 0x80) << 8; 142 int d = (*dest - 0x80) << 8;
138 143
139 d += (s * MV_LeftVolume) / MV_MaxVolume; 144 d += (s * MV_LeftVolume) / MV_MaxVolume;
140 145
141 if (d < -32768) *dest = 0; 146 if (d < -32768) *dest = 0;
142 else if (d > 32767) *dest = 255; 147 else if (d > 32767) *dest = 255;
143 else *dest = (d >> 8) + 128; 148 else *dest = (d >> 8) + 128;
144 149
145 position += rate; 150 position += rate;
146 dest += MV_SampleSize; 151 dest += MV_SampleSize;
147 } 152 }
148 153
149 MV_MixPosition = position; 154 MV_MixPosition = position;
150 MV_MixDestination = (char *)dest; 155 MV_MixDestination = (char *)dest;
151} 156}
152 157
153void MV_Mix8BitStereo( uint32_t position, 158void MV_Mix8BitStereo( uint32_t position,
154 uint32_t rate, const char *start, uint32_t length ) 159 uint32_t rate, const char *start, uint32_t length )
155{ 160{
156 const unsigned char *src; 161 const unsigned char *src;
157 unsigned char *dest; 162 unsigned char *dest;
158 unsigned int i; 163 unsigned int i;
159 164
160 src = (const unsigned char *)start; 165 src = (const unsigned char *)start;
161 dest = (unsigned char *)MV_MixDestination; 166 dest = (unsigned char *)MV_MixDestination;
162 167
163 for (i = 0; i < length; i++) { 168 for (i = 0; i < length; i++) {
164 int s = MV_cubic8to16(src, position, rate); 169 int s = MV_cubic8to16(src, position, rate);
165 int dl = (dest[0] - 0x80) << 8; 170 int dl = (dest[0] - 0x80) << 8;
166 int dr = (dest[MV_RightChannelOffset] - 0x80) << 8; 171 int dr = (dest[MV_RightChannelOffset] - 0x80) << 8;
167 172
168 dl += (MV_LeftVolume * s) / MV_MaxVolume; 173 dl += (MV_LeftVolume * s) / MV_MaxVolume;
169 dr += (MV_RightVolume * s) / MV_MaxVolume; 174 dr += (MV_RightVolume * s) / MV_MaxVolume;
170 175
171 if (dl < -32768) dest[0] = 0; 176 if (dl < -32768) dest[0] = 0;
172 else if (dl > 32767) dest[0] = 255; 177 else if (dl > 32767) dest[0] = 255;
173 else dest[0] = (dl >> 8) + 128; 178 else dest[0] = (dl >> 8) + 128;
174 179
175 if (dr < -32768) dest[MV_RightChannelOffset] = 0; 180 if (dr < -32768) dest[MV_RightChannelOffset] = 0;
176 else if (dr > 32767) dest[MV_RightChannelOffset] = 255; 181 else if (dr > 32767) dest[MV_RightChannelOffset] = 255;
177 else dest[MV_RightChannelOffset] = (dl >> 8) + 128; 182 else dest[MV_RightChannelOffset] = (dl >> 8) + 128;
178 183
179 position += rate; 184 position += rate;
180 dest += MV_SampleSize; 185 dest += MV_SampleSize;
181 } 186 }
182 187
183 MV_MixPosition = position; 188 MV_MixPosition = position;
184 MV_MixDestination = (char *)dest; 189 MV_MixDestination = (char *)dest;
185} 190}
186 191
187void MV_Mix16BitMono( uint32_t position, 192void MV_Mix16BitMono( uint32_t position,
188 uint32_t rate, const char *start, uint32_t length ) 193 uint32_t rate, const char *start, uint32_t length )
189{ 194{
190 const unsigned char *src; 195 const unsigned char *src;
191 short *dest; 196 short *dest;
192 unsigned int i; 197 unsigned int i;
193 198
194 src = (const unsigned char *)start; 199 src = (const unsigned char *)start;
195 dest = (short *)MV_MixDestination; 200 dest = (short *)MV_MixDestination;
196 201
197 for (i = 0; i < length; i++) { 202 for (i = 0; i < length; i++) {
198 int s = MV_cubic8to16(src, position, rate); 203 int s = MV_cubic8to16(src, position, rate);
199 int d = readLE16(dest); 204 int d = readLE16(dest);
200 205
201 d += (MV_LeftVolume * s) / MV_MaxVolume; 206 d += (MV_LeftVolume * s) / MV_MaxVolume;
202 207
203 if (d < -32768) *dest = -32768; 208 if (d < -32768) *dest = -32768;
204 else if (d > 32767) *dest = 32767; 209 else if (d > 32767) *dest = 32767;
205 else *dest = d; 210 else *dest = d;
206 211
207 position += rate; 212 position += rate;
208 dest += MV_SampleSize/2; 213 dest += MV_SampleSize/2;
209 } 214 }
210 215
211 MV_MixPosition = position; 216 MV_MixPosition = position;
212 MV_MixDestination = (char *)dest; 217 MV_MixDestination = (char *)dest;
213} 218}
214 219
215void MV_Mix16BitStereo( uint32_t position, 220void MV_Mix16BitStereo( uint32_t position,
216 uint32_t rate, const char *start, uint32_t length ) 221 uint32_t rate, const char *start, uint32_t length )
217{ 222{
218 const unsigned char *src; 223 const unsigned char *src;
219 short *dest; 224 short *dest;
220 unsigned int i; 225 unsigned int i;
221 226
222 src = (unsigned char *)start; 227 src = (unsigned char *)start;
223 dest = (short *)MV_MixDestination; 228 dest = (short *)MV_MixDestination;
224 229
225 for (i = 0; i < length; i++) { 230 for (i = 0; i < length; i++) {
226 int s = MV_cubic8to16(src, position, rate); 231 int s = MV_cubic8to16(src, position, rate);
227 int dl = readLE16(dest); 232 int dl = readLE16(dest);
228 int dr = readLE16(dest + MV_RightChannelOffset/2); 233 int dr = readLE16(dest + MV_RightChannelOffset/2);
229 234
230 dl += (MV_LeftVolume * s) / MV_MaxVolume; 235 dl += (MV_LeftVolume * s) / MV_MaxVolume;
231 dr += (MV_RightVolume * s) / MV_MaxVolume; 236 dr += (MV_RightVolume * s) / MV_MaxVolume;
232 237
233 if (dl < -32768) dest[0] = -32768; 238 if (dl < -32768) dest[0] = -32768;
234 else if (dl > 32767) dest[0] = 32767; 239 else if (dl > 32767) dest[0] = 32767;
235 else dest[0] = dl; 240 else dest[0] = dl;
236 241
237 if (dr < -32768) dest[MV_RightChannelOffset/2] = -32768; 242 if (dr < -32768) dest[MV_RightChannelOffset/2] = -32768;
238 else if (dr > 32767) dest[MV_RightChannelOffset/2] = 32767; 243 else if (dr > 32767) dest[MV_RightChannelOffset/2] = 32767;
239 else dest[MV_RightChannelOffset/2] = dr; 244 else dest[MV_RightChannelOffset/2] = dr;
240 245
241 position += rate; 246 position += rate;
242 dest += MV_SampleSize/2; 247 dest += MV_SampleSize/2;
243 } 248 }
244 249
245 MV_MixPosition = position; 250 MV_MixPosition = position;
246 MV_MixDestination = (char *)dest; 251 MV_MixDestination = (char *)dest;
247} 252}
248 253
249void MV_Mix8BitMono16( uint32_t position, uint32_t rate, 254void MV_Mix8BitMono16( uint32_t position, uint32_t rate,
250 const char *start, uint32_t length ) 255 const char *start, uint32_t length )
251{ 256{
252 const short *src; 257 const short *src;
253 unsigned char *dest; 258 unsigned char *dest;
254 unsigned int i; 259 unsigned int i;
255 260
256 src = (const short *)start; 261 src = (const short *)start;
257 dest = (unsigned char *)MV_MixDestination; 262 dest = (unsigned char *)MV_MixDestination;
258 263
259 for (i = 0; i < length; i++) { 264 for (i = 0; i < length; i++) {
260 int s = MV_cubic16(src, position, rate); 265 int s = MV_cubic16(src, position, rate);
261 int d = (*dest - 0x80) << 8; 266 int d = (*dest - 0x80) << 8;
262 267
263 d += (MV_LeftVolume * s) / MV_MaxVolume; 268 d += (MV_LeftVolume * s) / MV_MaxVolume;
264 269
265 if (d < -32768) *dest = 0; 270 if (d < -32768) *dest = 0;
266 else if (d > 32767) *dest = 255; 271 else if (d > 32767) *dest = 255;
267 else *dest = (d >> 8) + 128; 272 else *dest = (d >> 8) + 128;
268 273
269 position += rate; 274 position += rate;
270 dest += MV_SampleSize; 275 dest += MV_SampleSize;
271 } 276 }
272 277
273 MV_MixPosition = position; 278 MV_MixPosition = position;
274 MV_MixDestination = (char *)dest; 279 MV_MixDestination = (char *)dest;
275} 280}
276 281
277void MV_Mix8BitStereo16( uint32_t position, 282void MV_Mix8BitStereo16( uint32_t position,
278 uint32_t rate, const char *start, uint32_t length ) 283 uint32_t rate, const char *start, uint32_t length )
279{ 284{
280 const short *src; 285 const short *src;
281 unsigned char *dest; 286 unsigned char *dest;
282 unsigned int i; 287 unsigned int i;
283 288
284 src = (const short *)start; 289 src = (const short *)start;
285 dest = (unsigned char *)MV_MixDestination; 290 dest = (unsigned char *)MV_MixDestination;
286 291
287 for (i = 0; i < length; i++) { 292 for (i = 0; i < length; i++) {
288 int s = MV_cubic16(src, position, rate); 293 int s = MV_cubic16(src, position, rate);
289 int dl = (dest[0] - 0x80) << 8; 294 int dl = (dest[0] - 0x80) << 8;
290 int dr = (dest[MV_RightChannelOffset/2] - 0x80) << 8; 295 int dr = (dest[MV_RightChannelOffset/2] - 0x80) << 8;
291 296
292 dl += (MV_LeftVolume * s) / MV_MaxVolume; 297 dl += (MV_LeftVolume * s) / MV_MaxVolume;
293 dr += (MV_RightVolume * s) / MV_MaxVolume; 298 dr += (MV_RightVolume * s) / MV_MaxVolume;
294 299
295 if (dl < -32768) dest[0] = 0; 300 if (dl < -32768) dest[0] = 0;
296 else if (dl > 32767) dest[0] = 255; 301 else if (dl > 32767) dest[0] = 255;
297 else dest[0] = (dl >> 8) + 128; 302 else dest[0] = (dl >> 8) + 128;
298 303
299 if (dr < -32768) dest[MV_RightChannelOffset] = 0; 304 if (dr < -32768) dest[MV_RightChannelOffset] = 0;
300 else if (dr > 32767) dest[MV_RightChannelOffset] = 255; 305 else if (dr > 32767) dest[MV_RightChannelOffset] = 255;
301 else dest[MV_RightChannelOffset] = (dl >> 8) + 128; 306 else dest[MV_RightChannelOffset] = (dl >> 8) + 128;
302 307
303 position += rate; 308 position += rate;
304 dest += MV_SampleSize; 309 dest += MV_SampleSize;
305 } 310 }
306 311
307 MV_MixPosition = position; 312 MV_MixPosition = position;
308 MV_MixDestination = (char *)dest; 313 MV_MixDestination = (char *)dest;
309} 314}
310 315
311void MV_Mix16BitMono16( uint32_t position, 316void MV_Mix16BitMono16( uint32_t position,
312 uint32_t rate, const char *start, uint32_t length ) 317 uint32_t rate, const char *start, uint32_t length )
313{ 318{
314 const short *src; 319 const short *src;
315 short *dest; 320 short *dest;
316 unsigned int i; 321 unsigned int i;
317 322
318 src = (const short *)start; 323 src = (const short *)start;
319 dest = (short *)MV_MixDestination; 324 dest = (short *)MV_MixDestination;
320 325
321 for (i = 0; i < length; i++) { 326 for (i = 0; i < length; i++) {
322 int s = MV_cubic16(src, position, rate); 327 int s = MV_cubic16(src, position, rate);
323 int d = readLE16(dest); 328 int d = readLE16(dest);
324 329
325 d += (MV_LeftVolume * s) / MV_MaxVolume; 330 d += (MV_LeftVolume * s) / MV_MaxVolume;
326 331
327 if (d < -32768) *dest = -32768; 332 if (d < -32768) *dest = -32768;
328 else if (d > 32767) *dest = 32767; 333 else if (d > 32767) *dest = 32767;
329 else *dest = d; 334 else *dest = d;
330 335
331 position += rate; 336 position += rate;
332 dest += MV_SampleSize/2; 337 dest += MV_SampleSize/2;
333 } 338 }
334 339
335 MV_MixPosition = position; 340 MV_MixPosition = position;
336 MV_MixDestination = (char *)dest; 341 MV_MixDestination = (char *)dest;
337} 342}
338 343
339void MV_Mix16BitStereo16( uint32_t position, 344void MV_Mix16BitStereo16( uint32_t position,
340 uint32_t rate, const char *start, uint32_t length ) 345 uint32_t rate, const char *start, uint32_t length )
341{ 346{
342 const short *src; 347 const short *src;
343 short *dest; 348 short *dest;
344 unsigned int i; 349 unsigned int i;
345 350
346 src = (const short *)start; 351 src = (const short *)start;
347 dest = (short *)MV_MixDestination; 352 dest = (short *)MV_MixDestination;
348 353
349 for (i = 0; i < length; i++) { 354 for (i = 0; i < length; i++) {
350 int s = MV_cubic16(src, position, rate); 355 int s = MV_cubic16(src, position, rate);
351 int dl = readLE16(dest); 356 int dl = readLE16(dest);
352 int dr = readLE16(dest + MV_RightChannelOffset/2); 357 int dr = readLE16(dest + MV_RightChannelOffset/2);
353 358
354 dl += (MV_LeftVolume * s) / MV_MaxVolume; 359 dl += (MV_LeftVolume * s) / MV_MaxVolume;
355 dr += (MV_RightVolume * s) / MV_MaxVolume; 360 dr += (MV_RightVolume * s) / MV_MaxVolume;
356 361
357 if (dl < -32768) dest[0] = -32768; 362 if (dl < -32768) dest[0] = -32768;
358 else if (dl > 32767) dest[0] = 32767; 363 else if (dl > 32767) dest[0] = 32767;
359 else dest[0] = dl; 364 else dest[0] = dl;
360 365
361 if (dr < -32768) dest[MV_RightChannelOffset/2] = -32768; 366 if (dr < -32768) dest[MV_RightChannelOffset/2] = -32768;
362 else if (dr > 32767) dest[MV_RightChannelOffset/2] = 32767; 367 else if (dr > 32767) dest[MV_RightChannelOffset/2] = 32767;
363 else dest[MV_RightChannelOffset/2] = dl; 368 else dest[MV_RightChannelOffset/2] = dl;
364 369
365 position += rate; 370 position += rate;
366 dest += MV_SampleSize/2; 371 dest += MV_SampleSize/2;
367 } 372 }
368 373
369 MV_MixPosition = position; 374 MV_MixPosition = position;
370 MV_MixDestination = (char *)dest; 375 MV_MixDestination = (char *)dest;
371} 376}
377*/
378
379int fp_calls[4] = {0, 0, 0, 0};
380
381//static const double recip = 1/(double)(1<<FRACBITS);
372 382
383/* #2 */
373void MV_MixFPMono8( uint32_t position, 384void MV_MixFPMono8( uint32_t position,
374 uint32_t rate, const char *start, uint32_t length ) 385 uint32_t rate, const char *start, uint32_t length )
375{ 386{
376 const unsigned char *src; 387 ++fp_calls[0];
377 double *dest; 388 const unsigned char *src;
378 unsigned int i; 389 long *dest;
390 unsigned int i;
379 391
380 src = (const unsigned char *)start; 392 src = (const unsigned char *)start;
381 dest = (double *)MV_MixDestination; 393 dest = (long *)MV_MixDestination;
382 394
383 for (i = 0; i < length; i++) { 395 for (i = 0; i < length; i++) {
384 int s = MV_cubic8to16(src, position, rate); 396 int s = MV_cubic8to16(src, position, rate) << FRACBITS;
385 double out; 397 long out;
386 398
387 out = (double)s * (double)MV_LeftVolume / (double)MV_MaxVolume; 399 out = (s * MV_LeftScale) >> FRACBITS;
388 out = out / ((double)0x8000); 400 *dest += out;
389 *dest += out;
390 401
391 position += rate; 402 position += rate;
392 dest += MV_Channels; 403 dest += MV_Channels;
393 } 404 }
394 405
395 MV_MixPosition = position; 406 MV_MixPosition = position;
396 MV_MixDestination = (char *)dest; 407 MV_MixDestination = (char *)dest;
397} 408}
398 409
410/* #1 performance hog */
399void MV_MixFPStereo8( uint32_t position, 411void MV_MixFPStereo8( uint32_t position,
400 uint32_t rate, const char *start, uint32_t length ) 412 uint32_t rate, const char *start, uint32_t length )
401{ 413{
402 const unsigned char *src; 414 ++fp_calls[1];
403 double *dest; 415 const unsigned char *src;
404 unsigned int i; 416 long *dest;
417 unsigned int i;
405 418
406 src = (const unsigned char *)start; 419 src = (const unsigned char *)start;
407 dest = (double *)MV_MixDestination; 420 dest = (long *)MV_MixDestination;
408 421
409 for (i = 0; i < length; i++) { 422 for (i = 0; i < length; i++) {
410 int s = MV_cubic8to16(src, position, rate); 423 int s = MV_cubic8to16(src, position, rate) << FRACBITS;
411 double left, right; 424 long left, right;
412 425
413 left = (double)MV_LeftVolume * (double)s / (double)MV_MaxVolume; 426 left = (s * MV_LeftScale) >> FRACBITS;
414 left = left / ((double)0x8000); 427 right = (s * MV_RightScale) >> FRACBITS;
415 right = (double)(MV_RightVolume * s) / MV_MaxVolume; 428
416 right = right / ((double)0x8000); 429 dest[0] += left;
417 dest[0] += left; 430 dest[1] += right;
418 dest[1] += right; 431
419 432 position += rate;
420 position += rate; 433 dest += MV_Channels;
421 dest += MV_Channels; 434 }
422 }
423 435
424 MV_MixPosition = position; 436 MV_MixPosition = position;
425 MV_MixDestination = (char *)dest; 437 MV_MixDestination = (char *)dest;
426 438
427} 439}
428 440
441/* rarely called */
429void MV_MixFPMono16( uint32_t position, 442void MV_MixFPMono16( uint32_t position,
430 uint32_t rate, const char *start, uint32_t length ) 443 uint32_t rate, const char *start, uint32_t length )
431{ 444{
432 const short *src; 445 ++fp_calls[2];
433 double *dest; 446 const short *src;
434 unsigned int i; 447 long *dest;
448 unsigned int i;
435 449
436 src = (const short *)start; 450 src = (const short *)start;
437 dest = (double *)MV_MixDestination; 451 dest = (long *)MV_MixDestination;
438 452
439 for (i = 0; i < length; i++) { 453 for (i = 0; i < length; i++) {
440 int s = MV_cubic16(src, position, rate); 454 int s = MV_cubic16(src, position, rate) << FRACBITS;
441 double out; 455 long out;
442 456
443 out = (double)s * (double)MV_LeftVolume / (double)MV_MaxVolume; 457 out = (s * MV_LeftScale) >> FRACBITS;
444 out = out / ((double)0x8000); 458 *dest += out;
445 *dest += out;
446 459
447 position += rate; 460 position += rate;
448 dest += MV_Channels; 461 dest += MV_Channels;
449 } 462 }
450 463
451 MV_MixPosition = position; 464 MV_MixPosition = position;
452 MV_MixDestination = (char *)dest; 465 MV_MixDestination = (char *)dest;
453} 466}
454 467
468/* #3 performance hog */
455void MV_MixFPStereo16( uint32_t position, 469void MV_MixFPStereo16( uint32_t position,
456 uint32_t rate, const char *start, uint32_t length ) 470 uint32_t rate, const char *start, uint32_t length )
457{ 471{
458 const short *src; 472 ++fp_calls[3];
459 double *dest; 473 const short *src;
460 unsigned int i; 474 long *dest;
475 unsigned int i;
461 476
462 src = (const short *)start; 477 src = (const short *)start;
463 dest = (double *)MV_MixDestination; 478 dest = (long *)MV_MixDestination;
464 479
465 for (i = 0; i < length; i++) { 480 for (i = 0; i < length; i++) {
466 int s = MV_cubic16(src, position, rate); 481 int s = MV_cubic16(src, position, rate) << FRACBITS;
467 double left, right; 482
468 483 long left, right;
469 left = (double)MV_LeftVolume * (double)s / (double)MV_MaxVolume; 484
470 left = left / ((double)0x8000); 485 left = (s * MV_LeftScale) >> FRACBITS;
471 right = (double)(MV_RightVolume * s) / MV_MaxVolume; 486 right = (s * MV_RightScale) >> FRACBITS;
472 right = right / ((double)0x8000); 487
473 dest[0] += left; 488 dest[0] += left;
474 dest[1] += right; 489 dest[1] += right;
475 490
476 position += rate; 491 position += rate;
477 dest += MV_Channels; 492 dest += MV_Channels;
478 } 493 }
479 494
480 MV_MixPosition = position; 495 MV_MixPosition = position;
481 MV_MixDestination = (char *)dest; 496 MV_MixDestination = (char *)dest;
482 497
483} 498}
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c
index 0d058d85ee..7d48d3271e 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c
@@ -1,15 +1,16 @@
1#include "multivoc.h" 1#include "multivoc.h"
2#include "_multivc.h" 2#include "_multivc.h"
3#include "fixedpoint.h"
3 4
4extern double *MV_FooBuffer; 5extern long *MV_FooBuffer;
5extern int MV_BufferSize; 6extern int MV_BufferSize;
6extern int MV_SampleSize; 7extern int MV_SampleSize;
7extern int MV_MaxVolume; 8extern const int MV_MaxVolume;
8extern int MV_ReverbDelay; 9extern int MV_ReverbDelay;
9extern int MV_MixRate; 10extern int MV_MixRate;
10extern int MV_Channels; 11extern int MV_Channels;
11 12
12static double * reverbBuffer = 0; 13static long * reverbBuffer = 0;
13static int delay = 0, CurrAddr; 14static int delay = 0, CurrAddr;
14 15
15static int FB_SRC_A, FB_SRC_B, IIR_DEST_A0, IIR_DEST_A1, ACC_SRC_A0, ACC_SRC_A1, ACC_SRC_B0, 16static int FB_SRC_A, FB_SRC_B, IIR_DEST_A0, IIR_DEST_A1, ACC_SRC_A0, ACC_SRC_A1, ACC_SRC_B0,
@@ -17,10 +18,10 @@ static int FB_SRC_A, FB_SRC_B, IIR_DEST_A0, IIR_DEST_A1, ACC_SRC_A0, ACC_SRC_A1,
17 ACC_SRC_C1, ACC_SRC_D0, ACC_SRC_D1, IIR_SRC_B1, IIR_SRC_B0, MIX_DEST_A0, 18 ACC_SRC_C1, ACC_SRC_D0, ACC_SRC_D1, IIR_SRC_B1, IIR_SRC_B0, MIX_DEST_A0,
18 MIX_DEST_A1, MIX_DEST_B0, MIX_DEST_B1; 19 MIX_DEST_A1, MIX_DEST_B0, MIX_DEST_B1;
19 20
20static double IIR_ALPHA, ACC_COEF_A, ACC_COEF_B, ACC_COEF_C, ACC_COEF_D, IIR_COEF, FB_ALPHA, FB_X, 21static long IIR_ALPHA, ACC_COEF_A, ACC_COEF_B, ACC_COEF_C, ACC_COEF_D, IIR_COEF, FB_ALPHA, FB_X,
21 IN_COEF_L, IN_COEF_R; 22 IN_COEF_L, IN_COEF_R;
22 23
23static double iRVBLeft, iRVBRight; 24static long iRVBLeft, iRVBRight;
24 25
25static int cnv_offset(int src) 26static int cnv_offset(int src)
26{ 27{
@@ -32,6 +33,8 @@ static int cnv_offset(int src)
32 33
33// extern __stdcall OutputDebugStringA(char *); 34// extern __stdcall OutputDebugStringA(char *);
34 35
36static const double fp_scale = (double) (1 << FRACBITS);
37
35static void check_buffer() 38static void check_buffer()
36{ 39{
37 int new_delay = cnv_offset(MV_ReverbDelay); 40 int new_delay = cnv_offset(MV_ReverbDelay);
@@ -61,26 +64,26 @@ static void check_buffer()
61 MIX_DEST_A1 = cnv_offset(0x238); 64 MIX_DEST_A1 = cnv_offset(0x238);
62 MIX_DEST_B0 = cnv_offset(0x154); 65 MIX_DEST_B0 = cnv_offset(0x154);
63 MIX_DEST_B1 = cnv_offset(0xAA); 66 MIX_DEST_B1 = cnv_offset(0xAA);
64 IIR_ALPHA = 0.8701171875; 67 IIR_ALPHA = 0.8701171875 * fp_scale;
65 ACC_COEF_A = 0.622314453125; 68 ACC_COEF_A = 0.622314453125 * fp_scale;
66 ACC_COEF_B = -0.5244140625; 69 ACC_COEF_B = -0.5244140625 * fp_scale;
67 ACC_COEF_C = 0.53955078125; 70 ACC_COEF_C = 0.53955078125 * fp_scale;
68 ACC_COEF_D = -0.50830078125; 71 ACC_COEF_D = -0.50830078125 * fp_scale;
69 IIR_COEF = -0.69921875; 72 IIR_COEF = -0.69921875 * fp_scale;
70 FB_ALPHA = 0.67578125; 73 FB_ALPHA = 0.67578125 * fp_scale;
71 FB_X = 0.646484375; 74 FB_X = 0.646484375 * fp_scale;
72 IN_COEF_L = -2.; 75 IN_COEF_L = -2. * fp_scale;
73 IN_COEF_R = -2.; 76 IN_COEF_R = -2. * fp_scale;
74 if (reverbBuffer) reverbBuffer = (double*) realloc(reverbBuffer, new_delay * sizeof(double)); 77 if (reverbBuffer) reverbBuffer = (long*) realloc(reverbBuffer, new_delay * sizeof(long));
75 else reverbBuffer = (double*) malloc(new_delay * sizeof(double)); 78 else reverbBuffer = (long*) malloc(new_delay * sizeof(long));
76 memset(reverbBuffer, 0, new_delay * sizeof(double)); 79 memset(reverbBuffer, 0, new_delay * sizeof(long));
77 delay = new_delay; 80 delay = new_delay;
78 CurrAddr = 0; 81 CurrAddr = 0;
79 } 82 }
80 83
81} 84}
82 85
83double g_buffer(int iOff, double *ptr) // get_buffer content helper: takes care about wraps 86long g_buffer(int iOff, long *ptr) // get_buffer content helper: takes care about wraps
84{ 87{
85 int correctDelay = delay; 88 int correctDelay = delay;
86 if(!correctDelay) 89 if(!correctDelay)
@@ -98,10 +101,10 @@ double g_buffer(int iOff, double *ptr) // get_buffer co
98 { 101 {
99 iOff=correctDelay-(0-iOff); 102 iOff=correctDelay-(0-iOff);
100 } 103 }
101 return (double)*(ptr+iOff); 104 return (long)*(ptr+iOff);
102} 105}
103 106
104void s_buffer(int iOff,double iVal, double *ptr) // set_buffer content helper: takes care about wraps and clipping 107void s_buffer(int iOff,long iVal, long *ptr) // set_buffer content helper: takes care about wraps and clipping
105{ 108{
106 int correctDelay = delay; 109 int correctDelay = delay;
107 if(!correctDelay) 110 if(!correctDelay)
@@ -122,7 +125,7 @@ void s_buffer(int iOff,double iVal, double *ptr) // set_buffer co
122 *(ptr+iOff)=iVal; 125 *(ptr+iOff)=iVal;
123} 126}
124 127
125void s_buffer1(int iOff,double iVal, double *ptr) // set_buffer (+1 sample) content helper: takes care about wraps and clipping 128void s_buffer1(int iOff,long iVal, long *ptr) // set_buffer (+1 sample) content helper: takes care about wraps and clipping
126{ 129{
127 int correctDelay = delay; 130 int correctDelay = delay;
128 if(!correctDelay) 131 if(!correctDelay)
@@ -143,61 +146,63 @@ void s_buffer1(int iOff,double iVal, double *ptr) // set_buffer (
143 *(ptr+iOff)=iVal; 146 *(ptr+iOff)=iVal;
144} 147}
145 148
146double MixREVERBLeft(double INPUT_SAMPLE_L, double INPUT_SAMPLE_R, double *ptr) 149long MixREVERBLeft(long INPUT_SAMPLE_L, long INPUT_SAMPLE_R, long *ptr)
147{ 150{
148 double ACC0,ACC1,FB_A0,FB_A1,FB_B0,FB_B1; 151 long ACC0,ACC1,FB_A0,FB_A1,FB_B0,FB_B1;
149
150 const double IIR_INPUT_A0 = (g_buffer(IIR_SRC_A0, ptr) * IIR_COEF) + (INPUT_SAMPLE_L * IN_COEF_L);
151 const double IIR_INPUT_A1 = (g_buffer(IIR_SRC_A1, ptr) * IIR_COEF) + (INPUT_SAMPLE_R * IN_COEF_R);
152 const double IIR_INPUT_B0 = (g_buffer(IIR_SRC_B0, ptr) * IIR_COEF) + (INPUT_SAMPLE_L * IN_COEF_L);
153 const double IIR_INPUT_B1 = (g_buffer(IIR_SRC_B1, ptr) * IIR_COEF) + (INPUT_SAMPLE_R * IN_COEF_R);
154
155 const double IIR_A0 = (IIR_INPUT_A0 * IIR_ALPHA) + (g_buffer(IIR_DEST_A0, ptr) * (1.f - IIR_ALPHA));
156 const double IIR_A1 = (IIR_INPUT_A1 * IIR_ALPHA) + (g_buffer(IIR_DEST_A1, ptr) * (1.f - IIR_ALPHA));
157 const double IIR_B0 = (IIR_INPUT_B0 * IIR_ALPHA) + (g_buffer(IIR_DEST_B0, ptr) * (1.f - IIR_ALPHA));
158 const double IIR_B1 = (IIR_INPUT_B1 * IIR_ALPHA) + (g_buffer(IIR_DEST_B1, ptr) * (1.f - IIR_ALPHA));
159 152
153 const long IIR_INPUT_A0 = (fp_mul(g_buffer(IIR_SRC_A0, ptr), IIR_COEF, FRACBITS) + fp_mul(INPUT_SAMPLE_L, IN_COEF_L, FRACBITS));
154 const long IIR_INPUT_A1 = (fp_mul(g_buffer(IIR_SRC_A1, ptr), IIR_COEF, FRACBITS) + fp_mul(INPUT_SAMPLE_R, IN_COEF_R, FRACBITS));
155 const long IIR_INPUT_B0 = (fp_mul(g_buffer(IIR_SRC_B0, ptr), IIR_COEF, FRACBITS) + fp_mul(INPUT_SAMPLE_L, IN_COEF_L, FRACBITS));
156 const long IIR_INPUT_B1 = (fp_mul(g_buffer(IIR_SRC_B1, ptr), IIR_COEF, FRACBITS) + fp_mul(INPUT_SAMPLE_R, IN_COEF_R, FRACBITS));
157
158 const long one = (1 << FRACBITS);
159 const long IIR_A0 = fp_mul(IIR_INPUT_A0, IIR_ALPHA, FRACBITS) + fp_mul(g_buffer(IIR_DEST_A0, ptr), (one - IIR_ALPHA), FRACBITS);
160 const long IIR_A1 = fp_mul(IIR_INPUT_A1, IIR_ALPHA, FRACBITS) + fp_mul(g_buffer(IIR_DEST_A1, ptr), (one - IIR_ALPHA), FRACBITS);
161 const long IIR_B0 = fp_mul(IIR_INPUT_B0, IIR_ALPHA, FRACBITS) + fp_mul(g_buffer(IIR_DEST_B0, ptr), (one - IIR_ALPHA), FRACBITS);
162 const long IIR_B1 = fp_mul(IIR_INPUT_B1, IIR_ALPHA, FRACBITS) + fp_mul(g_buffer(IIR_DEST_B1, ptr), (one - IIR_ALPHA), FRACBITS);
163
160 s_buffer1(IIR_DEST_A0, IIR_A0, ptr); 164 s_buffer1(IIR_DEST_A0, IIR_A0, ptr);
161 s_buffer1(IIR_DEST_A1, IIR_A1, ptr); 165 s_buffer1(IIR_DEST_A1, IIR_A1, ptr);
162 s_buffer1(IIR_DEST_B0, IIR_B0, ptr); 166 s_buffer1(IIR_DEST_B0, IIR_B0, ptr);
163 s_buffer1(IIR_DEST_B1, IIR_B1, ptr); 167 s_buffer1(IIR_DEST_B1, IIR_B1, ptr);
164 168
165 ACC0 = (g_buffer(ACC_SRC_A0, ptr) * ACC_COEF_A) + 169 ACC0 = (fp_mul(g_buffer(ACC_SRC_A0, ptr), ACC_COEF_A, FRACBITS) +
166 (g_buffer(ACC_SRC_B0, ptr) * ACC_COEF_B) + 170 fp_mul(g_buffer(ACC_SRC_B0, ptr), ACC_COEF_B, FRACBITS) +
167 (g_buffer(ACC_SRC_C0, ptr) * ACC_COEF_C) + 171 fp_mul(g_buffer(ACC_SRC_C0, ptr), ACC_COEF_C, FRACBITS) +
168 (g_buffer(ACC_SRC_D0, ptr) * ACC_COEF_D); 172 fp_mul(g_buffer(ACC_SRC_D0, ptr), ACC_COEF_D, FRACBITS));
169 ACC1 = (g_buffer(ACC_SRC_A1, ptr) * ACC_COEF_A) + 173 ACC1 = (fp_mul(g_buffer(ACC_SRC_A1, ptr), ACC_COEF_A, FRACBITS) +
170 (g_buffer(ACC_SRC_B1, ptr) * ACC_COEF_B) + 174 fp_mul(g_buffer(ACC_SRC_B1, ptr), ACC_COEF_B, FRACBITS) +
171 (g_buffer(ACC_SRC_C1, ptr) * ACC_COEF_C) + 175 fp_mul(g_buffer(ACC_SRC_C1, ptr), ACC_COEF_C, FRACBITS) +
172 (g_buffer(ACC_SRC_D1, ptr) * ACC_COEF_D); 176 fp_mul(g_buffer(ACC_SRC_D1, ptr), ACC_COEF_D, FRACBITS));
173 177
174 FB_A0 = g_buffer(MIX_DEST_A0 - FB_SRC_A, ptr); 178 FB_A0 = g_buffer(MIX_DEST_A0 - FB_SRC_A, ptr);
175 FB_A1 = g_buffer(MIX_DEST_A1 - FB_SRC_A, ptr); 179 FB_A1 = g_buffer(MIX_DEST_A1 - FB_SRC_A, ptr);
176 FB_B0 = g_buffer(MIX_DEST_B0 - FB_SRC_B, ptr); 180 FB_B0 = g_buffer(MIX_DEST_B0 - FB_SRC_B, ptr);
177 FB_B1 = g_buffer(MIX_DEST_B1 - FB_SRC_B, ptr); 181 FB_B1 = g_buffer(MIX_DEST_B1 - FB_SRC_B, ptr);
178 182
179 s_buffer(MIX_DEST_A0, ACC0 - (FB_A0 * FB_ALPHA), ptr); 183 s_buffer(MIX_DEST_A0, ACC0 - fp_mul(FB_A0 , FB_ALPHA, FRACBITS), ptr);
180 s_buffer(MIX_DEST_A1, ACC1 - (FB_A1 * FB_ALPHA), ptr); 184 s_buffer(MIX_DEST_A1, ACC1 - fp_mul(FB_A1 , FB_ALPHA, FRACBITS), ptr);
181 185
182 s_buffer(MIX_DEST_B0, (FB_ALPHA * ACC0) - (FB_A0 * (FB_ALPHA - 1.f)) - (FB_B0 * FB_X), ptr); 186 s_buffer(MIX_DEST_B0, fp_mul(FB_ALPHA , ACC0, FRACBITS) - fp_mul(FB_A0, (FB_ALPHA - one), FRACBITS) - fp_mul(FB_B0, FB_X, FRACBITS), ptr);
183 s_buffer(MIX_DEST_B1, (FB_ALPHA * ACC1) - (FB_A1 * (FB_ALPHA - 1.f)) - (FB_B1 * FB_X), ptr); 187 s_buffer(MIX_DEST_B1, fp_mul(FB_ALPHA , ACC1, FRACBITS) - fp_mul(FB_A1, (FB_ALPHA - one), FRACBITS) - fp_mul(FB_B1, FB_X, FRACBITS), ptr);
184 188
185 iRVBLeft = (g_buffer(MIX_DEST_A0, ptr)+g_buffer(MIX_DEST_B0, ptr))/3.f; 189 iRVBLeft = fp_div((g_buffer(MIX_DEST_A0, ptr)+g_buffer(MIX_DEST_B0, ptr)), 3 << FRACBITS, FRACBITS);
186 iRVBRight = (g_buffer(MIX_DEST_A1, ptr)+g_buffer(MIX_DEST_B1, ptr))/3.f; 190 iRVBRight = fp_div((g_buffer(MIX_DEST_A1, ptr)+g_buffer(MIX_DEST_B1, ptr)), 3 << FRACBITS, FRACBITS);
187 191
188 CurrAddr++; 192 CurrAddr++;
189 if(CurrAddr>delay-1) CurrAddr=0; 193 if(CurrAddr>delay-1) CurrAddr=0;
190 194
191 return (double)iRVBLeft; 195 return (long)iRVBLeft;
192} 196}
193 197
194double MixREVERBRight(void) 198long MixREVERBRight(void)
195{ 199{
196 return (double)iRVBRight; 200 return (long)iRVBRight;
197} 201}
198 202
199void MV_FPReverb(int volume) 203void MV_FPReverb(int volume)
200{ 204{
205 //rb->splashf(HZ, "SLOW CODE!!!");
201 int i, count = MV_BufferSize / MV_SampleSize * MV_Channels; 206 int i, count = MV_BufferSize / MV_SampleSize * MV_Channels;
202 207
203// sprintf(err, "count: %d, old_delay: %d", count, delay); 208// sprintf(err, "count: %d, old_delay: %d", count, delay);
@@ -215,27 +220,32 @@ void MV_FPReverb(int volume)
215 } 220 }
216 221
217// OutputDebugStringA(err); 222// OutputDebugStringA(err);
223
224 long scale = (volume << FRACBITS) / MV_MaxVolume;
218 225
219 if (MV_Channels == 1) 226 if (MV_Channels == 1)
220 { 227 {
221 for (i = 0; i < count; i++) 228 for (i = 0; i < count; i++)
222 { 229 {
223 double temp = MV_FooBuffer[i]; 230 long temp = MV_FooBuffer[i];
224 MV_FooBuffer[i] += ((MixREVERBLeft(temp, temp, reverbBuffer) + MixREVERBRight()) * .5) * (double)volume / (double)MV_MaxVolume; 231 /* evaluation order matters */
232 long total = MixREVERBLeft(temp, temp, reverbBuffer);
233 total += MixREVERBRight();
234 total /= 2;
235 MV_FooBuffer[i] += (scale * total) >> FRACBITS;
225 } 236 }
226 } 237 }
227 else 238 else
228 { 239 {
229 count >>= 1; 240 count /= 2;
230 for (i = 0; i < count; i++) 241 for (i = 0; i < count; i++)
231 { 242 {
232 double left = MV_FooBuffer[i*2]; 243 long left = MV_FooBuffer[i*2];
233 double right = MV_FooBuffer[i*2+1]; 244 long right = MV_FooBuffer[i*2+1];
234 double scale = (double)volume / (double)MV_MaxVolume; 245 left += (scale * MixREVERBLeft(left, right, reverbBuffer)) >> FRACBITS;
235 left += MixREVERBLeft(left, right, reverbBuffer) * scale; 246 right += (scale * MixREVERBRight()) >> FRACBITS;
236 right += MixREVERBRight() * scale; 247 MV_FooBuffer[i*2] = left;
237 MV_FooBuffer[i*2] = left; 248 MV_FooBuffer[i*2+1] = right;
238 MV_FooBuffer[i*2+1] = right;
239 } 249 }
240 } 250 }
241 251
@@ -265,7 +275,7 @@ void MV_16BitDownmix(char *dest, int count)
265 275
266 for (i = 0; i < count; i++) 276 for (i = 0; i < count; i++)
267 { 277 {
268 int out = (int)((MV_FooBuffer[i] * (double)0x8000)); 278 int out = MV_FooBuffer[i] >> FRACBITS;
269 if (out < -32768) pdest[i] = -32768; 279 if (out < -32768) pdest[i] = -32768;
270 else if (out > 32767) pdest[i] = 32767; 280 else if (out > 32767) pdest[i] = 32767;
271 else pdest[i] = out; 281 else pdest[i] = out;
@@ -278,13 +288,14 @@ void MV_8BitDownmix(char *dest, int count)
278 288
279 for (i = 0; i < count; i++) 289 for (i = 0; i < count; i++)
280 { 290 {
281 int out = ((int)((MV_FooBuffer[i] * (double)0x80))); 291 int out = MV_FooBuffer[i] >> FRACBITS;
282 if (out < -128) dest[i] = 0; 292 if (out < -128) dest[i] = 0;
283 else if (out > 127) dest[i] = 255; 293 else if (out > 127) dest[i] = 255;
284 else dest[i] = out + 0x80; 294 else dest[i] = out + 0x80;
285 } 295 }
286} 296}
287 297
298/*
288void MV_16BitReverbFast( const char *src, char *dest, int count, int shift ) 299void MV_16BitReverbFast( const char *src, char *dest, int count, int shift )
289{ 300{
290 int i; 301 int i;
@@ -310,3 +321,4 @@ void MV_8BitReverbFast( const signed char *src, signed char *dest, int count, in
310 dest[i] = (signed char) (a + sh + c); 321 dest[i] = (signed char) (a + sh + c);
311 } 322 }
312} 323}
324*/
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/game.c b/apps/plugins/sdl/progs/duke3d/Game/src/game.c
index 303ac56ea9..0cb1d95b86 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/game.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/game.c
@@ -2227,8 +2227,9 @@ void duke_tics(short offx, short offy, short color)
2227 else 2227 else
2228 savedFps = fpsAvg; 2228 savedFps = fpsAvg;
2229 2229
2230 extern int rbaud_underruns; 2230 extern int rbaud_underruns, fp_calls[4];
2231 sprintf(fps," %d %d", savedFps, rbaud_underruns); 2231 sprintf(fps," %d %d %d %d %d %d", savedFps, rbaud_underruns, fp_calls[0],
2232 fp_calls[1], fp_calls[2], fp_calls[3]);
2232 strcat(text, fps); 2233 strcat(text, fps);
2233 2234
2234 minitext(offx,offy,text,color,2+8+16+128); 2235 minitext(offx,offy,text,color,2+8+16+128);
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/global.c b/apps/plugins/sdl/progs/duke3d/Game/src/global.c
index 9c8d3a607a..57c561edd6 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/global.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/global.c
@@ -32,18 +32,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
32#include "global.h" 32#include "global.h"
33#include "duke3d.h" 33#include "duke3d.h"
34 34
35uint16_t readLE16(void *addr)
36{
37 uint8_t *ptr = addr;
38 return (*(ptr+1) << 8) | *ptr;
39}
40
41uint32_t readLE32(void *addr)
42{
43 uint8_t *ptr = addr;
44 return (*(ptr+3) << 24) |(*(ptr+2) << 16) | (*(ptr+1) << 8) | *ptr;
45}
46
47char *mymembuf; 35char *mymembuf;
48uint8_t MusicPtr[72000]; 36uint8_t MusicPtr[72000];
49 37
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/global.h b/apps/plugins/sdl/progs/duke3d/Game/src/global.h
index f34ef7ab9f..e0be16f500 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/global.h
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/global.h
@@ -12,8 +12,6 @@
12#include "SDL.h" 12#include "SDL.h"
13 13
14#define open rb->open 14#define open rb->open
15uint16_t readLE16(void *addr);
16uint32_t readLE32(void *addr);
17 15
18void FixFilePath(char *filename); 16void FixFilePath(char *filename);
19int FindDistance3D(int ix, int iy, int iz); 17int FindDistance3D(int ix, int iy, int iz);
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/sounds.c b/apps/plugins/sdl/progs/duke3d/Game/src/sounds.c
index 4d40434011..0e3c8f6fa9 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/sounds.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/sounds.c
@@ -50,64 +50,64 @@ int32_t backflag,numenvsnds;
50*/ 50*/
51 51
52void SoundStartup( void ) 52void SoundStartup( void )
53 { 53{
54 int32 status; 54 int32 status;
55 55
56 // if they chose None lets return 56 // if they chose None lets return
57 if (FXDevice == NumSoundCards) return; 57 if (FXDevice == NumSoundCards) return;
58 58
59 // Do special Sound Blaster, AWE32 stuff 59 // Do special Sound Blaster, AWE32 stuff
60 if ( 60 if (
61 ( FXDevice == SoundBlaster ) || 61 ( FXDevice == SoundBlaster ) ||
62 ( FXDevice == Awe32 ) 62 ( FXDevice == Awe32 )
63 ) 63 )
64 { 64 {
65 int MaxVoices; 65 int MaxVoices;
66 int MaxBits; 66 int MaxBits;
67 int MaxChannels; 67 int MaxChannels;
68
69 status = FX_SetupSoundBlaster
70 (
71 BlasterConfig, (int *)&MaxVoices, (int *)&MaxBits, (int *)&MaxChannels
72 );
73 }
74 else
75 {
76 status = FX_Ok;
77 }
68 78
69 status = FX_SetupSoundBlaster 79 if ( status == FX_Ok )
70 ( 80 {
71 BlasterConfig, (int *)&MaxVoices, (int *)&MaxBits, (int *)&MaxChannels 81 if ( eightytwofifty && numplayers > 1)
72 ); 82 {
73 } 83 status = FX_Init( FXDevice, min( NumVoices,4 ), 1, 8, 8000 );
74 else 84 }
75 { 85 else
76 status = FX_Ok; 86 {
77 } 87 status = FX_Init( FXDevice, NumVoices, NumChannels, NumBits, MixRate );
88 }
89 if ( status == FX_Ok )
90 {
78 91
79 if ( status == FX_Ok ) 92 FX_SetVolume( FXVolume );
80 { 93 if (ReverseStereo == 1)
81 if ( eightytwofifty && numplayers > 1)
82 {
83 status = FX_Init( FXDevice, min( NumVoices,4 ), 1, 8, 8000 );
84 }
85 else
86 {
87 status = FX_Init( FXDevice, NumVoices, NumChannels, NumBits, MixRate );
88 }
89 if ( status == FX_Ok )
90 {
91
92 FX_SetVolume( FXVolume );
93 if (ReverseStereo == 1)
94 { 94 {
95 FX_SetReverseStereo(!FX_GetReverseStereo()); 95 FX_SetReverseStereo(!FX_GetReverseStereo());
96 } 96 }
97 } 97 }
98 } 98 }
99 if ( status != FX_Ok ) 99 if ( status != FX_Ok )
100 { 100 {
101 Error(EXIT_FAILURE, FX_ErrorString( FX_Error )); 101 Error(EXIT_FAILURE, FX_ErrorString( FX_Error ));
102 } 102 }
103 103
104 status = FX_SetCallBack( TestCallBack ); 104 status = FX_SetCallBack( TestCallBack );
105 105
106 if ( status != FX_Ok ) 106 if ( status != FX_Ok )
107 { 107 {
108 Error(EXIT_FAILURE, FX_ErrorString( FX_Error )); 108 Error(EXIT_FAILURE, FX_ErrorString( FX_Error ));
109 } 109 }
110 } 110}
111 111
112/* 112/*
113=================== 113===================
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/util_lib.h b/apps/plugins/sdl/progs/duke3d/Game/src/util_lib.h
index 8af441cfc7..bf9e22d2a6 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/util_lib.h
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/util_lib.h
@@ -66,9 +66,6 @@ int32_t Intelint32_t (int32_t l);
66 66
67void HeapSort(uint8_t * base, int32 nel, int32 width, int32 (*compare)(), void (*switcher)()); 67void HeapSort(uint8_t * base, int32 nel, int32 width, int32 (*compare)(), void (*switcher)());
68 68
69uint16_t readLE16(void *addr);
70uint32_t readLE32(void *addr);
71
72#ifdef __cplusplus 69#ifdef __cplusplus
73}; 70};
74#endif 71#endif