summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/sdl/progs/duke3d/Engine/src/display.c10
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c6
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mv_mix.c26
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c74
-rw-r--r--apps/plugins/sdl/progs/duke3d/Game/src/config.c1
5 files changed, 65 insertions, 52 deletions
diff --git a/apps/plugins/sdl/progs/duke3d/Engine/src/display.c b/apps/plugins/sdl/progs/duke3d/Engine/src/display.c
index 3883803bce..501ffa411c 100644
--- a/apps/plugins/sdl/progs/duke3d/Engine/src/display.c
+++ b/apps/plugins/sdl/progs/duke3d/Engine/src/display.c
@@ -1368,9 +1368,13 @@ int VBE_setPalette(uint8_t *palettebuffer)
1368 memcpy(lastPalette, palettebuffer, 768); 1368 memcpy(lastPalette, palettebuffer, 768);
1369 1369
1370 for (i = 0; i < 256; i++){ 1370 for (i = 0; i < 256; i++){
1371 sdlp->b = (Uint8) ((((float) *p++) / 63.0) * 255.0); 1371 /* doesn't map perfectly */
1372 sdlp->g = (Uint8) ((((float) *p++) / 63.0) * 255.0); 1372 sdlp->b = (Uint8) (*p << 2) | (*p >> 4);
1373 sdlp->r = (Uint8) ((((float) *p++) / 63.0) * 255.0); 1373 p++;
1374 sdlp->g = (Uint8) (*p << 2) | (*p >> 4);
1375 p++;
1376 sdlp->r = (Uint8) (*p << 2) | (*p >> 4);
1377 p++;
1374 sdlp->unused = *p++; /* This byte is unused in BUILD, too. */ 1378 sdlp->unused = *p++; /* This byte is unused in BUILD, too. */
1375 sdlp++; 1379 sdlp++;
1376 } 1380 }
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 7567d7314b..2c03a862f8 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/multivoc.c
@@ -122,7 +122,7 @@ static int MV_FooMemory;
122static int MV_BufferDescriptor; 122static int MV_BufferDescriptor;
123static int MV_BufferEmpty[ NumberOfBuffers ]; 123static int MV_BufferEmpty[ NumberOfBuffers ];
124char *MV_MixBuffer[ NumberOfBuffers + 1 ]; 124char *MV_MixBuffer[ NumberOfBuffers + 1 ];
125/* fixed-point */ 125/* raw samples in range [-2^15, 2^15-1], interleaved stereo */
126long *MV_FooBuffer = NULL; 126long *MV_FooBuffer = NULL;
127 127
128static VoiceNode *MV_Voices = NULL; 128static VoiceNode *MV_Voices = NULL;
@@ -465,8 +465,8 @@ void MV_ServiceVoc
465 } 465 }
466 466
467 { 467 {
468 ClearBuffer_DW( MV_FooBuffer, 0, sizeof(long) / 4 * MV_BufferSize / MV_SampleSize * MV_Channels); 468 ClearBuffer_DW( MV_FooBuffer, 0, (sizeof(long) * MV_BufferSize / MV_SampleSize * MV_Channels) / 4);
469 MV_BufferEmpty[ MV_MixPage ] = TRUE; 469 MV_BufferEmpty[ MV_MixPage ] = TRUE;
470 } 470 }
471 471
472 // Play any waiting voices 472 // Play any waiting voices
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 61485a1ca0..e44e432434 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
@@ -65,7 +65,7 @@ int MV_cubic(int position)
65 } 65 }
66*/ 66*/
67 67
68static int MV_cubic16(const short *src, int position, int rate) 68static inline int MV_cubic16(const short *src, int position, int rate)
69{ 69{
70 int temp, hpos = position >> 16; 70 int temp, hpos = position >> 16;
71 71
@@ -88,7 +88,7 @@ static int MV_cubic16(const short *src, int position, int rate)
88 return do_cubic ? MV_cubic(position) : gval(3); 88 return do_cubic ? MV_cubic(position) : gval(3);
89} 89}
90 90
91static int MV_cubic8to16(const unsigned char *src, int position, int rate) 91static inline int MV_cubic8to16(const unsigned char *src, int position, int rate)
92{ 92{
93 int temp, hpos = position >> 16; 93 int temp, hpos = position >> 16;
94 94
@@ -394,15 +394,17 @@ void MV_MixFPMono8( uint32_t position,
394 394
395 for (i = 0; i < length; i++) { 395 for (i = 0; i < length; i++) {
396 int s = MV_cubic8to16(src, position, rate) << FRACBITS; 396 int s = MV_cubic8to16(src, position, rate) << FRACBITS;
397 long out; 397 int out;
398
399 /* output is long in range [0, 2^16) */
400 out = (s * MV_LeftScale) >> (FRACBITS * 2);
398 401
399 out = (s * MV_LeftScale) >> FRACBITS;
400 *dest += out; 402 *dest += out;
401 403
402 position += rate; 404 position += rate;
403 dest += MV_Channels; 405 dest += MV_Channels;
404 } 406 }
405 407
406 MV_MixPosition = position; 408 MV_MixPosition = position;
407 MV_MixDestination = (char *)dest; 409 MV_MixDestination = (char *)dest;
408} 410}
@@ -423,8 +425,8 @@ void MV_MixFPStereo8( uint32_t position,
423 int s = MV_cubic8to16(src, position, rate) << FRACBITS; 425 int s = MV_cubic8to16(src, position, rate) << FRACBITS;
424 long left, right; 426 long left, right;
425 427
426 left = (s * MV_LeftScale) >> FRACBITS; 428 left = (s * MV_LeftScale) >> (FRACBITS * 2);
427 right = (s * MV_RightScale) >> FRACBITS; 429 right = (s * MV_RightScale) >> (FRACBITS * 2);
428 430
429 dest[0] += left; 431 dest[0] += left;
430 dest[1] += right; 432 dest[1] += right;
@@ -452,9 +454,9 @@ void MV_MixFPMono16( uint32_t position,
452 454
453 for (i = 0; i < length; i++) { 455 for (i = 0; i < length; i++) {
454 int s = MV_cubic16(src, position, rate) << FRACBITS; 456 int s = MV_cubic16(src, position, rate) << FRACBITS;
455 long out; 457 int out;
456 458
457 out = (s * MV_LeftScale) >> FRACBITS; 459 out = (s * MV_LeftScale) >> (FRACBITS * 2);
458 *dest += out; 460 *dest += out;
459 461
460 position += rate; 462 position += rate;
@@ -480,10 +482,10 @@ void MV_MixFPStereo16( uint32_t position,
480 for (i = 0; i < length; i++) { 482 for (i = 0; i < length; i++) {
481 int s = MV_cubic16(src, position, rate) << FRACBITS; 483 int s = MV_cubic16(src, position, rate) << FRACBITS;
482 484
483 long left, right; 485 int left, right;
484 486
485 left = (s * MV_LeftScale) >> FRACBITS; 487 left = (s * MV_LeftScale) >> (FRACBITS * 2);
486 right = (s * MV_RightScale) >> FRACBITS; 488 right = (s * MV_RightScale) >> (FRACBITS * 2);
487 489
488 dest[0] += left; 490 dest[0] += left;
489 dest[1] += right; 491 dest[1] += right;
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 7d48d3271e..4c82f6eec0 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/audiolib/mvreverb.c
@@ -18,24 +18,40 @@ static int FB_SRC_A, FB_SRC_B, IIR_DEST_A0, IIR_DEST_A1, ACC_SRC_A0, ACC_SRC_A1,
18 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,
19 MIX_DEST_A1, MIX_DEST_B0, MIX_DEST_B1; 19 MIX_DEST_A1, MIX_DEST_B0, MIX_DEST_B1;
20 20
21static long IIR_ALPHA, ACC_COEF_A, ACC_COEF_B, ACC_COEF_C, ACC_COEF_D, IIR_COEF, FB_ALPHA, FB_X, 21//static long IIR_ALPHA, ACC_COEF_A, ACC_COEF_B, ACC_COEF_C, ACC_COEF_D, IIR_COEF, FB_ALPHA, FB_X,
22 IN_COEF_L, IN_COEF_R; 22// IN_COEF_L, IN_COEF_R;
23 23
24static long iRVBLeft, iRVBRight;
25 24
26static int cnv_offset(int src) 25#define fp_scale ((double)(1<<FRACBITS))
26//static const double fp_scale = (double) (1 << FRACBITS);
27
28static const long IIR_ALPHA = 0.8701171875 * fp_scale,
29 ACC_COEF_A = 0.622314453125 * fp_scale,
30 ACC_COEF_B = -0.5244140625 * fp_scale,
31 ACC_COEF_C = 0.53955078125 * fp_scale,
32 ACC_COEF_D = -0.50830078125 * fp_scale,
33 IIR_COEF = -0.69921875 * fp_scale,
34 FB_ALPHA = 0.67578125 * fp_scale,
35 FB_X = 0.646484375 * fp_scale,
36 IN_COEF_L = -2. * fp_scale,
37 IN_COEF_R = -2. * fp_scale;
38
39static long iRVBLeft, iRVBRight;
40
41static inline int cnv_offset(int src)
27{ 42{
28 int64_t temp = ((int64_t)src * (int64_t)MV_MixRate) / 22050; 43 /* no need for 64-bit ints here */
29 return (int)temp; 44 /* src can be no greater than 2^16-1, which allows sample rates up
45 * to 65KHz */
46 int temp = (src * MV_MixRate) / 22050;
47 return temp;
30} 48}
31 49
32// static char err[256]; 50// static char err[256];
33 51
34// extern __stdcall OutputDebugStringA(char *); 52// extern __stdcall OutputDebugStringA(char *);
35 53
36static const double fp_scale = (double) (1 << FRACBITS); 54static inline void check_buffer()
37
38static void check_buffer()
39{ 55{
40 int new_delay = cnv_offset(MV_ReverbDelay); 56 int new_delay = cnv_offset(MV_ReverbDelay);
41 57
@@ -64,16 +80,6 @@ static void check_buffer()
64 MIX_DEST_A1 = cnv_offset(0x238); 80 MIX_DEST_A1 = cnv_offset(0x238);
65 MIX_DEST_B0 = cnv_offset(0x154); 81 MIX_DEST_B0 = cnv_offset(0x154);
66 MIX_DEST_B1 = cnv_offset(0xAA); 82 MIX_DEST_B1 = cnv_offset(0xAA);
67 IIR_ALPHA = 0.8701171875 * fp_scale;
68 ACC_COEF_A = 0.622314453125 * fp_scale;
69 ACC_COEF_B = -0.5244140625 * fp_scale;
70 ACC_COEF_C = 0.53955078125 * fp_scale;
71 ACC_COEF_D = -0.50830078125 * fp_scale;
72 IIR_COEF = -0.69921875 * fp_scale;
73 FB_ALPHA = 0.67578125 * fp_scale;
74 FB_X = 0.646484375 * fp_scale;
75 IN_COEF_L = -2. * fp_scale;
76 IN_COEF_R = -2. * fp_scale;
77 if (reverbBuffer) reverbBuffer = (long*) realloc(reverbBuffer, new_delay * sizeof(long)); 83 if (reverbBuffer) reverbBuffer = (long*) realloc(reverbBuffer, new_delay * sizeof(long));
78 else reverbBuffer = (long*) malloc(new_delay * sizeof(long)); 84 else reverbBuffer = (long*) malloc(new_delay * sizeof(long));
79 memset(reverbBuffer, 0, new_delay * sizeof(long)); 85 memset(reverbBuffer, 0, new_delay * sizeof(long));
@@ -83,7 +89,7 @@ static void check_buffer()
83 89
84} 90}
85 91
86long g_buffer(int iOff, long *ptr) // get_buffer content helper: takes care about wraps 92static inline long g_buffer(int iOff, long *ptr) // get_buffer content helper: takes care about wraps
87{ 93{
88 int correctDelay = delay; 94 int correctDelay = delay;
89 if(!correctDelay) 95 if(!correctDelay)
@@ -104,7 +110,7 @@ long g_buffer(int iOff, long *ptr) // get_buffer conten
104 return (long)*(ptr+iOff); 110 return (long)*(ptr+iOff);
105} 111}
106 112
107void s_buffer(int iOff,long iVal, long *ptr) // set_buffer content helper: takes care about wraps and clipping 113static inline void s_buffer(int iOff,long iVal, long *ptr) // set_buffer content helper: takes care about wraps and clipping
108{ 114{
109 int correctDelay = delay; 115 int correctDelay = delay;
110 if(!correctDelay) 116 if(!correctDelay)
@@ -125,7 +131,7 @@ void s_buffer(int iOff,long iVal, long *ptr) // set_buffer conten
125 *(ptr+iOff)=iVal; 131 *(ptr+iOff)=iVal;
126} 132}
127 133
128void s_buffer1(int iOff,long iVal, long *ptr) // set_buffer (+1 sample) content helper: takes care about wraps and clipping 134static inline void s_buffer1(int iOff,long iVal, long *ptr) // set_buffer (+1 sample) content helper: takes care about wraps and clipping
129{ 135{
130 int correctDelay = delay; 136 int correctDelay = delay;
131 if(!correctDelay) 137 if(!correctDelay)
@@ -146,7 +152,7 @@ void s_buffer1(int iOff,long iVal, long *ptr) // set_buffer (+1 s
146 *(ptr+iOff)=iVal; 152 *(ptr+iOff)=iVal;
147} 153}
148 154
149long MixREVERBLeft(long INPUT_SAMPLE_L, long INPUT_SAMPLE_R, long *ptr) 155static inline long MixREVERBLeft(long INPUT_SAMPLE_L, long INPUT_SAMPLE_R, long *ptr)
150{ 156{
151 long ACC0,ACC1,FB_A0,FB_A1,FB_B0,FB_B1; 157 long ACC0,ACC1,FB_A0,FB_A1,FB_B0,FB_B1;
152 158
@@ -186,8 +192,8 @@ long MixREVERBLeft(long INPUT_SAMPLE_L, long INPUT_SAMPLE_R, long *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); 192 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);
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); 193 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);
188 194
189 iRVBLeft = fp_div((g_buffer(MIX_DEST_A0, ptr)+g_buffer(MIX_DEST_B0, ptr)), 3 << FRACBITS, FRACBITS); 195 iRVBLeft = (g_buffer(MIX_DEST_A0, ptr)+g_buffer(MIX_DEST_B0, ptr)) / 3;
190 iRVBRight = fp_div((g_buffer(MIX_DEST_A1, ptr)+g_buffer(MIX_DEST_B1, ptr)), 3 << FRACBITS, FRACBITS); 196 iRVBRight = (g_buffer(MIX_DEST_A1, ptr)+g_buffer(MIX_DEST_B1, ptr)) / 3;
191 197
192 CurrAddr++; 198 CurrAddr++;
193 if(CurrAddr>delay-1) CurrAddr=0; 199 if(CurrAddr>delay-1) CurrAddr=0;
@@ -195,7 +201,7 @@ long MixREVERBLeft(long INPUT_SAMPLE_L, long INPUT_SAMPLE_R, long *ptr)
195 return (long)iRVBLeft; 201 return (long)iRVBLeft;
196} 202}
197 203
198long MixREVERBRight(void) 204static inline long MixREVERBRight(void)
199{ 205{
200 return (long)iRVBRight; 206 return (long)iRVBRight;
201} 207}
@@ -227,12 +233,12 @@ void MV_FPReverb(int volume)
227 { 233 {
228 for (i = 0; i < count; i++) 234 for (i = 0; i < count; i++)
229 { 235 {
230 long temp = MV_FooBuffer[i]; 236 long temp = MV_FooBuffer[i] << FRACBITS;
231 /* evaluation order matters */ 237 /* evaluation order matters */
232 long total = MixREVERBLeft(temp, temp, reverbBuffer); 238 long total = MixREVERBLeft(temp, temp, reverbBuffer);
233 total += MixREVERBRight(); 239 total += MixREVERBRight();
234 total /= 2; 240 total /= 2;
235 MV_FooBuffer[i] += (scale * total) >> FRACBITS; 241 MV_FooBuffer[i] += (scale * total) >> (FRACBITS * 2);
236 } 242 }
237 } 243 }
238 else 244 else
@@ -240,12 +246,12 @@ void MV_FPReverb(int volume)
240 count /= 2; 246 count /= 2;
241 for (i = 0; i < count; i++) 247 for (i = 0; i < count; i++)
242 { 248 {
243 long left = MV_FooBuffer[i*2]; 249 long left = MV_FooBuffer[i*2] << FRACBITS;
244 long right = MV_FooBuffer[i*2+1]; 250 long right = MV_FooBuffer[i*2+1] << FRACBITS;
245 left += (scale * MixREVERBLeft(left, right, reverbBuffer)) >> FRACBITS; 251 left += (scale * MixREVERBLeft(left, right, reverbBuffer)) >> FRACBITS;
246 right += (scale * MixREVERBRight()) >> FRACBITS; 252 right += (scale * MixREVERBRight()) >> FRACBITS;
247 MV_FooBuffer[i*2] = left; 253 MV_FooBuffer[i*2] = left >> FRACBITS;
248 MV_FooBuffer[i*2+1] = right; 254 MV_FooBuffer[i*2+1] = right >> FRACBITS;
249 } 255 }
250 } 256 }
251 257
@@ -275,7 +281,7 @@ void MV_16BitDownmix(char *dest, int count)
275 281
276 for (i = 0; i < count; i++) 282 for (i = 0; i < count; i++)
277 { 283 {
278 int out = MV_FooBuffer[i] >> FRACBITS; 284 int out = MV_FooBuffer[i];
279 if (out < -32768) pdest[i] = -32768; 285 if (out < -32768) pdest[i] = -32768;
280 else if (out > 32767) pdest[i] = 32767; 286 else if (out > 32767) pdest[i] = 32767;
281 else pdest[i] = out; 287 else pdest[i] = out;
@@ -288,7 +294,7 @@ void MV_8BitDownmix(char *dest, int count)
288 294
289 for (i = 0; i < count; i++) 295 for (i = 0; i < count; i++)
290 { 296 {
291 int out = MV_FooBuffer[i] >> FRACBITS; 297 int out = MV_FooBuffer[i] >> 8;
292 if (out < -128) dest[i] = 0; 298 if (out < -128) dest[i] = 0;
293 else if (out > 127) dest[i] = 255; 299 else if (out > 127) dest[i] = 255;
294 else dest[i] = out + 0x80; 300 else dest[i] = out + 0x80;
diff --git a/apps/plugins/sdl/progs/duke3d/Game/src/config.c b/apps/plugins/sdl/progs/duke3d/Game/src/config.c
index 038875a4e5..1649c40b07 100644
--- a/apps/plugins/sdl/progs/duke3d/Game/src/config.c
+++ b/apps/plugins/sdl/progs/duke3d/Game/src/config.c
@@ -728,6 +728,7 @@ void CONFIG_ReadSetup( void )
728 NumBits = 16; 728 NumBits = 16;
729 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MixRate",&MixRate); 729 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MixRate",&MixRate);
730 MixRate = RB_SAMPR; 730 MixRate = RB_SAMPR;
731 printf("MixRate = %d Hz", MixRate);
731 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MidiPort",&MidiPort); 732 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MidiPort",&MidiPort);
732 SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterAddress",&dummy); 733 SCRIPT_GetNumber( scripthandle, "Sound Setup", "BlasterAddress",&dummy);
733 BlasterConfig.Address = dummy; 734 BlasterConfig.Address = dummy;