aboutsummaryrefslogtreecommitdiffstats
path: root/src/atracdenc_ut.cpp
blob: 416b97293c684701a61690286e3373894592f22f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * This file is part of AtracDEnc.
 *
 * AtracDEnc is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * AtracDEnc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with AtracDEnc; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "atrac1denc.h"
#include <lib/mdct/mdct_ut_common.h>
#include <gtest/gtest.h>

#include <vector>
using std::vector;
using namespace NAtracDEnc;

void CheckResult128(const vector<float>& a, const vector<float>& b) {
    float m = 0.0;
    for (int i = 0; i < a.size(); i++) {
        m = fmax(m, (float)a[i]);
    }

    auto eps = CalcEps(m);

    for (int i = 0; i < 96; ++i ) {
        EXPECT_NEAR(a[i], 4 * b[i+32], eps);
    }
}

void CheckResult256(const vector<float>& a, const vector<float>& b) {
    float m = 0.0;
    for (int i = 0; i < a.size(); i++) {
        m = fmax(m, (float)a[i]);
    }

    auto eps = CalcEps(m);

    for (int i = 0; i < 192; ++i ) {
        EXPECT_NEAR(a[i], 2 * b[i+32], eps);
    }
}


TEST(TAtrac1MDCT, TAtrac1MDCTLongEncDec) {
    TAtrac1MDCT mdct;
    vector<float> low(128 * 2);
    vector<float> mid(128 * 2);
    vector<float> hi(256 * 2);
    vector<float> specs(512 * 2);

    vector<float> lowRes(128 * 2);
    vector<float> midRes(128 * 2);
    vector<float> hiRes(256 * 2);
 
    for (int i = 0; i < 128; i++) {
        low[i] = mid[i] = i;
    }

    for (int i = 0; i < 256; i++) {
        hi[i] = i;
    }
    const TBlockSize blockSize(false, false, false);

    mdct.Mdct(&specs[0], &low[0], &mid[0], &hi[0], blockSize);

    mdct.IMdct(&specs[0], blockSize, &lowRes[0], &midRes[0], &hiRes[0]);

    CheckResult128(low, lowRes);
    CheckResult128(mid, midRes);
    CheckResult256(hi, hiRes);
}

TEST(TAtrac1MDCT, TAtrac1MDCTShortEncDec) {
    TAtrac1MDCT mdct;
    vector<float> low(128 * 2);
    vector<float> mid(128 * 2);
    vector<float> hi(256 * 2);
    vector<float> specs(512 * 2);

    vector<float> lowRes(128 * 2);
    vector<float> midRes(128 * 2);
    vector<float> hiRes(256 * 2);
 
    for (int i = 0; i < 128; i++) {
        low[i] = mid[i] = i;
    }
    const vector<float> lowCopy = low; //in case of short wondow AtracMDCT changed input buffer during calculation
    const vector<float> midCopy = mid;

    for (int i = 0; i < 256; i++) {
        hi[i] = i;
    }
    const vector<float> hiCopy = hi;

    const TBlockSize blockSize(true, true, true); //short

    mdct.Mdct(&specs[0], &low[0], &mid[0], &hi[0], blockSize);

    mdct.IMdct(&specs[0], blockSize, &lowRes[0], &midRes[0], &hiRes[0]);

    CheckResult128(lowCopy, lowRes);
    CheckResult128(midCopy, midRes);
    CheckResult256(hiCopy, hiRes);
}