From a24b5055e9d7c92982e8a275fdc0e5682a68c243 Mon Sep 17 00:00:00 2001 From: Segfault1602 Date: Fri, 10 Nov 2023 17:44:09 -0800 Subject: [PATCH] Include libsndfile for tests build --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 16 ++++++++-------- format.py | 23 +++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/basic_oscillators.cpp | 14 ++++++-------- src/line.cpp | 8 +++----- 6 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 format.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3f6ef4..7ff977e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DLIBDSP_LIB_ONLY=ON + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DLIBDSP_LIB_ONLY=ON -DLIBDSP_BUILD_TESTS=ON - name: Build # Build your program with the given configuration diff --git a/CMakeLists.txt b/CMakeLists.txt index 6417fd3..d6af21e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,14 @@ if(LIBDSP_BUILD_TESTS) ON CACHE BOOL "" FORCE) add_subdirectory(externals/googletest) + endif() + +if (NOT LIBDSP_LIB_ONLY OR LIBDSP_BUILD_TESTS) + add_subdirectory(externals/libsndfile) + target_compile_definitions(sndfile PRIVATE _CRT_SECURE_NO_WARNINGS _USE_MATH_DEFINES) + if(NOT MSVC) + target_compile_options(sndfile PRIVATE -Wno-deprecated-declarations) + endif() endif() if(NOT LIBDSP_LIB_ONLY) @@ -62,12 +70,4 @@ if(NOT LIBDSP_LIB_ONLY) set(BUILD_TESTING OFF CACHE BOOL "Don't build libsndfile tests!" FORCE) - - add_subdirectory(externals/libsndfile) - target_compile_definitions(sndfile PRIVATE _CRT_SECURE_NO_WARNINGS - _USE_MATH_DEFINES) - if(NOT MSVC) - target_compile_options(sndfile PRIVATE -Wno-deprecated-declarations) - endif() - endif() diff --git a/format.py b/format.py new file mode 100644 index 0000000..eb9c545 --- /dev/null +++ b/format.py @@ -0,0 +1,23 @@ +import os + + +def main(): + # Get all files that end with .cpp or .h + src_files = [f for f in os.listdir("src") if f.endswith(".cpp")] + inc_files = [f for f in os.listdir("include") if f.endswith(".h")] + test_files = [f for f in os.listdir("tests") if f.endswith((".cpp", ".h"))] + tool_files = [f for f in os.listdir("tools") if f.endswith((".cpp", ".h"))] + + # Format all the files + for f in src_files: + os.system("clang-format -i src/" + f) + for f in inc_files: + os.system("clang-format -i include/" + f) + for f in test_files: + os.system("clang-format -i tests/" + f) + for f in tool_files: + os.system("clang-format -i tools/" + f) + + +if __name__ == "__main__": + main() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f2565c..7daefbe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,8 @@ set(LIB_SOURCES add_library(dsp STATIC ${LIB_SOURCES}) +set_target_properties(dsp PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + target_include_directories(dsp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") diff --git a/src/basic_oscillators.cpp b/src/basic_oscillators.cpp index e4c192a..309ef26 100644 --- a/src/basic_oscillators.cpp +++ b/src/basic_oscillators.cpp @@ -16,8 +16,8 @@ float Sine(float phase) } phase = std::fmod(phase, 1.f); float idx = phase * SIN_LUT_SIZE; - int idx0 = static_cast(idx); - float frac = idx - idx0; + auto idx0 = static_cast(idx); + auto frac = idx - static_cast(idx0); return sin_lut[idx0] + frac * (sin_lut[idx0 + 1] - sin_lut[idx0]); } @@ -28,10 +28,8 @@ float Tri(float phase) { return 2.f * phase - 1.f; } - else - { - return 2.f - 2.f * phase - 1.f; - } + + return 2.f - 2.f * phase - 1.f; } float Saw(float phase) @@ -46,8 +44,8 @@ float Square(float phase) float Noise() { - constexpr float kOneOverRandMax = 1.f / RAND_MAX; - return 2.f * rand() * kOneOverRandMax - 1.f; + constexpr float kOneOverRandMax = 1.f / static_cast(RAND_MAX); + return 2.f * static_cast(rand()) * kOneOverRandMax - 1.f; } } // namespace sfdsp \ No newline at end of file diff --git a/src/line.cpp b/src/line.cpp index 269580d..cffcacf 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -21,11 +21,9 @@ float Line::Tick() { return end_; } - else - { - output_ += increment_; - return output_; - } + + output_ += increment_; + return output_; } } // namespace sfdsp \ No newline at end of file