1 #ifndef AUDIOGRAPHER_ROUTINES_H
2 #define AUDIOGRAPHER_ROUTINES_H
8 #define routines_nframes_t uint32_t
10 namespace AudioGrapher
16 typedef float (*compute_peak_t) (float const *, routines_nframes_t, float);
17 typedef void (*apply_gain_to_buffer_t) (float *, routines_nframes_t, float);
19 static void override_compute_peak (compute_peak_t func) { _compute_peak = func; }
20 static void override_apply_gain_to_buffer (apply_gain_to_buffer_t func) { _apply_gain_to_buffer = func; }
22 static inline float compute_peak (float const * data, routines_nframes_t frames, float current_peak)
24 return (*_compute_peak) (data, frames, current_peak);
27 static inline void apply_gain_to_buffer (float * data, routines_nframes_t frames, float gain)
29 (*_apply_gain_to_buffer) (data, frames, gain);
33 static inline float default_compute_peak (float const * data, routines_nframes_t frames, float current_peak)
35 for (routines_nframes_t i = 0; i < frames; ++i) {
36 float abs = std::fabs(data[i]);
37 if (abs > current_peak) { current_peak = abs; }
42 static inline void default_apply_gain_to_buffer (float * data, routines_nframes_t frames, float gain)
44 for (routines_nframes_t i = 0; i < frames; ++i) {
49 static compute_peak_t _compute_peak;
50 static apply_gain_to_buffer_t _apply_gain_to_buffer;
55 #undef routines_nframes_t
57 #endif // AUDIOGRAPHER_ROUTINES_H