aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2018-07-04 02:21:25 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2018-07-04 02:21:25 +0300
commit4eade436667b31dd27f6bec7588c523d571eb664 (patch)
treefb871fdea6f2bbd4863653effe257fda4388d94a
parent005877ed1be0012444e6086d3d5d04d61c00a92f (diff)
downloadatracdenc-4eade436667b31dd27f6bec7588c523d571eb664.tar.gz
Scale float values to (-1; 1) for internal processing
-rw-r--r--src/atrac/atrac1.h2
-rw-r--r--src/atrac/atrac3.h2
-rw-r--r--src/atrac/atrac_scale.cpp2
-rw-r--r--src/atrac1denc.h12
-rw-r--r--src/atrac3denc.cpp6
-rw-r--r--src/atrac3denc.h2
-rw-r--r--src/wav.cpp6
7 files changed, 17 insertions, 15 deletions
diff --git a/src/atrac/atrac1.h b/src/atrac/atrac1.h
index bf3b7e3..460c86d 100644
--- a/src/atrac/atrac1.h
+++ b/src/atrac/atrac1.h
@@ -92,7 +92,7 @@ public:
TAtrac1Data() {
if (ScaleTable[0] == 0) {
for (uint32_t i = 0; i < 64; i++) {
- ScaleTable[i] = pow(2.0, (double)(i - 15.0) / 3.0);
+ ScaleTable[i] = pow(2.0, (double)(i / 3.0 - 21.0));
}
}
if (SineWindow[0] == 0) {
diff --git a/src/atrac/atrac3.h b/src/atrac/atrac3.h
index b313d88..b6594e5 100644
--- a/src/atrac/atrac3.h
+++ b/src/atrac/atrac3.h
@@ -169,7 +169,7 @@ public:
TAtrac3Data() {
if (ScaleTable[0] == 0) {
for (uint32_t i = 0; i < 64; i++) {
- ScaleTable[i] = pow(2.0, (double)(i - 15.0) / 3.0);
+ ScaleTable[i] = pow(2.0, (double)(i / 3.0 - 21.0));
}
}
for (int i = 0; i < 256; i++) {
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp
index b5c4e7f..e41c2a0 100644
--- a/src/atrac/atrac_scale.cpp
+++ b/src/atrac/atrac_scale.cpp
@@ -33,7 +33,7 @@ using std::endl;
using std::abs;
-static const uint32_t MAX_SCALE = 65536;
+static const TFloat MAX_SCALE = 1.0;
template<class TBaseData>
TScaledBlock TScaler<TBaseData>::Scale(const TFloat* in, uint16_t len) {
diff --git a/src/atrac1denc.h b/src/atrac1denc.h
index 0c010b5..821591a 100644
--- a/src/atrac1denc.h
+++ b/src/atrac1denc.h
@@ -49,8 +49,12 @@ public:
void IMdct(TFloat specs[512], const TBlockSize& mode, TFloat* low, TFloat* mid, TFloat* hi);
void Mdct(TFloat specs[512], TFloat* low, TFloat* mid, TFloat* hi, const TBlockSize& blockSize);
TAtrac1MDCT()
- : Mdct512(2)
- , Mdct256(1)
+ : Mdct512(1)
+ , Mdct256(0.5)
+ , Mdct64(0.5)
+ , Midct512(512*2)
+ , Midct256(256*2)
+ , Midct64(64*2)
{}
};
@@ -62,8 +66,8 @@ class TAtrac1Processor : public IProcessor<TFloat>, public TAtrac1MDCT, public v
TFloat PcmBufMid[2][256 + 16];
TFloat PcmBufHi[2][512 + 16];
- int32_t PcmValueMax = 32767;
- int32_t PcmValueMin = -32767;
+ int32_t PcmValueMax = 1;
+ int32_t PcmValueMin = -1;
Atrac1SynthesisFilterBank<TFloat> SynthesisFilterBank[2];
Atrac1SplitFilterBank<TFloat> SplitFilterBank[2];
diff --git a/src/atrac3denc.cpp b/src/atrac3denc.cpp
index 0dc9e4f..85b0c31 100644
--- a/src/atrac3denc.cpp
+++ b/src/atrac3denc.cpp
@@ -147,8 +147,8 @@ TAtrac3Data::TTonalComponents TAtrac3Processor::ExtractTonalComponents(TFloat* s
//TODO:
TFloat absValue = std::abs(specs[n]);
//std::cerr << n << " " << absValue << " " << level << std::endl;
- if (absValue > 65535.0) {
- TFloat shift = (specs[n] > 0) ? 65535.0 : -65535.0;
+ if (absValue > 0.999999) {
+ TFloat shift = (specs[n] > 0) ? 0.999999 : -0.999999;
std::cerr << "overflow: " << specs[n] << " at: " << n << std::endl;
//res.push_back({n, specs[n] - shift});
specs[n] = shift;
@@ -385,7 +385,7 @@ TPCMEngine<TFloat>::TProcessLambda TAtrac3Processor::GetEncodeLambda()
}
float median = CalcMedian(magnitude.data(), len);
for (uint16_t i = 0; i < len; ++i) {
- if (median > 1.0) {
+ if (median > 0.000015) {
return median;
}
}
diff --git a/src/atrac3denc.h b/src/atrac3denc.h
index 7c9e239..fb19c84 100644
--- a/src/atrac3denc.h
+++ b/src/atrac3denc.h
@@ -58,7 +58,7 @@ public:
typedef TGainProcessor<TAtrac3Data> TAtrac3GainProcessor;
TAtrac3GainProcessor GainProcessor;
TAtrac3MDCT()
- : Mdct512(2)
+ : Mdct512(1)
{}
public:
using TGainModulator = TAtrac3GainProcessor::TGainModulator;
diff --git a/src/wav.cpp b/src/wav.cpp
index c01e4a0..b5827b3 100644
--- a/src/wav.cpp
+++ b/src/wav.cpp
@@ -49,14 +49,12 @@ static int fileext_to_libsndfmt(const std::string& filename) {
TWav::TWav(const std::string& filename)
: File(SndfileHandle(filename)) {
- //disable scaling short -> [-1.0, 1.0]
- File.command(SFC_SET_NORM_DOUBLE /*| SFC_SET_NORM_FLOAT*/, nullptr, SF_FALSE);
+ File.command(SFC_SET_NORM_DOUBLE /*| SFC_SET_NORM_FLOAT*/, nullptr, SF_TRUE);
}
TWav::TWav(const std::string& filename, int channels, int sampleRate)
: File(SndfileHandle(filename, SFM_WRITE, fileext_to_libsndfmt(filename) | SF_FORMAT_PCM_16, channels, sampleRate)) {
- //disable scaling short -> [-1.0, 1.0]
- File.command(SFC_SET_NORM_DOUBLE /*| SFC_SET_NORM_FLOAT*/, nullptr, SF_FALSE);
+ File.command(SFC_SET_NORM_DOUBLE /*| SFC_SET_NORM_FLOAT*/, nullptr, SF_TRUE);
}
TWav::~TWav() {