1 #ifndef AUDIOGRAPHER_ROUTINES_H
2 #define AUDIOGRAPHER_ROUTINES_H
14 typedef float (*compute_peak_t) (float const *, nframes_t, float);
15 typedef void (*apply_gain_to_buffer_t) (float *, nframes_t, float);
17 static void override_compute_peak (compute_peak_t func) { _compute_peak = func; }
18 static void override_apply_gain_to_buffer (apply_gain_to_buffer_t func) { _apply_gain_to_buffer = func; }
20 static inline float compute_peak (float const * data, nframes_t frames, float current_peak)
22 return (*_compute_peak) (data, frames, current_peak);
25 static inline void apply_gain_to_buffer (float * data, nframes_t frames, float gain)
27 (*_apply_gain_to_buffer) (data, frames, gain);
31 static inline float default_compute_peak (float const * data, nframes_t frames, float current_peak)
33 for (nframes_t i = 0; i < frames; ++i) {
34 float abs = std::fabs(data[i]);
35 if (abs > current_peak) { current_peak = abs; }
40 static inline void default_apply_gain_to_buffer (float * data, nframes_t frames, float gain)
42 for (nframes_t i = 0; i < frames; ++i) {
47 static compute_peak_t _compute_peak;
48 static apply_gain_to_buffer_t _apply_gain_to_buffer;
53 #endif // AUDIOGRAPHER_ROUTINES_H