-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
performance testing and lfo improvements (#178)
* performance testing and lfo improvements * Fix a header * more missing headers in perftest
- Loading branch information
Showing
6 changed files
with
216 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* sst-basic-blocks - an open source library of core audio utilities | ||
* built by Surge Synth Team. | ||
* | ||
* Provides a collection of tools useful on the audio thread for blocks, | ||
* modulation, etc... or useful for adapting code to multiple environments. | ||
* | ||
* Copyright 2023, various authors, as described in the GitHub | ||
* transaction log. Parts of this code are derived from similar | ||
* functions original in Surge or ShortCircuit. | ||
* | ||
* sst-basic-blocks is released under the GNU General Public Licence v3 | ||
* or later (GPL-3.0-or-later). The license is found in the "LICENSE" | ||
* file in the root of this repository, or at | ||
* https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* | ||
* A very small number of explicitly chosen header files can also be | ||
* used in an MIT/BSD context. Please see the README.md file in this | ||
* repo or the comments in the individual files. Only headers with an | ||
* explicit mention that they are dual licensed may be copied and reused | ||
* outside the GPL3 terms. | ||
* | ||
* All source in sst-basic-blocks available at | ||
* https://github.com/surge-synthesizer/sst-basic-blocks | ||
*/ | ||
|
||
#include <iostream> | ||
#include <array> | ||
|
||
#include "sst/basic-blocks/modulators/SimpleLFO.h" | ||
#include "sst/basic-blocks/tables/TwoToTheXProvider.h" | ||
#include "sst/basic-blocks/dsp/RNG.h" | ||
#include "perfutils.h" | ||
|
||
template <int blockSize> struct SRProvider | ||
{ | ||
const sst::basic_blocks::tables::TwoToTheXProvider &ttx; | ||
SRProvider(const sst::basic_blocks::tables::TwoToTheXProvider &t) : ttx(t) {} | ||
float envelope_rate_linear_nowrap(float f) const | ||
{ | ||
return (blockSize * sampleRateInv) * ttx.twoToThe(-f); | ||
} | ||
|
||
void setSampleRate(double sr) | ||
{ | ||
samplerate = sr; | ||
sampleRate = sr; | ||
sampleRateInv = 1.0 / sr; | ||
} | ||
double samplerate{1}; | ||
double sampleRate{1}; | ||
double sampleRateInv{1}; | ||
}; | ||
|
||
template <int blockSize> | ||
void basicTest(sst::basic_blocks::tables::TwoToTheXProvider &ttx, sst::basic_blocks::dsp::RNG &rng) | ||
{ | ||
using srp_t = SRProvider<blockSize>; | ||
using lfo_t = sst::basic_blocks::modulators::SimpleLFO<SRProvider<blockSize>, blockSize>; | ||
|
||
auto srp = srp_t(ttx); | ||
srp.setSampleRate(48000 * 2.5); | ||
|
||
std::array<lfo_t, 8> lfos{ | ||
lfo_t(&srp, rng), lfo_t(&srp, rng), lfo_t(&srp, rng), lfo_t(&srp, rng), | ||
lfo_t(&srp, rng), lfo_t(&srp, rng), lfo_t(&srp, rng), lfo_t(&srp, rng), | ||
}; | ||
|
||
for (auto sh = lfo_t::SINE; sh <= lfo_t::SH_NOISE; sh = (typename lfo_t::Shape)((int)sh + 1)) | ||
for (auto def : {-0.1f, 0.f, 0.2f}) | ||
{ | ||
{ | ||
auto blocks = (int)(200 * srp.sampleRate / blockSize); | ||
perf::TimeGuard tg("LFO - shape=" + std::to_string(sh) + | ||
" def=" + std::to_string(def), | ||
__FILE__, __LINE__, 248688); | ||
for (int lf = 0; lf < lfos.size(); ++lf) | ||
lfos[lf].attack(sh); | ||
|
||
for (int i = 0; i < blocks; ++i) | ||
{ | ||
for (int lf = 0; lf < lfos.size(); ++lf) | ||
lfos[lf].process_block(2.4, def, sh, false, 1.0); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void lfoPerformance() | ||
{ | ||
sst::basic_blocks::tables::TwoToTheXProvider ttxlfo; | ||
sst::basic_blocks::dsp::RNG rng(782567); | ||
ttxlfo.init(); | ||
std::cout << __FILE__ << ":" << __LINE__ << " LFO Perf starting" << std::endl; | ||
basicTest<8>(ttxlfo, rng); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* sst-basic-blocks - an open source library of core audio utilities | ||
* built by Surge Synth Team. | ||
* | ||
* Provides a collection of tools useful on the audio thread for blocks, | ||
* modulation, etc... or useful for adapting code to multiple environments. | ||
* | ||
* Copyright 2023, various authors, as described in the GitHub | ||
* transaction log. Parts of this code are derived from similar | ||
* functions original in Surge or ShortCircuit. | ||
* | ||
* sst-basic-blocks is released under the GNU General Public Licence v3 | ||
* or later (GPL-3.0-or-later). The license is found in the "LICENSE" | ||
* file in the root of this repository, or at | ||
* https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* | ||
* A very small number of explicitly chosen header files can also be | ||
* used in an MIT/BSD context. Please see the README.md file in this | ||
* repo or the comments in the individual files. Only headers with an | ||
* explicit mention that they are dual licensed may be copied and reused | ||
* outside the GPL3 terms. | ||
* | ||
* All source in sst-basic-blocks available at | ||
* https://github.com/surge-synthesizer/sst-basic-blocks | ||
*/ | ||
|
||
#include <iostream> | ||
|
||
extern void lfoPerformance(); | ||
|
||
int main(int argc, char **argv) { lfoPerformance(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* sst-basic-blocks - an open source library of core audio utilities | ||
* built by Surge Synth Team. | ||
* | ||
* Provides a collection of tools useful on the audio thread for blocks, | ||
* modulation, etc... or useful for adapting code to multiple environments. | ||
* | ||
* Copyright 2023, various authors, as described in the GitHub | ||
* transaction log. Parts of this code are derived from similar | ||
* functions original in Surge or ShortCircuit. | ||
* | ||
* sst-basic-blocks is released under the GNU General Public Licence v3 | ||
* or later (GPL-3.0-or-later). The license is found in the "LICENSE" | ||
* file in the root of this repository, or at | ||
* https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
* | ||
* A very small number of explicitly chosen header files can also be | ||
* used in an MIT/BSD context. Please see the README.md file in this | ||
* repo or the comments in the individual files. Only headers with an | ||
* explicit mention that they are dual licensed may be copied and reused | ||
* outside the GPL3 terms. | ||
* | ||
* All source in sst-basic-blocks available at | ||
* https://github.com/surge-synthesizer/sst-basic-blocks | ||
*/ | ||
|
||
#ifndef SST_BASIC_BLOCK_TESTS_PERF_PERFUTILS_H | ||
#define SST_BASIC_BLOCK_TESTS_PERF_PERFUTILS_H | ||
|
||
#include <iostream> | ||
#include <chrono> | ||
#include <string> | ||
|
||
namespace perf | ||
{ | ||
struct TimeGuard | ||
{ | ||
std::string m; | ||
int d; | ||
std::chrono::high_resolution_clock::time_point t; | ||
TimeGuard(const std::string &msg, const std::string &f, int l, int divisor = 1) : d(divisor) | ||
{ | ||
m = f + ":" + std::to_string(l) + " " + msg; | ||
t = std::chrono::high_resolution_clock::now(); | ||
} | ||
~TimeGuard() | ||
{ | ||
auto e = std::chrono::high_resolution_clock::now(); | ||
auto us = std::chrono::duration_cast<std::chrono::microseconds>(e - t).count(); | ||
std::cout << m << " " << us << " us; pct=" << 100.0 * us / d << "%" << std::endl; | ||
} | ||
}; | ||
}; // namespace perf | ||
|
||
#endif |