diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-08-17 22:45:19 +0200 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-08-17 23:10:07 +0200 |
commit | 874db2b1a3e1961637f14626b843766a788e0e92 (patch) | |
tree | 2fb119b44293d7233d87b0e3d720a5d29210a0ee | |
parent | b223290c08204ac0d3e4a826cd586de7aec106cc (diff) | |
download | atracdenc-874db2b1a3e1961637f14626b843766a788e0e92.tar.gz |
[AT3P] GHA fixes
* Fix frequency to index converting
* Fix gha boundary calculation
* Fix case of empty GHA result
* Fix missed gha_free_ctx call
-rw-r--r-- | src/atrac/at3p/at3p_bitstream.cpp | 2 | ||||
-rw-r--r-- | src/atrac/at3p/at3p_gha.cpp | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/atrac/at3p/at3p_bitstream.cpp b/src/atrac/at3p/at3p_bitstream.cpp index df960c2..1e1cd50 100644 --- a/src/atrac/at3p/at3p_bitstream.cpp +++ b/src/atrac/at3p/at3p_bitstream.cpp @@ -258,7 +258,7 @@ void TAt3PBitStream::WriteFrame(int channels, const TAt3PGhaData* tonalBlock) // Bit indicate tonal block is used bitStream.Write((bool)tonalBlock, 1); - if (tonalBlock) { + if (tonalBlock && tonalBlock->NumToneBands) { WriteTonalBlock(bitStream, channels, tonalBlock); } diff --git a/src/atrac/at3p/at3p_gha.cpp b/src/atrac/at3p/at3p_gha.cpp index 79c2e8a..aa21918 100644 --- a/src/atrac/at3p/at3p_gha.cpp +++ b/src/atrac/at3p/at3p_gha.cpp @@ -44,7 +44,7 @@ namespace { uint32_t GhaFreqToIndex(float f, uint32_t sb) { - return static_cast<uint32_t>(lrintf(1024.0f * (f / M_PI)) & 1023) | (sb << 10); + return static_cast<uint32_t>(lrintf(1023.0f * (f / M_PI)) & 1023) | (sb << 10); } uint32_t GhaPhaseToIndex(float p) @@ -88,6 +88,11 @@ public: FillSubbandAth(&SubbandAth[0]); } + ~TGhaProcessor() + { + gha_free_ctx(LibGhaCtx); + } + const TAt3PGhaData* DoAnalize() override; private: static void FillSubbandAth(float* out) { @@ -309,11 +314,12 @@ pair<uint32_t, uint32_t> TGhaProcessor::FindPos(const float* src, const float* t } uint32_t start = 0; + uint32_t curStart = 0; uint32_t count = 0; uint32_t len = 0; bool found = false; - for (size_t i = 0; i < 128; i += windowSz) { + for (uint32_t i = 0; i < 128; i += windowSz) { float rmsIn = 0.0; float rmsOut = 0.0; for (size_t j = 0; j < windowSz; j++) { @@ -330,27 +336,21 @@ pair<uint32_t, uint32_t> TGhaProcessor::FindPos(const float* src, const float* t if (rmsIn / rmsOut < 1) { count = 0; found = false; + curStart = i; } else { count++; if (count > len) { len = count; if (!found) { - start = i; + start = curStart; found = true; } } } - } - //std::cerr << "start pos: " << start << " len: " << len * windowSz << " end: " << start + len * windowSz << std::endl; - auto end = start + len * windowSz; - //if (end - start < 64) { - // return {0, 0}; - //} - return {start, end}; } |