diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2017-10-29 00:44:35 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2017-10-29 00:44:35 +0300 |
commit | cb117c7dbe891d88b6a9a69654dfa7612fd57d59 (patch) | |
tree | a6eb0b2eb589a1874dbc779cb0f0dcefca4b2eed | |
parent | aad450378e603dfaa2b4de6496199b03d483056e (diff) | |
download | atracdenc-cb117c7dbe891d88b6a9a69654dfa7612fd57d59.tar.gz |
workaround problem with encoding extremely loud tracks
TODO: it looks like ugly hack, check it again
-rw-r--r-- | src/atrac/atrac_scale.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp index d031424..b5c4e7f 100644 --- a/src/atrac/atrac_scale.cpp +++ b/src/atrac/atrac_scale.cpp @@ -41,22 +41,22 @@ TScaledBlock TScaler<TBaseData>::Scale(const TFloat* in, uint16_t len) { for (uint16_t i = 0; i < len; ++i) { const TFloat absSpec = abs(in[i]); if (absSpec > maxAbsSpec) { - if (absSpec > MAX_SCALE) { - cerr << "Scale error: absSpec > MAX_SCALE, val: " << absSpec << endl; - maxAbsSpec = MAX_SCALE; - } else { - maxAbsSpec = absSpec; - } + maxAbsSpec = absSpec; } } + if (maxAbsSpec > MAX_SCALE) { + cerr << "Scale error: absSpec > MAX_SCALE, val: " << maxAbsSpec << endl; + maxAbsSpec = MAX_SCALE; + } const map<TFloat, uint8_t>::const_iterator scaleIter = ScaleIndex.lower_bound(maxAbsSpec); const TFloat scaleFactor = scaleIter->first; const uint8_t scaleFactorIndex = scaleIter->second; TScaledBlock res(scaleFactorIndex); for (uint16_t i = 0; i < len; ++i) { - const TFloat scaledValue = in[i] / scaleFactor; - if (scaledValue > 1.0) { + TFloat scaledValue = in[i] / scaleFactor; + if (abs(scaledValue) >= 1.0) { cerr << "got "<< scaledValue << " it is wrong scalling" << endl; + scaledValue = (scaledValue > 0) ? 0.99999 : -0.99999; } res.Values.push_back(scaledValue); } |