NAP
levelmeternode.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Std includes
8 #include <atomic>
9 
10 // Audio includes
11 #include <audio/core/audionode.h>
12 #include <audio/utility/dirtyflag.h>
13 #include <audio/utility/safeptr.h>
14 #include <audio/core/process.h>
15 
16 namespace nap
17 {
18  namespace audio
19  {
20 
21  // Forward declarations
22  class AudioService;
23 
29  class NAPAPI LevelMeterNode : public Node
30  {
31  public:
32  enum class EType
33  {
34  PEAK, RMS
35  };
36 
42  LevelMeterNode(NodeManager& nodeManager, TimeValue analysisWindowSize = 10, bool rootProcess = true);
43 
44  virtual ~LevelMeterNode();
45 
46  InputPin input = {this};
51  float getLevel();
52 
56  void setType(EType type) { mType = type; }
57 
58  // Inherited from Node
59  void process() override;
60  void sampleRateChanged(float sampleRate) override;
61 
62  private:
63  int mIndex = 0; // Current write index of the buffer being analyzed.
64  EType mType = EType::RMS; // Algorithm currently being used to calculate the output level value from one buffer.
65  TimeValue mAnalysisWindowSize = 0.f;
66  int mWindowSizeInSamples = 0;
67  std::atomic<float> mValue = 0.f; // Calculated output level value
68 
69  SampleBuffer mSquaredBuffer;
70  float mSquaredSum = 0.f;
71 
72  float mPeak = 0.f;
73  float mPeakTemp = 0.f;
74 
75  bool mRootProcess = false;
76  };
77 
78  }
79 }
nap::audio::LevelMeterNode
Definition: levelmeternode.h:29
nap::audio::TimeValue
float TimeValue
Definition: audiotypes.h:119
nap::audio::NodeManager
Definition: audionodemanager.h:33
nap::audio::Node
Definition: audionode.h:33
nap::audio::LevelMeterNode::setType
void setType(EType type)
Definition: levelmeternode.h:56
nap::audio::InputPin
Definition: audiopin.h:91
nap
Definition: templateapp.h:17
nap::audio::LevelMeterNode::EType
EType
Definition: levelmeternode.h:32
nap::audio::SampleBuffer
std::vector< SampleValue > SampleBuffer
Definition: audiotypes.h:34