Line data Source code
1 : #include "audio_metrics_service.h"
2 :
3 : namespace Amplitron {
4 :
5 3 : void AudioMetricsService::update(IAudioEngine& engine, float dt) {
6 : // 1. Update Level Analyzer
7 3 : const float input_rms = engine.get_input_rms();
8 3 : const float output_rms = engine.get_output_rms();
9 3 : const bool input_clipped = engine.consume_input_clipped();
10 3 : const bool output_clipped = engine.consume_output_clipped();
11 3 : level_analyzer_.update(input_rms, output_rms, input_clipped, output_clipped, dt);
12 :
13 : // 2. Update Spectrum Analyzer
14 3 : const uint64_t seq = engine.get_analyzer_sequence();
15 3 : if (seq == analyzer_last_sequence_ && seq != 0) {
16 0 : spectrum_analyzer_.update(analyzer_input_buf_.data(), analyzer_output_buf_.data(),
17 0 : engine.get_sample_rate(), dt);
18 0 : return;
19 : }
20 :
21 5 : if (engine.copy_analyzer_snapshot(analyzer_input_buf_.data(), analyzer_output_buf_.data(),
22 : IAudioEngine::ANALYZER_FFT_SIZE)) {
23 0 : spectrum_analyzer_.update(analyzer_input_buf_.data(), analyzer_output_buf_.data(),
24 0 : engine.get_sample_rate(), dt);
25 0 : analyzer_last_sequence_ = seq;
26 0 : }
27 1 : }
28 :
29 : } // namespace Amplitron
|