Skip to content

Commit

Permalink
Include libsndfile for tests build
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfault1602 committed Nov 11, 2023
1 parent 97c13d6 commit a24b505
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
23 changes: 23 additions & 0 deletions format.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 6 additions & 8 deletions src/basic_oscillators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ float Sine(float phase)
}
phase = std::fmod(phase, 1.f);
float idx = phase * SIN_LUT_SIZE;
int idx0 = static_cast<int>(idx);
float frac = idx - idx0;
auto idx0 = static_cast<size_t>(idx);
auto frac = idx - static_cast<float>(idx0);
return sin_lut[idx0] + frac * (sin_lut[idx0 + 1] - sin_lut[idx0]);
}

Expand All @@ -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)
Expand All @@ -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<float>(RAND_MAX);
return 2.f * static_cast<float>(rand()) * kOneOverRandMax - 1.f;
}

} // namespace sfdsp
8 changes: 3 additions & 5 deletions src/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ float Line::Tick()
{
return end_;
}
else
{
output_ += increment_;
return output_;
}

output_ += increment_;
return output_;
}

} // namespace sfdsp

0 comments on commit a24b505

Please sign in to comment.