diff --git a/codecov.yml b/codecov.yml index b590ac6..639bd40 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,4 +7,5 @@ coverage: ignore: - src/Utils/ - - samples/ \ No newline at end of file + - samples/ + - tools/ diff --git a/src/Core/AudioBuffer.cpp b/src/Core/AudioBuffer.cpp index a7ee3d8..19175a5 100644 --- a/src/Core/AudioBuffer.cpp +++ b/src/Core/AudioBuffer.cpp @@ -211,7 +211,7 @@ namespace SparkyStudios::Audio::Amplitude buffer._frameCount = 0; buffer._channels.clear(); - buffer._data.Clear(); + buffer._data.Release(); } AudioBuffer::~AudioBuffer() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e6de530..c666647 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,8 @@ add_executable(${PROJECT_NAME} math.cpp room.cpp shape.cpp - zone.cpp) + zone.cpp + audio_buffer.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2 Static) add_custom_target(ss_amplitude_audio_test_package diff --git a/tests/audio_buffer.cpp b/tests/audio_buffer.cpp new file mode 100644 index 0000000..be17843 --- /dev/null +++ b/tests/audio_buffer.cpp @@ -0,0 +1,117 @@ +// Copyright (c) 2024-present Sparky Studios. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include + +using namespace SparkyStudios::Audio::Amplitude; + +TEST_CASE("AudioBuffer Tests", "[audio_buffer][core][amplitude]") +{ + SECTION("can be created") + { + AudioBuffer buffer1; + REQUIRE(buffer1.IsEmpty()); + + AudioBuffer buffer2(12345, 3); + REQUIRE_FALSE(buffer2.IsEmpty()); + REQUIRE(buffer2.GetFrameCount() == 12345); + REQUIRE(buffer2.GetChannelCount() == 3); + + for (AmSize i = 0, l = buffer2.GetChannelCount(); i < l; ++i) + REQUIRE(buffer2[i].enabled()); + + AudioBuffer buffer3(std::move(buffer2)); + REQUIRE_FALSE(buffer3.IsEmpty()); + REQUIRE(buffer3.GetFrameCount() == 12345); + REQUIRE(buffer3.GetChannelCount() == 3); + REQUIRE(buffer2.IsEmpty()); + + for (AmSize i = 0, l = buffer3.GetChannelCount(); i < l; ++i) + REQUIRE(buffer3[i].enabled()); + + AudioBuffer buffer4; + buffer4 = buffer3; + REQUIRE_FALSE(buffer4.IsEmpty()); + REQUIRE(buffer4.GetFrameCount() == buffer3.GetFrameCount()); + REQUIRE(buffer4.GetChannelCount() == buffer3.GetChannelCount()); + + for (AmSize i = 0, l = buffer4.GetChannelCount(); i < l; ++i) + REQUIRE(buffer4[i].enabled()); + } + + SECTION("can make operations on channels") + { + AudioBuffer buffer1(123, 2); + const AmSize alignedSize = FindNextAlignedArrayIndex(123, AM_SIMD_ALIGNMENT); + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; j++) + buffer1.GetData().GetBuffer()[alignedSize * i + j] = (123.0f * i) + j; + + AudioBuffer buffer2(123, 2); + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + buffer2[i][j] = (123.0f * i) + j; + + AudioBuffer buffer3(123, 2); + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + REQUIRE(buffer3[i][j] == 0); + + buffer1 += buffer2; + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + REQUIRE(buffer1[i][j] == ((123.0f * i) + j) * 2.0f); + + buffer2 -= buffer1; + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + REQUIRE(buffer2[i][j] == ((123.0f * i) + j) * -1.0f); + + buffer1 *= buffer3; + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + REQUIRE(buffer1[i][j] == 0); + + buffer2 *= -1; + for (AmSize i = 0; i < 2; ++i) + for (AmSize j = 0; j < 123; ++j) + REQUIRE(buffer2[i][j] == (123.0f * i) + j); + } + + SECTION("can be cloned and copied") + { + AudioBuffer buffer1(123, 1); + for (AmSize i = 0; i < 123; ++i) + buffer1[0][i] = i; + + AudioBuffer buffer2; + buffer2 = buffer1.Clone(); + for (AmSize i = 0; i < 123; ++i) + REQUIRE(buffer2[0][i] == buffer1[0][i]); + + AudioBuffer buffer3(23, 1); + AudioBuffer::Copy(buffer2, 100, buffer3, 0, 23); + for (AmSize i = 0; i < 23; ++i) + REQUIRE(buffer3[0][i] == buffer2[0][100 + i]); + + AudioBuffer buffer4(123, 1); + const std::vector data(123, 1.0f); + buffer4[0] = data; + for (AmSize i = 0; i < 123; ++i) + REQUIRE(buffer4[0][i] == 1.0f); + } +} \ No newline at end of file