summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/general/peak_reader.h
blob: bb042395443eb31d0db9554cded1d068fc805171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef AUDIOGRAPHER_PEAK_READER_H
#define AUDIOGRAPHER_PEAK_READER_H

#include "audiographer/visibility.h"
#include "audiographer/sink.h"
#include "audiographer/routines.h"
#include "audiographer/utils/listed_source.h"

namespace AudioGrapher
{

/// A class that reads the maximum value from a stream
class /*LIBAUDIOGRAPHER_API*/ PeakReader : public ListedSource<float>, public Sink<float>
{
  public:
	/// Constructor \n RT safe
	PeakReader() : peak (0.0) {}

	/// Returns the highest absolute of the values found so far. \n RT safe
	float get_peak() { return peak; }

	/// Resets the peak to 0 \n RT safe
	void  reset() { peak = 0.0; }

	/// Finds peaks from the data \n RT safe
	void process (ProcessContext<float> const & c)
	{
		peak = Routines::compute_peak (c.data(), c.samples(), peak);
		ListedSource<float>::output(c);
	}

	using Sink<float>::process;

  private:
	float peak;
};


} // namespace

#endif // AUDIOGRAPHER_PEAK_READER_H