Skip to content

Commit 1c21b6f

Browse files
audexdevclaude
andcommitted
Remove dead code and empty files; widen CLI selftest coverage
- Drop Rice::compute_k: it has no callers and used a float k estimator inconsistent with the live integer Rice::adapt_k. - Delete empty placeholder files and remove them from CMake: bit_reader.cpp and logger.cpp (both header-only) and endian.hpp (unused). - Expand `lac_cli selftest` to also round-trip mono and per-block/auto stereo (mode 2), and document why the selftest stays in the CLI. The dead Encoder `order` parameter is intentionally left for #25, where the encoder constructors are reworked; removing it now would shift arguments across ~15 call sites in a way that compiles silently. Refs #30 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4b29c92 commit 1c21b6f

7 files changed

Lines changed: 33 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set(LAC_TEST_ASSETS_DIR "${PROJECT_BINARY_DIR}/lac-test-assets" CACHE PATH "Opti
1111
find_package(Threads REQUIRED)
1212

1313
add_library(lac STATIC
14-
src/codec/bitstream/bit_reader.cpp
1514
src/codec/bitstream/bit_writer.cpp
1615
src/codec/block/decoder.cpp
1716
src/codec/block/encoder.cpp
@@ -21,7 +20,6 @@ add_library(lac STATIC
2120
src/codec/rice/rice.cpp
2221
src/codec/simd/neon.cpp
2322
src/io/wav_io.cpp
24-
src/utils/logger.cpp
2523

2624
src/codec/bitstream/bit_reader.hpp
2725
src/codec/bitstream/bit_writer.hpp
@@ -37,7 +35,6 @@ add_library(lac STATIC
3735
src/codec/rice/rice.hpp
3836
src/codec/simd/neon.hpp
3937
src/io/wav_io.hpp
40-
src/utils/endian.hpp
4138
src/utils/logger.hpp
4239
include/lac/lac.hpp
4340
include/lac/version.hpp

src/codec/bitstream/bit_reader.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/codec/rice/rice.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,3 @@ bool Rice::decode(BitReader& r, uint32_t k, int32_t& value) {
4747
value = unsigned_to_signed(u);
4848
return true;
4949
}
50-
51-
uint32_t Rice::compute_k(const std::vector<int32_t>& residuals) {
52-
uint64_t sum = 0;
53-
for (int32_t v : residuals) {
54-
uint32_t u = signed_to_unsigned(v);
55-
sum += u;
56-
}
57-
58-
if (residuals.empty()) return 0;
59-
60-
double mean = double(sum) / double(residuals.size());
61-
62-
uint32_t k = 0;
63-
while ((1u << k) < (uint32_t)(mean + 0.5) && k < 31) {
64-
k++;
65-
}
66-
67-
return k;
68-
}

src/codec/rice/rice.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class Rice {
3535

3636
static bool decode(BitReader& r, uint32_t k, int32_t& value);
3737

38-
// Compute optimal k from residual block
39-
static uint32_t compute_k(const std::vector<int32_t>& residuals);
40-
4138
static uint32_t adapt_k(uint64_t sum, uint32_t count, AdaptState& state);
4239

4340
private:

src/main.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ int main(int argc, char** argv) {
792792
}
793793

794794
if (mode == "selftest") {
795+
// Kept in the CLI on purpose: CI runs `lac_cli selftest` as a build-time
796+
// smoke test, and it gives end users a dependency-free roundtrip check.
795797
const double pi = 3.14159265358979323846;
796798
constexpr int32_t pcm24_max = 0x7FFFFF;
797799

@@ -847,6 +849,37 @@ int main(int argc, char** argv) {
847849
return false;
848850
}
849851

852+
// Per-block (auto) stereo, stereo_mode 2.
853+
LAC::Encoder enc_auto(12, 2, sample_rate, bit_depth);
854+
std::vector<uint8_t> bs_auto = enc_auto.encode(src_left, src_right);
855+
std::vector<int32_t> dec_auto_left, dec_auto_right;
856+
FrameHeader hdr_auto;
857+
decoder.decode(bs_auto.data(), bs_auto.size(), dec_auto_left, dec_auto_right, &hdr_auto);
858+
if (dec_auto_left != src_left || dec_auto_right != src_right) {
859+
std::cerr << "Auto-stereo roundtrip mismatch for sr=" << sample_rate << " depth=" << int(bit_depth) << "\n";
860+
return false;
861+
}
862+
if (hdr_auto.stereo_mode != 2) {
863+
std::cerr << "Auto-stereo header mismatch stereo_mode=" << int(hdr_auto.stereo_mode) << "\n";
864+
return false;
865+
}
866+
867+
// Mono.
868+
std::vector<int32_t> empty_right;
869+
LAC::Encoder enc_mono(12, 0, sample_rate, bit_depth);
870+
std::vector<uint8_t> bs_mono = enc_mono.encode(src_left, empty_right);
871+
std::vector<int32_t> dec_mono_left, dec_mono_right;
872+
FrameHeader hdr_mono;
873+
decoder.decode(bs_mono.data(), bs_mono.size(), dec_mono_left, dec_mono_right, &hdr_mono);
874+
if (dec_mono_left != src_left || !dec_mono_right.empty()) {
875+
std::cerr << "Mono roundtrip mismatch for sr=" << sample_rate << " depth=" << int(bit_depth) << "\n";
876+
return false;
877+
}
878+
if (hdr_mono.channels != 1) {
879+
std::cerr << "Mono header mismatch channels=" << int(hdr_mono.channels) << "\n";
880+
return false;
881+
}
882+
850883
auto lr_us = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
851884
auto ms_us = std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2).count();
852885
bool ms_smaller = bs_ms.size() < bs_lr.size();

src/utils/endian.hpp

Whitespace-only changes.

src/utils/logger.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)