tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_LevelMeasurer.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
15{
16 uint32_t time = 0;
17 float dB = -100.0f;
18};
19
20//==============================================================================
26{
27public:
28 //==============================================================================
31
32 //==============================================================================
33 void processBuffer (juce::AudioBuffer<float>& buffer, int start, int numSamples);
34 void processMidi (MidiMessageArray& midiBuffer, const float* gains);
35 void processMidiLevel (float level);
36
37 void clear();
38 void clearOverload();
39 void clearPeak();
40
41 //==============================================================================
42 enum Mode
43 {
44 peakMode = 0,
45 RMSMode = 1,
46 sumDiffMode = 2
47 };
48
49 void setMode (Mode);
50 Mode getMode() const noexcept { return mode; }
51
52 void setShowMidi (bool showMidi);
53
54 int getNumActiveChannels() const noexcept { return numActiveChannels; }
55
56 //==============================================================================
57 struct Client
58 {
59 Client() = default;
60
61 int getNumChannelsUsed() const noexcept;
62 void reset() noexcept;
63 bool getAndClearOverload() noexcept;
64 bool getAndClearPeak() noexcept;
65 DbTimePair getAndClearMidiLevel() noexcept;
66 DbTimePair getAndClearAudioLevel (int chan) noexcept;
67
68 static constexpr auto maxNumChannels = 8;
69
71 void setNumChannelsUsed (int) noexcept;
72 void setOverload (int channel, bool hasOverloaded) noexcept;
73 void setClearOverload (bool) noexcept;
74 void setClearPeak (bool) noexcept;
75
76 void updateAudioLevel (int channel, DbTimePair) noexcept;
77 void updateMidiLevel (DbTimePair) noexcept;
78
79 private:
80 DbTimePair audioLevels[maxNumChannels];
81 bool overload[maxNumChannels] = {};
82 DbTimePair midiLevels;
83 std::atomic<int> numChannelsUsed { 0 };
84 bool clearOverload = true;
85 bool clearPeak = true;
86
87 juce::SpinLock mutex;
88 };
89
90 //==============================================================================
91 void addClient (Client&);
92 void removeClient (Client&);
93
94 void setLevelCache (float dBL, float dBR) noexcept { levelCacheL = dBL; levelCacheR = dBR; }
95 std::pair<float, float> getLevelCache() const noexcept { return { levelCacheL, levelCacheR }; }
96
97private:
98 Mode mode = peakMode;
99 std::atomic<int> numActiveChannels { 1 };
100 bool showMidi = false;
101 float levelCacheL = -100.0f;
102 float levelCacheR = -100.0f;
103
104 juce::Array<Client*> clients;
105 RealTimeSpinLock clientsMutex;
106
109};
110
111//==============================================================================
117{
118public:
120
121 void startNextBlock (double streamTime);
122 void setSize (int channels, int numSamples);
123 void addBuffer (const juce::AudioBuffer<float>& inBuffer, int startSample, int numSamples);
124
125 juce::SpinLock spinLock;
126 double lastStreamTime = 0;
127 juce::AudioBuffer<float> sumBuffer;
128};
129
130}} // namespace tracktion { inline namespace engine
Monitors the levels of buffers that are passed in, and keeps peak values, overloads,...
A shared level measurer that can be used by several threads to provide a total output level.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class)
typedef uint32_t