Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random sound pitch for arbitrary sample rate #512

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions prboom2/src/SDL/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ typedef struct

channel_info_t channelinfo[MAX_CHANNELS];

// Pitch to stepping lookup, unused.
// Pitch to stepping lookup.
int steptable[256];

// Volume lookups.
Expand Down Expand Up @@ -321,7 +321,6 @@ static void updateSoundParams(int handle, sfx_params_t *params)
int slot = handle;
int rightvol;
int leftvol;
int step = steptable[params->pitch];

#ifdef RANGECHECK
if ((handle < 0) || (handle >= MAX_CHANNELS))
Expand All @@ -336,7 +335,7 @@ static void updateSoundParams(int handle, sfx_params_t *params)
// Patched to shift left *then* divide, to minimize roundoff errors
// as well as to use SAMPLERATE as defined above, not to assume 11025 Hz
if (pitched_sounds)
channelinfo[slot].step = step + (((channelinfo[slot].samplerate << 16) / snd_samplerate) - 65536);
channelinfo[slot].step = (unsigned int)(((uint64_t)channelinfo[slot].samplerate * steptable[params->pitch]) / snd_samplerate);
else
channelinfo[slot].step = ((channelinfo[slot].samplerate << 16) / snd_samplerate);

Expand Down Expand Up @@ -403,9 +402,8 @@ void I_SetChannels(void)
}

// This table provides step widths for pitch parameters.
// I fail to see that this is currently used.
for (i = -128 ; i < 128 ; i++)
steptablemid[i] = (int)(pow(1.2, ((double)i / (64.0 * snd_samplerate / 11025))) * 65536.0);
steptablemid[i] = (int)(pow(1.2, (double)i / 64.0) * 65536.0);


// Generates volume lookup tables
Expand Down
Loading