Small FPU optimisations.

pull/4/head
Holger Wirtz 7 years ago
parent 823df46819
commit ce7d0133b9
  1. 4
      EngineMkI.cpp
  2. 10
      dx7note.cpp
  3. 4
      sin.cpp
  4. 4
      synth.h

@ -38,7 +38,7 @@
#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); return LOG_FUNC(n) / LOG_FUNC(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);
@ -83,7 +83,7 @@ EngineMkI::EngineMkI() {
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); float x1 = SIN_FUNC(((0.5+i)/bitReso) * M_PI/2.0);
sinLogTable[i] = round(-1024 * log2(x1)); sinLogTable[i] = round(-1024 * log2(x1));
} }

@ -27,7 +27,7 @@ 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 base = 50857777; // (1 << 24) * (LOG_FUNC(440) / LOG_FUNC(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;
} }
@ -46,14 +46,15 @@ int32_t osc_freq(int midinote, int mode, int coarse, int fine, int detune) {
if (mode == 0) { if (mode == 0) {
logfreq = midinote_to_logfreq(midinote); logfreq = midinote_to_logfreq(midinote);
// could use more precision, closer enough for now. those numbers comes from my DX7 // could use more precision, closer enough for now. those numbers comes from my DX7
FRAC_NUM detuneRatio = 0.0209 * exp(-0.396 * (((float)logfreq) / (1 << 24))) / 7; //FRAC_NUM detuneRatio = 0.0209 * exp(-0.396 * (((float)logfreq) / (1 << 24))) / 7;
FRAC_NUM detuneRatio = 0.0209 * EXP_FUNC(-0.396 * (((float)logfreq) / (1 << 24))) / 7;
logfreq += detuneRatio * logfreq * (detune - 7); logfreq += detuneRatio * logfreq * (detune - 7);
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); logfreq += (int32_t)floor(24204406.323123 * LOG_FUNC(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
@ -245,7 +246,8 @@ void Dx7Note::compute(int32_t *buf, int32_t lfo_val, int32_t lfo_delay, const Co
uint32_t sensamp = (uint32_t)(((uint64_t) amd_mod) * ((uint64_t) ampmodsens_[op]) >> 24); uint32_t sensamp = (uint32_t)(((uint64_t) amd_mod) * ((uint64_t) ampmodsens_[op]) >> 24);
// TODO: mehhh.. this needs some real tuning. // TODO: mehhh.. this needs some real tuning.
uint32_t pt = exp(((float)sensamp) / 262144 * 0.07 + 12.2); //uint32_t pt = exp(((float)sensamp) / 262144 * 0.07 + 12.2);
uint32_t pt = EXP_FUNC(((float)sensamp) / 262144 * 0.07 + 12.2);
uint32_t ldiff = (uint32_t)(((uint64_t)level) * (((uint64_t)pt << 4)) >> 28); uint32_t ldiff = (uint32_t)(((uint64_t)level) * (((uint64_t)pt << 4)) >> 28);
level -= ldiff; level -= ldiff;
} }

@ -31,9 +31,9 @@ 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 c = (int32_t)floor(cosf(dphase) * (1 << 30) + 0.5); int32_t c = (int32_t)floor(COS_FUNC(dphase) * (1 << 30) + 0.5);
//int32_t s = (int32_t)floor(sin(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 s = (int32_t)floor(SIN_FUNC(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++) {

@ -63,5 +63,9 @@ inline static T max(const T& a, const T& b) {
#define QER(n,b) ( ((float)n)/(1<<b) ) #define QER(n,b) ( ((float)n)/(1<<b) )
#define FRAC_NUM float #define FRAC_NUM float
#define SIN_FUNC sinf
#define COS_FUNC cosf
#define LOG_FUNC logf
#define EXP_FUNC expf
#endif // __SYNTH_H #endif // __SYNTH_H

Loading…
Cancel
Save