summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/routines.h
diff options
context:
space:
mode:
authorSakari Bergen <sakari.bergen@beatwaves.net>2009-12-27 14:46:23 +0000
committerSakari Bergen <sakari.bergen@beatwaves.net>2009-12-27 14:46:23 +0000
commitdde0848a984e06cbc1d4117d9cffa75c191f3b39 (patch)
tree11f3a5fe94ac792e753297e16e4e80dd7e296aea /libs/audiographer/audiographer/routines.h
parent35c72a53b4c6bbc61b4b86db9de629e18362b48d (diff)
Re-integrate export-optimization branch.
Export now happens directly to file (unless normalizing is required), and can be easily optimized even further. The Session process connection is still broken during export (as it was before this commit also). git-svn-id: svn://localhost/ardour2/branches/3.0@6401 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/audiographer/audiographer/routines.h')
-rw-r--r--libs/audiographer/audiographer/routines.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/libs/audiographer/audiographer/routines.h b/libs/audiographer/audiographer/routines.h
new file mode 100644
index 0000000000..9ae6b7a255
--- /dev/null
+++ b/libs/audiographer/audiographer/routines.h
@@ -0,0 +1,53 @@
+#ifndef AUDIOGRAPHER_ROUTINES_H
+#define AUDIOGRAPHER_ROUTINES_H
+
+#include "types.h"
+
+#include <cmath>
+
+namespace AudioGrapher
+{
+
+class Routines
+{
+ public:
+ typedef float (*compute_peak_t) (float const *, nframes_t, float);
+ typedef void (*apply_gain_to_buffer_t) (float *, nframes_t, float);
+
+ static void override_compute_peak (compute_peak_t func) { _compute_peak = func; }
+ static void override_apply_gain_to_buffer (apply_gain_to_buffer_t func) { _apply_gain_to_buffer = func; }
+
+ static inline float compute_peak (float const * data, nframes_t frames, float current_peak)
+ {
+ return (*_compute_peak) (data, frames, current_peak);
+ }
+
+ static inline void apply_gain_to_buffer (float * data, nframes_t frames, float gain)
+ {
+ (*_apply_gain_to_buffer) (data, frames, gain);
+ }
+
+ private:
+ static inline float default_compute_peak (float const * data, nframes_t frames, float current_peak)
+ {
+ for (nframes_t i = 0; i < frames; ++i) {
+ float abs = std::fabs(data[i]);
+ if (abs > current_peak) { current_peak = abs; }
+ }
+ return current_peak;
+ }
+
+ static inline void default_apply_gain_to_buffer (float * data, nframes_t frames, float gain)
+ {
+ for (nframes_t i = 0; i < frames; ++i) {
+ data[i] *= gain;
+ }
+ }
+
+ static compute_peak_t _compute_peak;
+ static apply_gain_to_buffer_t _apply_gain_to_buffer;
+};
+
+} // namespace
+
+#endif // AUDIOGRAPHER_ROUTINES_H