aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2024-12-20 22:31:20 +0100
committerDaniil Cherednik <dan.cherednik@gmail.com>2024-12-21 16:30:07 +0100
commit74d6e04c21bddd435bd74c34dbe027b883772a76 (patch)
tree4221df9da5a17897296e5f7f841f01b1f6428c74 /src/lib
parent78649b2f5941e0649db960cafb2997b5ca432be1 (diff)
downloadatracdenc-74d6e04c21bddd435bd74c34dbe027b883772a76.tar.gz
[refactoring] Get rid of TFloat parameter. Use float.HEADmaster
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/mdct/mdct.cpp10
-rw-r--r--src/lib/mdct/mdct.h42
-rw-r--r--src/lib/mdct/mdct_ut.cpp80
-rw-r--r--src/lib/mdct/mdct_ut_common.h4
4 files changed, 68 insertions, 68 deletions
diff --git a/src/lib/mdct/mdct.cpp b/src/lib/mdct/mdct.cpp
index 74b6d91..c2872db 100644
--- a/src/lib/mdct/mdct.cpp
+++ b/src/lib/mdct/mdct.cpp
@@ -22,11 +22,11 @@
namespace NMDCT {
-static std::vector<TFloat> CalcSinCos(size_t n, TFloat scale)
+static std::vector<float> CalcSinCos(size_t n, float scale)
{
- std::vector<TFloat> tmp(n >> 1);
- const TFloat alpha = 2.0 * M_PI / (8.0 * n);
- const TFloat omiga = 2.0 * M_PI / n;
+ std::vector<float> tmp(n >> 1);
+ const float alpha = 2.0 * M_PI / (8.0 * n);
+ const float omiga = 2.0 * M_PI / n;
scale = sqrt(scale/n);
for (size_t i = 0; i < (n >> 2); ++i) {
tmp[2 * i + 0] = scale * cos(omiga * i + alpha);
@@ -35,7 +35,7 @@ static std::vector<TFloat> CalcSinCos(size_t n, TFloat scale)
return tmp;
}
-TMDCTBase::TMDCTBase(size_t n, TFloat scale)
+TMDCTBase::TMDCTBase(size_t n, float scale)
: N(n)
, SinCos(CalcSinCos(n, scale))
{
diff --git a/src/lib/mdct/mdct.h b/src/lib/mdct/mdct.h
index 988d1e9..114af30 100644
--- a/src/lib/mdct/mdct.h
+++ b/src/lib/mdct/mdct.h
@@ -25,21 +25,21 @@
namespace NMDCT {
-static_assert(sizeof(kiss_fft_scalar) == sizeof(TFloat), "size of fft_scalar is not equal to size of TFloat");
+static_assert(sizeof(kiss_fft_scalar) == sizeof(float), "size of fft_scalar is not equal to size of float");
class TMDCTBase {
protected:
const size_t N;
- const std::vector<TFloat> SinCos;
+ const std::vector<float> SinCos;
kiss_fft_cpx* FFTIn;
kiss_fft_cpx* FFTOut;
kiss_fft_cfg FFTPlan;
- TMDCTBase(size_t n, TFloat scale);
+ TMDCTBase(size_t n, float scale);
virtual ~TMDCTBase();
};
-template<size_t TN, typename TIO = TFloat>
+template<size_t TN, typename TIO = float>
class TMDCT : public TMDCTBase {
std::vector<TIO> Buf;
public:
@@ -54,15 +54,15 @@ public:
const size_t n4 = N >> 2;
const size_t n34 = 3 * n4;
const size_t n54 = 5 * n4;
- const TFloat* cos = &SinCos[0];
- const TFloat* sin = &SinCos[1];
+ const float* cos = &SinCos[0];
+ const float* sin = &SinCos[1];
- TFloat *xr, *xi, r0, i0;
- TFloat c, s;
+ float *xr, *xi, r0, i0;
+ float c, s;
size_t n;
- xr = (TFloat*)FFTIn;
- xi = (TFloat*)FFTIn + 1;
+ xr = (float*)FFTIn;
+ xi = (float*)FFTIn + 1;
for (n = 0; n < n4; n += 2) {
r0 = in[n34 - 1 - n] + in[n34 + n];
i0 = in[n4 + n] - in[n4 - 1 - n];
@@ -87,8 +87,8 @@ public:
kiss_fft(FFTPlan, FFTIn, FFTOut);
- xr = (TFloat*)FFTOut;
- xi = (TFloat*)FFTOut + 1;
+ xr = (float*)FFTOut;
+ xi = (float*)FFTOut + 1;
for (n = 0; n < n2; n += 2) {
r0 = xr[n];
i0 = xi[n];
@@ -104,7 +104,7 @@ public:
}
};
-template<size_t TN, typename TIO = TFloat>
+template<size_t TN, typename TIO = float>
class TMIDCT : public TMDCTBase {
std::vector<TIO> Buf;
public:
@@ -118,15 +118,15 @@ public:
const size_t n4 = N >> 2;
const size_t n34 = 3 * n4;
const size_t n54 = 5 * n4;
- const TFloat* cos = &SinCos[0];
- const TFloat* sin = &SinCos[1];
+ const float* cos = &SinCos[0];
+ const float* sin = &SinCos[1];
- TFloat *xr, *xi, r0, i0, r1, i1;
- TFloat c, s;
+ float *xr, *xi, r0, i0, r1, i1;
+ float c, s;
size_t n;
- xr = (TFloat*)FFTIn;
- xi = (TFloat*)FFTIn + 1;
+ xr = (float*)FFTIn;
+ xi = (float*)FFTIn + 1;
for (n = 0; n < n2; n += 2) {
r0 = in[n];
@@ -141,8 +141,8 @@ public:
kiss_fft(FFTPlan, FFTIn, FFTOut);
- xr = (TFloat*)FFTOut;
- xi = (TFloat*)FFTOut + 1;
+ xr = (float*)FFTOut;
+ xi = (float*)FFTOut + 1;
for (n = 0; n < n4; n += 2) {
r0 = xr[n];
diff --git a/src/lib/mdct/mdct_ut.cpp b/src/lib/mdct/mdct_ut.cpp
index 6f49b59..d997b08 100644
--- a/src/lib/mdct/mdct_ut.cpp
+++ b/src/lib/mdct/mdct_ut.cpp
@@ -26,24 +26,24 @@
using std::vector;
using namespace NMDCT;
-static vector<TFloat> mdct(TFloat* x, int N) {
- vector<TFloat> res;
+static vector<float> mdct(float* x, int N) {
+ vector<float> res;
for (int k = 0; k < N; k++) {
- TFloat sum = 0;
+ float sum = 0;
for (int n = 0; n < 2 * N; n++)
- sum += x[n]* cos((M_PI/N) * ((TFloat)n + 0.5 + N/2) * ((TFloat)k + 0.5));
+ sum += x[n]* cos((M_PI/N) * ((float)n + 0.5 + N/2) * ((float)k + 0.5));
res.push_back(sum);
}
return res;
}
-static vector<TFloat> midct(TFloat* x, int N) {
- vector<TFloat> res;
+static vector<float> midct(float* x, int N) {
+ vector<float> res;
for (int n = 0; n < 2 * N; n++) {
- TFloat sum = 0;
+ float sum = 0;
for (int k = 0; k < N; k++)
- sum += (x[k] * cos((M_PI/N) * ((TFloat)n + 0.5 + N/2) * ((TFloat)k + 0.5)));
+ sum += (x[k] * cos((M_PI/N) * ((float)n + 0.5 + N/2) * ((float)k + 0.5)));
res.push_back(sum);
}
@@ -53,12 +53,12 @@ static vector<TFloat> midct(TFloat* x, int N) {
TEST(TMdctTest, MDCT32) {
const int N = 32;
TMDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = mdct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = mdct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N);
for (int i = 0; i < res1.size(); i++) {
@@ -69,12 +69,12 @@ TEST(TMdctTest, MDCT32) {
TEST(TMdctTest, MDCT64) {
const int N = 64;
TMDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = mdct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = mdct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N);
for (int i = 0; i < res1.size(); i++) {
@@ -85,12 +85,12 @@ TEST(TMdctTest, MDCT64) {
TEST(TMdctTest, MDCT128) {
const int N = 128;
TMDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = mdct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = mdct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N * 4);
for (int i = 0; i < res1.size(); i++) {
@@ -101,12 +101,12 @@ TEST(TMdctTest, MDCT128) {
TEST(TMdctTest, MDCT256) {
const int N = 256;
TMDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = mdct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = mdct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N * 4);
for (int i = 0; i < res1.size(); i++) {
@@ -117,14 +117,14 @@ TEST(TMdctTest, MDCT256) {
TEST(TMdctTest, MDCT256_RAND) {
const int N = 256;
TMDCT<N> transform(N);
- vector<TFloat> src(N);
- TFloat m = 0.0;
+ vector<float> src(N);
+ float m = 0.0;
for (int i = 0; i < N; i++) {
src[i] = rand();
m = std::max(m, src[i]);
}
- const vector<TFloat> res1 = mdct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = mdct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(m * 8);
for (int i = 0; i < res1.size(); i++) {
@@ -135,12 +135,12 @@ TEST(TMdctTest, MDCT256_RAND) {
TEST(TMdctTest, MIDCT32) {
const int N = 32;
TMIDCT<N> transform;
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N/2; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = midct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = midct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N);
for (int i = 0; i < N; i++) {
@@ -151,12 +151,12 @@ TEST(TMdctTest, MIDCT32) {
TEST(TMdctTest, MIDCT64) {
const int N = 64;
TMIDCT<N> transform;
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N/2; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = midct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = midct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N);
for (int i = 0; i < N; i++) {
@@ -167,12 +167,12 @@ TEST(TMdctTest, MIDCT64) {
TEST(TMdctTest, MIDCT128) {
const int N = 128;
TMIDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N/2; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = midct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = midct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N);
for (int i = 0; i < N; i++) {
@@ -183,12 +183,12 @@ TEST(TMdctTest, MIDCT128) {
TEST(TMdctTest, MIDCT256) {
const int N = 256;
TMIDCT<N> transform(N);
- vector<TFloat> src(N);
+ vector<float> src(N);
for (int i = 0; i < N/2; i++) {
src[i] = i;
}
- const vector<TFloat> res1 = midct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = midct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(N * 2);
for (int i = 0; i < N; i++) {
@@ -199,14 +199,14 @@ TEST(TMdctTest, MIDCT256) {
TEST(TMdctTest, MIDCT256_RAND) {
const int N = 256;
TMIDCT<N> transform(N);
- vector<TFloat> src(N);
- TFloat m = 0.0;
+ vector<float> src(N);
+ float m = 0.0;
for (int i = 0; i < N/2; i++) {
src[i] = rand();
m = std::max(m, src[i]);
}
- const vector<TFloat> res1 = midct(&src[0], N/2);
- const vector<TFloat> res2 = transform(&src[0]);
+ const vector<float> res1 = midct(&src[0], N/2);
+ const vector<float> res2 = transform(&src[0]);
EXPECT_EQ(res1.size(), res2.size());
auto eps = CalcEps(m * 4);
for (int i = 0; i < N; i++) {
diff --git a/src/lib/mdct/mdct_ut_common.h b/src/lib/mdct/mdct_ut_common.h
index 5c1096c..060e2d0 100644
--- a/src/lib/mdct/mdct_ut_common.h
+++ b/src/lib/mdct/mdct_ut_common.h
@@ -21,8 +21,8 @@
#include "mdct.h"
// Calculate value of error for given magnitude
-inline TFloat CalcEps(TFloat magn) {
- const float snr = (sizeof(TFloat) == 4) ? -114.0 : -240.0;
+inline float CalcEps(float magn) {
+ const float snr = (sizeof(float) == 4) ? -114.0 : -240.0;
return magn * pow(10, (snr / 20.0));
}