[beast] TESTS: speed up resamplehandle test signal generation by caching
- From: Stefan Westerfeld <stw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast] TESTS: speed up resamplehandle test signal generation by caching
- Date: Sun, 20 Feb 2011 17:47:56 +0000 (UTC)
commit 604c4e3a6721c0e7408b36b5aecf89b978f5f477
Author: Stefan Westerfeld <stefan space twc de>
Date: Sun Feb 20 19:31:15 2011 +0100
TESTS: speed up resamplehandle test signal generation by caching
bse/tests/resamplehandle.cc | 42 ++++++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/bse/tests/resamplehandle.cc b/bse/tests/resamplehandle.cc
index 6b36286..c7c454c 100644
--- a/bse/tests/resamplehandle.cc
+++ b/bse/tests/resamplehandle.cc
@@ -23,10 +23,14 @@
#include <bse/bseblockutils.hh>
#include <stdlib.h>
#include <vector>
+#include <string>
+#include <map>
using std::vector;
+using std::string;
using std::max;
using std::min;
+using std::map;
static void
read_through (GslDataHandle *handle)
@@ -173,20 +177,38 @@ generate_test_signal (vector<Sample> &signal,
const double frequency1,
const double frequency2 = -1)
{
- signal.clear();
- for (size_t i = 0; i < signal_length; i++)
+ static map<size_t, vector<float> > window_cache;
+ vector<float>& cached_window = window_cache[signal_length];
+ if (cached_window.empty())
{
- double wpos = (i * 2 - double (signal_length)) / signal_length;
+ cached_window.resize (signal_length);
- double phase1 = i * 2 * M_PI * frequency1 / sample_rate;
- signal.push_back (sin (phase1) * bse_window_blackman (wpos));
+ for (size_t i = 0; i < signal_length; i++)
+ {
+ double wpos = (i * 2 - double (signal_length)) / signal_length;
+ cached_window[i] = bse_window_blackman (wpos);
+ }
+ }
- if (frequency2 > 0) /* stereo */
- {
- double phase2 = i * 2 * M_PI * frequency2 / sample_rate;
- signal.push_back (sin (phase2) * bse_window_blackman (wpos));
- }
+ string signal_cache_key = Birnet::string_printf ("%zd/%.1f/%.1f/%.1f", signal_length, sample_rate, frequency1, frequency2);
+ static map<string, vector<Sample> > signal_cache;
+ vector<Sample>& cached_signal = signal_cache[signal_cache_key];
+
+ if (cached_signal.empty())
+ {
+ for (size_t i = 0; i < signal_length; i++)
+ {
+ double phase1 = i * 2 * M_PI * frequency1 / sample_rate;
+ cached_signal.push_back (sin (phase1) * cached_window[i]);
+
+ if (frequency2 > 0) /* stereo */
+ {
+ double phase2 = i * 2 * M_PI * frequency2 / sample_rate;
+ cached_signal.push_back (sin (phase2) * cached_window[i]);
+ }
+ }
}
+ signal = cached_signal;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]