Skip to content

Commit f018c66

Browse files
committed
Simple ipqf test and ref files
ref files contains samples just before and after ipqf
1 parent 065121a commit f018c66

File tree

7 files changed

+349
-1
lines changed

7 files changed

+349
-1
lines changed
+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
* ATRAC3+ compatible decoder
3+
*
4+
* Copyright (c) 2010-2013 Maxim Poliakovski
5+
*
6+
* This file is part of FFmpeg.
7+
*
8+
* FFmpeg is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* FFmpeg is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with FFmpeg; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
23+
/**
24+
* @file
25+
* DSP functions for ATRAC3+ decoder.
26+
*/
27+
28+
/**
29+
* This file was borrowed from FFmpeg to test analysis PQF implementation
30+
*/
31+
32+
#include <stdio.h>
33+
#include <math.h>
34+
#include <string.h>
35+
36+
#include "atrac3plusdsp.h"
37+
38+
/* lookup table for fast modulo 23 op required for cyclic buffers of the IPQF */
39+
static const int mod23_lut[26] = {
40+
23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
41+
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0
42+
};
43+
44+
/* First half of the 384-tap IPQF filtering coefficients. */
45+
static const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16] = {
46+
{ -5.8336207e-7, -8.0604229e-7, -4.2005411e-7, -4.4400572e-8,
47+
3.226247e-8, 3.530856e-8, 1.2660377e-8, 0.000010516783,
48+
-0.000011838618, 6.005389e-7, 0.0000014333754, 0.0000023108685,
49+
0.0000032569742, 0.0000046192422, 0.0000063894258, 0.0000070302972 },
50+
{ -0.0000091622824, -0.000010502935, -0.0000079212787, -0.0000041712024,
51+
-0.0000026336629, -0.0000015432918, -5.7168614e-7, 0.0000018111954,
52+
0.000023530851, 0.00002780562, 0.000032302323, 0.000036968919,
53+
0.000041575615, 0.000045337845, 0.000046043948, 0.000048585582 },
54+
{ -0.000064464548, -0.000068306952, -0.000073081472, -0.00007612785,
55+
-0.000074850752, -0.000070208509, -0.000062285151, -0.000058270442,
56+
-0.000056296329, -0.000049888811, -0.000035615325, -0.000018532943,
57+
0.0000016657353, 0.00002610587, 0.000053397067, 0.00008079566 },
58+
{ -0.00054488552, -0.00052537228, -0.00049731287, -0.00045778,
59+
-0.00040612387, -0.00034301577, -0.00026866337, -0.00018248901,
60+
-0.000084307925, 0.000025081157, 0.00014135583, 0.00026649953,
61+
0.00039945057, 0.00053928449, 0.00068422867, 0.00083093712 },
62+
{ -0.0014771431, -0.001283227, -0.0010566821, -0.00079780724,
63+
-0.00050782406, -0.00018855913, 0.00015771533, 0.00052769453,
64+
0.00091862219, 0.001326357, 0.0017469483, 0.0021754825,
65+
0.0026067684, 0.0030352892, 0.0034549395, 0.0038591374 },
66+
{ -0.0022995141, -0.001443546, -0.00049266568, 0.00055068987,
67+
0.001682895, 0.0028992873, 0.0041943151, 0.0055614738,
68+
0.0069935122, 0.0084823566, 0.010018963, 0.011593862,
69+
0.013196872, 0.014817309, 0.016444042, 0.018065533 },
70+
{ -0.034426283, -0.034281436, -0.033992987, -0.033563249,
71+
-0.032995768, -0.032295227, -0.031467363, -0.030518902,
72+
-0.02945766, -0.028291954, -0.027031265, -0.025685543,
73+
-0.024265358, -0.022781773, -0.021246184, -0.019670162 },
74+
{ -0.0030586775, -0.0037203205, -0.0042847847, -0.0047529764,
75+
-0.0051268316, -0.0054091476, -0.0056034233, -0.005714261,
76+
-0.0057445862, -0.0057025906, -0.0055920109, -0.0054194843,
77+
-0.0051914565, -0.0049146507, -0.0045959447, -0.0042418269 },
78+
{ -0.0016376863, -0.0017651899, -0.0018608454, -0.0019252141,
79+
-0.0019593791, -0.0019653172, -0.0019450618, -0.0018990048,
80+
-0.00183808, -0.0017501717, -0.0016481078, -0.0015320742,
81+
-0.0014046903, -0.0012685474, -0.001125814, -0.00097943726 },
82+
{ -0.00055432378, -0.00055472925, -0.00054783461, -0.00053276919,
83+
-0.00051135791, -0.00048466062, -0.00045358928, -0.00042499689,
84+
-0.00036942671, -0.0003392619, -0.00030001783, -0.00025986304,
85+
-0.0002197204, -0.00018116167, -0.00014691355, -0.00011279432 },
86+
{ -0.000064147389, -0.00006174868, -0.000054267788, -0.000047133824,
87+
-0.000042927582, -0.000039477309, -0.000036340745, -0.000029687517,
88+
-0.000049787737, -0.000041577889, -0.000033864744, -0.000026534748,
89+
-0.000019841305, -0.000014789486, -0.000013131184, -0.0000099198869 },
90+
{ -0.0000062990207, -0.0000072701259, -0.000011984052, -0.000017348082,
91+
-0.000019907106, -0.000021348773, -0.000021961965, -0.000012203576,
92+
-0.000010840992, 4.6299544e-7, 5.2588763e-7, 2.7792686e-7,
93+
-2.3649704e-7, -0.0000010897784, -9.171448e-7, -5.22682e-7 }
94+
};
95+
96+
/* Second half of the 384-tap IPQF filtering coefficients. */
97+
static const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = {
98+
{ 5.22682e-7, 9.171448e-7, 0.0000010897784, 2.3649704e-7,
99+
-2.7792686e-7, -5.2588763e-7, -4.6299544e-7, 0.000010840992,
100+
-0.000012203576, -0.000021961965, -0.000021348773, -0.000019907106,
101+
-0.000017348082, -0.000011984052, -0.0000072701259, -0.0000062990207 },
102+
{ 0.0000099198869, 0.000013131184, 0.000014789486, 0.000019841305,
103+
0.000026534748, 0.000033864744, 0.000041577889, 0.000049787737,
104+
-0.000029687517, -0.000036340745, -0.000039477309, -0.000042927582,
105+
-0.000047133824, -0.000054267788, -0.00006174868, -0.000064147389 },
106+
{ 0.00011279432, 0.00014691355, 0.00018116167, 0.0002197204,
107+
0.00025986304, 0.00030001783, 0.0003392619, 0.00036942671,
108+
-0.00042499689, -0.00045358928, -0.00048466062, -0.00051135791,
109+
-0.00053276919, -0.00054783461, -0.00055472925, -0.00055432378 },
110+
{ 0.00097943726, 0.001125814, 0.0012685474, 0.0014046903,
111+
0.0015320742, 0.0016481078, 0.0017501717, 0.00183808,
112+
-0.0018990048, -0.0019450618, -0.0019653172, -0.0019593791,
113+
-0.0019252141, -0.0018608454, -0.0017651899, -0.0016376863 },
114+
{ 0.0042418269, 0.0045959447, 0.0049146507, 0.0051914565,
115+
0.0054194843, 0.0055920109, 0.0057025906, 0.0057445862,
116+
-0.005714261, -0.0056034233, -0.0054091476, -0.0051268316,
117+
-0.0047529764, -0.0042847847, -0.0037203205, -0.0030586775 },
118+
{ 0.019670162, 0.021246184, 0.022781773, 0.024265358,
119+
0.025685543, 0.027031265, 0.028291954, 0.02945766,
120+
-0.030518902, -0.031467363, -0.032295227, -0.032995768,
121+
-0.033563249, -0.033992987, -0.034281436, -0.034426283 },
122+
{ -0.018065533, -0.016444042, -0.014817309, -0.013196872,
123+
-0.011593862, -0.010018963, -0.0084823566, -0.0069935122,
124+
0.0055614738, 0.0041943151, 0.0028992873, 0.001682895,
125+
0.00055068987, -0.00049266568, -0.001443546, -0.0022995141 },
126+
{ -0.0038591374, -0.0034549395, -0.0030352892, -0.0026067684,
127+
-0.0021754825, -0.0017469483, -0.001326357, -0.00091862219,
128+
0.00052769453, 0.00015771533, -0.00018855913, -0.00050782406,
129+
-0.00079780724, -0.0010566821, -0.001283227, -0.0014771431 },
130+
{ -0.00083093712, -0.00068422867, -0.00053928449, -0.00039945057,
131+
-0.00026649953, -0.00014135583, -0.000025081157, 0.000084307925,
132+
-0.00018248901, -0.00026866337, -0.00034301577, -0.00040612387,
133+
-0.00045778, -0.00049731287, -0.00052537228, -0.00054488552 },
134+
{ -0.00008079566, -0.000053397067, -0.00002610587, -0.0000016657353,
135+
0.000018532943, 0.000035615325, 0.000049888811, 0.000056296329,
136+
-0.000058270442, -0.000062285151, -0.000070208509, -0.000074850752,
137+
-0.00007612785, -0.000073081472, -0.000068306952, -0.000064464548 },
138+
{ -0.000048585582, -0.000046043948, -0.000045337845, -0.000041575615,
139+
-0.000036968919, -0.000032302323, -0.00002780562, -0.000023530851,
140+
0.0000018111954, -5.7168614e-7, -0.0000015432918, -0.0000026336629,
141+
-0.0000041712024, -0.0000079212787, -0.000010502935, -0.0000091622824 },
142+
{ -0.0000070302972, -0.0000063894258, -0.0000046192422, -0.0000032569742,
143+
-0.0000023108685, -0.0000014333754, -6.005389e-7, 0.000011838618,
144+
0.000010516783, 1.2660377e-8, 3.530856e-8, 3.226247e-8,
145+
-4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 }
146+
};
147+
148+
// Just for test
149+
static void dct4(float* out, const float* x, int N, float scale) {
150+
for (int k = 0; k < N; k++) {
151+
double sum = 0;
152+
for (int n = 0; n < N; n++) {
153+
sum += x[n] * cos((M_PI/N) * ((double)n + 0.5) * ((double)k + 0.5));
154+
}
155+
out[N - 1 - k] = sum * scale;
156+
}
157+
}
158+
159+
void ff_atrac3p_ipqf(Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
160+
{
161+
int i, s, sb, t, pos_now, pos_next;
162+
float idct_in[ATRAC3P_SUBBANDS];
163+
float idct_out[ATRAC3P_SUBBANDS];
164+
165+
memset(out, 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out));
166+
167+
for (s = 0; s < ATRAC3P_SUBBAND_SAMPLES; s++) {
168+
/* pick up one sample from each subband */
169+
for (sb = 0; sb < ATRAC3P_SUBBANDS; sb++)
170+
idct_in[sb] = in[sb * ATRAC3P_SUBBAND_SAMPLES + s];
171+
172+
dct4(idct_out, idct_in, ATRAC3P_SUBBANDS, 1.0/1024);
173+
174+
/* append the result to the history */
175+
for (i = 0; i < 8; i++) {
176+
hist->buf1[hist->pos][i] = idct_out[i + 8];
177+
hist->buf2[hist->pos][i] = idct_out[7 - i];
178+
}
179+
180+
pos_now = hist->pos;
181+
pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_now + 1) % 23;
182+
183+
for (t = 0; t < ATRAC3P_PQF_FIR_LEN; t++) {
184+
for (i = 0; i < 8; i++) {
185+
out[s * 16 + i + 0] += hist->buf1[pos_now][i] * ipqf_coeffs1[t][i] +
186+
hist->buf2[pos_next][i] * ipqf_coeffs2[t][i];
187+
out[s * 16 + i + 8] += hist->buf1[pos_now][7 - i] * ipqf_coeffs1[t][i + 8] +
188+
hist->buf2[pos_next][7 - i] * ipqf_coeffs2[t][i + 8];
189+
}
190+
pos_now = mod23_lut[pos_next + 2]; // pos_now = (pos_now + 2) % 23;
191+
pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_next + 2) % 23;
192+
}
193+
194+
hist->pos = mod23_lut[hist->pos]; // hist->pos = (hist->pos - 1) % 23;
195+
}
196+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of AtracDEnc.
3+
*
4+
* AtracDEnc is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* AtracDEnc is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with AtracDEnc; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef ATRAC3PLUSDSP_H
20+
#define ATRAC3PLUSDSP_H
21+
22+
#define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands
23+
#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband
24+
#define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
25+
26+
#define ATRAC3P_PQF_FIR_LEN 12
27+
28+
typedef struct Atrac3pIPQFChannelCtx {
29+
float buf1[ATRAC3P_PQF_FIR_LEN * 2][8];
30+
float buf2[ATRAC3P_PQF_FIR_LEN * 2][8];
31+
int pos;
32+
} Atrac3pIPQFChannelCtx;
33+
34+
#ifdef __cplusplus
35+
extern "C"
36+
{
37+
#endif /* __cplusplus */
38+
39+
void ff_atrac3p_ipqf(Atrac3pIPQFChannelCtx *hist, const float *in, float *out);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif /* __cplusplus */
44+
45+
46+
47+
#endif
48+
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* This file is part of AtracDEnc.
3+
*
4+
* AtracDEnc is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* AtracDEnc is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with AtracDEnc; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "atrac3plusdsp.h"
20+
21+
#include <gtest/gtest.h>
22+
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
#include <math.h>
27+
28+
#define SAMPLES 8192
29+
30+
static int read_file(FILE* f, float buf[SAMPLES]) {
31+
size_t ret = fread(&buf[0], sizeof(buf[0]), SAMPLES, f);
32+
33+
if (ret != SAMPLES) {
34+
return -1;
35+
}
36+
return 0;
37+
}
38+
39+
TEST(ipqf, CheckOnRefData) {
40+
FILE* mr_f = fopen("test_data/ipqftest_pcm_mr.dat", "r");
41+
if (!mr_f) {
42+
fprintf(stderr, "unable to open multirate file\n");
43+
FAIL();
44+
}
45+
46+
FILE* ref_f = fopen("test_data/ipqftest_pcm_out.dat", "r");
47+
if (!ref_f) {
48+
fclose(mr_f);
49+
fprintf(stderr, "unable to open reference file\n");
50+
FAIL();
51+
}
52+
53+
float mr_data[SAMPLES] = {0};
54+
float ref_data[SAMPLES] = {0};
55+
56+
if (read_file(mr_f, mr_data) < 0) {
57+
fprintf(stderr, "unable to read multirate file\n");
58+
FAIL();
59+
}
60+
61+
if (read_file(ref_f, ref_data) < 0) {
62+
fprintf(stderr, "unable to read reference file\n");
63+
FAIL();
64+
}
65+
66+
Atrac3pIPQFChannelCtx ctx;
67+
memset(&ctx, 0, sizeof(ctx));
68+
69+
float tmp[SAMPLES] = {0};
70+
71+
for (int i = 0; i < SAMPLES; i+= 2048) {
72+
ff_atrac3p_ipqf(&ctx, &mr_data[i], &tmp[i]);
73+
}
74+
75+
const static float err = 1.0 / (float)(1<<26);
76+
for (int i = 0; i < SAMPLES; i++) {
77+
//fprintf(stdout, "%f %f\n", tmp[i], ref_data[i]);
78+
EXPECT_NEAR(tmp[i], ref_data[i], err);
79+
}
80+
}
Binary file not shown.
Binary file not shown.

src/util_ut.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <vector>
2323

24-
2524
TEST(Util, SwapArrayTest) {
2625
TFloat arr[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
2726
SwapArray(arr, 8);

test/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,30 @@ target_link_libraries(atracdenc_ut
2121
GTest::gtest_main
2222
)
2323

24+
configure_file(
25+
../src/atrac/atrac3plus_pqf/ut/test_data/ipqftest_pcm_mr.dat
26+
${CMAKE_CURRENT_BINARY_DIR}/test_data/ipqftest_pcm_mr.dat
27+
COPYONLY
28+
)
29+
30+
configure_file(
31+
../src/atrac/atrac3plus_pqf/ut/test_data/ipqftest_pcm_out.dat
32+
${CMAKE_CURRENT_BINARY_DIR}/test_data/ipqftest_pcm_out.dat
33+
COPYONLY
34+
)
35+
36+
set(at3plus_pqf_ut
37+
../src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp
38+
../src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c
39+
)
40+
41+
add_executable(at3plus_pqf_ut ${at3plus_pqf_ut})
42+
43+
target_link_libraries(at3plus_pqf_ut
44+
m
45+
GTest::gtest_main
46+
)
47+
2448
enable_testing()
2549
add_test(ut atracdenc_ut)
50+
add_test(at3plus_pqf_ut at3plus_pqf_ut)

0 commit comments

Comments
 (0)