Ardour  9.0-pre0-582-g084a23a80d
routines.h
Go to the documentation of this file.
1 #ifndef AUDIOGRAPHER_ROUTINES_H
2 #define AUDIOGRAPHER_ROUTINES_H
3 
4 #include "types.h"
5 
6 #include <cmath>
7 
9 
10 namespace AudioGrapher
11 {
12 
15 {
16  public:
17  typedef uint32_t uint_type;
18 
19  typedef float (*compute_peak_t) (float const *, uint_type, float);
20  typedef void (*apply_gain_to_buffer_t) (float *, uint_type, float);
21 
22  static void override_compute_peak (compute_peak_t func) { _compute_peak = func; }
23  static void override_apply_gain_to_buffer (apply_gain_to_buffer_t func) { _apply_gain_to_buffer = func; }
24 
32  static inline float compute_peak (float const * data, uint_type samples, float current_peak)
33  {
34  return (*_compute_peak) (data, samples, current_peak);
35  }
36 
43  static inline void apply_gain_to_buffer (float * data, uint_type samples, float gain)
44  {
45  (*_apply_gain_to_buffer) (data, samples, gain);
46  }
47 
48  private:
49  static inline float default_compute_peak (float const * data, uint_type samples, float current_peak)
50  {
51  for (uint_type i = 0; i < samples; ++i) {
52  float abs = std::fabs(data[i]);
53  if (abs > current_peak) { current_peak = abs; }
54  }
55  return current_peak;
56  }
57 
58  static inline void default_apply_gain_to_buffer (float * data, uint_type samples, float gain)
59  {
60  for (uint_type i = 0; i < samples; ++i) {
61  data[i] *= gain;
62  }
63  }
64 
67 };
68 
69 } // namespace
70 
71 #endif // AUDIOGRAPHER_ROUTINES_H
Allows overriding some routines with more efficient ones.
Definition: routines.h:15
static void apply_gain_to_buffer(float *data, uint_type samples, float gain)
Definition: routines.h:43
static float compute_peak(float const *data, uint_type samples, float current_peak)
Definition: routines.h:32
static apply_gain_to_buffer_t _apply_gain_to_buffer
Definition: routines.h:66
static float default_compute_peak(float const *data, uint_type samples, float current_peak)
Definition: routines.h:49
static void override_compute_peak(compute_peak_t func)
Definition: routines.h:22
static void override_apply_gain_to_buffer(apply_gain_to_buffer_t func)
Definition: routines.h:23
static void default_apply_gain_to_buffer(float *data, uint_type samples, float gain)
Definition: routines.h:58
static compute_peak_t _compute_peak
Definition: routines.h:65
PBD::PropertyDescriptor< gain_t > gain
float(* compute_peak_t)(const ARDOUR::Sample *, pframes_t, float)
void(* apply_gain_to_buffer_t)(ARDOUR::Sample *, pframes_t, float)