diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a1e68..1c25a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ set(LAC_TEST_ASSETS_DIR "${PROJECT_BINARY_DIR}/lac-test-assets" CACHE PATH "Opti find_package(Threads REQUIRED) add_library(lac STATIC - src/codec/bitstream/bit_reader.cpp src/codec/bitstream/bit_writer.cpp src/codec/block/decoder.cpp src/codec/block/encoder.cpp @@ -21,7 +20,6 @@ add_library(lac STATIC src/codec/rice/rice.cpp src/codec/simd/neon.cpp src/io/wav_io.cpp - src/utils/logger.cpp src/codec/bitstream/bit_reader.hpp src/codec/bitstream/bit_writer.hpp @@ -37,7 +35,6 @@ add_library(lac STATIC src/codec/rice/rice.hpp src/codec/simd/neon.hpp src/io/wav_io.hpp - src/utils/endian.hpp src/utils/logger.hpp include/lac/lac.hpp include/lac/version.hpp diff --git a/src/codec/bitstream/bit_reader.cpp b/src/codec/bitstream/bit_reader.cpp deleted file mode 100644 index d9a7c93..0000000 --- a/src/codec/bitstream/bit_reader.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "bit_reader.hpp" diff --git a/src/codec/rice/rice.cpp b/src/codec/rice/rice.cpp index a7770c6..08245b9 100644 --- a/src/codec/rice/rice.cpp +++ b/src/codec/rice/rice.cpp @@ -47,22 +47,3 @@ bool Rice::decode(BitReader& r, uint32_t k, int32_t& value) { value = unsigned_to_signed(u); return true; } - -uint32_t Rice::compute_k(const std::vector& residuals) { - uint64_t sum = 0; - for (int32_t v : residuals) { - uint32_t u = signed_to_unsigned(v); - sum += u; - } - - if (residuals.empty()) return 0; - - double mean = double(sum) / double(residuals.size()); - - uint32_t k = 0; - while ((1u << k) < (uint32_t)(mean + 0.5) && k < 31) { - k++; - } - - return k; -} diff --git a/src/codec/rice/rice.hpp b/src/codec/rice/rice.hpp index e90a4c6..69ec262 100644 --- a/src/codec/rice/rice.hpp +++ b/src/codec/rice/rice.hpp @@ -35,9 +35,6 @@ class Rice { static bool decode(BitReader& r, uint32_t k, int32_t& value); - // Compute optimal k from residual block - static uint32_t compute_k(const std::vector& residuals); - static uint32_t adapt_k(uint64_t sum, uint32_t count, AdaptState& state); private: diff --git a/src/main.cpp b/src/main.cpp index 0ca9f4a..c35c0b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -792,6 +792,8 @@ int main(int argc, char** argv) { } if (mode == "selftest") { + // Kept in the CLI on purpose: CI runs `lac_cli selftest` as a build-time + // smoke test, and it gives end users a dependency-free roundtrip check. const double pi = 3.14159265358979323846; constexpr int32_t pcm24_max = 0x7FFFFF; @@ -847,6 +849,37 @@ int main(int argc, char** argv) { return false; } + // Per-block (auto) stereo, stereo_mode 2. + LAC::Encoder enc_auto(12, 2, sample_rate, bit_depth); + std::vector bs_auto = enc_auto.encode(src_left, src_right); + std::vector dec_auto_left, dec_auto_right; + FrameHeader hdr_auto; + decoder.decode(bs_auto.data(), bs_auto.size(), dec_auto_left, dec_auto_right, &hdr_auto); + if (dec_auto_left != src_left || dec_auto_right != src_right) { + std::cerr << "Auto-stereo roundtrip mismatch for sr=" << sample_rate << " depth=" << int(bit_depth) << "\n"; + return false; + } + if (hdr_auto.stereo_mode != 2) { + std::cerr << "Auto-stereo header mismatch stereo_mode=" << int(hdr_auto.stereo_mode) << "\n"; + return false; + } + + // Mono. + std::vector empty_right; + LAC::Encoder enc_mono(12, 0, sample_rate, bit_depth); + std::vector bs_mono = enc_mono.encode(src_left, empty_right); + std::vector dec_mono_left, dec_mono_right; + FrameHeader hdr_mono; + decoder.decode(bs_mono.data(), bs_mono.size(), dec_mono_left, dec_mono_right, &hdr_mono); + if (dec_mono_left != src_left || !dec_mono_right.empty()) { + std::cerr << "Mono roundtrip mismatch for sr=" << sample_rate << " depth=" << int(bit_depth) << "\n"; + return false; + } + if (hdr_mono.channels != 1) { + std::cerr << "Mono header mismatch channels=" << int(hdr_mono.channels) << "\n"; + return false; + } + auto lr_us = std::chrono::duration_cast(t1 - t0).count(); auto ms_us = std::chrono::duration_cast(t3 - t2).count(); bool ms_smaller = bs_ms.size() < bs_lr.size(); diff --git a/src/utils/endian.hpp b/src/utils/endian.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp deleted file mode 100644 index e69de29..0000000