diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-10-20 22:53:02 +0200 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-10-23 23:01:24 +0200 |
commit | d2359550a18f24c93b2ed9a23d222280150d2de8 (patch) | |
tree | 45e6ae57f5afae581efeef80699e0b0f5cb6c803 | |
parent | 436de04451c70f9f8c2e2df4ea4172d08f5c525e (diff) | |
download | atracdenc-d2359550a18f24c93b2ed9a23d222280150d2de8.tar.gz |
[AT3P] Improve accuracy of magnitude calculation in case of not full frame
-rw-r--r-- | src/atrac/at3p/at3p_gha.cpp | 34 | ||||
m--------- | src/lib/libgha | 0 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/atrac/at3p/at3p_gha.cpp b/src/atrac/at3p/at3p_gha.cpp index 24f3b7b..1f1823e 100644 --- a/src/atrac/at3p/at3p_gha.cpp +++ b/src/atrac/at3p/at3p_gha.cpp @@ -97,9 +97,13 @@ class TGhaProcessor : public IGhaProcessor { {} TChannelData* Data; size_t Sb; - struct { - bool Ok; - } Result; + + enum class EAdjustStatus { + Error, + Ok, + Repeat + } AdjustStatus; + size_t FrameSz = 0; }; public: @@ -248,17 +252,23 @@ void TGhaProcessor::CheckResuidalAndApply(float* resuidal, size_t size, void* d) const auto sb = ctx->Sb; // Do not encode too short frame if (len < 4) { - ctx->Result.Ok = false; + ctx->AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Error; return; } const uint32_t end = start + len * 4; + if (ctx->AdjustStatus != TChannelGhaCbCtx::EAdjustStatus::Repeat && end != SAMPLES_PER_SUBBAND) { + ctx->FrameSz = end; + ctx->AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Repeat; + return; + } + const float threshold = 1.4; //TODO: tune it if (static_cast<bool>(ctx->Data->LastResuidalEnergy[sb]) == false) { ctx->Data->LastResuidalEnergy[sb] = resuidalEnergy; } else if (ctx->Data->LastResuidalEnergy[sb] < resuidalEnergy * threshold) { - ctx->Result.Ok = false; + ctx->AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Error; return; } else { ctx->Data->LastResuidalEnergy[sb] = resuidalEnergy; @@ -268,13 +278,13 @@ void TGhaProcessor::CheckResuidalAndApply(float* resuidal, size_t size, void* d) envelope.first = start; if (envelope.second == TAt3PGhaData::EMPTY_POINT && end != SAMPLES_PER_SUBBAND) { - ctx->Result.Ok = false; + ctx->AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Error; return; } envelope.second = end; - ctx->Result.Ok = true; + ctx->AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Ok; float* b = &ctx->Data->Buf[sb * GHA_SUBBAND_BUF_SZ]; @@ -375,8 +385,14 @@ bool TGhaProcessor::DoRound(TChannelData& data, size_t& totalTones) const } if (tmp.size() > 0) { TChannelGhaCbCtx ctx(&data, sb); - int ar = gha_adjust_info(srcB, tmp.data(), tmp.size(), LibGhaCtx, CheckResuidalAndApply, &ctx); - if (ar == 0 && ctx.Result.Ok) { + do { + int ar = gha_adjust_info(srcB, tmp.data(), tmp.size(), LibGhaCtx, CheckResuidalAndApply, &ctx, ctx.FrameSz); + if (ar < 0) { + ctx.AdjustStatus = TChannelGhaCbCtx::EAdjustStatus::Error; + }; + } while (ctx.AdjustStatus == TChannelGhaCbCtx::EAdjustStatus::Repeat); + + if (ctx.AdjustStatus == TChannelGhaCbCtx::EAdjustStatus::Ok) { std::sort(tmp.begin(), tmp.end(), [](const gha_info& a, const gha_info& b) {return a.frequency < b.frequency;}); bool dupFound = false; diff --git a/src/lib/libgha b/src/lib/libgha -Subproject a9cefceaf856df82c6867e853a357b0298d566c +Subproject c8a2949960cc4850d1236de775e83944def7998 |