Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
ProcessorDataAnalyzer.h
Go to the documentation of this file.
1/* Copyright (c) 2024-2025, Christian Ahrens
2 *
3 * This file is part of Mema <https://github.com/ChristianAhrens/Mema>
4 *
5 * This tool is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3.0 as published
7 * by the Free Software Foundation.
8 *
9 * This tool is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this tool; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#pragma once
20
21#include <JuceHeader.h>
22
24#include "ProcessorLevelData.h"
26
27
28namespace Mema
29{
30
34class ProcessorDataAnalyzer : public juce::Timer
35{
36public:
39 {
40 public:
41 virtual ~Listener() {};
42
44 };
45
46public:
47 //==============================================================================
50
51 //==============================================================================
53 void setUseProcessingTypes(bool useLevelProcessing, bool useBufferProcessing, bool useSepctrumProcessing);
57
58 //==============================================================================
59 void initializeParameters(double sampleRate, int bufferSize);
60 void clearParameters();
61
62 void setHoldTime(int holdTimeMs);
63
64 ProcessorAudioSignalData& GetCentiSecondBuffer() { return m_centiSecondBuffer; };
65 ProcessorLevelData& GetLevel() { return m_level; };
66 ProcessorSpectrumData& GetSpectrum() { return m_spectrum; };
67 juce::String& GetName() { return m_Name; };
68
69 bool IsInitialized() { return (m_bufferSize != 0 && m_sampleRate != 0); };
70
71 //==============================================================================
72 void addListener(Listener* listener);
73 void removeListener(Listener* listener);
74
75 //==============================================================================
77 void analyzeData(const juce::AudioBuffer<float>& buffer);
78
79 //==============================================================================
81 void timerCallback() override;
82
83 //==============================================================================
85 {
86 min = -80,
87 max = 0,
88 };
89
90 static int getGlobalMindB()
91 {
92 return dBRange::min;
93 }
94
95 static int getGlobalMaxdB()
96 {
97 return dBRange::max;
98 }
99
100private:
101 //==============================================================================
102 void BroadcastData(AbstractProcessorData* data);
103 void FlushHold();
104
105 //==============================================================================
106 void processSpectrumForChannel(int channelIndex, const float* channelData, int numSamples);
107 void performFFTAndUpdateSpectrum(int channelIndex);
108
109 //==============================================================================
110 ProcessorAudioSignalData m_centiSecondBuffer;
111 ProcessorLevelData m_level;
112 ProcessorSpectrumData m_spectrum;
113
114 juce::String m_Name;
115 juce::Array<Listener*> m_callbackListeners;
116 std::mutex m_callbackListenersMutex;
117
118 //==============================================================================
119 juce::CriticalSection m_readLock;
120
121 float** m_processorChannels;
122
123 unsigned long m_sampleRate = 0;
124 int m_samplesPerCentiSecond = 0;
125 int m_bufferSize = 0;
126 int m_missingSamplesForCentiSecond = 0;
127
128 //==============================================================================
129 enum
130 {
131 fftOrder = 12,
132 fftSize = 1 << fftOrder
133 };
134 dsp::FFT m_fwdFFT;
135 dsp::WindowingFunction<float> m_windowF;
136 std::vector<std::vector<float>> m_FFTdata; // [channel][fftSize * 2]
137 std::vector<int> m_FFTdataPos; // [channel]
138
139 int m_holdTimeMs;
140
141 //==============================================================================
142 bool m_useLevelProcessing = false;
143 bool m_useBufferProcessing = false;
144 bool m_useSpectrumProcessing = false;
145
146 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ProcessorDataAnalyzer)
147};
148
149} // namespace Mema
Base class for all data objects exchanged between the audio processor and its analyzers/visualisers.
virtual void processingDataChanged(AbstractProcessorData *data)=0
Analyses a stream of audio buffers and broadcasts level and spectrum data to registered listeners.
void addListener(Listener *listener)
void analyzeData(const juce::AudioBuffer< float > &buffer)
Submits a new audio buffer for analysis.
ProcessorAudioSignalData & GetCentiSecondBuffer()
void removeListener(Listener *listener)
void setUseProcessingTypes(bool useLevelProcessing, bool useBufferProcessing, bool useSepctrumProcessing)
Configures which data types (level, spectrum, audio signal) the analyzer computes.
ProcessorSpectrumData & GetSpectrum()
ProcessorLevelData & GetLevel()
void timerCallback() override
Timer callback that broadcasts pending data changes to all registered listeners.
void initializeParameters(double sampleRate, int bufferSize)
Definition Mema.cpp:27