From 7327522e00ba4a1f3a5f0b07bd9bd710f7c1f818 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Sun, 17 Dec 2023 19:45:14 +0100 Subject: [PATCH 01/21] Apply latest clang-format --- .clang-format | 14 +++++++++++++- impl/oalpp/effects/distortion/tanh_distortion.hpp | 1 + impl/oalpp/effects/filter/moog_filter_stilson.cpp | 2 +- impl/oalpp/effects/filter/moog_filter_stilson.hpp | 2 +- impl/oalpp/effects/mono_effect_interface.hpp | 2 +- impl/oalpp/sound/sound.cpp | 4 ++++ impl/oalpp/sound_context/sound_context.cpp | 1 + .../sound_context/sound_context_interface.hpp | 2 +- impl/oalpp/sound_data/sound_data_interface.hpp | 10 +++++----- impl/oalpp/sound_data/sound_data_left_to_mono.cpp | 2 ++ impl/oalpp/sound_data/sound_data_left_to_mono.hpp | 1 + impl/oalpp/sound_data/sound_data_mid_to_mono.cpp | 2 ++ .../oalpp/sound_data/sound_data_mono_to_stereo.cpp | 3 +++ impl/oalpp/sound_data/sound_data_right_to_mono.cpp | 2 ++ impl/oalpp/sound_data/sound_data_side_to_mono.cpp | 2 ++ impl/oalpp/sound_data/sound_data_with_effect.cpp | 4 +++- impl/oalpp/sound_data/sound_data_with_effect.hpp | 2 +- test/approval_tests/approval_test_helpers.cpp | 4 ++-- test/approval_tests/effect_convolution_test.cpp | 5 +++-- test/approval_tests/effect_phase_flip_test.cpp | 2 +- 20 files changed, 50 insertions(+), 17 deletions(-) diff --git a/.clang-format b/.clang-format index a5a922d..f5d98ae 100644 --- a/.clang-format +++ b/.clang-format @@ -4,10 +4,22 @@ Language: Cpp PointerAlignment: Left SpaceBeforeParens: ControlStatements SpacesInParentheses: 'false' -Standard: Cpp11 +SeparateDefinitionBlocks: Always +Standard: c++14 UseTab: Never ColumnLimit: 100 FixNamespaceComments: 'true' NamespaceIndentation: 'None' AlwaysBreakTemplateDeclarations: 'Yes' +QualifierAlignment: Right + + +SortIncludes: 'true' +IncludeCategories: + - Regex: '"*(.hpp)"' + Priority: 2 + - Regex: '<*(.hpp)>' + Priority: 2 + - Regex: '^((?!(.hpp)).)*$' + Priority: 4 ... diff --git a/impl/oalpp/effects/distortion/tanh_distortion.hpp b/impl/oalpp/effects/distortion/tanh_distortion.hpp index e606261..546083a 100644 --- a/impl/oalpp/effects/distortion/tanh_distortion.hpp +++ b/impl/oalpp/effects/distortion/tanh_distortion.hpp @@ -2,6 +2,7 @@ #define OPENALPP_EFFECTS_DISTORTION_TANH_DISTORTION_HPP #include "oalpp/effects/mono_effect_interface.hpp" + namespace oalpp { namespace effects { namespace distortion { diff --git a/impl/oalpp/effects/filter/moog_filter_stilson.cpp b/impl/oalpp/effects/filter/moog_filter_stilson.cpp index 91836dd..befb381 100644 --- a/impl/oalpp/effects/filter/moog_filter_stilson.cpp +++ b/impl/oalpp/effects/filter/moog_filter_stilson.cpp @@ -58,7 +58,7 @@ oalpp::effects::filter::MoogFilterStilson::MoogFilterStilson( } std::vector oalpp::effects::filter::MoogFilterStilson::process( - const std::vector& input) + std::vector const& input) { std::vector output; output.resize(input.size()); diff --git a/impl/oalpp/effects/filter/moog_filter_stilson.hpp b/impl/oalpp/effects/filter/moog_filter_stilson.hpp index 4caa772..f92728c 100644 --- a/impl/oalpp/effects/filter/moog_filter_stilson.hpp +++ b/impl/oalpp/effects/filter/moog_filter_stilson.hpp @@ -16,7 +16,7 @@ class MoogFilterStilson : public MonoEffectInterface { public: MoogFilterStilson(float sampleRate, float cutoff, float resonance); - std::vector process(const std::vector& input) override; + std::vector process(std::vector const& input) override; private: float m_sampleRate { 0.0f }; diff --git a/impl/oalpp/effects/mono_effect_interface.hpp b/impl/oalpp/effects/mono_effect_interface.hpp index bd5c7ea..1a57937 100644 --- a/impl/oalpp/effects/mono_effect_interface.hpp +++ b/impl/oalpp/effects/mono_effect_interface.hpp @@ -13,7 +13,7 @@ class MonoEffectInterface { // avoid slicing via polymorphic copy or move MonoEffectInterface(MonoEffectInterface const& /*other*/) = delete; MonoEffectInterface(MonoEffectInterface&& /*other*/) = delete; - MonoEffectInterface& operator=(const MonoEffectInterface&) = delete; + MonoEffectInterface& operator=(MonoEffectInterface const&) = delete; MonoEffectInterface& operator=(MonoEffectInterface&&) = delete; protected: diff --git a/impl/oalpp/sound/sound.cpp b/impl/oalpp/sound/sound.cpp index 01912b4..07c8c1d 100644 --- a/impl/oalpp/sound/sound.cpp +++ b/impl/oalpp/sound/sound.cpp @@ -22,6 +22,7 @@ Sound::Sound(SoundDataInterface const& soundData) + std::to_string(errorIfAny) }; } } + void Sound::initSourceAndBuffers() { // Create source @@ -213,6 +214,7 @@ bool Sound::hasDataForFullBufferToEnqueue() const { return m_cursor + BUFFER_SIZE <= m_soundData.getSamples().size(); } + bool Sound::hasDataToEnqueue() const { if (m_isLooping) { @@ -222,6 +224,7 @@ bool Sound::hasDataToEnqueue() const } bool Sound::getIsLooping() const { return m_isLooping; } + void Sound::setIsLooping(bool value) { m_isLooping = value; @@ -239,6 +242,7 @@ size_t Sound::getLengthInSamples() const { return m_soundData.getSamples().size() / m_soundData.getNumberOfChannels(); } + float Sound::getLengthInSeconds() const { return static_cast(getLengthInSamples()) diff --git a/impl/oalpp/sound_context/sound_context.cpp b/impl/oalpp/sound_context/sound_context.cpp index fd3fcbb..9968cd4 100644 --- a/impl/oalpp/sound_context/sound_context.cpp +++ b/impl/oalpp/sound_context/sound_context.cpp @@ -4,6 +4,7 @@ namespace oalpp { namespace { + auto defaultDeviceFactory() { return std::unique_ptr( diff --git a/impl/oalpp/sound_context/sound_context_interface.hpp b/impl/oalpp/sound_context/sound_context_interface.hpp index 833c2fa..83957a6 100644 --- a/impl/oalpp/sound_context/sound_context_interface.hpp +++ b/impl/oalpp/sound_context/sound_context_interface.hpp @@ -9,7 +9,7 @@ class SoundContextInterface { // avoid slicing via polymorphic copy or move SoundContextInterface(SoundContextInterface const& /*other*/) = delete; SoundContextInterface(SoundContextInterface&& /*other*/) = delete; - SoundContextInterface& operator=(const SoundContextInterface&) = delete; + SoundContextInterface& operator=(SoundContextInterface const&) = delete; SoundContextInterface& operator=(SoundContextInterface&&) = delete; protected: diff --git a/impl/oalpp/sound_data/sound_data_interface.hpp b/impl/oalpp/sound_data/sound_data_interface.hpp index 364725d..b4fd341 100644 --- a/impl/oalpp/sound_data/sound_data_interface.hpp +++ b/impl/oalpp/sound_data/sound_data_interface.hpp @@ -10,16 +10,16 @@ class SoundDataInterface { public: virtual ~SoundDataInterface() = default; + virtual int getNumberOfChannels() const = 0; + virtual int getSampleRate() const = 0; + virtual std::vector const& getSamples() const = 0; + // avoid slicing via polymorphic copy or move SoundDataInterface(SoundDataInterface const& /*other*/) = delete; SoundDataInterface(SoundDataInterface&& /*other*/) = delete; - SoundDataInterface& operator=(const SoundDataInterface&) = delete; + SoundDataInterface& operator=(SoundDataInterface const&) = delete; SoundDataInterface& operator=(SoundDataInterface&&) = delete; - virtual int getNumberOfChannels() const = 0; - virtual int getSampleRate() const = 0; - virtual std::vector const& getSamples() const = 0; - protected: // allow default construction for derived classes SoundDataInterface() = default; diff --git a/impl/oalpp/sound_data/sound_data_left_to_mono.cpp b/impl/oalpp/sound_data/sound_data_left_to_mono.cpp index ee110f2..c3ea5d4 100644 --- a/impl/oalpp/sound_data/sound_data_left_to_mono.cpp +++ b/impl/oalpp/sound_data/sound_data_left_to_mono.cpp @@ -18,7 +18,9 @@ SoundDataLeftToMono::SoundDataLeftToMono(SoundDataInterface& source) } int SoundDataLeftToMono::getNumberOfChannels() const { return 1; } + int SoundDataLeftToMono::getSampleRate() const { return m_sampleRate; } + std::vector const& SoundDataLeftToMono::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_left_to_mono.hpp b/impl/oalpp/sound_data/sound_data_left_to_mono.hpp index df5dd91..2d59ee7 100644 --- a/impl/oalpp/sound_data/sound_data_left_to_mono.hpp +++ b/impl/oalpp/sound_data/sound_data_left_to_mono.hpp @@ -4,6 +4,7 @@ #include "sound_data_interface.hpp" namespace oalpp { + class SoundDataLeftToMono : public SoundDataInterface { public: explicit SoundDataLeftToMono(SoundDataInterface& source); diff --git a/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp b/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp index 1623cf0..631d198 100644 --- a/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp +++ b/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp @@ -21,7 +21,9 @@ SoundDataMidToMono::SoundDataMidToMono(SoundDataInterface& source) } int SoundDataMidToMono::getNumberOfChannels() const { return 1; } + int SoundDataMidToMono::getSampleRate() const { return m_sampleRate; } + std::vector const& SoundDataMidToMono::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp b/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp index cf45e31..b500941 100644 --- a/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp +++ b/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp @@ -1,5 +1,6 @@ #include "sound_data_mono_to_stereo.hpp" #include + namespace oalpp { SoundDataMonoToStereo::SoundDataMonoToStereo(SoundDataInterface& source) @@ -17,7 +18,9 @@ SoundDataMonoToStereo::SoundDataMonoToStereo(SoundDataInterface& source) } int SoundDataMonoToStereo::getNumberOfChannels() const { return 2; } + int SoundDataMonoToStereo::getSampleRate() const { return m_sampleRate; } + std::vector const& SoundDataMonoToStereo::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_right_to_mono.cpp b/impl/oalpp/sound_data/sound_data_right_to_mono.cpp index d98b4ae..f39f608 100644 --- a/impl/oalpp/sound_data/sound_data_right_to_mono.cpp +++ b/impl/oalpp/sound_data/sound_data_right_to_mono.cpp @@ -18,7 +18,9 @@ SoundDataRightToMono::SoundDataRightToMono(SoundDataInterface& source) } int SoundDataRightToMono::getNumberOfChannels() const { return 1; } + int SoundDataRightToMono::getSampleRate() const { return m_sampleRate; } + std::vector const& SoundDataRightToMono::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_side_to_mono.cpp b/impl/oalpp/sound_data/sound_data_side_to_mono.cpp index cb0cb48..30cf13e 100644 --- a/impl/oalpp/sound_data/sound_data_side_to_mono.cpp +++ b/impl/oalpp/sound_data/sound_data_side_to_mono.cpp @@ -21,7 +21,9 @@ SoundDataSideToMono::SoundDataSideToMono(SoundDataInterface& source) } int SoundDataSideToMono::getNumberOfChannels() const { return 1; } + int SoundDataSideToMono::getSampleRate() const { return m_sampleRate; } + std::vector const& SoundDataSideToMono::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_with_effect.cpp b/impl/oalpp/sound_data/sound_data_with_effect.cpp index 27d5214..0ddcda4 100644 --- a/impl/oalpp/sound_data/sound_data_with_effect.cpp +++ b/impl/oalpp/sound_data/sound_data_with_effect.cpp @@ -37,7 +37,9 @@ SoundDataWithEffect::SoundDataWithEffect( } int SoundDataWithEffect::getNumberOfChannels() const { return m_numberOfChannels; } + int SoundDataWithEffect::getSampleRate() const { return m_sampleRate; } -const std::vector& SoundDataWithEffect::getSamples() const { return m_samples; } + +std::vector const& SoundDataWithEffect::getSamples() const { return m_samples; } } // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_with_effect.hpp b/impl/oalpp/sound_data/sound_data_with_effect.hpp index de02008..41780e6 100644 --- a/impl/oalpp/sound_data/sound_data_with_effect.hpp +++ b/impl/oalpp/sound_data/sound_data_with_effect.hpp @@ -12,7 +12,7 @@ class SoundDataWithEffect : public SoundDataInterface { SoundDataWithEffect(SoundDataInterface const& decoratee, effects::MonoEffectInterface& effect); int getSampleRate() const override; - const std::vector& getSamples() const override; + std::vector const& getSamples() const override; int getNumberOfChannels() const override; private: diff --git a/test/approval_tests/approval_test_helpers.cpp b/test/approval_tests/approval_test_helpers.cpp index fe36f17..81eda3e 100644 --- a/test/approval_tests/approval_test_helpers.cpp +++ b/test/approval_tests/approval_test_helpers.cpp @@ -5,7 +5,7 @@ std::vector ApprovalTestHelpers::asInt(std::vector const& numbers, u { std::vector numbersAsInts; numbersAsInts.resize(numbers.size()); - std::transform(numbers.cbegin(), numbers.cend(), numbersAsInts.begin(), [digits](float number) - {return static_cast(number * digits);}); + std::transform(numbers.cbegin(), numbers.cend(), numbersAsInts.begin(), + [digits](float number) { return static_cast(number * digits); }); return numbersAsInts; } diff --git a/test/approval_tests/effect_convolution_test.cpp b/test/approval_tests/effect_convolution_test.cpp index ecb40c0..8cc7a30 100644 --- a/test/approval_tests/effect_convolution_test.cpp +++ b/test/approval_tests/effect_convolution_test.cpp @@ -1,8 +1,8 @@ #include "ApprovalTests/ApprovalTests.hpp" +#include "approval_test_helpers.hpp" #include "catch2/catch.hpp" #include "oalpp/effects/utility/convolution.hpp" #include "oalpp/sound_data.hpp" -#include "approval_test_helpers.hpp" TEST_CASE("convolution") { @@ -13,5 +13,6 @@ TEST_CASE("convolution") // note: Due to platform dependent float behavior, the result needs to be converted to int for // the approval tests to work. - ApprovalTests::Approvals::verifyAll(ApprovalTestHelpers::asInt(soundWithEffect.getSamples(), 100)); + ApprovalTests::Approvals::verifyAll( + ApprovalTestHelpers::asInt(soundWithEffect.getSamples(), 100)); } diff --git a/test/approval_tests/effect_phase_flip_test.cpp b/test/approval_tests/effect_phase_flip_test.cpp index e23275c..0d43105 100644 --- a/test/approval_tests/effect_phase_flip_test.cpp +++ b/test/approval_tests/effect_phase_flip_test.cpp @@ -7,7 +7,7 @@ TEST_CASE("phase_flip") { std::string const fileName { "assets/test1.wav" }; oalpp::SoundData buffer { fileName }; - oalpp::effects::utility::PhaseFlip phaseFlip { }; + oalpp::effects::utility::PhaseFlip phaseFlip {}; oalpp::SoundDataWithEffect soundWithEffect { buffer, phaseFlip }; ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples()); From d9b87b134341c3c3054e9f06172a988db09e0d4f Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 07:53:27 +0100 Subject: [PATCH 02/21] Replace different instances of SoundData with SoundDataBuilder --- .github/workflows/test_verification.yml | 3 + impl/oalpp/sound_data.hpp | 4 +- impl/oalpp/sound_data/sound_data.cpp | 25 ++- impl/oalpp/sound_data/sound_data.hpp | 12 +- impl/oalpp/sound_data/sound_data_builder.cpp | 120 +++++++++++++ impl/oalpp/sound_data/sound_data_builder.hpp | 30 ++++ .../sound_data/sound_data_left_to_mono.cpp | 26 --- .../sound_data/sound_data_left_to_mono.hpp | 23 --- .../sound_data/sound_data_mid_to_mono.cpp | 29 --- .../sound_data/sound_data_mid_to_mono.hpp | 22 --- .../sound_data/sound_data_mono_to_stereo.cpp | 26 --- .../sound_data/sound_data_mono_to_stereo.hpp | 23 --- .../sound_data/sound_data_right_to_mono.cpp | 26 --- .../sound_data/sound_data_right_to_mono.hpp | 22 --- .../sound_data/sound_data_side_to_mono.cpp | 29 --- .../sound_data/sound_data_side_to_mono.hpp | 22 --- .../sound_data/sound_data_text_writer.cpp | 22 --- .../sound_data/sound_data_text_writer.hpp | 17 -- .../sound_data/sound_data_with_effect.cpp | 45 ----- .../sound_data/sound_data_with_effect.hpp | 26 --- .../effect_convolution_test.cpp | 9 +- test/approval_tests/effect_gain_test.cpp | 10 +- .../approval_tests/effect_phase_flip_test.cpp | 5 +- test/integration_tests/main.cpp | 8 +- test/unit_tests/sound_data_builder_test.cpp | 138 ++++++++++++++ .../sound_data_channel_conversion_test.cpp | 169 ------------------ 26 files changed, 338 insertions(+), 553 deletions(-) create mode 100644 impl/oalpp/sound_data/sound_data_builder.cpp create mode 100644 impl/oalpp/sound_data/sound_data_builder.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_left_to_mono.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_left_to_mono.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_mid_to_mono.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_mid_to_mono.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_mono_to_stereo.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_right_to_mono.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_right_to_mono.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_side_to_mono.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_side_to_mono.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_text_writer.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_text_writer.hpp delete mode 100644 impl/oalpp/sound_data/sound_data_with_effect.cpp delete mode 100644 impl/oalpp/sound_data/sound_data_with_effect.hpp create mode 100644 test/unit_tests/sound_data_builder_test.cpp delete mode 100644 test/unit_tests/sound_data_channel_conversion_test.cpp diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 1a63ae1..2e2d45e 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -131,6 +131,9 @@ jobs: Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream + - name: Copy assets + run: cp -r assets ${{github.workspace}}/build/test/unit_tests/Debug + - name: Test working-directory: ${{github.workspace}}/build run: test/unit_tests/Debug/OpenALpp_UnitTests.exe --order rand diff --git a/impl/oalpp/sound_data.hpp b/impl/oalpp/sound_data.hpp index 28fac54..3cb75aa 100644 --- a/impl/oalpp/sound_data.hpp +++ b/impl/oalpp/sound_data.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_SOUND_DATA_INCLUDE_HPP #define OPENALPP_SOUND_DATA_INCLUDE_HPP -#include "oalpp/sound_data/sound_data.hpp" -#include "oalpp/sound_data/sound_data_with_effect.hpp" +#include +#include #endif // OPENALPP_SOUND_DATA_INCLUDE_HPP diff --git a/impl/oalpp/sound_data/sound_data.cpp b/impl/oalpp/sound_data/sound_data.cpp index 990d0cb..0b9776f 100644 --- a/impl/oalpp/sound_data/sound_data.cpp +++ b/impl/oalpp/sound_data/sound_data.cpp @@ -4,15 +4,26 @@ namespace oalpp { -SoundData::SoundData(std::string const& fileName) +SoundData::SoundData(std::vector const& data, int sampleRate, int numberOfChannels) + : m_samples { data } + , m_sampleRate { sampleRate } + , m_numberOfChannels { numberOfChannels } { - auto fileData = std::make_unique(); - nqr::NyquistIO loader; - loader.Load(fileData.get(), fileName); +} - m_numberOfChannels = fileData->channelCount; - m_sampleRate = fileData->sampleRate; - m_samples = std::move(fileData->samples); +SoundData::SoundData(SoundData&& data) noexcept + : m_samples { std::move(data.m_samples) } + , m_sampleRate { std::exchange(data.m_sampleRate, 0) } + , m_numberOfChannels { std::exchange(data.m_numberOfChannels, 0) } +{ +} + +SoundData& SoundData::operator=(SoundData&& other) noexcept +{ + m_samples = std::move(other.m_samples); + m_sampleRate = std::exchange(other.m_sampleRate, 0); + m_numberOfChannels = std::exchange(other.m_numberOfChannels, 0); + return *this; } int SoundData::getNumberOfChannels() const { return m_numberOfChannels; } diff --git a/impl/oalpp/sound_data/sound_data.hpp b/impl/oalpp/sound_data/sound_data.hpp index aff03a6..1824901 100644 --- a/impl/oalpp/sound_data/sound_data.hpp +++ b/impl/oalpp/sound_data/sound_data.hpp @@ -2,13 +2,21 @@ #define OPENALPP_SOUND_DATA_HPP #include "sound_data_interface.hpp" -#include namespace oalpp { class SoundData : public SoundDataInterface { public: - explicit SoundData(std::string const& fileName); + SoundData(std::vector const& data, int sampleRate, int numberOfChannels); + SoundData() = delete; + ~SoundData() override = default; + + SoundData(SoundData const& data) = delete; + SoundData(SoundData&& data) noexcept; + + SoundData& operator=(SoundData const&) = delete; + SoundData& operator=(SoundData&&) noexcept; + int getNumberOfChannels() const override; int getSampleRate() const override; diff --git a/impl/oalpp/sound_data/sound_data_builder.cpp b/impl/oalpp/sound_data/sound_data_builder.cpp new file mode 100644 index 0000000..d71de7e --- /dev/null +++ b/impl/oalpp/sound_data/sound_data_builder.cpp @@ -0,0 +1,120 @@ +#include "sound_data_builder.hpp" +#include + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::fromFile(std::string const& file) +{ + nqr::NyquistIO loader; + auto const audioData = std::make_unique(); + loader.Load(audioData.get(), file); + m_data = std::move(audioData->samples); + m_sampleRate = audioData->sampleRate; + m_numberOfChannels = audioData->channelCount; + return *this; +} + +oalpp::SoundData oalpp::SoundDataBuilder::create() +{ + return oalpp::SoundData { m_data, m_sampleRate, m_numberOfChannels }; +} + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str) +{ + str = "# Sound Data\n"; + str += "# sampleRate: " + std::to_string(m_sampleRate) + "\n"; + str += "# numberOfChannels: " + std::to_string(m_numberOfChannels) + "\n"; + + for (auto index = 0U; index != m_data.size(); ++index) { + str += std::to_string(index) + " " + std::to_string(m_data[index]) + "\n"; + } + str += "\n"; + + return *this; +} + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::withEffect( + oalpp::effects::MonoEffectInterface& effect) +{ + if (m_numberOfChannels == 1) { + m_data = effect.process(m_data); + } else { + std::vector lefts; + std::vector rights; + auto const halfSize = m_data.size() / 2; + lefts.resize(halfSize); + rights.resize(halfSize); + + bool toggle = false; + std::partition_copy( + m_data.begin(), m_data.end(), lefts.begin(), rights.begin(), [&toggle](float) { + toggle = !toggle; + return toggle; + }); + + std::vector const leftsProcessed = effect.process(lefts); + std::vector const rightsProcessed = effect.process(rights); + + m_data.resize(leftsProcessed.size() * 2U); + for (auto i = 0U; i != leftsProcessed.size(); ++i) { + m_data[i * 2U + 0U] = leftsProcessed[i]; + m_data[i * 2U + 1U] = rightsProcessed[i]; + } + } + + return *this; +} + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::onlyLeftChannel() +{ + if (m_numberOfChannels != 2) { + throw std::invalid_argument { "Can not use left channel from mono sound data." }; + } + + std::vector samples; + samples.resize(m_data.size() / 2); + + for (auto index = 0U; index != samples.size(); ++index) { + samples.at(index) = m_data.at(index * 2); + } + + m_numberOfChannels = 1; + m_data = samples; + return *this; +} + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::onlyRightChannel() +{ + if (m_numberOfChannels != 2) { + throw std::invalid_argument { "Can not use right channel from mono sound data." }; + } + + std::vector samples; + samples.resize(m_data.size() / 2); + + for (auto index = 0U; index != samples.size(); ++index) { + samples.at(index) = m_data.at(index * 2 + 1); + } + + m_numberOfChannels = 1; + m_data = samples; + return *this; +} + +oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toStereo() +{ + if (m_numberOfChannels != 1) { + throw std::invalid_argument { "Can not make stereo sound data from non-mono file." }; + } + + std::vector samples; + samples.resize(m_data.size() * 2); + + for (auto index = 0U; index != m_data.size(); ++index) { + samples.at(index * 2 + 0) = m_data.at(index); + samples.at(index * 2 + 1) = m_data.at(index); + } + + m_data = samples; + m_numberOfChannels = 2; + + return *this; +} diff --git a/impl/oalpp/sound_data/sound_data_builder.hpp b/impl/oalpp/sound_data/sound_data_builder.hpp new file mode 100644 index 0000000..f3b6184 --- /dev/null +++ b/impl/oalpp/sound_data/sound_data_builder.hpp @@ -0,0 +1,30 @@ +#ifndef SOUND_DATA_BUILDER_HPP +#define SOUND_DATA_BUILDER_HPP + +#include "oalpp/effects/utility/gain.hpp" +#include +#include +#include + +namespace oalpp { + +class SoundDataBuilder { +public: + [[nodiscard]] SoundData create(); + + [[nodiscard]] SoundDataBuilder& fromFile(std::string const& file); + [[nodiscard]] SoundDataBuilder& toString(std::string& str); + [[nodiscard]] SoundDataBuilder& withEffect(oalpp::effects::MonoEffectInterface& effect); + [[nodiscard]] SoundDataBuilder& onlyLeftChannel(); + [[nodiscard]] SoundDataBuilder& onlyRightChannel(); + [[nodiscard]] SoundDataBuilder& toStereo(); + +private: + std::vector m_data {}; + int m_sampleRate { 0 }; + int m_numberOfChannels { 0 }; +}; + +} // namespace oalpp + +#endif // SOUND_DATA_BUILDER_HPP diff --git a/impl/oalpp/sound_data/sound_data_left_to_mono.cpp b/impl/oalpp/sound_data/sound_data_left_to_mono.cpp deleted file mode 100644 index c3ea5d4..0000000 --- a/impl/oalpp/sound_data/sound_data_left_to_mono.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "sound_data_left_to_mono.hpp" -#include - -namespace oalpp { - -SoundDataLeftToMono::SoundDataLeftToMono(SoundDataInterface& source) -{ - if (source.getNumberOfChannels() != 2) { - throw std::invalid_argument { "Can not convert left to mono from mono file." }; - } - - m_samples.resize(source.getSamples().size() / 2); - - for (auto index = 0U; index != m_samples.size(); ++index) { - m_samples.at(index) = source.getSamples().at(index * 2); - } - m_sampleRate = source.getSampleRate(); -} - -int SoundDataLeftToMono::getNumberOfChannels() const { return 1; } - -int SoundDataLeftToMono::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataLeftToMono::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_left_to_mono.hpp b/impl/oalpp/sound_data/sound_data_left_to_mono.hpp deleted file mode 100644 index 2d59ee7..0000000 --- a/impl/oalpp/sound_data/sound_data_left_to_mono.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_LEFT_TO_MONO_HPP -#define OPENALPP_SOUND_DATA_LEFT_TO_MONO_HPP - -#include "sound_data_interface.hpp" - -namespace oalpp { - -class SoundDataLeftToMono : public SoundDataInterface { -public: - explicit SoundDataLeftToMono(SoundDataInterface& source); - - int getNumberOfChannels() const override; - int getSampleRate() const override; - std::vector const& getSamples() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_LEFT_TO_MONO_HPP diff --git a/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp b/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp deleted file mode 100644 index 631d198..0000000 --- a/impl/oalpp/sound_data/sound_data_mid_to_mono.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "sound_data_mid_to_mono.hpp" -#include - -namespace oalpp { - -SoundDataMidToMono::SoundDataMidToMono(SoundDataInterface& source) -{ - if (source.getNumberOfChannels() != 2) { - throw std::invalid_argument { "Can not convert left to mono from mono file." }; - } - - m_samples.resize(source.getSamples().size() / 2); - - for (auto index = 0U; index != m_samples.size(); ++index) { - auto const left = source.getSamples().at(index * 2); - auto const right = source.getSamples().at(index * 2 + 1); - - m_samples.at(index) = (left + right) / 2.0f; - } - m_sampleRate = source.getSampleRate(); -} - -int SoundDataMidToMono::getNumberOfChannels() const { return 1; } - -int SoundDataMidToMono::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataMidToMono::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_mid_to_mono.hpp b/impl/oalpp/sound_data/sound_data_mid_to_mono.hpp deleted file mode 100644 index e34d80e..0000000 --- a/impl/oalpp/sound_data/sound_data_mid_to_mono.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_MID_TO_MONO_HPP -#define OPENALPP_SOUND_DATA_MID_TO_MONO_HPP - -#include "sound_data_interface.hpp" - -namespace oalpp { -class SoundDataMidToMono : public SoundDataInterface { -public: - explicit SoundDataMidToMono(SoundDataInterface& source); - - int getNumberOfChannels() const override; - int getSampleRate() const override; - std::vector const& getSamples() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_MID_TO_MONO_HPP diff --git a/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp b/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp deleted file mode 100644 index b500941..0000000 --- a/impl/oalpp/sound_data/sound_data_mono_to_stereo.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "sound_data_mono_to_stereo.hpp" -#include - -namespace oalpp { - -SoundDataMonoToStereo::SoundDataMonoToStereo(SoundDataInterface& source) -{ - if (source.getNumberOfChannels() != 1) { - throw std::invalid_argument { "Can not convert mono to stereo from non mono file." }; - } - m_samples.resize(source.getSamples().size() * 2); - - for (auto index = 0U; index != source.getSamples().size(); ++index) { - m_samples.at(index * 2 + 0) = source.getSamples().at(index); - m_samples.at(index * 2 + 1) = source.getSamples().at(index); - } - m_sampleRate = source.getSampleRate(); -} - -int SoundDataMonoToStereo::getNumberOfChannels() const { return 2; } - -int SoundDataMonoToStereo::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataMonoToStereo::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_mono_to_stereo.hpp b/impl/oalpp/sound_data/sound_data_mono_to_stereo.hpp deleted file mode 100644 index 578442c..0000000 --- a/impl/oalpp/sound_data/sound_data_mono_to_stereo.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_MONO_TO_STEREO_HPP -#define OPENALPP_SOUND_DATA_MONO_TO_STEREO_HPP - -#include "sound_data_interface.hpp" - -namespace oalpp { - -class SoundDataMonoToStereo : public SoundDataInterface { -public: - explicit SoundDataMonoToStereo(SoundDataInterface& source); - - int getNumberOfChannels() const override; - int getSampleRate() const override; - std::vector const& getSamples() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_MONO_TO_STEREO_HPP diff --git a/impl/oalpp/sound_data/sound_data_right_to_mono.cpp b/impl/oalpp/sound_data/sound_data_right_to_mono.cpp deleted file mode 100644 index f39f608..0000000 --- a/impl/oalpp/sound_data/sound_data_right_to_mono.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "sound_data_right_to_mono.hpp" -#include - -namespace oalpp { - -SoundDataRightToMono::SoundDataRightToMono(SoundDataInterface& source) -{ - if (source.getNumberOfChannels() != 2) { - throw std::invalid_argument { "Can not convert left to mono from mono file." }; - } - - m_samples.resize(source.getSamples().size() / 2); - - for (auto index = 0U; index != m_samples.size(); ++index) { - m_samples.at(index) = source.getSamples().at(index * 2 + 1); - } - m_sampleRate = source.getSampleRate(); -} - -int SoundDataRightToMono::getNumberOfChannels() const { return 1; } - -int SoundDataRightToMono::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataRightToMono::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_right_to_mono.hpp b/impl/oalpp/sound_data/sound_data_right_to_mono.hpp deleted file mode 100644 index 061e778..0000000 --- a/impl/oalpp/sound_data/sound_data_right_to_mono.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_RIGHT_TO_MONO_HPP -#define OPENALPP_SOUND_DATA_RIGHT_TO_MONO_HPP - -#include "sound_data_interface.hpp" - -namespace oalpp { -class SoundDataRightToMono : public SoundDataInterface { -public: - explicit SoundDataRightToMono(SoundDataInterface& source); - - int getNumberOfChannels() const override; - int getSampleRate() const override; - std::vector const& getSamples() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_RIGHT_TO_MONO_HPP diff --git a/impl/oalpp/sound_data/sound_data_side_to_mono.cpp b/impl/oalpp/sound_data/sound_data_side_to_mono.cpp deleted file mode 100644 index 30cf13e..0000000 --- a/impl/oalpp/sound_data/sound_data_side_to_mono.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "sound_data_side_to_mono.hpp" -#include - -namespace oalpp { - -SoundDataSideToMono::SoundDataSideToMono(SoundDataInterface& source) -{ - if (source.getNumberOfChannels() != 2) { - throw std::invalid_argument { "Can not convert left to mono from mono file." }; - } - - m_samples.resize(source.getSamples().size() / 2); - - for (auto index = 0U; index != m_samples.size(); ++index) { - auto const left = source.getSamples().at(index * 2); - auto const right = source.getSamples().at(index * 2 + 1); - - m_samples.at(index) = (left - right) / 2.0f; - } - m_sampleRate = source.getSampleRate(); -} - -int SoundDataSideToMono::getNumberOfChannels() const { return 1; } - -int SoundDataSideToMono::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataSideToMono::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_side_to_mono.hpp b/impl/oalpp/sound_data/sound_data_side_to_mono.hpp deleted file mode 100644 index eebc386..0000000 --- a/impl/oalpp/sound_data/sound_data_side_to_mono.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_SIDE_TO_MONO_HPP -#define OPENALPP_SOUND_DATA_SIDE_TO_MONO_HPP - -#include "sound_data_interface.hpp" - -namespace oalpp { -class SoundDataSideToMono : public SoundDataInterface { -public: - explicit SoundDataSideToMono(SoundDataInterface& source); - - int getNumberOfChannels() const override; - int getSampleRate() const override; - std::vector const& getSamples() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_SIDE_TO_MONO_HPP diff --git a/impl/oalpp/sound_data/sound_data_text_writer.cpp b/impl/oalpp/sound_data/sound_data_text_writer.cpp deleted file mode 100644 index cc8fa18..0000000 --- a/impl/oalpp/sound_data/sound_data_text_writer.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "sound_data_text_writer.hpp" - -namespace oalpp { - -SoundDataTextWriter::SoundDataTextWriter(SoundDataInterface& soundData) - : m_soundData { soundData } -{ -} - -std::string SoundDataTextWriter::getText() const -{ - std::string str = "# Sound Data\n"; - str += "# SampleRate: " + std::to_string(m_soundData.getSampleRate()) + "\n"; - - for (auto index = 0U; index != m_soundData.getSamples().size(); ++index) { - str += std::to_string(index) + " " + std::to_string(m_soundData.getSamples()[index]) + "\n"; - } - str += "\n"; - return str; -} - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_text_writer.hpp b/impl/oalpp/sound_data/sound_data_text_writer.hpp deleted file mode 100644 index 9b2bcc1..0000000 --- a/impl/oalpp/sound_data/sound_data_text_writer.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_TEXT_WRITER_HPP -#define OPENALPP_SOUND_DATA_TEXT_WRITER_HPP - -#include "sound_data_interface.hpp" -#include - -namespace oalpp { -class SoundDataTextWriter { -public: - explicit SoundDataTextWriter(SoundDataInterface& soundData); - std::string getText() const; - - SoundDataInterface& m_soundData; -}; - -} // namespace oalpp -#endif // OPENALPP_SOUND_DATA_TEXT_WRITER_HPP diff --git a/impl/oalpp/sound_data/sound_data_with_effect.cpp b/impl/oalpp/sound_data/sound_data_with_effect.cpp deleted file mode 100644 index 0ddcda4..0000000 --- a/impl/oalpp/sound_data/sound_data_with_effect.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "sound_data_with_effect.hpp" -#include -#include - -namespace oalpp { - -SoundDataWithEffect::SoundDataWithEffect( - SoundDataInterface const& decoratee, effects::MonoEffectInterface& effect) -{ - m_sampleRate = decoratee.getSampleRate(); - m_numberOfChannels = decoratee.getNumberOfChannels(); - if (m_numberOfChannels == 1) { - m_samples = effect.process(decoratee.getSamples()); - } else { - std::vector lefts; - std::vector rights; - auto const halfSize = static_cast(decoratee.getSamples().size() / 2); - lefts.resize(halfSize); - rights.resize(halfSize); - - bool toggle = false; - std::partition_copy(decoratee.getSamples().begin(), decoratee.getSamples().end(), - lefts.begin(), rights.begin(), [&toggle](float) { - toggle = !toggle; - return toggle; - }); - - std::vector const leftsProcessed = effect.process(lefts); - std::vector const rightsProcessed = effect.process(rights); - - m_samples.resize(leftsProcessed.size() * 2U); - for (auto i = 0U; i != leftsProcessed.size(); ++i) { - m_samples[i * 2U + 0U] = leftsProcessed[i]; - m_samples[i * 2U + 1U] = rightsProcessed[i]; - } - } -} - -int SoundDataWithEffect::getNumberOfChannels() const { return m_numberOfChannels; } - -int SoundDataWithEffect::getSampleRate() const { return m_sampleRate; } - -std::vector const& SoundDataWithEffect::getSamples() const { return m_samples; } - -} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_with_effect.hpp b/impl/oalpp/sound_data/sound_data_with_effect.hpp deleted file mode 100644 index 41780e6..0000000 --- a/impl/oalpp/sound_data/sound_data_with_effect.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef OPENALPP_SOUND_DATA_WITH_EFFECT_HPP -#define OPENALPP_SOUND_DATA_WITH_EFFECT_HPP - -#include "oalpp/effects/mono_effect_interface.hpp" -#include "sound_data_interface.hpp" -#include - -namespace oalpp { - -class SoundDataWithEffect : public SoundDataInterface { -public: - SoundDataWithEffect(SoundDataInterface const& decoratee, effects::MonoEffectInterface& effect); - - int getSampleRate() const override; - std::vector const& getSamples() const override; - int getNumberOfChannels() const override; - -private: - std::vector m_samples {}; - int m_sampleRate { 0 }; - int m_numberOfChannels { 0 }; -}; - -} // namespace oalpp - -#endif // OPENALPP_SOUND_DATA_WITH_EFFECT_HPP diff --git a/test/approval_tests/effect_convolution_test.cpp b/test/approval_tests/effect_convolution_test.cpp index 8cc7a30..fe9a580 100644 --- a/test/approval_tests/effect_convolution_test.cpp +++ b/test/approval_tests/effect_convolution_test.cpp @@ -7,9 +7,12 @@ TEST_CASE("convolution") { std::string const fileName { "assets/test1.wav" }; - oalpp::SoundData buffer { fileName }; - oalpp::effects::utility::Convolution convolution { buffer.getSamples() }; - oalpp::SoundDataWithEffect soundWithEffect { buffer, convolution }; + oalpp::effects::utility::Convolution convolution { + oalpp::SoundDataBuilder().fromFile(fileName).create().getSamples() + }; + + auto const soundWithEffect + = oalpp::SoundDataBuilder().fromFile("assets/test1.wav").withEffect(convolution).create(); // note: Due to platform dependent float behavior, the result needs to be converted to int for // the approval tests to work. diff --git a/test/approval_tests/effect_gain_test.cpp b/test/approval_tests/effect_gain_test.cpp index bea7ce1..3ad2c03 100644 --- a/test/approval_tests/effect_gain_test.cpp +++ b/test/approval_tests/effect_gain_test.cpp @@ -5,21 +5,19 @@ TEST_CASE("gain") { + std::string const fileName { "assets/test1.wav" }; + oalpp::SoundDataBuilder builder; SECTION("1.0") { - std::string const fileName { "assets/test1.wav" }; oalpp::effects::utility::Gain gain { 1.0f }; - oalpp::SoundData buffer { fileName }; - oalpp::SoundDataWithEffect soundWithEffect { buffer, gain }; + auto const soundWithEffect = builder.fromFile("assets/test1.wav").withEffect(gain).create(); ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples()); } SECTION("2.0") { - std::string const fileName { "assets/test1.wav" }; oalpp::effects::utility::Gain gain { 2.0f }; - oalpp::SoundData buffer { fileName }; - oalpp::SoundDataWithEffect soundWithEffect { buffer, gain }; + auto const soundWithEffect = builder.fromFile("assets/test1.wav").withEffect(gain).create(); ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples()); } diff --git a/test/approval_tests/effect_phase_flip_test.cpp b/test/approval_tests/effect_phase_flip_test.cpp index 0d43105..5bcf5f4 100644 --- a/test/approval_tests/effect_phase_flip_test.cpp +++ b/test/approval_tests/effect_phase_flip_test.cpp @@ -6,9 +6,10 @@ TEST_CASE("phase_flip") { std::string const fileName { "assets/test1.wav" }; - oalpp::SoundData buffer { fileName }; oalpp::effects::utility::PhaseFlip phaseFlip {}; - oalpp::SoundDataWithEffect soundWithEffect { buffer, phaseFlip }; + + oalpp::SoundDataBuilder builder; + auto const soundWithEffect = builder.fromFile(fileName).withEffect(phaseFlip).create(); ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples()); } diff --git a/test/integration_tests/main.cpp b/test/integration_tests/main.cpp index 477fb5d..a3888ac 100644 --- a/test/integration_tests/main.cpp +++ b/test/integration_tests/main.cpp @@ -1,7 +1,8 @@ #include "oalpp/effects/filter/moog_filter_stilson.hpp" #include "oalpp/sound/sound.hpp" #include "oalpp/sound_context.hpp" -#include "oalpp/sound_data.hpp" +#include "oalpp/sound_data/sound_data_builder.hpp" + #include #include #ifdef __EMSCRIPTEN__ @@ -34,9 +35,8 @@ int main() effects::filter::MoogFilterStilson moog { 44100, 1800, 0.5f }; SoundContext ctx; - SoundData buffer { fileName }; - - SoundDataWithEffect soundDataWithEffect { buffer, moog }; + SoundDataBuilder builder; + SoundData soundDataWithEffect = builder.fromFile(fileName).withEffect(moog).create(); snd = std::make_shared(soundDataWithEffect); snd->setVolume(0.5f); diff --git a/test/unit_tests/sound_data_builder_test.cpp b/test/unit_tests/sound_data_builder_test.cpp new file mode 100644 index 0000000..641accf --- /dev/null +++ b/test/unit_tests/sound_data_builder_test.cpp @@ -0,0 +1,138 @@ +#include "catch2/catch.hpp" +#include "oalpp/effects/utility/effect_chain.hpp" +#include "oalpp/effects/utility/gain.hpp" +#include +#include +#include + +TEST_CASE("SoundDataBuilder", "[SoundDataBuilder]") +{ + oalpp::SoundDataBuilder builder {}; + + SECTION("With Default Builder") + { + SECTION("Creates empty SoundData") + { + auto const data = builder.create(); + REQUIRE(data.getNumberOfChannels() == 0); + REQUIRE(data.getSampleRate() == 0); + REQUIRE(data.getSamples().empty()); + } + SECTION("OnlyLeftChannel raises Exception") { REQUIRE_THROWS(builder.onlyLeftChannel()); } + SECTION("OnlyRightChannel raises Exception") { REQUIRE_THROWS(builder.onlyRightChannel()); } + SECTION("MonoToStereo raises Exception") { REQUIRE_THROWS(builder.toStereo()); } + } + + SECTION("With Stereo file") + { + nqr::NyquistIO loader; + auto const fileData = std::make_unique(); + loader.Load(fileData.get(), "assets/test.mp3"); + auto samples_expected = std::move(fileData->samples); + + SECTION("From Stereo File") + { + oalpp::SoundData const data = builder.fromFile("assets/test.mp3").create(); + + REQUIRE(data.getNumberOfChannels() == 2); + REQUIRE(data.getSampleRate() == 44100); + + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded == samples_expected); + } + + SECTION("With Gain Effect") + { + oalpp::effects::utility::Gain gain { 0.5f }; + oalpp::SoundData const data + = builder.fromFile("assets/test.mp3").withEffect(gain).create(); + + REQUIRE(data.getNumberOfChannels() == 2); + REQUIRE(data.getSampleRate() == 44100); + + for (auto& s : samples_expected) { + s *= 0.5f; + } + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded == samples_expected); + } + + SECTION("Left To Mono") + { + oalpp::SoundData const data + = builder.fromFile("assets/test.mp3").onlyLeftChannel().create(); + + REQUIRE(data.getNumberOfChannels() == 1); + REQUIRE(data.getSampleRate() == 44100); + + std::vector samples_expected_left; + samples_expected_left.resize(samples_expected.size() / 2); + + for (auto index = 0U; index != samples_expected_left.size(); ++index) { + samples_expected_left.at(index) = samples_expected.at(index * 2); + } + + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded.size() == samples_expected_left.size()); + REQUIRE(samples_loaded == samples_expected_left); + } + + SECTION("Right To Mono") + { + oalpp::SoundData const data + = builder.fromFile("assets/test.mp3").onlyRightChannel().create(); + + REQUIRE(data.getNumberOfChannels() == 1); + REQUIRE(data.getSampleRate() == 44100); + + std::vector samples_expected_left; + samples_expected_left.resize(samples_expected.size() / 2); + + for (auto index = 0U; index != samples_expected_left.size(); ++index) { + samples_expected_left.at(index) = samples_expected.at(index * 2 + 1); + } + + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded.size() == samples_expected_left.size()); + REQUIRE(samples_loaded == samples_expected_left); + } + } + SECTION("With Mono File") + { + nqr::NyquistIO loader; + auto const fileData = std::make_unique(); + loader.Load(fileData.get(), "assets/test_mono.mp3"); + auto samples_expected = std::move(fileData->samples); + + SECTION("From Mono File") + { + oalpp::SoundData const data = builder.fromFile("assets/test_mono.mp3").create(); + + REQUIRE(data.getNumberOfChannels() == 1); + REQUIRE(data.getSampleRate() == 44100); + + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded == samples_expected); + } + + SECTION("Mono To Stereo") + { + oalpp::SoundData const data + = builder.fromFile("assets/test_mono.mp3").toStereo().create(); + + REQUIRE(data.getNumberOfChannels() == 2); + REQUIRE(data.getSampleRate() == 44100); + + std::vector samples_expected_stereo; + samples_expected_stereo.resize(samples_expected.size() * 2); + + for (auto index = 0U; index != samples_expected.size(); ++index) { + samples_expected_stereo.at(index * 2 + 0) = samples_expected.at(index); + samples_expected_stereo.at(index * 2 + 1) = samples_expected.at(index); + } + + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded == samples_expected_stereo); + } + } +} diff --git a/test/unit_tests/sound_data_channel_conversion_test.cpp b/test/unit_tests/sound_data_channel_conversion_test.cpp deleted file mode 100644 index 26533c7..0000000 --- a/test/unit_tests/sound_data_channel_conversion_test.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "catch2/catch.hpp" -#include "oalpp/sound_data/sound_data_left_to_mono.hpp" -#include "oalpp/sound_data/sound_data_mid_to_mono.hpp" -#include "oalpp/sound_data/sound_data_mono_to_stereo.hpp" -#include "oalpp/sound_data/sound_data_right_to_mono.hpp" -#include "oalpp/sound_data/sound_data_side_to_mono.hpp" -#include "sound_data_fake.hpp" - -using namespace oalpp; - -TEST_CASE("SoundDataMonoToStereo", "[SoundConversion]") -{ - SoundDataMonoFake fake {}; - - SECTION("Correct number of channels") - { - SoundDataMonoToStereo stereo { fake }; - REQUIRE(stereo.getNumberOfChannels() == 2); - } - - SECTION("Same sample rate as original") - { - SoundDataMonoToStereo stereo { fake }; - REQUIRE(stereo.getSampleRate() == fake.getSampleRate()); - } - - SECTION("Correct samples after conversion") - { - fake.m_samples = std::vector { 1.0f, 2.0f, 3.0f, 4.0f }; - std::vector const expected_result { 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 4.0f, 4.0f }; - SoundDataMonoToStereo stereo { fake }; - - REQUIRE(expected_result == stereo.getSamples()); - } - - SECTION("Raises exception on stereo data") - { - SoundDataStereoFake fakeStereo {}; - REQUIRE_THROWS(SoundDataMonoToStereo { fakeStereo }); - } -} - -TEST_CASE("SoundDataLeftToMono", "[SoundConversion]") -{ - SoundDataStereoFake fake {}; - - SECTION("Correct number of channels") - { - SoundDataLeftToMono mono { fake }; - REQUIRE(mono.getNumberOfChannels() == 1); - } - - SECTION("Same sample rate as original") - { - SoundDataLeftToMono mono { fake }; - REQUIRE(mono.getSampleRate() == fake.getSampleRate()); - } - - SECTION("Correct samples after conversion") - { - fake.m_samples = std::vector { 1.0f, 2.0f, 3.0f, 4.0f }; - std::vector const expected_result { 1.0f, 3.0f }; - SoundDataLeftToMono mono { fake }; - - REQUIRE(expected_result == mono.getSamples()); - } - - SECTION("Raises exception on mono data") - { - SoundDataMonoFake fakeStereo {}; - REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo }); - } -} - -TEST_CASE("SoundDataRightToMono", "[SoundConversion]") -{ - SoundDataStereoFake fake {}; - - SECTION("Correct number of channels") - { - SoundDataRightToMono mono { fake }; - REQUIRE(mono.getNumberOfChannels() == 1); - } - - SECTION("Same sample rate as original") - { - SoundDataRightToMono mono { fake }; - REQUIRE(mono.getSampleRate() == fake.getSampleRate()); - } - - SECTION("Correct samples after conversion") - { - fake.m_samples = std::vector { 1.0f, 2.0f, 3.0f, 4.0f }; - std::vector const expected_result { 2.0f, 4.0f }; - SoundDataRightToMono mono { fake }; - - REQUIRE(expected_result == mono.getSamples()); - } - - SECTION("Raises exception on mono data") - { - SoundDataMonoFake fakeMono {}; - REQUIRE_THROWS(SoundDataRightToMono { fakeMono }); - } -} - -TEST_CASE("SoundDataMidToMono", "[SoundConversion]") -{ - SoundDataStereoFake fake {}; - - SECTION("Correct number of channels") - { - SoundDataMidToMono mono { fake }; - REQUIRE(mono.getNumberOfChannels() == 1); - } - - SECTION("Same sample rate as original") - { - SoundDataMidToMono mono { fake }; - REQUIRE(mono.getSampleRate() == fake.getSampleRate()); - } - - SECTION("Correct samples after conversion") - { - fake.m_samples = std::vector { 1.0f, 2.0f, 3.0f, 4.0f }; - std::vector const expected_result { 1.5f, 3.5f }; - SoundDataMidToMono mono { fake }; - - REQUIRE(expected_result == mono.getSamples()); - } - - SECTION("Raises exception on mono data") - { - SoundDataMonoFake fakeMono {}; - REQUIRE_THROWS(SoundDataMidToMono { fakeMono }); - } -} - -TEST_CASE("SoundDataSideToMono", "[SoundConversion]") -{ - SoundDataStereoFake fake {}; - - SECTION("Correct number of channels") - { - SoundDataSideToMono mono { fake }; - REQUIRE(mono.getNumberOfChannels() == 1); - } - - SECTION("Same sample rate as original") - { - SoundDataSideToMono mono { fake }; - REQUIRE(mono.getSampleRate() == fake.getSampleRate()); - } - - SECTION("Correct samples after conversion") - { - fake.m_samples = std::vector { 1.0f, 2.0f, 3.0f, 4.0f }; - std::vector const expected_result { -0.5f, -0.5f }; - SoundDataSideToMono mono { fake }; - - REQUIRE(expected_result == mono.getSamples()); - } - - SECTION("Raises exception on mono data") - { - SoundDataMonoFake fakeMono {}; - REQUIRE_THROWS(SoundDataSideToMono { fakeMono }); - } -} From 835e4845f8817646ca532d875db5692c74e5646b Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 08:46:19 +0100 Subject: [PATCH 03/21] Add documentation --- .../sound_context/sound_context_interface.hpp | 2 ++ impl/oalpp/sound_data/sound_data_builder.cpp | 4 ++++ impl/oalpp/sound_data/sound_data_builder.hpp | 22 ++++++++++++++++++- .../oalpp/sound_data/sound_data_interface.hpp | 16 +++++++++++--- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/impl/oalpp/sound_context/sound_context_interface.hpp b/impl/oalpp/sound_context/sound_context_interface.hpp index 83957a6..385e208 100644 --- a/impl/oalpp/sound_context/sound_context_interface.hpp +++ b/impl/oalpp/sound_context/sound_context_interface.hpp @@ -2,6 +2,7 @@ #define OPENALPP_SOUNDCONTEXTINTERFACE_HPP namespace oalpp { + class SoundContextInterface { public: virtual ~SoundContextInterface() = default; @@ -16,6 +17,7 @@ class SoundContextInterface { // allow default construction for derived classes SoundContextInterface() = default; }; + } // namespace oalpp #endif // OPENALPP_SOUNDCONTEXTINTERFACE_HPP diff --git a/impl/oalpp/sound_data/sound_data_builder.cpp b/impl/oalpp/sound_data/sound_data_builder.cpp index d71de7e..69a6871 100644 --- a/impl/oalpp/sound_data/sound_data_builder.cpp +++ b/impl/oalpp/sound_data/sound_data_builder.cpp @@ -17,6 +17,8 @@ oalpp::SoundData oalpp::SoundDataBuilder::create() return oalpp::SoundData { m_data, m_sampleRate, m_numberOfChannels }; } +// TODO does not need to be part of builder, extract into free function +#if false oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str) { str = "# Sound Data\n"; @@ -31,6 +33,8 @@ oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str) return *this; } +#endif + oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::withEffect( oalpp::effects::MonoEffectInterface& effect) { diff --git a/impl/oalpp/sound_data/sound_data_builder.hpp b/impl/oalpp/sound_data/sound_data_builder.hpp index f3b6184..8365bc0 100644 --- a/impl/oalpp/sound_data/sound_data_builder.hpp +++ b/impl/oalpp/sound_data/sound_data_builder.hpp @@ -10,13 +10,33 @@ namespace oalpp { class SoundDataBuilder { public: + /// create SoundData from the builder + /// \return SoundData object [[nodiscard]] SoundData create(); + /// Load SoundData content from file. This will overwrite any previously stored SoundData + /// \param file path to the file + /// \return SoundDataBuilder object (fluent interface) [[nodiscard]] SoundDataBuilder& fromFile(std::string const& file); - [[nodiscard]] SoundDataBuilder& toString(std::string& str); + + /// Apply an effect to the SoundData + /// \param effect effect to be applied + /// \return SoundDataBuilder object (fluent interface) [[nodiscard]] SoundDataBuilder& withEffect(oalpp::effects::MonoEffectInterface& effect); + + /// Use only the left channel of the SoundData. If this is called on any non-stereo SoundData, + /// an exception is raised. + /// \return SoundDataBuilder object (fluent interface) [[nodiscard]] SoundDataBuilder& onlyLeftChannel(); + + /// Use only the right channel of the SoundData. If this is called on any non-stereo SoundData, + /// an exception is raised. + /// \return SoundDataBuilder object (fluent interface) [[nodiscard]] SoundDataBuilder& onlyRightChannel(); + + /// Convert a mono SoundData to a stereo SoundData. If this is called on any non-mono + /// SoundData, an exception is raised. + /// \return SoundDataBuilder object (fluent interface) [[nodiscard]] SoundDataBuilder& toStereo(); private: diff --git a/impl/oalpp/sound_data/sound_data_interface.hpp b/impl/oalpp/sound_data/sound_data_interface.hpp index b4fd341..48404eb 100644 --- a/impl/oalpp/sound_data/sound_data_interface.hpp +++ b/impl/oalpp/sound_data/sound_data_interface.hpp @@ -8,12 +8,22 @@ namespace oalpp { class SoundDataInterface { public: - virtual ~SoundDataInterface() = default; - + /// Get number of channels. This will return 1 for mono and 2 for stereo SoundData + /// \return number of channels virtual int getNumberOfChannels() const = 0; + + /// Get sample rate + /// \return sample rate in Hz virtual int getSampleRate() const = 0; + + /// access samples + /// \return reference to const data virtual std::vector const& getSamples() const = 0; + + // virtual destructor, avoid leaking data + virtual ~SoundDataInterface() = default; + // avoid slicing via polymorphic copy or move SoundDataInterface(SoundDataInterface const& /*other*/) = delete; SoundDataInterface(SoundDataInterface&& /*other*/) = delete; @@ -21,7 +31,7 @@ class SoundDataInterface { SoundDataInterface& operator=(SoundDataInterface&&) = delete; protected: - // allow default construction for derived classes + // allow default construction only for derived classes SoundDataInterface() = default; }; From 76a2faf38f3eeb9cb71432caeeef06e7de33390a Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 08:46:32 +0100 Subject: [PATCH 04/21] Use windows-2022 and start audiosrv --- .github/workflows/test_verification.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 2e2d45e..af303b5 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -107,7 +107,7 @@ jobs: # working-directory: ${{github.workspace}}/build/test/approval_tests Windows: - runs-on: windows-2019 + runs-on: windows-2022 steps: - name: Set up cmake uses: jwlawson/actions-setup-cmake@v1.11 @@ -123,17 +123,11 @@ jobs: working-directory: ${{github.workspace}}/build run: cmake --build . - - name: Install Scream - shell: powershell - run: | - Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.8/Scream3.8.zip -OutFile Scream3.8.zip - Expand-Archive -Path Scream3.8.zip -DestinationPath Scream - Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher - Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream - - name: Copy assets run: cp -r assets ${{github.workspace}}/build/test/unit_tests/Debug + - run: net start audiosrv + - name: Test working-directory: ${{github.workspace}}/build run: test/unit_tests/Debug/OpenALpp_UnitTests.exe --order rand From 57316f42bb758edef17bb02644e6cfcd935f08de Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 08:52:55 +0100 Subject: [PATCH 05/21] enable developer command prompt --- .github/workflows/test_verification.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index af303b5..2ff8aaa 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -116,6 +116,9 @@ jobs: - uses: actions/checkout@v2 + - name: Enable Developer Command Prompt + uses: ilammy/msvc-dev-cmd@v1.12.1 + - name: CMake run: cmake -B ${{github.workspace}}/build . -DOALPP_STATIC_LIBRARY=ON From e663e269ce74f28b079b71250d8cbaf2bc540bdd Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 09:01:08 +0100 Subject: [PATCH 06/21] printf debugging my pipeline --- .github/workflows/test_verification.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 2ff8aaa..558d238 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -118,7 +118,7 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.12.1 - + - name: CMake run: cmake -B ${{github.workspace}}/build . -DOALPP_STATIC_LIBRARY=ON @@ -131,6 +131,18 @@ jobs: - run: net start audiosrv + - name: ls1 + working-directory: ${{github.workspace}}/build + run: ls test/ + + - name: ls2 + working-directory: ${{github.workspace}}/build + run: ls test/unit_tests/ + + - name: ls3 + working-directory: ${{github.workspace}}/build + run: ls test/unit_tests/Debug + - name: Test working-directory: ${{github.workspace}}/build run: test/unit_tests/Debug/OpenALpp_UnitTests.exe --order rand From a4761dd48f0b5b0cfdcba971cd5e67946380736f Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 09:07:07 +0100 Subject: [PATCH 07/21] Fix windows change in output path --- .github/workflows/test_verification.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 558d238..dc4f6ac 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -127,25 +127,13 @@ jobs: run: cmake --build . - name: Copy assets - run: cp -r assets ${{github.workspace}}/build/test/unit_tests/Debug + run: cp -r assets ${{github.workspace}}/build/test/unit_tests/assets - run: net start audiosrv - - name: ls1 - working-directory: ${{github.workspace}}/build - run: ls test/ - - - name: ls2 - working-directory: ${{github.workspace}}/build - run: ls test/unit_tests/ - - - name: ls3 - working-directory: ${{github.workspace}}/build - run: ls test/unit_tests/Debug - - name: Test working-directory: ${{github.workspace}}/build - run: test/unit_tests/Debug/OpenALpp_UnitTests.exe --order rand + run: test/unit_tests/OpenALpp_UnitTests.exe --order rand Web: runs-on: ubuntu-latest From 9d59b50e86d99161ce7296c93aab4f88d52fe16e Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 09:12:53 +0100 Subject: [PATCH 08/21] Try setting up a virtual soundcard --- .github/workflows/test_verification.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index dc4f6ac..80ed42b 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -131,6 +131,9 @@ jobs: - run: net start audiosrv + - name: Setup virtual soundcard + uses: LABSN/sound-ci-helpers@v1.0.1 + - name: Test working-directory: ${{github.workspace}}/build run: test/unit_tests/OpenALpp_UnitTests.exe --order rand From f9bf906f2d26da37bced14cd0a3979f0a40887b7 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 09:21:04 +0100 Subject: [PATCH 09/21] ls to Copy to correct folder --- .github/workflows/test_verification.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 80ed42b..003ce44 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -131,6 +131,12 @@ jobs: - run: net start audiosrv + - name: ls1 + run: ls ${{github.workspace}}/build/test/unit_tests + + - name: ls2 + run: ls ${{github.workspace}}/build/test/unit_tests/assets + - name: Setup virtual soundcard uses: LABSN/sound-ci-helpers@v1.0.1 From 15e03ab77226154c0019a9232c0fb0ea5322e242 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 09:28:25 +0100 Subject: [PATCH 10/21] Execute from local directory to avoid path issues --- .github/workflows/test_verification.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index 003ce44..e59dfc8 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -131,18 +131,12 @@ jobs: - run: net start audiosrv - - name: ls1 - run: ls ${{github.workspace}}/build/test/unit_tests - - - name: ls2 - run: ls ${{github.workspace}}/build/test/unit_tests/assets - - name: Setup virtual soundcard uses: LABSN/sound-ci-helpers@v1.0.1 - name: Test - working-directory: ${{github.workspace}}/build - run: test/unit_tests/OpenALpp_UnitTests.exe --order rand + working-directory: ${{github.workspace}}/build/test/unit_tests + run: OpenALpp_UnitTests.exe --order rand Web: runs-on: ubuntu-latest From aea1f6ea8c1cf36cbd525d51683411d74ff1a403 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 11:33:35 +0100 Subject: [PATCH 11/21] correctly execute executable? --- .github/workflows/test_verification.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index e59dfc8..cd92735 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -136,7 +136,7 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build/test/unit_tests - run: OpenALpp_UnitTests.exe --order rand + run: ./OpenALpp_UnitTests.exe --order rand Web: runs-on: ubuntu-latest From c07fb863c5ff20ef3774ad0ddb8290aeafa9548e Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 11:51:16 +0100 Subject: [PATCH 12/21] clone lfs files --- .github/workflows/test_verification.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_verification.yml b/.github/workflows/test_verification.yml index cd92735..dd4b415 100644 --- a/.github/workflows/test_verification.yml +++ b/.github/workflows/test_verification.yml @@ -114,7 +114,9 @@ jobs: with: cmake-version: '3.19.x' - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + lfs: true - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.12.1 From 80c143015e1bf8045e51f70e0d28103b4f114597 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 12:17:39 +0100 Subject: [PATCH 13/21] try to fix windows ci build for coverage --- .github/workflows/code_coverage.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index a577b83..3f4a447 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -6,7 +6,7 @@ on: branches: [ master ] jobs: run: - runs-on: windows-2019 + runs-on: windows-2022 name: Code Coverage Report steps: - name: Set up cmake @@ -14,7 +14,9 @@ jobs: with: cmake-version: '3.19.x' - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + lfs: true - name: CMake run: cmake -B ${{github.workspace}}/build . -DOALPP_STATIC_LIBRARY=ON -DOALPP_ENABLE_APPROVAL_TESTS=OFF -DOALPP_ENABLE_INTEGRATION_TESTS=OFF @@ -23,13 +25,11 @@ jobs: working-directory: ${{github.workspace}}/build run: cmake --build . - - name: Install Scream - shell: powershell - run: | - Invoke-WebRequest https://github.com/duncanthrax/scream/releases/download/3.8/Scream3.8.zip -OutFile Scream3.8.zip - Expand-Archive -Path Scream3.8.zip -DestinationPath Scream - Import-Certificate -FilePath Scream\Install\driver\x64\Scream.cat -CertStoreLocation Cert:\LocalMachine\TrustedPublisher - Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream + - run: net start audiosrv + + - name: Setup virtual soundcard + uses: LABSN/sound-ci-helpers@v1.0.1 + - name: Setup OpenCppCoverage and add to PATH id: setup_opencppcoverage @@ -37,6 +37,9 @@ jobs: choco install OpenCppCoverage -y echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH + - name: Copy assets + run: cp -r assets ${{github.workspace}}/build/test/unit_tests/Debug + - name: Generate Report id: generate_test_report working-directory: ${{github.workspace}}/build From 4b9275173c81aa394ce7ea6b729995b6f4c6c264 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 12:21:39 +0100 Subject: [PATCH 14/21] try to fix windows ci build for coverage --- .github/workflows/code_coverage.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index 3f4a447..3bc7e43 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -14,6 +14,9 @@ jobs: with: cmake-version: '3.19.x' + - name: Enable Developer Command Prompt + uses: ilammy/msvc-dev-cmd@v1.12.1 + - uses: actions/checkout@v4 with: lfs: true From 5523f420ebc0314b7d6640a5cd4e4c56ee642ef2 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 12:50:56 +0100 Subject: [PATCH 15/21] call executable from correct path --- .github/workflows/code_coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index 3bc7e43..5cbba24 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -45,9 +45,9 @@ jobs: - name: Generate Report id: generate_test_report - working-directory: ${{github.workspace}}/build + working-directory: ${{github.workspace}}/build/test/unit_tests shell: cmd - run: OpenCppCoverage.exe --export_type cobertura:OpenALppCoverage.xml --sources ${{github.workspace}}\impl --excluded_sources ${{github.workspace}}\build\test\ --excluded_sources ${{github.workspace}}\build\ext\* --excluded_sources ${{github.workspace}}\build ${{github.workspace}}\build\test\unit_tests\Debug\OpenALpp_UnitTests.exe + run: OpenCppCoverage.exe --export_type cobertura:${{github.workspace}}/build/OpenALppCoverage.xml --sources ${{github.workspace}}\impl --excluded_sources ${{github.workspace}}\build\test\ --excluded_sources ${{github.workspace}}\build\ext\* --excluded_sources ${{github.workspace}}\build ${{github.workspace}}\build\test\unit_tests\OpenALpp_UnitTests.exe - name: Upload Report to Codecov uses: codecov/codecov-action@v2 From 0e3a137d5209fbea2625ede80e8bbe1de3f229fd Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 13:01:05 +0100 Subject: [PATCH 16/21] call executable from correct path --- .github/workflows/code_coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index 5cbba24..deaa604 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -41,7 +41,7 @@ jobs: echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH - name: Copy assets - run: cp -r assets ${{github.workspace}}/build/test/unit_tests/Debug + run: cp -r assets ${{github.workspace}}/build/test/unit_tests/assets - name: Generate Report id: generate_test_report From 98e6d46b750b5973a78a01beb6caebb7e0233c7f Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 20:05:59 +0100 Subject: [PATCH 17/21] Use CMP instead of FetchContent for external libraries --- ext/CMakeLists.txt | 47 ++++++++++++++++++++++++++--- ext/approvaltestscpp/CMakeLists.txt | 9 ------ ext/catch2/CMakeLists.txt | 9 ------ ext/libnyquist/CMakeLists.txt | 11 ------- ext/openal-soft/CMakeLists.txt | 14 --------- 5 files changed, 43 insertions(+), 47 deletions(-) delete mode 100644 ext/approvaltestscpp/CMakeLists.txt delete mode 100644 ext/catch2/CMakeLists.txt delete mode 100644 ext/libnyquist/CMakeLists.txt delete mode 100644 ext/openal-soft/CMakeLists.txt diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index c16dc88..973b42f 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -1,14 +1,53 @@ +message(STATUS "Add CPM.cmake") +# download CPM.cmake +file( + DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.6/CPM.cmake + ${CMAKE_BINARY_DIR}/cmake/CPM.cmake + EXPECTED_HASH SHA256=11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07 +) +include(${CMAKE_BINARY_DIR}/cmake/CPM.cmake) + +message(STATUS "Fetching external libraries started") + + if (NOT EMSCRIPTEN) - add_subdirectory(openal-soft) + message(STATUS "Fetching openal-soft") + CPMAddPackage( + NAME openal-soft + GITHUB_REPOSITORY kcat/openal-soft + GIT_TAG 1.21.1 + OPTIONS + "ALSOFT_UTILS OFF" + "ALSOFT_EXAMPLES OFF" + "ALSOFT_UPDATE_BUILD_VERSION OFF" + ) endif () -add_subdirectory(libnyquist) +message(STATUS "Fetching libnyquist") +CPMAddPackage( + NAME libnyquist + GITHUB_REPOSITORY ddiakopoulos/libnyquist + GIT_TAG master + OPTIONS + "LIBNYQUIST_BUILD_EXAMPLE OFF" +) if (OALPP_ENABLE_UNIT_TESTS) - add_subdirectory(catch2) + message(STATUS "Fetching catch2") + CPMAddPackage( + NAME catch2 + GITHUB_REPOSITORY catchorg/Catch2 + GIT_TAG v2.13.8 + ) endif () if (OALPP_ENABLE_APPROVAL_TESTS) - add_subdirectory(approvaltestscpp) + message(STATUS "Fetching approvaltests") + CPMAddPackage( + NAME approvaltests + GITHUB_REPOSITORY approvals/ApprovalTests.cpp + GIT_TAG v.10.12.2 + ) endif () diff --git a/ext/approvaltestscpp/CMakeLists.txt b/ext/approvaltestscpp/CMakeLists.txt deleted file mode 100644 index e530c0d..0000000 --- a/ext/approvaltestscpp/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -message(STATUS "Fetching approvaltests") -include(FetchContent) - -FetchContent_Declare( - approvaltests - GIT_REPOSITORY https://github.com/approvals/ApprovalTests.cpp - GIT_TAG v.10.12.2 -) -FetchContent_MakeAvailable(approvaltests) diff --git a/ext/catch2/CMakeLists.txt b/ext/catch2/CMakeLists.txt deleted file mode 100644 index 4b5c996..0000000 --- a/ext/catch2/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -message(STATUS "Fetching catch2") -include(FetchContent) - -FetchContent_Declare( - catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2 - GIT_TAG v2.13.8 -) -FetchContent_MakeAvailable(catch2) diff --git a/ext/libnyquist/CMakeLists.txt b/ext/libnyquist/CMakeLists.txt deleted file mode 100644 index ecfc597..0000000 --- a/ext/libnyquist/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -message(STATUS "Fetching libnyquist") -include(FetchContent) - -set(LIBNYQUIST_BUILD_EXAMPLE OFF CACHE BOOL "") - -FetchContent_Declare( - libnyquist - GIT_REPOSITORY https://github.com/ddiakopoulos/libnyquist - GIT_TAG master -) -FetchContent_MakeAvailable(libnyquist) diff --git a/ext/openal-soft/CMakeLists.txt b/ext/openal-soft/CMakeLists.txt deleted file mode 100644 index a99742f..0000000 --- a/ext/openal-soft/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -message(STATUS "Fetching openal-soft") -include(FetchContent) - -set(ALSOFT_UTILS OFF CACHE BOOL "") -set(ALSOFT_EXAMPLES OFF CACHE BOOL "") -set(ALSOFT_UPDATE_BUILD_VERSION OFF CACHE BOOL "") - -FetchContent_Declare( - openal-soft - GIT_REPOSITORY https://github.com/kcat/openal-soft - GIT_TAG 1.21.1 -) - -FetchContent_MakeAvailable(openal-soft) From 468a563bc182da32d5e88d927a5b5ff10dab458a Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 20:11:44 +0100 Subject: [PATCH 18/21] Add documentation --- impl/oalpp/sound_data/sound_data.hpp | 1 - impl/oalpp/sound_data/sound_data_builder.cpp | 28 ++++--------------- impl/oalpp/sound_data/sound_data_builder.hpp | 2 +- impl/oalpp/sound_data/sound_data_helper.cpp | 19 +++++++++++++ impl/oalpp/sound_data/sound_data_helper.hpp | 13 +++++++++ .../oalpp/sound_data/sound_data_interface.hpp | 4 +-- 6 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 impl/oalpp/sound_data/sound_data_helper.cpp create mode 100644 impl/oalpp/sound_data/sound_data_helper.hpp diff --git a/impl/oalpp/sound_data/sound_data.hpp b/impl/oalpp/sound_data/sound_data.hpp index 1824901..60b5dba 100644 --- a/impl/oalpp/sound_data/sound_data.hpp +++ b/impl/oalpp/sound_data/sound_data.hpp @@ -17,7 +17,6 @@ class SoundData : public SoundDataInterface { SoundData& operator=(SoundData const&) = delete; SoundData& operator=(SoundData&&) noexcept; - int getNumberOfChannels() const override; int getSampleRate() const override; std::vector const& getSamples() const override; diff --git a/impl/oalpp/sound_data/sound_data_builder.cpp b/impl/oalpp/sound_data/sound_data_builder.cpp index 69a6871..1f7768c 100644 --- a/impl/oalpp/sound_data/sound_data_builder.cpp +++ b/impl/oalpp/sound_data/sound_data_builder.cpp @@ -1,6 +1,11 @@ #include "sound_data_builder.hpp" #include +oalpp::SoundData oalpp::SoundDataBuilder::create() const +{ + return oalpp::SoundData { m_data, m_sampleRate, m_numberOfChannels }; +} + oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::fromFile(std::string const& file) { nqr::NyquistIO loader; @@ -12,29 +17,6 @@ oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::fromFile(std::string const& fi return *this; } -oalpp::SoundData oalpp::SoundDataBuilder::create() -{ - return oalpp::SoundData { m_data, m_sampleRate, m_numberOfChannels }; -} - -// TODO does not need to be part of builder, extract into free function -#if false -oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str) -{ - str = "# Sound Data\n"; - str += "# sampleRate: " + std::to_string(m_sampleRate) + "\n"; - str += "# numberOfChannels: " + std::to_string(m_numberOfChannels) + "\n"; - - for (auto index = 0U; index != m_data.size(); ++index) { - str += std::to_string(index) + " " + std::to_string(m_data[index]) + "\n"; - } - str += "\n"; - - return *this; -} - -#endif - oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::withEffect( oalpp::effects::MonoEffectInterface& effect) { diff --git a/impl/oalpp/sound_data/sound_data_builder.hpp b/impl/oalpp/sound_data/sound_data_builder.hpp index 8365bc0..4e9af46 100644 --- a/impl/oalpp/sound_data/sound_data_builder.hpp +++ b/impl/oalpp/sound_data/sound_data_builder.hpp @@ -12,7 +12,7 @@ class SoundDataBuilder { public: /// create SoundData from the builder /// \return SoundData object - [[nodiscard]] SoundData create(); + [[nodiscard]] SoundData create() const; /// Load SoundData content from file. This will overwrite any previously stored SoundData /// \param file path to the file diff --git a/impl/oalpp/sound_data/sound_data_helper.cpp b/impl/oalpp/sound_data/sound_data_helper.cpp new file mode 100644 index 0000000..0785a30 --- /dev/null +++ b/impl/oalpp/sound_data/sound_data_helper.cpp @@ -0,0 +1,19 @@ +#include "sound_data_helper.hpp" + +namespace oalpp { + +std::string to_string(SoundData const& soundData) +{ + std::string str = "# Sound Data\n"; + str += "# sampleRate: " + std::to_string(soundData.getSampleRate()) + "\n"; + str += "# numberOfChannels: " + std::to_string(soundData.getNumberOfChannels()) + "\n"; + + for (auto index = 0U; index != soundData.getSamples().size(); ++index) { + str += std::to_string(index) + " " + std::to_string(soundData.getSamples()[index]) + "\n"; + } + str += "\n"; + + return str; +} + +} // namespace oalpp diff --git a/impl/oalpp/sound_data/sound_data_helper.hpp b/impl/oalpp/sound_data/sound_data_helper.hpp new file mode 100644 index 0000000..8434d5f --- /dev/null +++ b/impl/oalpp/sound_data/sound_data_helper.hpp @@ -0,0 +1,13 @@ +#ifndef SOUND_DATA_HELPER_HPP +#define SOUND_DATA_HELPER_HPP + +#include +#include + +namespace oalpp { + +std::string to_string(SoundData const& soundData); + +} // namespace oalpp + +#endif // SOUND_DATA_HELPER_HPP diff --git a/impl/oalpp/sound_data/sound_data_interface.hpp b/impl/oalpp/sound_data/sound_data_interface.hpp index 48404eb..ed2a19a 100644 --- a/impl/oalpp/sound_data/sound_data_interface.hpp +++ b/impl/oalpp/sound_data/sound_data_interface.hpp @@ -1,7 +1,6 @@ #ifndef OPENALPP_SOUND_DATA_INTERFACE_HPP #define OPENALPP_SOUND_DATA_INTERFACE_HPP -#include #include namespace oalpp { @@ -16,11 +15,10 @@ class SoundDataInterface { /// \return sample rate in Hz virtual int getSampleRate() const = 0; - /// access samples + /// Read access to samples /// \return reference to const data virtual std::vector const& getSamples() const = 0; - // virtual destructor, avoid leaking data virtual ~SoundDataInterface() = default; From fd26207d6745cd44e7c2d3d10ae13562f8acd14f Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 20:36:21 +0100 Subject: [PATCH 19/21] Add missing test cases --- test/unit_tests/sound_data_builder_test.cpp | 16 ++++++++++++ test/unit_tests/sound_data_test.cpp | 27 +++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/unit_tests/sound_data_test.cpp diff --git a/test/unit_tests/sound_data_builder_test.cpp b/test/unit_tests/sound_data_builder_test.cpp index 641accf..431c480 100644 --- a/test/unit_tests/sound_data_builder_test.cpp +++ b/test/unit_tests/sound_data_builder_test.cpp @@ -115,6 +115,22 @@ TEST_CASE("SoundDataBuilder", "[SoundDataBuilder]") REQUIRE(samples_loaded == samples_expected); } + SECTION("With Gain Effect") + { + oalpp::effects::utility::Gain gain { 0.5f }; + oalpp::SoundData const data + = builder.fromFile("assets/test_mono.mp3").withEffect(gain).create(); + + REQUIRE(data.getNumberOfChannels() == 1); + REQUIRE(data.getSampleRate() == 44100); + + for (auto& s : samples_expected) { + s *= 0.5f; + } + auto const& samples_loaded = data.getSamples(); + REQUIRE(samples_loaded == samples_expected); + } + SECTION("Mono To Stereo") { oalpp::SoundData const data diff --git a/test/unit_tests/sound_data_test.cpp b/test/unit_tests/sound_data_test.cpp new file mode 100644 index 0000000..91bfd19 --- /dev/null +++ b/test/unit_tests/sound_data_test.cpp @@ -0,0 +1,27 @@ +#include +#include + +TEST_CASE("SoundData Move constructor", "[SoundData]") +{ + oalpp::SoundData data1 { std::vector { 1.0f, 2.0f }, 44100, 2 }; + oalpp::SoundData data2 { std::move(data1) }; + REQUIRE(data2.getSamples().size() == 2); + REQUIRE(data2.getSamples().at(0) == 1.0f); + REQUIRE(data2.getSamples().at(1) == 2.0f); + + REQUIRE(data2.getSampleRate() == 44100); + REQUIRE(data2.getNumberOfChannels() == 2); +} + +TEST_CASE("SoundData Move assignment operator", "[SoundData]") +{ + oalpp::SoundData data1 { std::vector { 1.0f, 2.0f }, 44100, 2 }; + oalpp::SoundData data2 = std::move(data1); + + REQUIRE(data2.getSamples().size() == 2); + REQUIRE(data2.getSamples().at(0) == 1.0f); + REQUIRE(data2.getSamples().at(1) == 2.0f); + + REQUIRE(data2.getSampleRate() == 44100); + REQUIRE(data2.getNumberOfChannels() == 2); +} From cdc5b7d73acd3c1f66890be5548a9be31512fb77 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 20:46:42 +0100 Subject: [PATCH 20/21] Try to trigger move assignment operator --- test/unit_tests/sound_data_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit_tests/sound_data_test.cpp b/test/unit_tests/sound_data_test.cpp index 91bfd19..40b494e 100644 --- a/test/unit_tests/sound_data_test.cpp +++ b/test/unit_tests/sound_data_test.cpp @@ -16,7 +16,8 @@ TEST_CASE("SoundData Move constructor", "[SoundData]") TEST_CASE("SoundData Move assignment operator", "[SoundData]") { oalpp::SoundData data1 { std::vector { 1.0f, 2.0f }, 44100, 2 }; - oalpp::SoundData data2 = std::move(data1); + oalpp::SoundData data2 { std::vector {}, 100, 1 }; + data2 = std::move(data1); REQUIRE(data2.getSamples().size() == 2); REQUIRE(data2.getSamples().at(0) == 1.0f); From a30d440674673282021eb23e3eccf95abf4f7952 Mon Sep 17 00:00:00 2001 From: Simon Weis Date: Mon, 18 Dec 2023 20:56:12 +0100 Subject: [PATCH 21/21] Fix include quotation marks --- impl/oalpp/effects/distortion/decimator.hpp | 2 +- .../effects/distortion/tanh_distortion.hpp | 2 +- .../filter/butterworth_24db_lowpass.hpp | 2 +- .../effects/filter/moog_filter_stilson.hpp | 2 +- impl/oalpp/effects/filter/simple_highpass.hpp | 2 +- impl/oalpp/effects/filter/simple_lowpass.hpp | 2 +- impl/oalpp/effects/utility/convolution.cpp | 2 +- impl/oalpp/effects/utility/convolution.hpp | 2 +- impl/oalpp/effects/utility/effect_chain.hpp | 2 +- impl/oalpp/effects/utility/gain.hpp | 2 +- impl/oalpp/effects/utility/phase_flip.hpp | 4 +++- impl/oalpp/sound.hpp | 2 +- impl/oalpp/sound/sound.cpp | 2 +- impl/oalpp/sound/sound.hpp | 6 +++--- impl/oalpp/sound_context.hpp | 2 +- impl/oalpp/sound_context/sound_context.cpp | 2 +- impl/oalpp/sound_context/sound_context.hpp | 4 ++-- impl/oalpp/sound_data/sound_data.cpp | 1 - impl/oalpp/sound_data/sound_data.hpp | 2 +- impl/oalpp/sound_data/sound_data_builder.hpp | 2 +- test/approval_tests/approval_test_helpers.hpp | 1 + .../effect_convolution_test.cpp | 6 +++--- test/approval_tests/effect_gain_test.cpp | 6 +++--- .../approval_tests/effect_phase_flip_test.cpp | 6 +++--- test/integration_tests/main.cpp | 9 ++++----- test/unit_tests/audio_exceptions_test.cpp | 4 ++-- test/unit_tests/main.cpp | 2 +- test/unit_tests/sound_context_test.cpp | 4 ++-- test/unit_tests/sound_data_builder_test.cpp | 6 +++--- test/unit_tests/sound_data_fake.hpp | 2 +- test/unit_tests/sound_effects_test.cpp | 20 +++++++++---------- test/unit_tests/sound_test.cpp | 6 +++--- 32 files changed, 60 insertions(+), 59 deletions(-) diff --git a/impl/oalpp/effects/distortion/decimator.hpp b/impl/oalpp/effects/distortion/decimator.hpp index 47e257e..147d4e5 100644 --- a/impl/oalpp/effects/distortion/decimator.hpp +++ b/impl/oalpp/effects/distortion/decimator.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_DISTORTION_DECIMATOR_HPP #define OPENALPP_EFFECTS_DISTORTION_DECIMATOR_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/distortion/tanh_distortion.hpp b/impl/oalpp/effects/distortion/tanh_distortion.hpp index 546083a..6565755 100644 --- a/impl/oalpp/effects/distortion/tanh_distortion.hpp +++ b/impl/oalpp/effects/distortion/tanh_distortion.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_DISTORTION_TANH_DISTORTION_HPP #define OPENALPP_EFFECTS_DISTORTION_TANH_DISTORTION_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/filter/butterworth_24db_lowpass.hpp b/impl/oalpp/effects/filter/butterworth_24db_lowpass.hpp index 5bf314f..fd5624b 100644 --- a/impl/oalpp/effects/filter/butterworth_24db_lowpass.hpp +++ b/impl/oalpp/effects/filter/butterworth_24db_lowpass.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_FILTER_BUTTERWORTH_24_D_B_HPP #define OPENALPP_EFFECTS_FILTER_BUTTERWORTH_24_D_B_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/filter/moog_filter_stilson.hpp b/impl/oalpp/effects/filter/moog_filter_stilson.hpp index f92728c..f224141 100644 --- a/impl/oalpp/effects/filter/moog_filter_stilson.hpp +++ b/impl/oalpp/effects/filter/moog_filter_stilson.hpp @@ -5,7 +5,7 @@ // 6.14.2019 David Lowenfels stated "You're welcome to use the Moog~ code, // license it free as in beer or whatever :)" -#include "oalpp/effects/mono_effect_interface.hpp" +#include #include namespace oalpp { diff --git a/impl/oalpp/effects/filter/simple_highpass.hpp b/impl/oalpp/effects/filter/simple_highpass.hpp index 0a9c429..fc8d2f8 100644 --- a/impl/oalpp/effects/filter/simple_highpass.hpp +++ b/impl/oalpp/effects/filter/simple_highpass.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_FILTER_SIMPLE_HIGHPASS_HPP #define OPENALPP_EFFECTS_FILTER_SIMPLE_HIGHPASS_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/filter/simple_lowpass.hpp b/impl/oalpp/effects/filter/simple_lowpass.hpp index 7319831..f9b4e6c 100644 --- a/impl/oalpp/effects/filter/simple_lowpass.hpp +++ b/impl/oalpp/effects/filter/simple_lowpass.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_FILTER_SIMPLE_LOWPASS_HPP #define OPENALPP_EFFECTS_FILTER_SIMPLE_LOWPASS_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/utility/convolution.cpp b/impl/oalpp/effects/utility/convolution.cpp index 8d8762b..ac6246b 100644 --- a/impl/oalpp/effects/utility/convolution.cpp +++ b/impl/oalpp/effects/utility/convolution.cpp @@ -1,7 +1,7 @@ #include "convolution.hpp" -#include "dj_fft.h" #include #include +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/utility/convolution.hpp b/impl/oalpp/effects/utility/convolution.hpp index 56b8805..ac9013a 100644 --- a/impl/oalpp/effects/utility/convolution.hpp +++ b/impl/oalpp/effects/utility/convolution.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_CONVOLUTION_HPP #define OPENALPP_CONVOLUTION_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include #include #include diff --git a/impl/oalpp/effects/utility/effect_chain.hpp b/impl/oalpp/effects/utility/effect_chain.hpp index e16e85b..59b0475 100644 --- a/impl/oalpp/effects/utility/effect_chain.hpp +++ b/impl/oalpp/effects/utility/effect_chain.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_UTILITY_EFFECT_CHAIN_HPP #define OPENALPP_EFFECTS_UTILITY_EFFECT_CHAIN_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include #include #include diff --git a/impl/oalpp/effects/utility/gain.hpp b/impl/oalpp/effects/utility/gain.hpp index 93bef9d..3db2885 100644 --- a/impl/oalpp/effects/utility/gain.hpp +++ b/impl/oalpp/effects/utility/gain.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_EFFECTS_UTILITY_GAIN_HPP #define OPENALPP_EFFECTS_UTILITY_GAIN_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { diff --git a/impl/oalpp/effects/utility/phase_flip.hpp b/impl/oalpp/effects/utility/phase_flip.hpp index cd8198a..a0592c8 100644 --- a/impl/oalpp/effects/utility/phase_flip.hpp +++ b/impl/oalpp/effects/utility/phase_flip.hpp @@ -1,15 +1,17 @@ #ifndef OPENALPP_EFFECTS_UTILITY_PHASE_FLIP_HPP #define OPENALPP_EFFECTS_UTILITY_PHASE_FLIP_HPP -#include "oalpp/effects/mono_effect_interface.hpp" +#include namespace oalpp { namespace effects { namespace utility { + class PhaseFlip : public oalpp::effects::MonoEffectInterface { public: std::vector process(std::vector const& input) override; }; + } // namespace utility } // namespace effects } // namespace oalpp diff --git a/impl/oalpp/sound.hpp b/impl/oalpp/sound.hpp index 0defd91..c17f944 100644 --- a/impl/oalpp/sound.hpp +++ b/impl/oalpp/sound.hpp @@ -1,6 +1,6 @@ #ifndef OPENALPP_SOUND_INCLUDE_HPP #define OPENALPP_SOUND_INCLUDE_HPP -#include "oalpp/sound/sound.hpp" +#include #endif // OPENALPP_SOUND_INCLUDE_HPP diff --git a/impl/oalpp/sound/sound.cpp b/impl/oalpp/sound/sound.cpp index 07c8c1d..f748a7a 100644 --- a/impl/oalpp/sound/sound.cpp +++ b/impl/oalpp/sound/sound.cpp @@ -1,5 +1,5 @@ #include "sound.hpp" -#include "oalpp/common/audio_exceptions.hpp" +#include #include #include #include diff --git a/impl/oalpp/sound/sound.hpp b/impl/oalpp/sound/sound.hpp index 78fc5e9..95dbaf0 100644 --- a/impl/oalpp/sound/sound.hpp +++ b/impl/oalpp/sound/sound.hpp @@ -1,9 +1,9 @@ #ifndef OPENALPP_SOUND_HPP #define OPENALPP_SOUND_HPP -#include "oalpp/common/al.hpp" -#include "oalpp/sound_data/sound_data_interface.hpp" -#include "position.hpp" +#include +#include +#include #include #include diff --git a/impl/oalpp/sound_context.hpp b/impl/oalpp/sound_context.hpp index 56f5e40..e1d337e 100644 --- a/impl/oalpp/sound_context.hpp +++ b/impl/oalpp/sound_context.hpp @@ -1,6 +1,6 @@ #ifndef OPENALPP_SOUND_CONTEXT_INCLUDE_HPP #define OPENALPP_SOUND_CONTEXT_INCLUDE_HPP -#include "oalpp/sound_context/sound_context.hpp" +#include #endif // OPENALPP_SOUND_CONTEXT_INCLUDE_HPP diff --git a/impl/oalpp/sound_context/sound_context.cpp b/impl/oalpp/sound_context/sound_context.cpp index 9968cd4..8234131 100644 --- a/impl/oalpp/sound_context/sound_context.cpp +++ b/impl/oalpp/sound_context/sound_context.cpp @@ -1,5 +1,5 @@ #include "sound_context.hpp" -#include "oalpp/common/audio_exceptions.hpp" +#include namespace oalpp { diff --git a/impl/oalpp/sound_context/sound_context.hpp b/impl/oalpp/sound_context/sound_context.hpp index 1a1711e..6c00d50 100644 --- a/impl/oalpp/sound_context/sound_context.hpp +++ b/impl/oalpp/sound_context/sound_context.hpp @@ -1,8 +1,8 @@ #ifndef OPENALPP_SOUND_CONTEXT_HPP #define OPENALPP_SOUND_CONTEXT_HPP -#include "oalpp/common/alc.hpp" -#include "sound_context_interface.hpp" +#include +#include #include #include #include diff --git a/impl/oalpp/sound_data/sound_data.cpp b/impl/oalpp/sound_data/sound_data.cpp index 0b9776f..66497d0 100644 --- a/impl/oalpp/sound_data/sound_data.cpp +++ b/impl/oalpp/sound_data/sound_data.cpp @@ -1,5 +1,4 @@ #include "sound_data.hpp" -#include "libnyquist/Decoders.h" #include namespace oalpp { diff --git a/impl/oalpp/sound_data/sound_data.hpp b/impl/oalpp/sound_data/sound_data.hpp index 60b5dba..5f924da 100644 --- a/impl/oalpp/sound_data/sound_data.hpp +++ b/impl/oalpp/sound_data/sound_data.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_SOUND_DATA_HPP #define OPENALPP_SOUND_DATA_HPP -#include "sound_data_interface.hpp" +#include namespace oalpp { diff --git a/impl/oalpp/sound_data/sound_data_builder.hpp b/impl/oalpp/sound_data/sound_data_builder.hpp index 4e9af46..5b9f44a 100644 --- a/impl/oalpp/sound_data/sound_data_builder.hpp +++ b/impl/oalpp/sound_data/sound_data_builder.hpp @@ -1,7 +1,7 @@ #ifndef SOUND_DATA_BUILDER_HPP #define SOUND_DATA_BUILDER_HPP -#include "oalpp/effects/utility/gain.hpp" +#include #include #include #include diff --git a/test/approval_tests/approval_test_helpers.hpp b/test/approval_tests/approval_test_helpers.hpp index 3364336..dbfed3f 100644 --- a/test/approval_tests/approval_test_helpers.hpp +++ b/test/approval_tests/approval_test_helpers.hpp @@ -1,5 +1,6 @@ #ifndef OPENALPP_APPROVAL_TEST_HELPERS_HPP #define OPENALPP_APPROVAL_TEST_HELPERS_HPP + #include struct ApprovalTestHelpers { diff --git a/test/approval_tests/effect_convolution_test.cpp b/test/approval_tests/effect_convolution_test.cpp index fe9a580..ac58529 100644 --- a/test/approval_tests/effect_convolution_test.cpp +++ b/test/approval_tests/effect_convolution_test.cpp @@ -1,8 +1,8 @@ #include "ApprovalTests/ApprovalTests.hpp" #include "approval_test_helpers.hpp" -#include "catch2/catch.hpp" -#include "oalpp/effects/utility/convolution.hpp" -#include "oalpp/sound_data.hpp" +#include +#include +#include TEST_CASE("convolution") { diff --git a/test/approval_tests/effect_gain_test.cpp b/test/approval_tests/effect_gain_test.cpp index 3ad2c03..53a90be 100644 --- a/test/approval_tests/effect_gain_test.cpp +++ b/test/approval_tests/effect_gain_test.cpp @@ -1,7 +1,7 @@ #include "ApprovalTests/ApprovalTests.hpp" -#include "catch2/catch.hpp" -#include "oalpp/effects/utility/gain.hpp" -#include "oalpp/sound_data.hpp" +#include +#include +#include TEST_CASE("gain") { diff --git a/test/approval_tests/effect_phase_flip_test.cpp b/test/approval_tests/effect_phase_flip_test.cpp index 5bcf5f4..d6d3a8a 100644 --- a/test/approval_tests/effect_phase_flip_test.cpp +++ b/test/approval_tests/effect_phase_flip_test.cpp @@ -1,7 +1,7 @@ #include "ApprovalTests/ApprovalTests.hpp" -#include "catch2/catch.hpp" -#include "oalpp/effects/utility/phase_flip.hpp" -#include "oalpp/sound_data.hpp" +#include +#include +#include TEST_CASE("phase_flip") { diff --git a/test/integration_tests/main.cpp b/test/integration_tests/main.cpp index a3888ac..c9505f3 100644 --- a/test/integration_tests/main.cpp +++ b/test/integration_tests/main.cpp @@ -1,8 +1,7 @@ -#include "oalpp/effects/filter/moog_filter_stilson.hpp" -#include "oalpp/sound/sound.hpp" -#include "oalpp/sound_context.hpp" -#include "oalpp/sound_data/sound_data_builder.hpp" - +#include +#include +#include +#include #include #include #ifdef __EMSCRIPTEN__ diff --git a/test/unit_tests/audio_exceptions_test.cpp b/test/unit_tests/audio_exceptions_test.cpp index 8752774..165b5f9 100644 --- a/test/unit_tests/audio_exceptions_test.cpp +++ b/test/unit_tests/audio_exceptions_test.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" -#include "oalpp/common/audio_exceptions.hpp" +#include +#include TEST_CASE("AudioException returns correct message on what", "[Audio Exception]") { diff --git a/test/unit_tests/main.cpp b/test/unit_tests/main.cpp index 8e686aa..d156bbb 100644 --- a/test/unit_tests/main.cpp +++ b/test/unit_tests/main.cpp @@ -1,5 +1,5 @@ #define CATCH_CONFIG_RUNNER -#include "catch2/catch.hpp" +#include int main(int argc, char* argv[]) { diff --git a/test/unit_tests/sound_context_test.cpp b/test/unit_tests/sound_context_test.cpp index f737e7a..ff40f63 100644 --- a/test/unit_tests/sound_context_test.cpp +++ b/test/unit_tests/sound_context_test.cpp @@ -1,5 +1,5 @@ -#include "catch2/catch.hpp" -#include "oalpp/sound_context/sound_context.hpp" +#include +#include using namespace oalpp; diff --git a/test/unit_tests/sound_data_builder_test.cpp b/test/unit_tests/sound_data_builder_test.cpp index 431c480..4b13244 100644 --- a/test/unit_tests/sound_data_builder_test.cpp +++ b/test/unit_tests/sound_data_builder_test.cpp @@ -1,6 +1,6 @@ -#include "catch2/catch.hpp" -#include "oalpp/effects/utility/effect_chain.hpp" -#include "oalpp/effects/utility/gain.hpp" +#include +#include +#include #include #include #include diff --git a/test/unit_tests/sound_data_fake.hpp b/test/unit_tests/sound_data_fake.hpp index 222e395..dead4d6 100644 --- a/test/unit_tests/sound_data_fake.hpp +++ b/test/unit_tests/sound_data_fake.hpp @@ -1,7 +1,7 @@ #ifndef OPENALPP_SOUND_DATA_FAKE_HPP #define OPENALPP_SOUND_DATA_FAKE_HPP -#include "oalpp/sound_data/sound_data_interface.hpp" +#include class SoundDataMonoFake : public oalpp::SoundDataInterface { public: diff --git a/test/unit_tests/sound_effects_test.cpp b/test/unit_tests/sound_effects_test.cpp index 6f89dfe..13f56d1 100644 --- a/test/unit_tests/sound_effects_test.cpp +++ b/test/unit_tests/sound_effects_test.cpp @@ -1,13 +1,13 @@ -#include "catch2/catch.hpp" -#include "oalpp/effects/distortion/decimator.hpp" -#include "oalpp/effects/distortion/tanh_distortion.hpp" -#include "oalpp/effects/filter/butterworth_24db_lowpass.hpp" -#include "oalpp/effects/filter/simple_highpass.hpp" -#include "oalpp/effects/filter/simple_lowpass.hpp" -#include "oalpp/effects/utility/convolution.hpp" -#include "oalpp/effects/utility/effect_chain.hpp" -#include "oalpp/effects/utility/gain.hpp" -#include "oalpp/effects/utility/phase_flip.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include TEST_CASE("SoundEffect returns zero on zero input", "[SoundEffect]") { diff --git a/test/unit_tests/sound_test.cpp b/test/unit_tests/sound_test.cpp index bcf4fae..8de393e 100644 --- a/test/unit_tests/sound_test.cpp +++ b/test/unit_tests/sound_test.cpp @@ -1,7 +1,7 @@ -#include "catch2/catch.hpp" -#include "oalpp/sound/sound.hpp" -#include "oalpp/sound_context/sound_context.hpp" #include "sound_data_fake.hpp" +#include +#include +#include using namespace oalpp;