2009-07-27 05:47:50 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1994-1995 Apogee Software, Ltd.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
/**********************************************************************
|
|
|
|
module: PITCH.C
|
|
|
|
|
|
|
|
author: James R. Dose
|
|
|
|
date: June 14, 1993
|
|
|
|
|
|
|
|
Routines for pitch scaling.
|
|
|
|
|
|
|
|
(c) Copyright 1993 James R. Dose. All Rights Reserved.
|
|
|
|
**********************************************************************/
|
|
|
|
|
2017-02-25 08:15:36 +00:00
|
|
|
#include "compat.h"
|
2009-07-27 05:47:50 +00:00
|
|
|
#include "pitch.h"
|
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
#define MAXDETUNE 50
|
2009-10-03 14:34:05 +00:00
|
|
|
|
2018-10-25 23:30:51 +00:00
|
|
|
static uint32_t PitchTable[12][MAXDETUNE];
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: PITCH_Init
|
|
|
|
|
|
|
|
Initializes pitch table.
|
|
|
|
---------------------------------------------------------------------*/
|
2009-10-03 14:34:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PITCH_Init(void)
|
|
|
|
{
|
2016-08-27 01:39:30 +00:00
|
|
|
for (int note = 0; note < 12; note++)
|
|
|
|
for (int detune = 0; detune < MAXDETUNE; detune++)
|
2015-04-11 13:53:06 +00:00
|
|
|
PitchTable[note][detune] = (uint32_t) (65536.f * powf(2.f, (note * MAXDETUNE + detune) / (12.f * MAXDETUNE)));
|
2009-10-03 14:34:05 +00:00
|
|
|
}
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: PITCH_GetScale
|
|
|
|
|
|
|
|
Returns a fixed-point value to scale number the specified amount.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2018-10-25 23:30:51 +00:00
|
|
|
uint32_t PITCH_GetScale(int const pitchoffset)
|
2009-10-03 14:34:05 +00:00
|
|
|
{
|
2018-10-25 23:30:51 +00:00
|
|
|
static bool bInitialized;
|
|
|
|
|
|
|
|
if (!bInitialized)
|
|
|
|
{
|
2009-10-03 14:34:05 +00:00
|
|
|
PITCH_Init();
|
2018-10-25 23:30:51 +00:00
|
|
|
bInitialized = true;
|
|
|
|
}
|
2009-10-03 14:34:05 +00:00
|
|
|
|
|
|
|
if (pitchoffset == 0)
|
2016-08-27 01:39:30 +00:00
|
|
|
return PitchTable[0][0];
|
|
|
|
|
|
|
|
int noteshift = pitchoffset % 1200;
|
2009-10-03 14:34:05 +00:00
|
|
|
|
|
|
|
if (noteshift < 0)
|
|
|
|
noteshift += 1200;
|
|
|
|
|
2018-10-25 23:30:51 +00:00
|
|
|
int const note = noteshift / 100;
|
|
|
|
int const detune = (noteshift % 100) / (100 / MAXDETUNE);
|
|
|
|
int const oshift = (pitchoffset - noteshift) / 1200;
|
|
|
|
auto const &scale = PitchTable[note][detune];
|
2009-10-03 14:34:05 +00:00
|
|
|
|
2018-10-25 23:30:51 +00:00
|
|
|
return (oshift < 0) ? (scale >> -oshift) : (scale << oshift);
|
2009-10-03 14:34:05 +00:00
|
|
|
}
|