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
132132 float interpolate3max(float *buf, const int peakindex);
133133 float interpolate3phase(float *buf, const int peakindex);
134134
135+
136+ float fastcosf(float fAngle);
137+
138+ float fastercosf(float fAngle);
135139 // alternative implementation for abs()
136140 // REQUIRES: 32 bit integers
137141 int fastabs_int(int in);
@@ -159,6 +163,11 @@ extern "C" { · 21 unmodified lines
159163 //1000 gives a good curve from -1.0 to 0.0
160164 void LEAF_generate_exp(float* buffer, float base, float start, float end, float offset, int size);
161165
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+
162171 float LEAF_poly_blep(float t, float dt);
163172 float LEAF_midiToFrequency(float f);
164173
leaf/Src/leaf-math.c+57−0
@@ -64,6 +64,38 @@ float interpolate3phase(float *buf, const int peakindex) · 63 unmodified lines
6464 return(fraction);
6565 }
6666
67+
68+// from http://www.wild-magic.com - found on music-dsp list
69+float 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+
86+float 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+
6799 // alternative implementation for abs()
68100 // REQUIRES: 32 bit integers
69101 int fastabs_int(int in){
@@ -444,6 +476,31 @@ void LEAF_generate_exp(float* buffer, float base, float start, float end, float · 374 unmodified lines
444476 }
445477 }
446478
479+void 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+
491+void 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+}
447504
448505 // http://www.martin-finke.de/blog/articles/audio-plugins-018-polyblep-oscillator/
449506 // 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