@@ -67,7 +67,9 @@ enum class DisplayMode
6767{
6868 CURVE,
6969 BAR,
70- STEPPED_BAR
70+ STEPPED_BAR,
71+ METER,
72+ STEPPED_METER
7173};
7274
7375class WAVSource
@@ -88,16 +90,25 @@ class WAVSource
8890 circlebuf m_capturebufs[2 ]{};
8991 uint32_t m_capture_channels = 0 ; // audio input channels
9092 uint32_t m_output_channels = 0 ; // fft output channels (*not* display channels)
91- bool m_output_bus_captured = false ; // do we have an active audio output callback? (via audio_output_connect())
93+ bool m_output_bus_captured = false ; // do we have an active audio output callback? (via audio_output_connect())
9294
9395 // 32-byte aligned buffers for FFT/AVX processing
9496 AVXBufR m_fft_input;
9597 AVXBufC m_fft_output;
9698 fftwf_plan m_fft_plan{};
9799 AVXBufR m_window_coefficients;
98100 AVXBufR m_tsmooth_buf[2 ]; // last frames magnitudes
99- AVXBufR m_decibels[2 ]; // dBFS
100- size_t m_fft_size = 0 ; // number of fft elements (not bytes, multiple of 16)
101+ AVXBufR m_decibels[2 ]; // dBFS, or audio sample buffer in meter mode
102+ size_t m_fft_size = 0 ; // number of fft elements, or audio samples in meter mode (not bytes, multiple of 16)
103+ // in meter mode m_fft_size is the size of of the circular buffer in samples
104+
105+ // meter mode
106+ size_t m_meter_pos[2 ] = { 0 , 0 }; // circular buffer position (per channel)
107+ float m_meter_val[2 ] = { 0 .0f , 0 .0f }; // dBFS
108+ float m_meter_buf[2 ] = { 0 .0f , 0 .0f }; // EMA
109+ bool m_meter_rms = false ; // RMS mode
110+ bool m_meter_mode = false ; // either meter or stepped meter display mode is selected
111+ int m_meter_ms = 100 ; // milliseconds of audio data to buffer
101112
102113 // video fps
103114 double m_fps = 0.0 ;
@@ -116,9 +127,6 @@ class WAVSource
116127 int m_retries = 0 ;
117128 float m_next_retry = 0 .0f ;
118129
119- // vertex buffer
120- gs_vertbuffer_t *m_vbuf = nullptr ;
121-
122130 // settings
123131 RenderMode m_render_mode = RenderMode::SOLID;
124132 FFTWindow m_window_func = FFTWindow::HANN;
@@ -160,18 +168,26 @@ class WAVSource
160168 // slope
161169 AVXBufR m_slope_modifiers;
162170
171+ // rounded caps
172+ float m_cap_radius = 0 .0f ;
173+ int m_cap_tris = 4 ; // number of triangles each cap is composed of (4 min)
174+ std::vector<vec2> m_cap_verts; // pre-rotated cap vertices (to be translated to final pos)
175+
163176 void get_settings (obs_data_t *settings);
164177
165178 void recapture_audio ();
166179 void release_audio_capture ();
167- bool check_audio_capture (float seconds);
180+ bool check_audio_capture (float seconds); // check if capture is valid and retry if not
168181 void free_bufs ();
169182
170183 void init_interp (unsigned int sz);
171184
172185 void render_curve (gs_effect_t *effect);
173186 void render_bars (gs_effect_t *effect);
174187
188+ virtual void tick_spectrum (float ) = 0; // process audio data in frequency spectrum mode
189+ virtual void tick_meter (float ); // process audio data in meter mode
190+
175191 // constants
176192 static const float DB_MIN;
177193 static constexpr auto RETRY_DELAY = 2 .0f ;
@@ -197,7 +213,7 @@ class WAVSource
197213
198214 // main callbacks
199215 virtual void update (obs_data_t *settings);
200- virtual void tick (float seconds) = 0 ;
216+ virtual void tick (float seconds);
201217 virtual void render (gs_effect_t *effect);
202218
203219 void show ();
@@ -224,7 +240,7 @@ class WAVSourceAVX2 : public WAVSource
224240 using WAVSource::WAVSource;
225241 ~WAVSourceAVX2 () override {}
226242
227- void tick (float seconds) override ;
243+ void tick_spectrum (float seconds) override ;
228244};
229245
230246class WAVSourceAVX : public WAVSource
@@ -233,7 +249,7 @@ class WAVSourceAVX : public WAVSource
233249 using WAVSource::WAVSource;
234250 ~WAVSourceAVX () override {}
235251
236- void tick (float seconds) override ;
252+ void tick_spectrum (float seconds) override ;
237253};
238254
239255class WAVSourceSSE2 : public WAVSource
@@ -242,5 +258,6 @@ class WAVSourceSSE2 : public WAVSource
242258 using WAVSource::WAVSource;
243259 ~WAVSourceSSE2 () override {}
244260
245- void tick (float seconds) override ;
261+ void tick_spectrum (float seconds) override ;
262+ void tick_meter (float seconds) override ;
246263};
0 commit comments