From 17c8fe268be2b69db2804372a865a3f320e548fd Mon Sep 17 00:00:00 2001 From: Randy Jones Date: Sat, 16 Mar 2024 16:25:43 -0700 Subject: [PATCH] fix TestUtils bugs --- Tests/dspOpsTest.cpp | 5 +++++ source/DSP/MLDSPProjections.h | 2 +- source/DSP/MLDSPSample.h | 3 +++ source/app/MLTextUtils.cpp | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Tests/dspOpsTest.cpp b/Tests/dspOpsTest.cpp index ada76195..2adab05f 100644 --- a/Tests/dspOpsTest.cpp +++ b/Tests/dspOpsTest.cpp @@ -335,6 +335,11 @@ TEST_CASE("madronalib/core/projections", "[projections]") REQUIRE(nearlyEqual(p0(p1(x)), x)); } } + + // print interval + Interval v1{0.123, 5.567}; + + std::cout << "interval: " << v1 << "\n"; } TEST_CASE("madronalib/core/sse-ops", "[sse-ops]") { diff --git a/source/DSP/MLDSPProjections.h b/source/DSP/MLDSPProjections.h index 14ecf169..bc6cc409 100644 --- a/source/DSP/MLDSPProjections.h +++ b/source/DSP/MLDSPProjections.h @@ -302,7 +302,7 @@ inline void printTable(const Projection& p, std::string pName, Interval domain, inline std::ostream& operator<<(std::ostream& out, const ml::Interval& m) { - std::cout << "[" << m.mX1 << "–" << m.mX2 << "]"; + std::cout << "[" << m.mX1 << " - " << m.mX2 << "]"; return out; } diff --git a/source/DSP/MLDSPSample.h b/source/DSP/MLDSPSample.h index 01ad8d2f..9e983157 100644 --- a/source/DSP/MLDSPSample.h +++ b/source/DSP/MLDSPSample.h @@ -36,6 +36,7 @@ inline size_t getSize(const Sample& s) inline size_t getFrames(const Sample& s) { + if (s.channels == 0) return 0; return s.sampleData.size() / s.channels; } @@ -56,6 +57,7 @@ inline float getRate(const Sample& s) inline float getDuration(const Sample& s) { + if (s.sampleRate == 0) return 0.f; return getFrames(s) / (float)(s.sampleRate); } @@ -87,6 +89,7 @@ inline float findMaximumValue(const Sample& x) inline void normalize(Sample& x) { + if (x.sampleData.size() == 0) return; float ratio = 1.0f / findMaximumValue(x); for (int i = 0; i < x.sampleData.size(); ++i) { diff --git a/source/app/MLTextUtils.cpp b/source/app/MLTextUtils.cpp index 89ae9032..aa92c070 100644 --- a/source/app/MLTextUtils.cpp +++ b/source/app/MLTextUtils.cpp @@ -545,7 +545,7 @@ TextFragment getExtension(const TextFragment& frag) size_t len = frag.lengthInCodePoints(); return subText(frag, dotLoc + 1, len); } - return frag; + return TextFragment(); } @@ -566,7 +566,7 @@ TextFragment getPath(const TextFragment& frag) { return subText(frag, 0, slashLoc); } - return frag; + return TextFragment(); } // TODO extend to recognize Cyrillic and other scripts