mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
pitch.cpp cleanup.
git-svn-id: https://svn.eduke32.com/eduke32@7101 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
c0889dab31
commit
f1cf0bafdd
2 changed files with 14 additions and 29 deletions
|
@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#define MAXDETUNE 50
|
||||
|
||||
static uint32_t PitchTable[12][MAXDETUNE];
|
||||
static int32_t PITCH_Installed = 0;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
|
@ -47,15 +46,9 @@ static int32_t PITCH_Installed = 0;
|
|||
void PITCH_Init(void)
|
||||
{
|
||||
for (int note = 0; note < 12; note++)
|
||||
{
|
||||
for (int detune = 0; detune < MAXDETUNE; detune++)
|
||||
{
|
||||
PitchTable[note][detune] = (uint32_t) (65536.f * powf(2.f, (note * MAXDETUNE + detune) / (12.f * MAXDETUNE)));
|
||||
}
|
||||
}
|
||||
|
||||
PITCH_Installed = 1;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
|
@ -64,10 +57,15 @@ void PITCH_Init(void)
|
|||
Returns a fixed-point value to scale number the specified amount.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
uint32_t PITCH_GetScale(int32_t pitchoffset)
|
||||
uint32_t PITCH_GetScale(int const pitchoffset)
|
||||
{
|
||||
static bool bInitialized;
|
||||
|
||||
if (!bInitialized)
|
||||
{
|
||||
if (!PITCH_Installed)
|
||||
PITCH_Init();
|
||||
bInitialized = true;
|
||||
}
|
||||
|
||||
if (pitchoffset == 0)
|
||||
return PitchTable[0][0];
|
||||
|
@ -77,23 +75,10 @@ uint32_t PITCH_GetScale(int32_t pitchoffset)
|
|||
if (noteshift < 0)
|
||||
noteshift += 1200;
|
||||
|
||||
int note = noteshift / 100;
|
||||
int detune = (noteshift % 100) / (100 / MAXDETUNE);
|
||||
int octaveshift = (pitchoffset - noteshift) / 1200;
|
||||
int const note = noteshift / 100;
|
||||
int const detune = (noteshift % 100) / (100 / MAXDETUNE);
|
||||
int const oshift = (pitchoffset - noteshift) / 1200;
|
||||
auto const &scale = PitchTable[note][detune];
|
||||
|
||||
if (detune < 0)
|
||||
{
|
||||
detune += (100 / MAXDETUNE);
|
||||
note--;
|
||||
if (note < 0)
|
||||
{
|
||||
note += 12;
|
||||
octaveshift--;
|
||||
return (oshift < 0) ? (scale >> -oshift) : (scale << oshift);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t scale = PitchTable[note][detune];
|
||||
|
||||
return (octaveshift < 0) ? (scale >> -octaveshift) : (scale <<= octaveshift);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,5 +33,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
#include "inttypes.h"
|
||||
|
||||
uint32_t PITCH_GetScale(int32_t pitchoffset);
|
||||
uint32_t PITCH_GetScale(int pitchoffset);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue