ref: be0bd464d19758f3e87b79766e9820b1efbda04b
parent: 4878ba55d2db88aaab117628cc1e91933cc0e50e
author: Simon Howard <fraggle@gmail.com>
date: Sat Mar 22 21:15:03 EDT 2014
pcsound: Extend frequency table to 128 entries. Extend from 96 to the full 128 entries found in the frequency table in the Vanilla .exes. This was helpfully posted by Gez to the Doom wiki: http://doomwiki.org/wiki/Talk:PC_speaker_sound_effects Change from the current scheme of storing frequency values to using the timer divisor values used by the Vanilla .exes; divide into the PC timer frequency to calculate the frequencies to play. Thanks to Gez for dumping the full list of frequencies; this fixes #336.
--- a/src/i_pcsound.c
+++ b/src/i_pcsound.c
@@ -36,6 +36,8 @@
#include "pcsound.h"
+#define TIMER_FREQ 1193181 /* hz */
+
static boolean pcs_initialized = false;
static SDL_mutex *sound_lock;
@@ -47,18 +49,24 @@
static int current_sound_handle = 0;
static int current_sound_lump_num = -1;
-static const float frequencies[] = {
- 0.0f, 175.00f, 180.02f, 185.01f, 190.02f, 196.02f, 202.02f, 208.01f, 214.02f, 220.02f,
- 226.02f, 233.04f, 240.02f, 247.03f, 254.03f, 262.00f, 269.03f, 277.03f, 285.04f,
- 294.03f, 302.07f, 311.04f, 320.05f, 330.06f, 339.06f, 349.08f, 359.06f, 370.09f,
- 381.08f, 392.10f, 403.10f, 415.01f, 427.05f, 440.12f, 453.16f, 466.08f, 480.15f,
- 494.07f, 508.16f, 523.09f, 539.16f, 554.19f, 571.17f, 587.19f, 604.14f, 622.09f,
- 640.11f, 659.21f, 679.10f, 698.17f, 719.21f, 740.18f, 762.41f, 784.47f, 807.29f,
- 831.48f, 855.32f, 880.57f, 906.67f, 932.17f, 960.69f, 988.55f, 1017.20f, 1046.64f,
- 1077.85f, 1109.93f, 1141.79f, 1175.54f, 1210.12f, 1244.19f, 1281.61f, 1318.43f,
- 1357.42f, 1397.16f, 1439.30f, 1480.37f, 1523.85f, 1569.97f, 1614.58f, 1661.81f,
- 1711.87f, 1762.45f, 1813.34f, 1864.34f, 1921.38f, 1975.46f, 2036.14f, 2093.29f,
- 2157.64f, 2217.80f, 2285.78f, 2353.41f, 2420.24f, 2490.98f, 2565.97f, 2639.77f,
+static const uint16_t divisors[] = {
+ 0,
+ 6818, 6628, 6449, 6279, 6087, 5906, 5736, 5575,
+ 5423, 5279, 5120, 4971, 4830, 4697, 4554, 4435,
+ 4307, 4186, 4058, 3950, 3836, 3728, 3615, 3519,
+ 3418, 3323, 3224, 3131, 3043, 2960, 2875, 2794,
+ 2711, 2633, 2560, 2485, 2415, 2348, 2281, 2213,
+ 2153, 2089, 2032, 1975, 1918, 1864, 1810, 1757,
+ 1709, 1659, 1612, 1565, 1521, 1478, 1435, 1395,
+ 1355, 1316, 1280, 1242, 1207, 1173, 1140, 1107,
+ 1075, 1045, 1015, 986, 959, 931, 905, 879,
+ 854, 829, 806, 783, 760, 739, 718, 697,
+ 677, 658, 640, 621, 604, 586, 570, 553,
+ 538, 522, 507, 493, 479, 465, 452, 439,
+ 427, 415, 403, 391, 380, 369, 359, 348,
+ 339, 329, 319, 310, 302, 293, 285, 276,
+ 269, 261, 253, 246, 239, 232, 226, 219,
+ 213, 207, 201, 195, 190, 184, 179,
};
static void PCSCallbackFunc(int *duration, int *freq)
@@ -72,7 +80,7 @@
*freq = 0;
return;
}
-
+
if (current_sound_lump != NULL && current_sound_remaining > 0)
{
// Read the next tone
@@ -83,9 +91,9 @@
// for a full discussion of this.
// Check we don't overflow the frequency table.
- if (tone < arrlen(frequencies))
+ if (tone < arrlen(divisors) && divisors[tone] != 0)
{
- *freq = (int) frequencies[tone];
+ *freq = (int) (TIMER_FREQ / divisors[tone]);
}
else
{