Replaced sin() to sinf() and log() to logf() for using floats instead of doubles.

pull/4/head
Holger Wirtz 7 years ago
parent 06dbd23898
commit 288c1f69b8
  1. 6
      EngineMkI.cpp
  2. 6
      dx7note.cpp
  3. 6
      sin.cpp

@ -37,7 +37,8 @@
#ifdef _WIN32 #ifdef _WIN32
#if _MSC_VER < 1800 #if _MSC_VER < 1800
FRAC_NUM log2(FRAC_NUM n) { FRAC_NUM log2(FRAC_NUM n) {
return log(n) / log(2.0); //return log(n) / log(2.0);
return logf(n) / logf(2.0);
} }
FRAC_NUM round(FRAC_NUM n) { FRAC_NUM round(FRAC_NUM n) {
return n < 0.0 ? ceil(n - 0.5) : floor(n + 0.5); return n < 0.0 ? ceil(n - 0.5) : floor(n + 0.5);
@ -81,7 +82,8 @@ EngineMkI::EngineMkI() {
float bitReso = SINLOG_TABLESIZE; float bitReso = SINLOG_TABLESIZE;
for(int i=0;i<SINLOG_TABLESIZE;i++) { for(int i=0;i<SINLOG_TABLESIZE;i++) {
float x1 = sin(((0.5+i)/bitReso) * M_PI/2.0); //float x1 = sin(((0.5+i)/bitReso) * M_PI/2.0);
float x1 = sinf(((0.5+i)/bitReso) * M_PI/2.0);
sinLogTable[i] = round(-1024 * log2(x1)); sinLogTable[i] = round(-1024 * log2(x1));
} }

@ -26,7 +26,8 @@
const int FEEDBACK_BITDEPTH = 8; const int FEEDBACK_BITDEPTH = 8;
int32_t midinote_to_logfreq(int midinote) { int32_t midinote_to_logfreq(int midinote) {
const int32_t base = 50857777; // (1 << 24) * (log(440) / log(2) - 69/12) //const int32_t base = 50857777; // (1 << 24) * (log(440) / log(2) - 69/12)
const int32_t base = 50857777; // (1 << 24) * (logf(440) / logf(2) - 69/12)
const int32_t step = (1 << 24) / 12; const int32_t step = (1 << 24) / 12;
return base + step * midinote; return base + step * midinote;
} }
@ -51,7 +52,8 @@ int32_t osc_freq(int midinote, int mode, int coarse, int fine, int detune) {
logfreq += coarsemul[coarse & 31]; logfreq += coarsemul[coarse & 31];
if (fine) { if (fine) {
// (1 << 24) / log(2) // (1 << 24) / log(2)
logfreq += (int32_t)floor(24204406.323123 * log(1 + 0.01 * fine) + 0.5); //logfreq += (int32_t)floor(24204406.323123 * log(1 + 0.01 * fine) + 0.5);
logfreq += (int32_t)floor(24204406.323123 * logf(1 + 0.01 * fine) + 0.5);
} }
// // This was measured at 7.213Hz per count at 9600Hz, but the exact // // This was measured at 7.213Hz per count at 9600Hz, but the exact

@ -30,8 +30,10 @@ int32_t sintab[SIN_N_SAMPLES + 1];
void Sin::init() { void Sin::init() {
FRAC_NUM dphase = 2 * M_PI / SIN_N_SAMPLES; FRAC_NUM dphase = 2 * M_PI / SIN_N_SAMPLES;
int32_t c = (int32_t)floor(cos(dphase) * (1 << 30) + 0.5); //int32_t c = (int32_t)floor(cos(dphase) * (1 << 30) + 0.5);
int32_t s = (int32_t)floor(sin(dphase) * (1 << 30) + 0.5); int32_t c = (int32_t)floor(cosf(dphase) * (1 << 30) + 0.5);
//int32_t s = (int32_t)floor(sin(dphase) * (1 << 30) + 0.5);
int32_t s = (int32_t)floor(sinf(dphase) * (1 << 30) + 0.5);
int32_t u = 1 << 30; int32_t u = 1 << 30;
int32_t v = 0; int32_t v = 0;
for (int i = 0; i < SIN_N_SAMPLES / 2; i++) { for (int i = 0; i < SIN_N_SAMPLES / 2; i++) {

Loading…
Cancel
Save