History

added atodb table generators and fast cosine functions to math

spiricom committed 6 years ago

Commit 60e4c521 parent 5670f0b2 files · +66 −0Browse files

Unified · Split

2 files
  1. leaf/Inc/leaf-math.h +9 −0
  2. leaf/Src/leaf-math.c +57 −0
leaf/Inc/leaf-math.h+9−0
@@ -132,6 +132,10 @@ extern "C" { · 131 unmodified lines
132 float interpolate3max(float *buf, const int peakindex);132 float interpolate3max(float *buf, const int peakindex);
133 float interpolate3phase(float *buf, const int peakindex);133 float interpolate3phase(float *buf, const int peakindex);
134 134
135
136 float fastcosf(float fAngle);
137
138 float fastercosf(float fAngle);
135 // alternative implementation for abs()139 // alternative implementation for abs()
136 // REQUIRES: 32 bit integers140 // REQUIRES: 32 bit integers
137 int fastabs_int(int in);141 int fastabs_int(int in);
@@ -159,6 +163,11 @@ extern "C" { · 21 unmodified lines
159 //1000 gives a good curve from -1.0 to 0.0163 //1000 gives a good curve from -1.0 to 0.0
160 void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size);164 void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size);
161 165
166
167 void LEAF_generate_atodb(float* buffer, int size);
168 void LEAF_generate_atodbPositiveClipped(float* buffer, float lowerThreshold, float range, int size);
169
170
162 float LEAF_poly_blep(float t, float dt);171 float LEAF_poly_blep(float t, float dt);
163 float LEAF_midiToFrequency(float f);172 float LEAF_midiToFrequency(float f);
164 173
leaf/Src/leaf-math.c+57−0
@@ -64,6 +64,38 @@ float interpolate3phase(float *buf, const int peakindex) · 63 unmodified lines
64 return(fraction);64 return(fraction);
65}65}
66 66
67
68// from http://www.wild-magic.com - found on music-dsp list
69float fastcosf(float fAngle)
70{
71 float fASqr = fAngle*fAngle;
72 float fResult = -2.605e-07f;
73 fResult *= fASqr;
74 fResult += 2.47609e-05f;
75 fResult *= fASqr;
76 fResult -= 1.3888397e-03f;
77 fResult *= fASqr;
78 fResult += 4.16666418e-02f;
79 fResult *= fASqr;
80 fResult -= 4.999999963e-01f;
81 fResult *= fASqr;
82 fResult += 1.0f;
83 return fResult;
84}
85
86float fastercosf(float fAngle)
87{
88 float fASqr = fAngle*fAngle;
89 float fResult = 3.705e-02f;
90 fResult *= fASqr;
91 fResult -= 4.967e-01f;
92 fResult *= fASqr;
93 fResult += 1.0f;
94 return fResult;
95}
96
97
98
67// alternative implementation for abs()99// alternative implementation for abs()
68// REQUIRES: 32 bit integers100// REQUIRES: 32 bit integers
69int fastabs_int(int in){101int fastabs_int(int in){
@@ -444,6 +476,31 @@ void LEAF_generate_exp(float* buffer, float base, float start, float end, float · 374 unmodified lines
444 }476 }
445}477}
446 478
479void LEAF_generate_atodb(float* buffer, int size)
480{
481 float increment = 1.0f / (float)size;
482 float x = 0.0f;
483 for (int i = 0; i < size; i++)
484 {
485 buffer[i] = atodb(x);
486 x += increment;
487 }
488}
489
490
491void LEAF_generate_atodbPositiveClipped(float* buffer, float lowerThreshold, float range, int size)
492{
493 float increment = 1.0f / (float)size;
494 float x = 0.0f;
495 float scalar = range / fastabsf(lowerThreshold);
496 for (int i = 0; i < size; i++)
497 {
498 float temp = atodb(x);
499 temp = LEAF_clip(lowerThreshold, temp, 0.0f);
500 buffer[i] = (temp-lowerThreshold) * scalar;
501 x += increment;
502 }
503}
447 504
448// http://www.martin-finke.de/blog/articles/audio-plugins-018-polyblep-oscillator/505// http://www.martin-finke.de/blog/articles/audio-plugins-018-polyblep-oscillator/
449// http://www.kvraudio.com/forum/viewtopic.php?t=375517506// http://www.kvraudio.com/forum/viewtopic.php?t=375517

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t