Merge branch 'master' into windows
[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/sink.h"
5 #include "audiographer/routines.h"
6 #include "audiographer/utils/listed_source.h"
7
8 namespace AudioGrapher
9 {
10
11 /// A class that reads the maximum value from a stream
12 class PeakReader : public ListedSource<float>, public Sink<float>
13 {
14   public:
15         /// Constructor \n RT safe
16         PeakReader() : peak (0.0) {}
17         
18         /// Returns the highest absolute of the values found so far. \n RT safe
19         float get_peak() { return peak; }
20         
21         /// Resets the peak to 0 \n RT safe
22         void  reset() { peak = 0.0; }
23
24         /// Finds peaks from the data \n RT safe
25         void process (ProcessContext<float> const & c)
26         {
27                 peak = Routines::compute_peak (c.data(), c.frames(), peak);
28                 ListedSource<float>::output(c);
29         }
30         
31         using Sink<float>::process;
32         
33   private:
34         float peak;
35 };
36
37
38 } // namespace
39
40 #endif // AUDIOGRAPHER_PEAK_READER_H