mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 19:20: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
|
@ -33,8 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#define MAXDETUNE 50
|
#define MAXDETUNE 50
|
||||||
|
|
||||||
static uint32_t PitchTable[ 12 ][ MAXDETUNE ];
|
static uint32_t PitchTable[12][MAXDETUNE];
|
||||||
static int32_t PITCH_Installed = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------
|
/*---------------------------------------------------------------------
|
||||||
|
@ -47,14 +46,8 @@ static int32_t PITCH_Installed = 0;
|
||||||
void PITCH_Init(void)
|
void PITCH_Init(void)
|
||||||
{
|
{
|
||||||
for (int note = 0; note < 12; note++)
|
for (int note = 0; note < 12; note++)
|
||||||
{
|
|
||||||
for (int detune = 0; detune < MAXDETUNE; detune++)
|
for (int detune = 0; detune < MAXDETUNE; detune++)
|
||||||
{
|
|
||||||
PitchTable[note][detune] = (uint32_t) (65536.f * powf(2.f, (note * MAXDETUNE + detune) / (12.f * MAXDETUNE)));
|
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.
|
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)
|
||||||
{
|
{
|
||||||
if (!PITCH_Installed)
|
static bool bInitialized;
|
||||||
|
|
||||||
|
if (!bInitialized)
|
||||||
|
{
|
||||||
PITCH_Init();
|
PITCH_Init();
|
||||||
|
bInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (pitchoffset == 0)
|
if (pitchoffset == 0)
|
||||||
return PitchTable[0][0];
|
return PitchTable[0][0];
|
||||||
|
@ -77,23 +75,10 @@ uint32_t PITCH_GetScale(int32_t pitchoffset)
|
||||||
if (noteshift < 0)
|
if (noteshift < 0)
|
||||||
noteshift += 1200;
|
noteshift += 1200;
|
||||||
|
|
||||||
int note = noteshift / 100;
|
int const note = noteshift / 100;
|
||||||
int detune = (noteshift % 100) / (100 / MAXDETUNE);
|
int const detune = (noteshift % 100) / (100 / MAXDETUNE);
|
||||||
int octaveshift = (pitchoffset - noteshift) / 1200;
|
int const oshift = (pitchoffset - noteshift) / 1200;
|
||||||
|
auto const &scale = PitchTable[note][detune];
|
||||||
|
|
||||||
if (detune < 0)
|
return (oshift < 0) ? (scale >> -oshift) : (scale << oshift);
|
||||||
{
|
|
||||||
detune += (100 / MAXDETUNE);
|
|
||||||
note--;
|
|
||||||
if (note < 0)
|
|
||||||
{
|
|
||||||
note += 12;
|
|
||||||
octaveshift--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
#include "inttypes.h"
|
||||||
|
|
||||||
uint32_t PITCH_GetScale(int32_t pitchoffset);
|
uint32_t PITCH_GetScale(int pitchoffset);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue