Skip to content

Commit

Permalink
added new path to possible default.sofa file paths (Spatializer)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozguronsoy committed Sep 26, 2024
1 parent 1abc317 commit 32de231
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25)

set(HEPHAUDIO_VERSION_MAJOR 2)
set(HEPHAUDIO_VERSION_MINOR 2)
set(HEPHAUDIO_VERSION_PATCH 1)
set(HEPHAUDIO_VERSION_PATCH 2)
set(HEPHAUDIO_VERSION ${HEPHAUDIO_VERSION_MAJOR}.${HEPHAUDIO_VERSION_MINOR}.${HEPHAUDIO_VERSION_PATCH})

option(ENABLE_STATIC "ENABLE_STATIC" Off)
Expand Down Expand Up @@ -255,6 +255,8 @@ endif ()

if (ENABLE_STATIC OR ENABLE_SHARED)

add_compile_options(-w -O3 -march=native)

if (ENABLE_SHARED)
add_definitions(-DHEPH_SHARED_LIB -DHEPH_EXPORTS)
add_library(
Expand Down
48 changes: 29 additions & 19 deletions HephAudio/SourceFiles/Spatializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,46 @@

using namespace Heph;


namespace HephAudio
{
Spatializer::Spatializer() : pEasy(nullptr), frameCount(0), sampleRate(48000)
{
// check the possible paths to find the default sofa file
// if found, initialize with it.
if (std::filesystem::exists("dependencies/libmysofa/default.sofa"))
{
this->OpenSofaFile("HephAudio/dependencies/libmysofa/default.sofa", this->sampleRate);
}
else if (std::filesystem::exists("../dependencies/libmysofa/default.sofa"))
const std::vector<std::filesystem::path> possiblePaths =
{
this->OpenSofaFile("../dependencies/libmysofa/default.sofa", this->sampleRate);
}
else if (std::filesystem::exists("../../dependencies/libmysofa/default.sofa"))
{
this->OpenSofaFile("../../dependencies/libmysofa/default.sofa", this->sampleRate);
}
else if (std::filesystem::exists("HephAudio/dependencies/libmysofa/default.sofa"))
"dependencies/libmysofa/default.sofa",
"../dependencies/libmysofa/default.sofa",
"../../dependencies/libmysofa/default.sofa",
"HephAudio/default.sofa",
"HephAudio/dependencies/libmysofa/default.sofa"
};

for (const std::filesystem::path& path : possiblePaths)
{
this->OpenSofaFile("HephAudio/dependencies/libmysofa/default.sofa", this->sampleRate);
}
else
{
HEPHAUDIO_LOG("Could not find the default sofa file. Provide one before proceeding.", HEPH_CL_WARNING);
if (std::filesystem::exists(path))
{
this->OpenSofaFile(path, this->sampleRate);
return;
}
}
HEPHAUDIO_LOG("Could not find the default sofa file. Provide one before proceeding.", HEPH_CL_WARNING);
}

Spatializer::Spatializer(const std::filesystem::path& sofaFilePath, uint32_t sampleRate) : pEasy(nullptr), frameCount(0), sampleRate(sampleRate)
{
this->OpenSofaFile(sofaFilePath, sampleRate);
}

Spatializer::Spatializer(Spatializer&& rhs) noexcept : pEasy(rhs.pEasy), frameCount(rhs.frameCount), sampleRate(rhs.sampleRate)
{
rhs.pEasy = nullptr;
}

Spatializer::~Spatializer()
{
this->CloseSofaFile();
}

Spatializer& Spatializer::operator=(Spatializer&& rhs) noexcept
{
if (this != &rhs)
Expand All @@ -65,18 +66,23 @@ namespace HephAudio
this->sampleRate = rhs.sampleRate;

rhs.pEasy = nullptr;
rhs.frameCount = 0;
rhs.sampleRate = 0;
}

return *this;
}

uint32_t Spatializer::GetSampleRate() const
{
return this->sampleRate;
}

size_t Spatializer::GetFrameCount() const
{
return this->frameCount;
}

void Spatializer::OpenSofaFile(const std::filesystem::path& sofaFilePath, uint32_t sampleRate)
{
int filter_length;
Expand All @@ -91,6 +97,7 @@ namespace HephAudio
}
this->frameCount = filter_length;
}

void Spatializer::CloseSofaFile()
{
if (this->pEasy != nullptr)
Expand All @@ -99,11 +106,13 @@ namespace HephAudio
this->pEasy = nullptr;
}
}

void Spatializer::Process(AudioBuffer& buffer, float azimuth_deg, float elevation_deg)
{
HannWindow hannWindow(this->frameCount);
this->Process(buffer, azimuth_deg, elevation_deg, hannWindow.GenerateBuffer());
}

void Spatializer::Process(AudioBuffer& buffer, float azimuth_deg, float elevation_deg, const DoubleBuffer& windowBuffer)
{
if (this->pEasy == nullptr)
Expand Down Expand Up @@ -160,6 +169,7 @@ namespace HephAudio
}
}
}

std::string Spatializer::GetErrorString(int errorCode)
{
switch (errorCode)
Expand Down
4 changes: 2 additions & 2 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "HephAudio"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "v2.2.0"
PROJECT_NUMBER = "v2.2.2"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -1378,7 +1378,7 @@ HTML_EXTRA_FILES =
# The default value is: AUTO_LIGHT.
# This tag requires that the tag GENERATE_HTML is set to YES.

HTML_COLORSTYLE = AUTO_DARK
HTML_COLORSTYLE = LIGHT

# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
# will adjust the colors in the style sheet and background images according to
Expand Down

0 comments on commit 32de231

Please sign in to comment.