globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / libs / audiographer / audiographer / general / peak_reader.h
1 #ifndef AUDIOGRAPHER_PEAK_READER_H
2 #define AUDIOGRAPHER_PEAK_READER_H
3
4 #include "audiographer/visibility.h"
5 #include "audiographer/sink.h"
6 #include "audiographer/routines.h"
7 #include "audiographer/utils/listed_source.h"
8
9 namespace AudioGrapher
10 {
11
12 /// A class that reads the maximum value from a stream
13 class /*LIBAUDIOGRAPHER_API*/ PeakReader : public ListedSource<float>, public Sink<float>
14 {
15   public:
16         /// Constructor \n RT safe
17         PeakReader() : peak (0.0) {}
18
19         /// Returns the highest absolute of the values found so far. \n RT safe
20         float get_peak() { return peak; }
21
22         /// Resets the peak to 0 \n RT safe
23         void  reset() { peak = 0.0; }
24
25         /// Finds peaks from the data \n RT safe
26         void process (ProcessContext<float> const & c)
27         {
28                 peak = Routines::compute_peak (c.data(), c.samples(), peak);
29                 ListedSource<float>::output(c);
30         }
31
32         using Sink<float>::process;
33
34   private:
35         float peak;
36 };
37
38
39 } // namespace
40
41 #endif // AUDIOGRAPHER_PEAK_READER_H