Skip to content

Commit

Permalink
added SAF library
Browse files Browse the repository at this point in the history
  • Loading branch information
vackva committed Apr 13, 2024
1 parent 725d29c commit cc65ba5
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
choco install ninja
elif [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
sudo apt-get update && sudo apt install libasound2-dev libx11-dev libxcomposite-dev libxcursor-dev libxext-dev libxinerama-dev libxrandr-dev libxrender-dev ninja-build
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev libnetcdff-dev liblapack3 liblapack-dev libopenblas-base libopenblas-dev liblapacke-dev
else
echo "Unknown OS";
fi;
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake-build*
build*/
.idea/
.idea/
modules/OpenBLAS*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "modules/JUCE"]
path = modules/JUCE
url = https://github.com/juce-framework/JUCE
[submodule "modules/SAF"]
path = modules/SAF
url = https://github.com/leomccormack/Spatial_Audio_Framework
51 changes: 48 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ endif()
# find_package(JUCE CONFIG REQUIRED)
add_subdirectory(modules/JUCE)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared instead of static libraries." FORCE)
set(SAF_BUILD_TESTS OFF CACHE BOOL "Build SAF unit tests." FORCE)
set(SAF_BUILD_EXAMPLES OFF CACHE BOOL "Build SAF examples." FORCE)
set(SAF_BUILD_EXTRAS OFF CACHE BOOL "Build SAF extras." FORCE)
set(SAF_ENABLE_SOFA_READER_MODULE ON CACHE BOOL "Enable the SAF SOFA READER module" FORCE)

if (MSVC)
include(cmake/openBLAS.cmake)
set(SAF_PERFORMANCE_LIB "SAF_USE_OPEN_BLAS_AND_LAPACKE")
set(OPENBLAS_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/modules/OpenBLAS-${OPEN_BLAS_VERSION}/lib/libopenblas.lib")
set(LAPACKE_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/modules/OpenBLAS-${OPEN_BLAS_VERSION}/lib/libopenblas.lib")
set(OPENBLAS_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules/OpenBLAS-${OPEN_BLAS_VERSION}/include")
elseif (APPLE)
set(SAF_PERFORMANCE_LIB "SAF_USE_APPLE_ACCELERATE")
else ()
# LINUX
# sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev libnetcdff-dev liblapack3 liblapack-dev libopenblas-base libopenblas-dev liblapacke-dev
set(SAF_PERFORMANCE_LIB "SAF_USE_OPEN_BLAS_AND_LAPACKE")
endif ()

add_subdirectory(modules/SAF)

juce_add_plugin(${TARGET_NAME}
# VERSION ... # Set this if the plugin version is different to the project version
# ICON_BIG ... # ICON_* arguments specify a path to an image file to use as an icon for the Standalone
Expand Down Expand Up @@ -48,19 +70,42 @@ target_sources(${TARGET_NAME}
source/ui/BackgroundComponent.cpp
)

set(SOFA_TEST_FILE "${CMAKE_CURRENT_LIST_DIR}/assets/pp1_HRIRs_measured.sofa")

target_compile_definitions(${TARGET_NAME}
PUBLIC
JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call
JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call
JUCE_VST3_CAN_REPLACE_VST2=0)
JUCE_VST3_CAN_REPLACE_VST2=0
SOFA_TEST_FILE_PATH="${SOFA_TEST_FILE}"
)

# juce_add_binary_data(AudioPluginData SOURCES ...)
juce_add_binary_data(AudioPluginData SOURCES
assets/pp1_HRIRs_measured.sofa
)

target_link_libraries(${TARGET_NAME}
PRIVATE
# AudioPluginData # If we'd created a binary data target, we'd link to it here
AudioPluginData
saf
juce::juce_audio_utils
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)


if (MSVC)
set(copy_shard_libs
"${CMAKE_CURRENT_SOURCE_DIR}/modules/OpenBLAS-${OPEN_BLAS_VERSION}/bin/libopenblas.dll"
)

foreach(FORMAT IN LISTS FORMATS_TO_BUILD)
string(CONCAT CONCATENATED_TARGET ${TARGET_NAME}_${FORMAT})
add_custom_command(TARGET ${CONCATENATED_TARGET}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${copy_shard_libs}
$<TARGET_FILE_DIR:${TARGET_NAME}>/${FORMAT})
endforeach()
endif (MSVC)
Binary file added assets/pp1_HRIRs_measured.sofa
Binary file not shown.
45 changes: 45 additions & 0 deletions cmake/openBLAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if(MSVC)
set(OPEN_BLAS_VERSION 0.3.26)
set(OPEN_BLAS_DIR_NAME "OpenBLAS-${OPEN_BLAS_VERSION}")
set(OPEN_BLAS_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${OPEN_BLAS_DIR_NAME})

if(EXISTS ${OPEN_BLAS_ROOTDIR}/)
message(STATUS "OpenBLAS found at ${OPEN_BLAS_ROOTDIR}")
else()
file(MAKE_DIRECTORY ${OPEN_BLAS_ROOTDIR}/)
message(STATUS "OpenBLAS library not found - preparing to download.")

set(OPEN_BLAS_LIB_NAME "OpenBLAS-${OPEN_BLAS_VERSION}-x64.zip")
set(OPEN_BLAS_URL "https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPEN_BLAS_VERSION}/${OPEN_BLAS_LIB_NAME}")
set(OPEN_BLAS_PATH ${CMAKE_BINARY_DIR}/import/${OPEN_BLAS_LIB_NAME})

message(STATUS "Downloading: ${OPEN_BLAS_URL}")

file(DOWNLOAD ${OPEN_BLAS_URL} ${OPEN_BLAS_PATH}
STATUS OPEN_BLAS_DOWNLOAD_STATUS
SHOW_PROGRESS)

list(GET OPEN_BLAS_DOWNLOAD_STATUS 0 OPEN_BLAS_DOWNLOAD_STATUS_NO)

if(OPEN_BLAS_DOWNLOAD_STATUS_NO EQUAL 0)
message(STATUS "Successfully downloaded OpenBLAS library.")
file(ARCHIVE_EXTRACT
INPUT ${OPEN_BLAS_PATH}
DESTINATION ${OPEN_BLAS_ROOTDIR})

message(STATUS "Extracted OpenBLAS to ${OPEN_BLAS_ROOTDIR}")
else()
message(WARNING "Failed to download OpenBLAS. Check your internet connection and try again.")
file(REMOVE_RECURSE ${OPEN_BLAS_ROOTDIR})
file(REMOVE ${OPEN_BLAS_PATH})
endif()
endif()

get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(OPEN_BLAS_VERSION_USED "${OPEN_BLAS_VERSION}" PARENT_SCOPE)
else ()
set(OPEN_BLAS_VERSION_USED "${OPEN_BLAS_VERSION}")
endif()

endif ()
1 change: 1 addition & 0 deletions modules/SAF
Submodule SAF added at 018e06
4 changes: 4 additions & 0 deletions source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <JuceHeader.h>
#include "PluginParameters.h"

#include "dsp/SofaReader.h"

//==============================================================================
class AudioPluginAudioProcessor final : public juce::AudioProcessor, private juce::AudioProcessorValueTreeState::Listener
{
Expand Down Expand Up @@ -52,6 +54,8 @@ class AudioPluginAudioProcessor final : public juce::AudioProcessor, private juc
private:
juce::AudioProcessorValueTreeState parameters;

SofaReader sofaReader;

std::atomic<float> paramAzimuth { 0.0f };
std::atomic<float> paramElevation { 0.0f };

Expand Down
46 changes: 46 additions & 0 deletions source/dsp/SofaReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Created by Valentin Ackva on 13/04/2024.
//

#ifndef BINAURALPANNER_SOFAREADER_H
#define BINAURALPANNER_SOFAREADER_H

#include <JuceHeader.h>
#include <saf.h>

class SofaReader {
public:
SofaReader() {
// SOFA_TEST_FILE_PATH defined in CMakeLists.txt - TODO load as Binary if possible
error = saf_sofa_open(&sofa, SOFA_TEST_FILE_PATH, SAF_SOFA_READER_OPTION_DEFAULT);

switch (error) {
case SAF_SOFA_OK:
std::cout << "Successfully loaded Sofa File" << std::endl;
std::cout << "APIName: " << sofa.APIName << std::endl;
std::cout << "APIVersion: " << sofa.APIVersion << std::endl;
std::cout << "DataSamplingRate: " << sofa.DataSamplingRate << std::endl;
break;
case SAF_SOFA_ERROR_INVALID_FILE_OR_FILE_PATH:
std::cout << "Not a SOFA file, or no such file was found in the specified location" << std::endl;
break;
case SAF_SOFA_ERROR_DIMENSIONS_UNEXPECTED:
std::cout << "Dimensions of the SOFA data were not as expected" << std::endl;
break;
case SAF_SOFA_ERROR_FORMAT_UNEXPECTED:
std::cout << "The data-type of the SOFA data was not as expected" << std::endl;
break;
case SAF_SOFA_ERROR_NETCDF_IN_USE:
std::cout << "NetCDF is not thread safe!" << std::endl;
break;
}


}

private:
SAF_SOFA_ERROR_CODES error;
saf_sofa_container sofa;
};

#endif //BINAURALPANNER_SOFAREADER_H

0 comments on commit cc65ba5

Please sign in to comment.