From b88cc56103ebdc232e32eb6b5477e73f042ca033 Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Sat, 11 May 2024 04:26:16 +0200 Subject: [PATCH] Apply clang-tidy fixes --- .clang-tidy | 3 + src/mc/acoustics/absorber/porous_absorber.hpp | 8 +- src/mc/raum_akustik/app/application.hpp | 2 +- src/mc/raum_akustik/app/main_component.hpp | 8 +- .../tabs/absorber_simulation_tab.cpp | 4 +- .../tabs/absorber_simulation_tab.hpp | 2 +- .../tabs/first_reflections_tab.hpp | 6 +- src/mc/raum_akustik/tabs/generator_tab.cpp | 11 +- src/mc/raum_akustik/tabs/generator_tab.hpp | 8 +- src/mc/raum_akustik/tool/latency_tester.cpp | 193 +++++++++--------- src/mc/raum_akustik/tool/latency_tester.hpp | 34 +-- .../tool/measurement_recorder.cpp | 86 ++++---- .../tool/measurement_recorder.hpp | 28 +-- src/mc/raum_akustik/tool/noise_generator.cpp | 2 +- src/mc/raum_akustik/tool/noise_generator.hpp | 2 +- src/mc/raum_akustik/widget/level_meter.hpp | 6 +- .../widget/scrolling_waveform.cpp | 2 +- .../widget/scrolling_waveform.hpp | 2 +- src/mc/raum_akustik/widget/spectogram.cpp | 12 +- src/mc/raum_akustik/widget/spectogram.hpp | 6 +- 20 files changed, 225 insertions(+), 200 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 39bac89..8316436 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: > bugprone-*, -bugprone-macro-parentheses, + -bugprone-chained-comparison, cert-*, @@ -20,10 +21,12 @@ Checks: > -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, hicpp-*, misc-*, + -misc-include-cleaner, modernize-*, diff --git a/src/mc/acoustics/absorber/porous_absorber.hpp b/src/mc/acoustics/absorber/porous_absorber.hpp index d7a5554..7bbf398 100644 --- a/src/mc/acoustics/absorber/porous_absorber.hpp +++ b/src/mc/acoustics/absorber/porous_absorber.hpp @@ -29,10 +29,10 @@ struct PorousAbsorberSpecs struct PorousAbsorberImpedance { // Intermediate term cot(k*ta) - std::complex intermediateTerm{}; + std::complex intermediateTerm; // Impedance at absorber surface (zsa) - std::complex atSurface{}; + std::complex atSurface; }; struct PorousAbsorberProperties @@ -66,7 +66,7 @@ struct PorousAbsorberProperties PorousAbsorberImpedance impedance{}; - std::complex reflectionFactorNoAirGap{}; + std::complex reflectionFactorNoAirGap; double absorptionFactorNoAirGap{}; std::complex kAirY{0.0}; @@ -77,7 +77,7 @@ struct PorousAbsorberProperties std::complex ki{0}; std::complex zaAir{0}; - std::complex reflectionFactorWithAirGap{}; + std::complex reflectionFactorWithAirGap; double absorptionFactorWithAirGap{}; }; diff --git a/src/mc/raum_akustik/app/application.hpp b/src/mc/raum_akustik/app/application.hpp index e171634..bdb4026 100644 --- a/src/mc/raum_akustik/app/application.hpp +++ b/src/mc/raum_akustik/app/application.hpp @@ -21,7 +21,7 @@ struct RaumAkustikApplication : juce::JUCEApplication private: juce::AudioDeviceManager _deviceManager; - std::unique_ptr _mainWindow{}; + std::unique_ptr _mainWindow; }; [[nodiscard]] auto raumAkusticApplication() -> RaumAkustikApplication&; diff --git a/src/mc/raum_akustik/app/main_component.hpp b/src/mc/raum_akustik/app/main_component.hpp index 38893a2..95ca2a9 100644 --- a/src/mc/raum_akustik/app/main_component.hpp +++ b/src/mc/raum_akustik/app/main_component.hpp @@ -35,10 +35,10 @@ struct MainComponent final auto reloadUI() -> void; auto toggleFullscreen() -> void; - juce::ApplicationCommandManager _commandManager{}; + juce::ApplicationCommandManager _commandManager; juce::UndoManager _undoManager; juce::ValueTree _valueTree{"RaumAkustik"}; - LookAndFeel _lnf{}; + LookAndFeel _lnf; MenuBar _menuBar{_commandManager}; LevelMeter _levelMeter; @@ -47,8 +47,8 @@ struct MainComponent final juce::TabbedComponent _tabs{juce::TabbedButtonBar::TabsAtTop}; AudioInputView _audioInputView; GeneratorTab _generatorTab; - std::unique_ptr _firstReflectionsView{}; - std::unique_ptr _absorberSimulationView{}; + std::unique_ptr _firstReflectionsView; + std::unique_ptr _absorberSimulationView; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent) // NOLINT }; diff --git a/src/mc/raum_akustik/tabs/absorber_simulation_tab.cpp b/src/mc/raum_akustik/tabs/absorber_simulation_tab.cpp index e32dac9..738e181 100644 --- a/src/mc/raum_akustik/tabs/absorber_simulation_tab.cpp +++ b/src/mc/raum_akustik/tabs/absorber_simulation_tab.cpp @@ -7,7 +7,7 @@ namespace ra { namespace { auto positionForFrequency(Hertz const freq) noexcept -> double { - return (std::log(freq.number() / 20.0) / std::log(2.0)) / 10.0; + return (std::log(freq.number() / 20.0) / std::numbers::ln2) / 10.0; } } // namespace @@ -85,7 +85,7 @@ PorousAbsorberSimulationView::PorousAbsorberSimulationView(juce::ValueTree vt, j auto PorousAbsorberSimulationView::paint(juce::Graphics& g) -> void { - juce::Graphics::ScopedSaveState state{g}; + juce::Graphics::ScopedSaveState const state{g}; g.reduceClipRegion(_plotArea); diff --git a/src/mc/raum_akustik/tabs/absorber_simulation_tab.hpp b/src/mc/raum_akustik/tabs/absorber_simulation_tab.hpp index 09f6fde..2927185 100644 --- a/src/mc/raum_akustik/tabs/absorber_simulation_tab.hpp +++ b/src/mc/raum_akustik/tabs/absorber_simulation_tab.hpp @@ -29,7 +29,7 @@ struct PorousAbsorberSimulationView final auto updateSimulation() -> void; juce::TableListBox _table{"Table", this}; - juce::PropertyPanel _absorberSpecs{}; + juce::PropertyPanel _absorberSpecs; juce::Rectangle _plotArea; juce::UndoManager* _undoManager{nullptr}; diff --git a/src/mc/raum_akustik/tabs/first_reflections_tab.hpp b/src/mc/raum_akustik/tabs/first_reflections_tab.hpp index 3f20505..d65a75c 100644 --- a/src/mc/raum_akustik/tabs/first_reflections_tab.hpp +++ b/src/mc/raum_akustik/tabs/first_reflections_tab.hpp @@ -50,10 +50,10 @@ struct FirstReflectionsView final juce::Drawable::createFromImageData(mcbd::insert_emoticon_svg, mcbd::insert_emoticon_svgSize) }; - juce::PropertyPanel _roomProperties{}; - juce::PropertyPanel _renderProperties{}; + juce::PropertyPanel _roomProperties; + juce::PropertyPanel _renderProperties; - juce::Rectangle _drawArea{}; + juce::Rectangle _drawArea; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FirstReflectionsView) // NOLINT }; diff --git a/src/mc/raum_akustik/tabs/generator_tab.cpp b/src/mc/raum_akustik/tabs/generator_tab.cpp index ebad0b5..bf80acf 100644 --- a/src/mc/raum_akustik/tabs/generator_tab.cpp +++ b/src/mc/raum_akustik/tabs/generator_tab.cpp @@ -34,9 +34,9 @@ static auto frequencyToX(float minFreq, float maxFreq, float freq, float width) static auto amplitudeToY(float amplitude, juce::Rectangle const bounds) -> float { - auto const infinity = -96.0f; + auto const infinity = -96.0F; auto const dB = juce::Decibels::gainToDecibels(amplitude, infinity); - return juce::jmap(dB, infinity, 0.0f, bounds.getBottom(), bounds.getY()); + return juce::jmap(dB, infinity, 0.0F, bounds.getBottom(), bounds.getY()); } static auto getFrequencyAndAmplitude(std::span const> bins, double sampleRate) @@ -61,8 +61,9 @@ makePathFromAnalysis(std::span analysis, float fs, -> juce::Path { auto const size = static_cast(analysis.size()); - if (size == 0) + if (size == 0) { return {}; + } auto frequencyLess = [](auto bin, auto target) { return bin.frequency < target; }; auto first = std::lower_bound(begin(analysis), end(analysis), 1.0F, frequencyLess); @@ -75,11 +76,11 @@ makePathFromAnalysis(std::span analysis, float fs, auto const width = bounds.getWidth(); auto const startY = amplitudeToY(first->amplitude, bounds); - p.startNewSubPath(bounds.getX() + frequencyToX(1.0f, fs * 0.5F, first->frequency, width), startY); + p.startNewSubPath(bounds.getX() + frequencyToX(1.0F, fs * 0.5F, first->frequency, width), startY); for (; first != end(analysis); ++first) { auto const y = amplitudeToY(first->amplitude, bounds); - p.lineTo(bounds.getX() + frequencyToX(1.0f, fs * 0.5F, first->frequency, width), y); + p.lineTo(bounds.getX() + frequencyToX(1.0F, fs * 0.5F, first->frequency, width), y); } return p; diff --git a/src/mc/raum_akustik/tabs/generator_tab.hpp b/src/mc/raum_akustik/tabs/generator_tab.hpp index 1b4c38b..683a440 100644 --- a/src/mc/raum_akustik/tabs/generator_tab.hpp +++ b/src/mc/raum_akustik/tabs/generator_tab.hpp @@ -23,10 +23,10 @@ struct GeneratorTab final auto valueTreePropertyChanged(juce::ValueTree& tree, juce::Identifier const& property) -> void override; private: - juce::PropertyPanel _sweepSpecPanel{}; + juce::PropertyPanel _sweepSpecPanel; MeasurementRecorderEditor _recorder; - juce::Rectangle _thumbnailBounds{}; - juce::Rectangle _spectrumBounds{}; + juce::Rectangle _thumbnailBounds; + juce::Rectangle _spectrumBounds; juce::UndoManager* _undoManager{nullptr}; juce::ValueTree _valueTree{"SineSweep"}; @@ -38,7 +38,7 @@ struct GeneratorTab final juce::CachedValue _sampleRate{_valueTree, "sampleRate", _undoManager}; juce::AudioFormatManager _formatManager; - juce::AudioBuffer _thumbnailBuffer{}; + juce::AudioBuffer _thumbnailBuffer; juce::AudioThumbnailCache _thumbnailCache{1}; juce::AudioThumbnail _thumbnail{32, _formatManager, _thumbnailCache}; diff --git a/src/mc/raum_akustik/tool/latency_tester.cpp b/src/mc/raum_akustik/tool/latency_tester.cpp index a274019..f0ce994 100644 --- a/src/mc/raum_akustik/tool/latency_tester.cpp +++ b/src/mc/raum_akustik/tool/latency_tester.cpp @@ -2,52 +2,54 @@ #include +#include + namespace ra { -LatencyTester::LatencyTester(juce::TextEditor& editorBox) : resultsBox(editorBox) {} +LatencyTester::LatencyTester(juce::TextEditor& editorBox) : _resultsBox(editorBox) {} void LatencyTester::beginTest() { - resultsBox.moveCaretToEnd(); - resultsBox.insertTextAtCaret(juce::newLine + juce::newLine + "Starting test..." + juce::newLine); - resultsBox.moveCaretToEnd(); + _resultsBox.moveCaretToEnd(); + _resultsBox.insertTextAtCaret(juce::newLine + juce::newLine + "Starting test..." + juce::newLine); + _resultsBox.moveCaretToEnd(); startTimer(50); - juce::ScopedLock const sl(lock); + juce::ScopedLock const sl(_lock); createTestSound(); - recordedSound.clear(); - playingSampleNum = recordedSampleNum = 0; - testIsRunning = true; + _recordedSound.clear(); + _playingSampleNum = _recordedSampleNum = 0; + _testIsRunning = true; } void LatencyTester::timerCallback() { - if (testIsRunning && recordedSampleNum >= recordedSound.getNumSamples()) { - testIsRunning = false; + if (_testIsRunning && _recordedSampleNum >= _recordedSound.getNumSamples()) { + _testIsRunning = false; stopTimer(); // Test has finished, so calculate the result.. auto latencySamples = calculateLatencySamples(); - resultsBox.moveCaretToEnd(); - resultsBox.insertTextAtCaret(getMessageDescribingResult(latencySamples)); - resultsBox.moveCaretToEnd(); + _resultsBox.moveCaretToEnd(); + _resultsBox.insertTextAtCaret(getMessageDescribingResult(latencySamples)); + _resultsBox.moveCaretToEnd(); } } -juce::String LatencyTester::getMessageDescribingResult(int latencySamples) +auto LatencyTester::getMessageDescribingResult(int latencySamples) -> juce::String const { juce::String message; if (latencySamples >= 0) { - message << juce::newLine << "Results (" << bufferSize << "): " << juce::newLine << latencySamples - << " samples (" << juce::String(latencySamples * 1000.0 / sampleRate, 1) << " milliseconds)" - << juce::newLine << "The audio device reports an input latency of " << deviceInputLatency - << " samples, output latency of " << deviceOutputLatency << " samples." << juce::newLine - << "So the corrected latency = " << (latencySamples - deviceInputLatency - deviceOutputLatency) + message << juce::newLine << "Results (" << _bufferSize << "): " << juce::newLine << latencySamples + << " samples (" << juce::String(latencySamples * 1000.0 / _sampleRate, 1) << " milliseconds)" + << juce::newLine << "The audio device reports an input latency of " << _deviceInputLatency + << " samples, output latency of " << _deviceOutputLatency << " samples." << juce::newLine + << "So the corrected latency = " << (latencySamples - _deviceInputLatency - _deviceOutputLatency) << " samples (" - << juce::String((latencySamples - deviceInputLatency - deviceOutputLatency) * 1000.0 / sampleRate, 2) + << juce::String((latencySamples - _deviceInputLatency - _deviceOutputLatency) * 1000.0 / _sampleRate, 2) << " milliseconds)"; } else { message << juce::newLine << "Couldn't detect the test signal!!" << juce::newLine @@ -59,16 +61,16 @@ juce::String LatencyTester::getMessageDescribingResult(int latencySamples) void LatencyTester::audioDeviceAboutToStart(juce::AudioIODevice* device) { - testIsRunning = false; - playingSampleNum = recordedSampleNum = 0; + _testIsRunning = false; + _playingSampleNum = _recordedSampleNum = 0; - bufferSize = device->getCurrentBufferSizeSamples(); - sampleRate = device->getCurrentSampleRate(); - deviceInputLatency = device->getInputLatencyInSamples(); - deviceOutputLatency = device->getOutputLatencyInSamples(); + _bufferSize = device->getCurrentBufferSizeSamples(); + _sampleRate = device->getCurrentSampleRate(); + _deviceInputLatency = device->getInputLatencyInSamples(); + _deviceOutputLatency = device->getOutputLatencyInSamples(); - recordedSound.setSize(1, (int)(0.9 * sampleRate)); - recordedSound.clear(); + _recordedSound.setSize(1, (int)(0.9 * _sampleRate)); + _recordedSound.clear(); } void LatencyTester::audioDeviceStopped() {} @@ -84,9 +86,9 @@ void LatencyTester::audioDeviceIOCallbackWithContext( { ignoreUnused(context); - juce::ScopedLock const sl(lock); + juce::ScopedLock const sl(_lock); - if (!testIsRunning) { + if (!_testIsRunning) { auto const output = juce::dsp::AudioBlock{ outputChannelData, static_cast(numOutputChannels), @@ -97,54 +99,59 @@ void LatencyTester::audioDeviceIOCallbackWithContext( return; } - auto* recordingBuffer = recordedSound.getWritePointer(0); - auto* playBuffer = testSound.getReadPointer(0); + auto* recordingBuffer = _recordedSound.getWritePointer(0); + auto const* playBuffer = _testSound.getReadPointer(0); for (int i = 0; i < numSamples; ++i) { - if (recordedSampleNum < recordedSound.getNumSamples()) { - auto inputSamp = 0.0f; + if (_recordedSampleNum < _recordedSound.getNumSamples()) { + auto inputSamp = 0.0F; - for (auto j = numInputChannels; --j >= 0;) - if (inputChannelData[j] != nullptr) + for (auto j = numInputChannels; --j >= 0;) { + if (inputChannelData[j] != nullptr) { inputSamp += inputChannelData[j][i]; + } + } - recordingBuffer[recordedSampleNum] = inputSamp; + recordingBuffer[_recordedSampleNum] = inputSamp; } - ++recordedSampleNum; + ++_recordedSampleNum; - auto outputSamp = (playingSampleNum < testSound.getNumSamples()) ? playBuffer[playingSampleNum] : 0.0f; + auto outputSamp = (_playingSampleNum < _testSound.getNumSamples()) ? playBuffer[_playingSampleNum] : 0.0F; - for (auto j = numOutputChannels; --j >= 0;) - if (outputChannelData[j] != nullptr) + for (auto j = numOutputChannels; --j >= 0;) { + if (outputChannelData[j] != nullptr) { outputChannelData[j][i] = outputSamp; + } + } - ++playingSampleNum; + ++_playingSampleNum; } } // create a test sound which consists of a series of randomly-spaced audio spikes.. void LatencyTester::createTestSound() { - auto length = ((int)sampleRate) / 4; - testSound.setSize(1, length); - testSound.clear(); + auto length = ((int)_sampleRate) / 4; + _testSound.setSize(1, length); + _testSound.clear(); juce::Random rand; - for (int i = 0; i < length; ++i) - testSound.setSample(0, i, (rand.nextFloat() - rand.nextFloat() + rand.nextFloat() - rand.nextFloat()) * 0.06f); + for (int i = 0; i < length; ++i) { + _testSound.setSample(0, i, (rand.nextFloat() - rand.nextFloat() + rand.nextFloat() - rand.nextFloat()) * 0.06F); + } - spikePositions.clear(); + _spikePositions.clear(); int spikePos = 0; int spikeDelta = 50; while (spikePos < length - 1) { - spikePositions.add(spikePos); + _spikePositions.add(spikePos); - testSound.setSample(0, spikePos, 0.99f); - testSound.setSample(0, spikePos + 1, -0.99f); + _testSound.setSample(0, spikePos, 0.99F); + _testSound.setSample(0, spikePos + 1, -0.99F); spikePos += spikeDelta; spikeDelta += spikeDelta / 6 + rand.nextInt(5); @@ -152,12 +159,12 @@ void LatencyTester::createTestSound() } // Searches a buffer for a set of spikes that matches those in the test sound -int LatencyTester::findOffsetOfSpikes(juce::AudioBuffer const& buffer) const +auto LatencyTester::findOffsetOfSpikes(juce::AudioBuffer const& buffer) const -> int { - auto minSpikeLevel = 5.0f; - auto smooth = 0.975; - auto* s = buffer.getReadPointer(0); - int spikeDriftAllowed = 5; + auto minSpikeLevel = 5.0F; + auto smooth = 0.975; + auto const* s = buffer.getReadPointer(0); + int const spikeDriftAllowed = 5; juce::Array spikesFound; spikesFound.ensureStorageAllocated(100); @@ -176,92 +183,96 @@ int LatencyTester::findOffsetOfSpikes(juce::AudioBuffer const& buffer) co } int bestMatch = -1; - auto bestNumMatches = spikePositions.size() / 3; // the minimum number of matches required + auto bestNumMatches = _spikePositions.size() / 3; // the minimum number of matches required - if (spikesFound.size() < bestNumMatches) + if (spikesFound.size() < bestNumMatches) { return -1; + } for (int offsetToTest = 0; offsetToTest < buffer.getNumSamples() - 2048; ++offsetToTest) { int numMatchesHere = 0; int foundIndex = 0; - for (int refIndex = 0; refIndex < spikePositions.size(); ++refIndex) { - auto referenceSpike = spikePositions.getUnchecked(refIndex) + offsetToTest; + for (int refIndex = 0; refIndex < _spikePositions.size(); ++refIndex) { + auto referenceSpike = _spikePositions.getUnchecked(refIndex) + offsetToTest; int spike = 0; while ((spike = spikesFound.getUnchecked(foundIndex)) < referenceSpike - spikeDriftAllowed - && foundIndex < spikesFound.size() - 1) + && foundIndex < spikesFound.size() - 1) { ++foundIndex; + } - if (spike >= referenceSpike - spikeDriftAllowed && spike <= referenceSpike + spikeDriftAllowed) + if (spike >= referenceSpike - spikeDriftAllowed && spike <= referenceSpike + spikeDriftAllowed) { ++numMatchesHere; + } } if (numMatchesHere > bestNumMatches) { bestNumMatches = numMatchesHere; bestMatch = offsetToTest; - if (numMatchesHere == spikePositions.size()) + if (numMatchesHere == _spikePositions.size()) { break; + } } } return bestMatch; } -int LatencyTester::calculateLatencySamples() const +auto LatencyTester::calculateLatencySamples() const -> int { // Detect the sound in both our test sound and the recording of it, and measure the difference // in their start times.. - auto referenceStart = findOffsetOfSpikes(testSound); + auto referenceStart = findOffsetOfSpikes(_testSound); jassert(referenceStart >= 0); - auto recordedStart = findOffsetOfSpikes(recordedSound); + auto recordedStart = findOffsetOfSpikes(_recordedSound); return (recordedStart < 0) ? -1 : (recordedStart - referenceStart); } -LatencyTesterEditor::LatencyTesterEditor(juce::AudioDeviceManager& deviceManager) : audioDeviceManager{deviceManager} +LatencyTesterEditor::LatencyTesterEditor(juce::AudioDeviceManager& deviceManager) : _audioDeviceManager{deviceManager} { setOpaque(true); - addAndMakeVisible(resultsBox); - resultsBox.setMultiLine(true); - resultsBox.setReturnKeyStartsNewLine(true); - resultsBox.setReadOnly(true); - resultsBox.setScrollbarsShown(true); - resultsBox.setCaretVisible(false); - resultsBox.setPopupMenuEnabled(true); + addAndMakeVisible(_resultsBox); + _resultsBox.setMultiLine(true); + _resultsBox.setReturnKeyStartsNewLine(true); + _resultsBox.setReadOnly(true); + _resultsBox.setScrollbarsShown(true); + _resultsBox.setCaretVisible(false); + _resultsBox.setPopupMenuEnabled(true); - resultsBox.setColour(juce::TextEditor::outlineColourId, juce::Colour(0x1c000000)); - resultsBox.setColour(juce::TextEditor::shadowColourId, juce::Colour(0x16000000)); + _resultsBox.setColour(juce::TextEditor::outlineColourId, juce::Colour(0x1c000000)); + _resultsBox.setColour(juce::TextEditor::shadowColourId, juce::Colour(0x16000000)); - resultsBox.setText("Running this test measures the round-trip latency between the audio output and input " - "devices you\'ve got selected.\n\n" - "It\'ll play a sound, then try to measure the time at which the sound arrives " - "back at the audio input. Obviously for this to work you need to have your " - "microphone somewhere near your speakers..."); + _resultsBox.setText("Running this test measures the round-trip latency between the audio output and input " + "devices you\'ve got selected.\n\n" + "It\'ll play a sound, then try to measure the time at which the sound arrives " + "back at the audio input. Obviously for this to work you need to have your " + "microphone somewhere near your speakers..."); - addAndMakeVisible(startTestButton); - startTestButton.onClick = [this] { startTest(); }; + addAndMakeVisible(_startTestButton); + _startTestButton.onClick = [this] { startTest(); }; setSize(500, 500); } LatencyTesterEditor::~LatencyTesterEditor() { - audioDeviceManager.removeAudioCallback(latencyTester.get()); - latencyTester.reset(); + _audioDeviceManager.removeAudioCallback(_latencyTester.get()); + _latencyTester.reset(); } void LatencyTesterEditor::startTest() { - if (latencyTester.get() == nullptr) { - latencyTester.reset(new LatencyTester(resultsBox)); - audioDeviceManager.addAudioCallback(latencyTester.get()); + if (_latencyTester == nullptr) { + _latencyTester = std::make_unique(_resultsBox); + _audioDeviceManager.addAudioCallback(_latencyTester.get()); } - latencyTester->beginTest(); + _latencyTester->beginTest(); } void LatencyTesterEditor::paint(juce::Graphics& g) { g.fillAll(findColour(juce::ResizableWindow::backgroundColourId)); } @@ -269,9 +280,9 @@ void LatencyTesterEditor::paint(juce::Graphics& g) { g.fillAll(findColour(juce:: void LatencyTesterEditor::resized() { auto b = getLocalBounds().reduced(5); - startTestButton.setBounds(b.removeFromBottom(b.getHeight() / 10)); + _startTestButton.setBounds(b.removeFromBottom(b.getHeight() / 10)); b.removeFromBottom(10); - resultsBox.setBounds(b); + _resultsBox.setBounds(b); } } // namespace ra diff --git a/src/mc/raum_akustik/tool/latency_tester.hpp b/src/mc/raum_akustik/tool/latency_tester.hpp index 63499a9..8fc2419 100644 --- a/src/mc/raum_akustik/tool/latency_tester.hpp +++ b/src/mc/raum_akustik/tool/latency_tester.hpp @@ -14,7 +14,7 @@ struct LatencyTester final void beginTest(); void timerCallback() override; - juce::String getMessageDescribingResult(int latencySamples); + auto getMessageDescribingResult(int latencySamples) -> juce::String const; void audioDeviceAboutToStart(juce::AudioIODevice* device) override; void audioDeviceStopped() override; void audioDeviceIOCallbackWithContext( @@ -31,20 +31,20 @@ struct LatencyTester final void createTestSound(); // Searches a buffer for a set of spikes that matches those in the test sound - int findOffsetOfSpikes(juce::AudioBuffer const& buffer) const; - int calculateLatencySamples() const; + auto findOffsetOfSpikes(juce::AudioBuffer const& buffer) const -> int; + auto calculateLatencySamples() const -> int; - juce::TextEditor& resultsBox; - juce::AudioBuffer testSound, recordedSound; - juce::Array spikePositions; - juce::CriticalSection lock; + juce::TextEditor& _resultsBox; + juce::AudioBuffer _testSound, _recordedSound; + juce::Array _spikePositions; + juce::CriticalSection _lock; - int playingSampleNum = 0; - int recordedSampleNum = -1; - int bufferSize = 0; - double sampleRate = 0.0; - bool testIsRunning = false; - int deviceInputLatency, deviceOutputLatency; + int _playingSampleNum = 0; + int _recordedSampleNum = -1; + int _bufferSize = 0; + double _sampleRate = 0.0; + bool _testIsRunning = false; + int _deviceInputLatency{}, _deviceOutputLatency{}; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LatencyTester) }; @@ -60,12 +60,12 @@ struct LatencyTesterEditor final : juce::Component void resized() override; private: - juce::AudioDeviceManager& audioDeviceManager; + juce::AudioDeviceManager& _audioDeviceManager; - std::unique_ptr latencyTester; + std::unique_ptr _latencyTester; - juce::TextButton startTestButton{"Test Latency"}; - juce::TextEditor resultsBox; + juce::TextButton _startTestButton{"Test Latency"}; + juce::TextEditor _resultsBox; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LatencyTesterEditor) }; diff --git a/src/mc/raum_akustik/tool/measurement_recorder.cpp b/src/mc/raum_akustik/tool/measurement_recorder.cpp index a67faff..ac32d9f 100644 --- a/src/mc/raum_akustik/tool/measurement_recorder.cpp +++ b/src/mc/raum_akustik/tool/measurement_recorder.cpp @@ -1,5 +1,7 @@ #include "measurement_recorder.hpp" +#include + namespace ra { MeasurementRecorder::MeasurementRecorder(juce::AudioThumbnail& thumbnail) : _thumbnail(thumbnail) @@ -21,21 +23,21 @@ void MeasurementRecorder::startRecording(juce::File const& file) // Now create a WAV writer object that writes to our output stream... juce::WavAudioFormat wavFormat; - if (auto writer = wavFormat.createWriterFor(fileStream.get(), _sampleRate, 1, 16, {}, 0)) { + if (auto* writer = wavFormat.createWriterFor(fileStream.get(), _sampleRate, 1, 16, {}, 0)) { fileStream.release(); // (passes responsibility for deleting the stream to the writer object that // is now using it) // Now we'll create one of these helper objects which will act as a FIFO buffer, and will // write the data to disk on our background thread. - _writer.reset(new juce::AudioFormatWriter::ThreadedWriter(writer, _writerThread, 32768)); + _writer = std::make_unique(writer, _writerThread, 32768); // Reset our recording thumbnail _thumbnail.reset(writer->getNumChannels(), writer->getSampleRate()); - nextSampleNum = 0; + _nextSampleNum = 0; // And now, swap over our active writer pointer so that the audio callback will start using it.. - juce::ScopedLock const sl(writerLock); - activeWriter = _writer.get(); + juce::ScopedLock const sl(_writerLock); + _activeWriter = _writer.get(); } } } @@ -58,8 +60,8 @@ void MeasurementRecorder::stop() { // First, clear this pointer to stop the audio callback from using our writer object.. { - juce::ScopedLock const sl(writerLock); - activeWriter = nullptr; + juce::ScopedLock const sl(_writerLock); + _activeWriter = nullptr; } // Now we can delete the writer object. It's done in this order because the deletion could @@ -68,7 +70,7 @@ void MeasurementRecorder::stop() _writer.reset(); } -bool MeasurementRecorder::isRecording() const { return activeWriter.load() != nullptr; } +auto MeasurementRecorder::isRecording() const -> bool { return _activeWriter.load() != nullptr; } void MeasurementRecorder::audioDeviceAboutToStart(juce::AudioIODevice* device) { @@ -103,58 +105,63 @@ void MeasurementRecorder::audioDeviceIOCallbackWithContext( } } - juce::ScopedLock const sl(writerLock); + juce::ScopedLock const sl(_writerLock); auto const lastSample = std::ssize(_sweep) + juce::roundToInt(_sampleRate * 2.0); - if (activeWriter.load() != nullptr && numInputChannels >= _thumbnail.getNumChannels()) { - activeWriter.load()->write(inputChannelData, numSamples); + if (_activeWriter.load() != nullptr && numInputChannels >= _thumbnail.getNumChannels()) { + _activeWriter.load()->write(inputChannelData, numSamples); // Create an AudioBuffer to wrap our incoming data, note that this does no allocations or copies, it simply // references our input data - juce::AudioBuffer buffer(const_cast(inputChannelData), _thumbnail.getNumChannels(), numSamples); - _thumbnail.addBlock(nextSampleNum, buffer, 0, numSamples); + juce::AudioBuffer const buffer( + const_cast(inputChannelData), + _thumbnail.getNumChannels(), + numSamples + ); + _thumbnail.addBlock(_nextSampleNum, buffer, 0, numSamples); if (numOutputChannels > 0) { auto const* sweep = std::data(_sweep); auto const* end = std::next(sweep, std::ssize(_sweep)); - auto const* first = std::min(end, std::next(sweep, nextSampleNum)); + auto const* first = std::min(end, std::next(sweep, _nextSampleNum)); auto const* last = std::min(end, std::next(first, numSamples)); std::copy(first, last, outputChannelData[0]); } - nextSampleNum += numSamples; + _nextSampleNum += numSamples; } - if (nextSampleNum >= lastSample) { + if (_nextSampleNum >= lastSample) { _doneRecording.store(true); } } MeasurementRecorderEditor::MeasurementRecorderEditor(juce::AudioDeviceManager& deviceManager) - : audioDeviceManager{deviceManager} + : _audioDeviceManager{deviceManager} { setOpaque(true); - addAndMakeVisible(recordButton); - recordButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xffff5c5c)); - recordButton.setColour(juce::TextButton::textColourOnId, juce::Colours::black); + addAndMakeVisible(_recordButton); + _recordButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xffff5c5c)); + _recordButton.setColour(juce::TextButton::textColourOnId, juce::Colours::black); - recordButton.onClick = [this] { - if (recorder.isRecording()) + _recordButton.onClick = [this] { + if (_recorder.isRecording()) { stopRecording(); - else + } else { startRecording(); + } }; addAndMakeVisible(_thumbnail); - audioDeviceManager.addAudioCallback(&recorder); + _audioDeviceManager.addAudioCallback(&_recorder); setSize(500, 500); } -MeasurementRecorderEditor::~MeasurementRecorderEditor() { audioDeviceManager.removeAudioCallback(&recorder); } +MeasurementRecorderEditor::~MeasurementRecorderEditor() { _audioDeviceManager.removeAudioCallback(&_recorder); } void MeasurementRecorderEditor::paint(juce::Graphics& g) { @@ -166,22 +173,22 @@ void MeasurementRecorderEditor::resized() auto area = getLocalBounds(); _thumbnail.setBounds(area.removeFromTop(80).reduced(8)); - recordButton.setBounds(area.removeFromTop(36).removeFromLeft(140).reduced(8)); + _recordButton.setBounds(area.removeFromTop(36).removeFromLeft(140).reduced(8)); } MeasurementRecorderEditor::Thumbnail::Thumbnail() { - formatManager.registerBasicFormats(); + _formatManager.registerBasicFormats(); _thumbnail.addChangeListener(this); } MeasurementRecorderEditor::Thumbnail::~Thumbnail() { _thumbnail.removeChangeListener(this); } -juce::AudioThumbnail& MeasurementRecorderEditor::Thumbnail::getAudioThumbnail() { return _thumbnail; } +auto MeasurementRecorderEditor::Thumbnail::getAudioThumbnail() -> juce::AudioThumbnail& { return _thumbnail; } void MeasurementRecorderEditor::Thumbnail::setDisplayFullThumbnail(bool displayFull) { - displayFullThumb = displayFull; + _displayFullThumb = displayFull; repaint(); } @@ -191,40 +198,41 @@ void MeasurementRecorderEditor::Thumbnail::paint(juce::Graphics& g) g.setColour(juce::Colours::lightgrey); if (_thumbnail.getTotalLength() > 0.0) { - auto endTime = displayFullThumb ? _thumbnail.getTotalLength() : juce::jmax(30.0, _thumbnail.getTotalLength()); + auto endTime = _displayFullThumb ? _thumbnail.getTotalLength() : juce::jmax(30.0, _thumbnail.getTotalLength()); auto thumbArea = getLocalBounds(); - _thumbnail.drawChannels(g, thumbArea.reduced(2), 0.0, endTime, 1.0f); + _thumbnail.drawChannels(g, thumbArea.reduced(2), 0.0, endTime, 1.0F); } else { - g.setFont(14.0f); + g.setFont(14.0F); g.drawFittedText("(No file recorded)", getLocalBounds(), juce::Justification::centred, 2); } } void MeasurementRecorderEditor::Thumbnail::changeListenerCallback(juce::ChangeBroadcaster* source) { - if (source == &_thumbnail) + if (source == &_thumbnail) { repaint(); + } } void MeasurementRecorderEditor::startRecording() { auto parentDir = juce::File::getSpecialLocation(juce::File::userDocumentsDirectory); - lastRecording = parentDir.getNonexistentChildFile("JUCE Demo Audio Recording", ".wav"); + _lastRecording = parentDir.getNonexistentChildFile("JUCE Demo Audio Recording", ".wav"); - recorder.startRecording(lastRecording); + _recorder.startRecording(_lastRecording); - recordButton.setButtonText("Stop"); + _recordButton.setButtonText("Stop"); _thumbnail.setDisplayFullThumbnail(false); } void MeasurementRecorderEditor::stopRecording() { - recorder.stop(); + _recorder.stop(); - lastRecording = juce::File(); - recordButton.setButtonText("Record"); + _lastRecording = juce::File(); + _recordButton.setButtonText("Record"); _thumbnail.setDisplayFullThumbnail(true); } diff --git a/src/mc/raum_akustik/tool/measurement_recorder.hpp b/src/mc/raum_akustik/tool/measurement_recorder.hpp index e069ce0..189cf77 100644 --- a/src/mc/raum_akustik/tool/measurement_recorder.hpp +++ b/src/mc/raum_akustik/tool/measurement_recorder.hpp @@ -17,7 +17,7 @@ struct MeasurementRecorder final void startRecording(juce::File const& file); void stop(); - bool isRecording() const; + auto isRecording() const -> bool; void timerCallback() override; @@ -37,13 +37,13 @@ struct MeasurementRecorder final juce::TimeSliceThread _writerThread{"Audio Recorder Thread"}; std::unique_ptr _writer; double _sampleRate{0.0}; - juce::int64 nextSampleNum{0}; + juce::int64 _nextSampleNum{0}; - std::vector _sweep{}; + std::vector _sweep; std::atomic _doneRecording{false}; - juce::CriticalSection writerLock; - std::atomic activeWriter{nullptr}; + juce::CriticalSection _writerLock; + std::atomic _activeWriter{nullptr}; }; struct MeasurementRecorderEditor final : juce::Component @@ -62,30 +62,30 @@ struct MeasurementRecorderEditor final : juce::Component Thumbnail(); ~Thumbnail() override; - juce::AudioThumbnail& getAudioThumbnail(); + auto getAudioThumbnail() -> juce::AudioThumbnail&; void setDisplayFullThumbnail(bool displayFull); void paint(juce::Graphics& g) override; void changeListenerCallback(juce::ChangeBroadcaster* source) override; private: - juce::AudioFormatManager formatManager; - juce::AudioThumbnailCache thumbnailCache{10}; - juce::AudioThumbnail _thumbnail{512, formatManager, thumbnailCache}; + juce::AudioFormatManager _formatManager; + juce::AudioThumbnailCache _thumbnailCache{10}; + juce::AudioThumbnail _thumbnail{512, _formatManager, _thumbnailCache}; - bool displayFullThumb{false}; + bool _displayFullThumb{false}; }; void startRecording(); void stopRecording(); - juce::AudioDeviceManager& audioDeviceManager; + juce::AudioDeviceManager& _audioDeviceManager; Thumbnail _thumbnail; - MeasurementRecorder recorder{_thumbnail.getAudioThumbnail()}; + MeasurementRecorder _recorder{_thumbnail.getAudioThumbnail()}; - juce::TextButton recordButton{"Record"}; - juce::File lastRecording; + juce::TextButton _recordButton{"Record"}; + juce::File _lastRecording; }; } // namespace ra diff --git a/src/mc/raum_akustik/tool/noise_generator.cpp b/src/mc/raum_akustik/tool/noise_generator.cpp index fb9ebcd..82d16fd 100644 --- a/src/mc/raum_akustik/tool/noise_generator.cpp +++ b/src/mc/raum_akustik/tool/noise_generator.cpp @@ -32,7 +32,7 @@ auto NoiseGenerator::resized() -> void _play.setBounds(area); } -auto NoiseGenerator::audioDeviceAboutToStart(juce::AudioIODevice*) -> void {} +auto NoiseGenerator::audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) -> void {} auto NoiseGenerator::audioDeviceStopped() -> void {} diff --git a/src/mc/raum_akustik/tool/noise_generator.hpp b/src/mc/raum_akustik/tool/noise_generator.hpp index 1d87a34..1ef6777 100644 --- a/src/mc/raum_akustik/tool/noise_generator.hpp +++ b/src/mc/raum_akustik/tool/noise_generator.hpp @@ -16,7 +16,7 @@ struct NoiseGenerator final auto resized() -> void override; - auto audioDeviceAboutToStart(juce::AudioIODevice*) -> void override; + auto audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) -> void override; auto audioDeviceStopped() -> void override; auto audioDeviceIOCallbackWithContext( float const* const* inputChannelData, diff --git a/src/mc/raum_akustik/widget/level_meter.hpp b/src/mc/raum_akustik/widget/level_meter.hpp index ad02d31..470f89d 100644 --- a/src/mc/raum_akustik/widget/level_meter.hpp +++ b/src/mc/raum_akustik/widget/level_meter.hpp @@ -17,7 +17,7 @@ struct LevelMeter final auto resized() -> void override; auto timerCallback() -> void override; - auto audioDeviceAboutToStart(juce::AudioIODevice*) -> void override; + auto audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) -> void override; auto audioDeviceStopped() -> void override; auto audioDeviceIOCallbackWithContext( float const* const* inputChannelData, @@ -33,7 +33,7 @@ struct LevelMeter final std::atomic _rms{0.0F}; std::atomic _smoothValue{15.0F}; juce::AudioBuffer _rmsBuffer; - juce::dsp::StateVariableTPTFilter _peakFilter{}; + juce::dsp::StateVariableTPTFilter _peakFilter; int _writePosition{0}; juce::Label _peakLabel; @@ -41,7 +41,7 @@ struct LevelMeter final juce::ComboBox _unit; juce::Slider _refVoltage{juce::Slider::IncDecButtons, juce::Slider::TextBoxRight}; juce::Slider _smooth{juce::Slider::IncDecButtons, juce::Slider::TextBoxRight}; - juce::Rectangle _meter{}; + juce::Rectangle _meter; }; } // namespace ra diff --git a/src/mc/raum_akustik/widget/scrolling_waveform.cpp b/src/mc/raum_akustik/widget/scrolling_waveform.cpp index 80d1c15..5fd5f3d 100644 --- a/src/mc/raum_akustik/widget/scrolling_waveform.cpp +++ b/src/mc/raum_akustik/widget/scrolling_waveform.cpp @@ -10,7 +10,7 @@ ScrollingWaveform::ScrollingWaveform() : juce::AudioVisualiserComponent(1) setBufferSize(2048); } -auto ScrollingWaveform::audioDeviceAboutToStart(juce::AudioIODevice*) -> void { clear(); } +auto ScrollingWaveform::audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) -> void { clear(); } auto ScrollingWaveform::audioDeviceStopped() -> void { clear(); } diff --git a/src/mc/raum_akustik/widget/scrolling_waveform.hpp b/src/mc/raum_akustik/widget/scrolling_waveform.hpp index 53c01dc..11421f6 100644 --- a/src/mc/raum_akustik/widget/scrolling_waveform.hpp +++ b/src/mc/raum_akustik/widget/scrolling_waveform.hpp @@ -11,7 +11,7 @@ struct ScrollingWaveform final ScrollingWaveform(); ~ScrollingWaveform() override = default; - auto audioDeviceAboutToStart(juce::AudioIODevice*) -> void override; + auto audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) -> void override; auto audioDeviceStopped() -> void override; auto audioDeviceIOCallbackWithContext( float const* const* inputChannelData, diff --git a/src/mc/raum_akustik/widget/spectogram.cpp b/src/mc/raum_akustik/widget/spectogram.cpp index 9d0e604..c81d572 100644 --- a/src/mc/raum_akustik/widget/spectogram.cpp +++ b/src/mc/raum_akustik/widget/spectogram.cpp @@ -10,7 +10,7 @@ Spectogram::Spectogram() setSize(700, 500); } -void Spectogram::audioDeviceAboutToStart(juce::AudioIODevice*) {} +void Spectogram::audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) {} void Spectogram::audioDeviceStopped() {} @@ -44,7 +44,7 @@ void Spectogram::paint(juce::Graphics& g) { g.fillAll(juce::Colours::black); - g.setOpacity(1.0f); + g.setOpacity(1.0F); g.drawImage(_image, getLocalBounds().toFloat()); } @@ -95,17 +95,17 @@ void Spectogram::drawNextLineOfSpectrogram() // show up the detail clearly auto const maxLevel = juce::FloatVectorOperations::findMinAndMax(_fftBuffer.data(), fftSize / 2); - auto const maxGain = juce::jmax(maxLevel.getEnd(), 1e-5f); + auto const maxGain = juce::jmax(maxLevel.getEnd(), 1e-5F); // auto const maxDB = juce::Decibels::gainToDecibels(maxGain); // auto const minDB = juce::Decibels::gainToDecibels(0.0F); for (auto y = 1; y < imageHeight; ++y) { - auto const skewedY = 1.0f - std::exp(std::log((float)y / (float)imageHeight) * 0.2f); + auto const skewedY = 1.0F - std::exp(std::log((float)y / (float)imageHeight) * 0.2F); auto const index = static_cast(juce::jlimit(0, fftSize / 2, (int)(skewedY * (int)fftSize / 2))); auto const gain = _fftBuffer[index]; - auto const levelGain = juce::jmap(gain, 0.0F, maxGain, 0.0f, 1.0f); - auto const colorGain = juce::Colour::fromHSV(levelGain, 1.0f, levelGain, 1.0f); + auto const levelGain = juce::jmap(gain, 0.0F, maxGain, 0.0F, 1.0F); + auto const colorGain = juce::Colour::fromHSV(levelGain, 1.0F, levelGain, 1.0F); // auto const dB = juce::Decibels::gainToDecibels(gain); // auto const levelDB = juce::jmap(dB, minDB, maxDB, 0.0f, 1.0f); diff --git a/src/mc/raum_akustik/widget/spectogram.hpp b/src/mc/raum_akustik/widget/spectogram.hpp index 26b4bbb..f2697a4 100644 --- a/src/mc/raum_akustik/widget/spectogram.hpp +++ b/src/mc/raum_akustik/widget/spectogram.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace ra { struct Spectogram @@ -13,7 +15,7 @@ struct Spectogram Spectogram(); ~Spectogram() override = default; - void audioDeviceAboutToStart(juce::AudioIODevice*) override; + void audioDeviceAboutToStart(juce::AudioIODevice* /*device*/) override; void audioDeviceStopped() override; void audioDeviceIOCallbackWithContext( float const* const* inputChannelData, @@ -45,7 +47,7 @@ struct Spectogram int _fifoIndex{0}; std::atomic _nextBlockReady{false}; - std::array _fftBuffer{}; + std::array(fftSize) * 2UL> _fftBuffer{}; std::array _fifoBuffer{}; };