@@ -28,10 +28,11 @@ If negative powers are needed, you may use a lower bound and rescale. | |||||
*/ | */ | ||||
template <typename T> | template <typename T> | ||||
T approxExp2_taylor5(T x) { | T approxExp2_taylor5(T x) { | ||||
// Use bit-shifting for integer part of x. | |||||
int xi = x; | int xi = x; | ||||
x -= xi; | x -= xi; | ||||
T y = 1 << xi; | T y = 1 << xi; | ||||
// Fifth order expansion of 2^x around 0.4752 in Horner form. | |||||
// 5th order expansion of 2^x around 0.4752 in Horner form. | |||||
// The center is chosen so that the endpoints of [0, 1] have equal error, creating no discontinuity at integers. | // The center is chosen so that the endpoints of [0, 1] have equal error, creating no discontinuity at integers. | ||||
y *= T(0.9999976457798443) + x * (T(0.6931766804601935) + x * (T(0.2400729486415728) + x * (T(0.05592817518644387) + x * (T(0.008966320633544) + x * T(0.001853512473884202))))); | y *= T(0.9999976457798443) + x * (T(0.6931766804601935) + x * (T(0.2400729486415728) + x * (T(0.05592817518644387) + x * (T(0.008966320633544) + x * T(0.001853512473884202))))); | ||||
return y; | return y; | ||||
@@ -7,14 +7,6 @@ namespace rack { | |||||
namespace tag { | namespace tag { | ||||
/** Searches for a tag ID. | |||||
Searches tag aliases. | |||||
Case-insensitive. | |||||
Returns -1 if not found. | |||||
*/ | |||||
int findId(const std::string& tag); | |||||
/** List of tags and their aliases. | /** List of tags and their aliases. | ||||
The first alias of each tag `tag[tagId][0]` is the "canonical" alias. | The first alias of each tag `tag[tagId][0]` is the "canonical" alias. | ||||
It is guaranteed to exist and should be used as the human-readable form. | It is guaranteed to exist and should be used as the human-readable form. | ||||
@@ -24,5 +16,13 @@ This list is manually alphabetized by the canonical alias. | |||||
extern const std::vector<std::vector<std::string>> tagAliases; | extern const std::vector<std::vector<std::string>> tagAliases; | ||||
/** Searches for a tag ID. | |||||
Searches tag aliases. | |||||
Case-insensitive. | |||||
Returns -1 if not found. | |||||
*/ | |||||
int findId(const std::string& tag); | |||||
} // namespace tag | } // namespace tag | ||||
} // namespace rack | } // namespace rack |
@@ -1,6 +1,5 @@ | |||||
#include <tag.hpp> | #include <tag.hpp> | ||||
#include <string.hpp> | #include <string.hpp> | ||||
#include <map> | #include <map> | ||||
@@ -8,18 +7,6 @@ namespace rack { | |||||
namespace tag { | namespace tag { | ||||
int findId(const std::string& tag) { | |||||
std::string lowercaseTag = string::lowercase(tag); | |||||
for (int tagId = 0; tagId < (int) tagAliases.size(); tagId++) { | |||||
for (const std::string& alias : tagAliases[tagId]) { | |||||
if (string::lowercase(alias) == lowercaseTag) | |||||
return tagId; | |||||
} | |||||
} | |||||
return -1; | |||||
} | |||||
const std::vector<std::vector<std::string>> tagAliases = { | const std::vector<std::vector<std::string>> tagAliases = { | ||||
{"Arpeggiator"}, | {"Arpeggiator"}, | ||||
{"Attenuator"}, // With a level knob and not much else. | {"Attenuator"}, // With a level knob and not much else. | ||||
@@ -79,5 +66,17 @@ const std::vector<std::vector<std::string>> tagAliases = { | |||||
}; | }; | ||||
int findId(const std::string& tag) { | |||||
std::string lowercaseTag = string::lowercase(tag); | |||||
for (int tagId = 0; tagId < (int) tagAliases.size(); tagId++) { | |||||
for (const std::string& alias : tagAliases[tagId]) { | |||||
if (string::lowercase(alias) == lowercaseTag) | |||||
return tagId; | |||||
} | |||||
} | |||||
return -1; | |||||
} | |||||
} // namespace tag | } // namespace tag | ||||
} // namespace rack | } // namespace rack |