From 797e8dc54c41576e6c7328d534800ba958e23550 Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sun, 9 Aug 2026 15:09:25 -0700 Subject: [PATCH 1/2] test: cover UTF-8 WAV paths --- CMakeLists.txt | 2 ++ tools/CMakeLists.txt | 5 +++- tools/test_wav.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tools/test_wav.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 27b822c..0662d37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10) project(NAM VERSION 0.0.1) +include(CTest) + set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_CXX_STANDARD 20) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index fb7fc0f..2a7b4b0 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -11,6 +11,9 @@ include_directories(tools ${NAM_DEPS_PATH}/nlohmann) add_executable(loadmodel loadmodel.cpp ${AUDIO_DSP_TOOLS_SOURCES}) add_executable(benchmodel benchmodel.cpp ${AUDIO_DSP_TOOLS_SOURCES}) +add_executable(test_wav test_wav.cpp ${AUDIO_DSP_TOOLS_SOURCES}) + +add_test(NAME wav_unicode_path COMMAND test_wav) source_group(NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${AUDIO_DSP_TOOLS_SOURCES}) @@ -38,4 +41,4 @@ else() "$<$:-Og;-ggdb;-Werror>" "$<$:-Ofast>" ) -endif() \ No newline at end of file +endif() diff --git a/tools/test_wav.cpp b/tools/test_wav.cpp new file mode 100644 index 0000000..9abc64e --- /dev/null +++ b/tools/test_wav.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include + +#include "dsp/wav.h" + +namespace +{ +std::string ToUTF8(const std::filesystem::path& path) +{ + const auto utf8 = path.u8string(); + return {utf8.begin(), utf8.end()}; +} +} // namespace + +int main() +{ +#ifdef _WIN32 + const auto emojiDirectoryName = std::filesystem::path(L"nam-\U0001F3B8"); +#else + const auto emojiDirectoryName = std::filesystem::path("nam-\xF0\x9F\x8E\xB8"); +#endif + const auto testDirectory = std::filesystem::temp_directory_path() / emojiDirectoryName; + const auto wavPath = testDirectory / "ir.wav"; + + std::filesystem::create_directories(testDirectory); + + // 16-bit, mono, 48 kHz PCM WAV containing one silent sample. + constexpr std::array wavData{ + 'R', 'I', 'F', 'F', 38, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0, 0, 1, 0, 1, + 0, 0x80, 0xBB, 0, 0, 0, 0x77, 1, 0, 2, 0, 16, 0, 'd', 'a', 't', 'a', 2, 0, 0, 0, 0, 0}; + + { + std::ofstream wavFile(wavPath, std::ios::binary); + wavFile.write(reinterpret_cast(wavData.data()), wavData.size()); + } + + std::vector audio; + double sampleRate = 0.0; + const auto utf8Path = ToUTF8(wavPath); + const auto result = dsp::wav::Load(utf8Path.c_str(), audio, sampleRate); + + std::filesystem::remove_all(testDirectory); + + if (result != dsp::wav::LoadReturnCode::SUCCESS || audio.size() != 1 || sampleRate != 48000.0) + { + std::cerr << "Failed to load WAV from UTF-8 path" << std::endl; + return 1; + } + + return 0; +} From 4efce9afad9b6502f53289648e330cfab483f474 Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sun, 9 Aug 2026 15:10:37 -0700 Subject: [PATCH 2/2] fix: open WAV files with native paths --- dsp/wav.cpp | 8 +++++++- tools/test_wav.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dsp/wav.cpp b/dsp/wav.cpp index b9ffe45..f77b31a 100644 --- a/dsp/wav.cpp +++ b/dsp/wav.cpp @@ -8,6 +8,7 @@ #include #include // strncmp #include // pow +#include #include #include #include @@ -341,7 +342,12 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const char* fileName, std::vector { // FYI: https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html // Open the WAV file for reading - std::ifstream wavFile(fileName, std::ios::binary); +#ifdef __cpp_char8_t + const auto filePath = std::filesystem::path(reinterpret_cast(fileName)); +#else + const auto filePath = std::filesystem::u8path(fileName); +#endif + std::ifstream wavFile(filePath, std::ios::binary); // Check if the file was opened successfully if (!wavFile.is_open()) diff --git a/tools/test_wav.cpp b/tools/test_wav.cpp index 9abc64e..964c56f 100644 --- a/tools/test_wav.cpp +++ b/tools/test_wav.cpp @@ -30,8 +30,8 @@ int main() // 16-bit, mono, 48 kHz PCM WAV containing one silent sample. constexpr std::array wavData{ - 'R', 'I', 'F', 'F', 38, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0, 0, 1, 0, 1, - 0, 0x80, 0xBB, 0, 0, 0, 0x77, 1, 0, 2, 0, 16, 0, 'd', 'a', 't', 'a', 2, 0, 0, 0, 0, 0}; + 'R', 'I', 'F', 'F', 38, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0, 0, 1, 0, 1, + 0, 0x80, 0xBB, 0, 0, 0, 0x77, 1, 0, 2, 0, 16, 0, 'd', 'a', 't', 'a', 2, 0, 0, 0, 0, 0}; { std::ofstream wavFile(wavPath, std::ios::binary);