NAP
levelmetercomponent.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 // Nap includes
8 #include <component.h>
9 #include <audio/utility/safeptr.h>
10 
11 // Audio includes
12 #include <audio/node/levelmeternode.h>
13 #include <audio/component/audiocomponentbase.h>
14 #include <audio/node/filternode.h>
15 
16 namespace nap
17 {
18 
19  namespace audio
20  {
21 
22  class LevelMeterComponentInstance;
23 
24 
29  class NAPAPI LevelMeterComponent : public Component
30  {
31  RTTI_ENABLE(Component)
33 
34  public:
36  {}
37 
39  TimeValue mAnalysisWindowSize = 10;
40  LevelMeterNode::Type mMeterType = LevelMeterNode::Type::RMS;
41  bool mFilterInput = false;
42  ControllerValue mCenterFrequency = 10000.f;
43  ControllerValue mBandWidth = 10000.f;
44  ControllerValue mFilterGain = 1.0f;
45  int mChannel = 0;
46 
47  private:
48  };
49 
50 
56  {
57  RTTI_ENABLE(ComponentInstance)
58  public:
60  resource)
61  {}
62 
63  // Initialize the component
64  bool init(utility::ErrorState& errorState) override;
65 
69  ControllerValue getLevel();
70 
75  void setCenterFrequency(ControllerValue centerFrequency);
76 
81  void setBandWidth(ControllerValue bandWidth);
82 
87  void setFilterGain(ControllerValue gain);
88 
93  ControllerValue getCenterFrequency() const;
94 
99  ControllerValue getBandWidth() const;
100 
105  ControllerValue getFilterGain() const;
106 
110  void setInput(AudioComponentBaseInstance& input);
111 
112  private:
114  &LevelMeterComponent::mInput}; // Pointer to component that outputs this components audio input
115  SafeOwner<LevelMeterNode> mMeter = nullptr; // Node doing the actual analysis
116  SafeOwner<FilterNode> mFilter = nullptr; // Filter filtering the audio signal for each channel before analysis
117 
118  LevelMeterComponent* mResource = nullptr;
119  AudioService* mAudioService = nullptr;
120 
121  ControllerValue mCenterFrequency = 10000.f; // Center frequency of the frequency band that will be analyzed. Only has effect when mFilterInput = true.
122  ControllerValue mBandWidth = 10000.f; // 'BandWidth' Width in Hz of the frequency band that will be analyzed. Only has effect when mFilterInput = true.
123  ControllerValue mFilterGain = 1.0f; // 'FilterGain' Gain factor of the filtered input signal. Only has effect when mFilterInput = true.
124  };
125 
126  }
127 
128 }
nap::audio::LevelMeterComponent
Definition: levelmetercomponent.h:29
nap::utility::ErrorState
Definition: errorstate.h:19
nap::audio::AudioComponentBaseInstance
Definition: audiocomponentbase.h:47
nap::audio::LevelMeterComponentInstance::LevelMeterComponentInstance
LevelMeterComponentInstance(EntityInstance &entity, Component &resource)
Definition: levelmetercomponent.h:59
nap::audio::TimeValue
float TimeValue
Definition: audiotypes.h:119
nap::audio::ControllerValue
float ControllerValue
Definition: audiotypes.h:113
nap::audio::LevelMeterNode::Type
Type
Definition: levelmeternode.h:32
nap::EntityInstance
Definition: entity.h:34
nap::ComponentInstancePtr
Definition: component.h:28
nap::ComponentInstance
Definition: component.h:43
nap::audio::LevelMeterComponent::mInput
nap::ComponentPtr< AudioComponentBase > mInput
property: 'Input' The component whose audio output will be measured.
Definition: levelmetercomponent.h:38
nap::Component
Definition: component.h:151
nap
Definition: templateapp.h:17
nap::audio::LevelMeterComponent::LevelMeterComponent
LevelMeterComponent()
Definition: levelmetercomponent.h:35
nap::ComponentPtr
Definition: component.h:31
nap::audio::LevelMeterComponentInstance
Definition: levelmetercomponent.h:55