diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-05-19 09:44:38 +0000 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-06-14 18:58:21 +0200 |
commit | ee120708d72db31012a6aa7b2f6b99960ae1f6d7 (patch) | |
tree | 3eae72eb8ee2c337500d0ff8252e69ffe86e1f4b | |
parent | f018c661a7a6093cabc40784ae3b1fefb96c82de (diff) | |
download | atracdenc-ee120708d72db31012a6aa7b2f6b99960ae1f6d7.tar.gz |
[AT3P] PQF implementation
M=16 perfect reconstruction polyphase quadrature analysis filter bank
-rw-r--r-- | src/atrac/atrac3plus_pqf/atrac3plus_pqf.c | 138 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/atrac3plus_pqf.h | 6 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/atrac3plus_pqf_data.h | 132 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/atrac3plus_pqf_prototype.h | 411 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/tools/plot/main.py | 69 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/tools/plot/pqf/pqf_binding.c | 187 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/tools/plot/pqf/setup.py | 6 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/tools/plot/run.sh | 12 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c | 114 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.h | 2 | ||||
-rw-r--r-- | src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp | 217 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 |
12 files changed, 407 insertions, 888 deletions
diff --git a/src/atrac/atrac3plus_pqf/atrac3plus_pqf.c b/src/atrac/atrac3plus_pqf/atrac3plus_pqf.c index 2515a6d..30dbbc8 100644 --- a/src/atrac/atrac3plus_pqf/atrac3plus_pqf.c +++ b/src/atrac/atrac3plus_pqf/atrac3plus_pqf.c @@ -28,7 +28,7 @@ #include <math.h> #include "atrac3plus_pqf.h" -#include "atrac3plus_pqf_prototype.h" +#include "atrac3plus_pqf_data.h" /* * Number of subbands to split input signal @@ -44,111 +44,84 @@ #define PROTO_SZ 384 #define FRAME_SZ ((SUBBANDS_NUM * SUBBAND_SIZE)) -#define EXTRA_SZ ((PROTO_SZ - SUBBANDS_NUM)) +#define OVERLAP_SZ ((PROTO_SZ - SUBBANDS_NUM)) -const uint16_t at3plus_pqf_frame_sz = FRAME_SZ; -const uint16_t at3plus_pqf_proto_sz = PROTO_SZ; -static float C[PROTO_SZ]; -static float M[256]; +static float fir[PROTO_SZ]; + +static void dct4(float* out, const float* x, int N, float scale) { + for (int k = 0; k < N; k++) { + double sum = 0; + for (int n = 0; n < N; n++) { + sum += ((double)x[n] * cosl((M_PI/(double)N) * ((double)n + 0.5) * ((double)k + 0.5))); + } + out[N - 1 - k] = sum * scale; + } +} struct at3plus_pqf_a_ctx { - float buf[FRAME_SZ + EXTRA_SZ]; + float buf[FRAME_SZ + OVERLAP_SZ]; }; static void init(void) { - int i; - int j; - const float* const t = at3plus_pqf_prototype; static int inited = 0; if (inited) return; - inited = 1; - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { - M[i*16 + j] = (float)cos(((2 * i + 1) * j & 127) * M_PI / 32); - } - } + inited = 1; - for (i = 0; i < 6; i++) { - for (j = 0; j < 32; j++) { - if (i & 1) { - C[j * 12 + i] = 1.489 * t[j * 2 + 64 * i]; - C[j * 12 + 6 + i] = 1.489 * t[j * 2 + 1 + 64 * i]; - } else { - C[j * 12 + i] = -1.489 * t[j * 2 + 64 * i]; - C[j * 12 + 6 + i] = -1.489 * t[j * 2 + 1 + 64 * i]; - } + for (int i = 0; i < 16; i++) { + for (int j = 0; j < ATRAC3P_PQF_FIR_LEN; j++) { + if (i >= 8) { + fir[j + 96 + (i - 8) * 12] = ff_ipqf_coeffs1[j][i]; + fir[j + 288 + (i - 8) * 12] = ff_ipqf_coeffs2[j][i]; + } else { + fir[j + 192 + i * 12] = ff_ipqf_coeffs2[j][i]; + fir[j + 0 + i * 12] = ff_ipqf_coeffs1[j][i]; + } } } } -static void vectoring(const float* x, float* y) +static void vectoring(const float* const x, float* y) { - int i; - int j; - const float* c = C; - - for ( i = 0; i < SUBBANDS_NUM * 2; i++, c += 12, x += 1, y += 1 ) { - y[0] = 0; - for (j = 0; j < 12; j++) { - y[0] += c[j] * x[j * 32]; + for (int i = 0; i < 32; i++) { + y[i] = 0; + for (int j = 0; j < ATRAC3P_PQF_FIR_LEN; j++) { + y[i] += fir[i * 12 + j] * x[j * 32 + i]; } } } -static void matrixing(const float* mi, const float* y, float* samples ) -{ - int i; - for (i = 0; i < SUBBANDS_NUM; i++, mi += 16, samples += SUBBAND_SIZE) { - samples[0] = y[8] + mi[ 1] * (y[7]+y[9]) - + mi[ 2] * (y[6]+y[10]) + mi[ 3] * (y[5]+y[11]) - + mi[ 4] * (y[4]+y[12]) + mi[ 5] * (y[3]+y[13]) - + mi[ 6] * (y[2]+y[14]) + mi[ 7] * (y[ 1]+y[15]) - + mi[ 8] * (y[ 0]+y[16]) - + mi[15] * (y[23]-y[25]) + mi[14] * (y[22]-y[26]) - + mi[13] * (y[21]-y[27]) + mi[12] * (y[20]-y[28]) - + mi[11] * (y[19]-y[29]) + mi[10] * (y[18]-y[30]) - + mi[ 9] * (y[17]-y[31]); - } -} - -static void a_init(at3plus_pqf_a_ctx_t ctx) +static void matrixing(const float* y, float* samples ) { - float y[SUBBANDS_NUM * 2]; - float out[FRAME_SZ]; - float* x; - int n, i; - - float* buf = ctx->buf; - init(); + float yy[SUBBANDS_NUM]; + float res[SUBBANDS_NUM]; - memcpy ( buf + FRAME_SZ, buf, EXTRA_SZ * sizeof(*buf) ); - x = buf + FRAME_SZ; - - for ( n = 0; n < SUBBAND_SIZE; n++ ) { - x -= SUBBANDS_NUM; + for (int i = 0; i < 8; i++) { + yy[i] = y[i + 8] + y[7 - i]; + yy[i + 8] = y[i + 16] + y[31 - i]; + } - for (i = 0; i < SUBBANDS_NUM; i++) - x[i] = 0.0; + dct4(res, yy, SUBBANDS_NUM, 128.0 * 512.0); - vectoring(x, y); - matrixing (M, y, &out[n]); + for (int i = 0; i < SUBBANDS_NUM; i++) { + samples[i * SUBBAND_SIZE] = res[SUBBANDS_NUM - 1 - i]; } } at3plus_pqf_a_ctx_t at3plus_pqf_create_a_ctx() { - int i = 0; at3plus_pqf_a_ctx_t ctx = (at3plus_pqf_a_ctx_t)malloc(sizeof(struct at3plus_pqf_a_ctx)); - for (i = 0; i < FRAME_SZ + EXTRA_SZ; i++) { + + for (int i = 0; i < FRAME_SZ + OVERLAP_SZ; i++) { ctx->buf[i] = 0.0; } - a_init(ctx); + init(); + return ctx; } @@ -160,29 +133,18 @@ void at3plus_pqf_free_a_ctx(at3plus_pqf_a_ctx_t ctx) void at3plus_pqf_do_analyse(at3plus_pqf_a_ctx_t ctx, const float* in, float* out) { float y[SUBBANDS_NUM * 2]; - float* x; - const float* pcm; - int n, i; - float* buf = ctx->buf; + float* const buf = ctx->buf; - memcpy(buf + FRAME_SZ, buf, EXTRA_SZ * sizeof(float)); - x = buf + FRAME_SZ; + const float* x = buf; - pcm = in + (SUBBANDS_NUM - 1); + memcpy(buf + OVERLAP_SZ, in, sizeof(in[0]) * FRAME_SZ); - for (n = 0; n < SUBBAND_SIZE; n++, pcm += SUBBANDS_NUM * 2) { - x -= SUBBANDS_NUM; - for (i = 0; i < SUBBANDS_NUM; i++) { - x[i] = *pcm--; - } + for (int i = 0; i < SUBBAND_SIZE; i++) { vectoring(x, y); - matrixing (M, y, &out[n]); + matrixing (y, &out[i]); + x += SUBBANDS_NUM; } -} -const float* at3plus_pqf_get_proto(void) -{ - return at3plus_pqf_prototype; + memcpy(buf, buf + FRAME_SZ, sizeof(buf[0]) * OVERLAP_SZ); } - diff --git a/src/atrac/atrac3plus_pqf/atrac3plus_pqf.h b/src/atrac/atrac3plus_pqf/atrac3plus_pqf.h index 1be44d0..8e75b0e 100644 --- a/src/atrac/atrac3plus_pqf/atrac3plus_pqf.h +++ b/src/atrac/atrac3plus_pqf/atrac3plus_pqf.h @@ -27,16 +27,10 @@ typedef struct at3plus_pqf_a_ctx *at3plus_pqf_a_ctx_t; extern "C" { #endif -extern const uint16_t at3plus_pqf_frame_sz; -extern const uint16_t at3plus_pqf_proto_sz; - at3plus_pqf_a_ctx_t at3plus_pqf_create_a_ctx(void); void at3plus_pqf_free_a_ctx(at3plus_pqf_a_ctx_t ctx); void at3plus_pqf_do_analyse(at3plus_pqf_a_ctx_t ctx, const float* in, float* out); -// Debug functions -const float* at3plus_pqf_get_proto(void); - #ifdef __cplusplus } #endif diff --git a/src/atrac/atrac3plus_pqf/atrac3plus_pqf_data.h b/src/atrac/atrac3plus_pqf/atrac3plus_pqf_data.h new file mode 100644 index 0000000..c83720c --- /dev/null +++ b/src/atrac/atrac3plus_pqf/atrac3plus_pqf_data.h @@ -0,0 +1,132 @@ +/* + * 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 + */ + +#ifndef ATRAC3PLUSPQFDATA_H +#define ATRAC3PLUSPQFDATA_H + +#define ATRAC3P_PQF_FIR_LEN 12 + +/* + * Borrowed from FFmpeg + */ + +/* First half of the 384-tap IPQF filtering coefficients. */ +static const float ff_ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16] = { + { -5.8336207e-7, -8.0604229e-7, -4.2005411e-7, -4.4400572e-8, + 3.226247e-8, 3.530856e-8, 1.2660377e-8, 0.000010516783, + -0.000011838618, 6.005389e-7, 0.0000014333754, 0.0000023108685, + 0.0000032569742, 0.0000046192422, 0.0000063894258, 0.0000070302972 }, + { -0.0000091622824, -0.000010502935, -0.0000079212787, -0.0000041712024, + -0.0000026336629, -0.0000015432918, -5.7168614e-7, 0.0000018111954, + 0.000023530851, 0.00002780562, 0.000032302323, 0.000036968919, + 0.000041575615, 0.000045337845, 0.000046043948, 0.000048585582 }, + { -0.000064464548, -0.000068306952, -0.000073081472, -0.00007612785, + -0.000074850752, -0.000070208509, -0.000062285151, -0.000058270442, + -0.000056296329, -0.000049888811, -0.000035615325, -0.000018532943, + 0.0000016657353, 0.00002610587, 0.000053397067, 0.00008079566 }, + { -0.00054488552, -0.00052537228, -0.00049731287, -0.00045778, + -0.00040612387, -0.00034301577, -0.00026866337, -0.00018248901, + -0.000084307925, 0.000025081157, 0.00014135583, 0.00026649953, + 0.00039945057, 0.00053928449, 0.00068422867, 0.00083093712 }, + { -0.0014771431, -0.001283227, -0.0010566821, -0.00079780724, + -0.00050782406, -0.00018855913, 0.00015771533, 0.00052769453, + 0.00091862219, 0.001326357, 0.0017469483, 0.0021754825, + 0.0026067684, 0.0030352892, 0.0034549395, 0.0038591374 }, + { -0.0022995141, -0.001443546, -0.00049266568, 0.00055068987, + 0.001682895, 0.0028992873, 0.0041943151, 0.0055614738, + 0.0069935122, 0.0084823566, 0.010018963, 0.011593862, + 0.013196872, 0.014817309, 0.016444042, 0.018065533 }, + { -0.034426283, -0.034281436, -0.033992987, -0.033563249, + -0.032995768, -0.032295227, -0.031467363, -0.030518902, + -0.02945766, -0.028291954, -0.027031265, -0.025685543, + -0.024265358, -0.022781773, -0.021246184, -0.019670162 }, + { -0.0030586775, -0.0037203205, -0.0042847847, -0.0047529764, + -0.0051268316, -0.0054091476, -0.0056034233, -0.005714261, + -0.0057445862, -0.0057025906, -0.0055920109, -0.0054194843, + -0.0051914565, -0.0049146507, -0.0045959447, -0.0042418269 }, + { -0.0016376863, -0.0017651899, -0.0018608454, -0.0019252141, + -0.0019593791, -0.0019653172, -0.0019450618, -0.0018990048, + -0.00183808, -0.0017501717, -0.0016481078, -0.0015320742, + -0.0014046903, -0.0012685474, -0.001125814, -0.00097943726 }, + { -0.00055432378, -0.00055472925, -0.00054783461, -0.00053276919, + -0.00051135791, -0.00048466062, -0.00045358928, -0.00042499689, + -0.00036942671, -0.0003392619, -0.00030001783, -0.00025986304, + -0.0002197204, -0.00018116167, -0.00014691355, -0.00011279432 }, + { -0.000064147389, -0.00006174868, -0.000054267788, -0.000047133824, + -0.000042927582, -0.000039477309, -0.000036340745, -0.000029687517, + -0.000049787737, -0.000041577889, -0.000033864744, -0.000026534748, + -0.000019841305, -0.000014789486, -0.000013131184, -0.0000099198869 }, + { -0.0000062990207, -0.0000072701259, -0.000011984052, -0.000017348082, + -0.000019907106, -0.000021348773, -0.000021961965, -0.000012203576, + -0.000010840992, 4.6299544e-7, 5.2588763e-7, 2.7792686e-7, + -2.3649704e-7, -0.0000010897784, -9.171448e-7, -5.22682e-7 } +}; + +/* Second half of the 384-tap IPQF filtering coefficients. */ +static const float ff_ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = { + { 5.22682e-7, 9.171448e-7, 0.0000010897784, 2.3649704e-7, + -2.7792686e-7, -5.2588763e-7, -4.6299544e-7, 0.000010840992, + -0.000012203576, -0.000021961965, -0.000021348773, -0.000019907106, + -0.000017348082, -0.000011984052, -0.0000072701259, -0.0000062990207 }, + { 0.0000099198869, 0.000013131184, 0.000014789486, 0.000019841305, + 0.000026534748, 0.000033864744, 0.000041577889, 0.000049787737, + -0.000029687517, -0.000036340745, -0.000039477309, -0.000042927582, + -0.000047133824, -0.000054267788, -0.00006174868, -0.000064147389 }, + { 0.00011279432, 0.00014691355, 0.00018116167, 0.0002197204, + 0.00025986304, 0.00030001783, 0.0003392619, 0.00036942671, + -0.00042499689, -0.00045358928, -0.00048466062, -0.00051135791, + -0.00053276919, -0.00054783461, -0.00055472925, -0.00055432378 }, + { 0.00097943726, 0.001125814, 0.0012685474, 0.0014046903, + 0.0015320742, 0.0016481078, 0.0017501717, 0.00183808, + -0.0018990048, -0.0019450618, -0.0019653172, -0.0019593791, + -0.0019252141, -0.0018608454, -0.0017651899, -0.0016376863 }, + { 0.0042418269, 0.0045959447, 0.0049146507, 0.0051914565, + 0.0054194843, 0.0055920109, 0.0057025906, 0.0057445862, + -0.005714261, -0.0056034233, -0.0054091476, -0.0051268316, + -0.0047529764, -0.0042847847, -0.0037203205, -0.0030586775 }, + { 0.019670162, 0.021246184, 0.022781773, 0.024265358, + 0.025685543, 0.027031265, 0.028291954, 0.02945766, + -0.030518902, -0.031467363, -0.032295227, -0.032995768, + -0.033563249, -0.033992987, -0.034281436, -0.034426283 }, + { -0.018065533, -0.016444042, -0.014817309, -0.013196872, + -0.011593862, -0.010018963, -0.0084823566, -0.0069935122, + 0.0055614738, 0.0041943151, 0.0028992873, 0.001682895, + 0.00055068987, -0.00049266568, -0.001443546, -0.0022995141 }, + { -0.0038591374, -0.0034549395, -0.0030352892, -0.0026067684, + -0.0021754825, -0.0017469483, -0.001326357, -0.00091862219, + 0.00052769453, 0.00015771533, -0.00018855913, -0.00050782406, + -0.00079780724, -0.0010566821, -0.001283227, -0.0014771431 }, + { -0.00083093712, -0.00068422867, -0.00053928449, -0.00039945057, + -0.00026649953, -0.00014135583, -0.000025081157, 0.000084307925, + -0.00018248901, -0.00026866337, -0.00034301577, -0.00040612387, + -0.00045778, -0.00049731287, -0.00052537228, -0.00054488552 }, + { -0.00008079566, -0.000053397067, -0.00002610587, -0.0000016657353, + 0.000018532943, 0.000035615325, 0.000049888811, 0.000056296329, + -0.000058270442, -0.000062285151, -0.000070208509, -0.000074850752, + -0.00007612785, -0.000073081472, -0.000068306952, -0.000064464548 }, + { -0.000048585582, -0.000046043948, -0.000045337845, -0.000041575615, + -0.000036968919, -0.000032302323, -0.00002780562, -0.000023530851, + 0.0000018111954, -5.7168614e-7, -0.0000015432918, -0.0000026336629, + -0.0000041712024, -0.0000079212787, -0.000010502935, -0.0000091622824 }, + { -0.0000070302972, -0.0000063894258, -0.0000046192422, -0.0000032569742, + -0.0000023108685, -0.0000014333754, -6.005389e-7, 0.000011838618, + 0.000010516783, 1.2660377e-8, 3.530856e-8, 3.226247e-8, + -4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 } +}; + +#endif diff --git a/src/atrac/atrac3plus_pqf/atrac3plus_pqf_prototype.h b/src/atrac/atrac3plus_pqf/atrac3plus_pqf_prototype.h deleted file mode 100644 index 6cfa070..0000000 --- a/src/atrac/atrac3plus_pqf/atrac3plus_pqf_prototype.h +++ /dev/null @@ -1,411 +0,0 @@ -/* - * 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 - */ - -#ifndef ATRAC3PLUSPQFPROTOTPE_H -#define ATRAC3PLUSPQFPROTOTPE_H - -const float at3plus_pqf_prototype[384] = -{ -0.00000058336207, -0.00000080604229, -0.00000042005411, -0.00000004440057, --0.00000003226247, --0.00000003530856, --0.00000001266038, --0.00001051678282, -0.00001183861787, --0.00000060053890, --0.00000143337536, --0.00000231086847, --0.00000325697420, --0.00000461924219, --0.00000638942583, --0.00000703029718, --0.00000052268200, --0.00000091714480, --0.00000108977838, --0.00000023649704, -0.00000027792686, -0.00000052588763, -0.00000046299544, --0.00001084099222, --0.00001220357626, --0.00002196196510, --0.00002134877286, --0.00001990710552, --0.00001734808211, --0.00001198405243, --0.00000727012593, --0.00000629902070, --0.00000916228237, --0.00001050293486, --0.00000792127867, --0.00000417120236, --0.00000263366292, --0.00000154329177, --0.00000057168614, -0.00000181119538, -0.00002353085074, -0.00002780561954, -0.00003230232323, -0.00003696891872, -0.00004157561489, -0.00004533784522, -0.00004604394780, -0.00004858558168, -0.00000991988691, -0.00001313118355, -0.00001478948616, -0.00001984130540, -0.00002653474803, -0.00003386474418, -0.00004157788862, -0.00004978773723, -0.00002968751687, -0.00003634074528, -0.00003947730875, -0.00004292758240, -0.00004713382441, -0.00005426778807, -0.00006174868031, -0.00006414738891, -0.00006446454790, -0.00006830695202, -0.00007308147178, -0.00007612784975, -0.00007485075184, -0.00007020850899, -0.00006228515122, -0.00005827044151, -0.00005629632869, -0.00004988881119, -0.00003561532503, -0.00001853294270, --0.00000166573534, --0.00002610587035, --0.00005339706695, --0.00008079566032, --0.00011279431783, --0.00014691354590, --0.00018116166757, --0.00021972040122, --0.00025986303808, --0.00030001782579, --0.00033926189644, --0.00036942670704, --0.00042499689152, --0.00045358928037, --0.00048466061708, --0.00051135791000, --0.00053276919061, --0.00054783461383, --0.00055472925305, --0.00055432377849, --0.00054488552269, --0.00052537227748, --0.00049731286708, --0.00045777999912, --0.00040612387238, --0.00034301576670, --0.00026866336702, --0.00018248900597, --0.00008430792514, -0.00002508115722, -0.00014135583478, -0.00026649952633, -0.00039945056778, -0.00053928449051, -0.00068422866752, -0.00083093711874, -0.00097943725996, -0.00112581404392, -0.00126854737755, -0.00140469032340, -0.00153207418043, -0.00164810777642, -0.00175017165020, -0.00183808000293, -0.00189900479745, -0.00194506184198, -0.00196531717665, -0.00195937906392, -0.00192521407735, -0.00186084536836, -0.00176518992521, -0.00163768627681, -0.00147714314517, -0.00128322700039, -0.00105668208562, -0.00079780723900, -0.00050782406470, -0.00018855913368, --0.00015771533072, --0.00052769453032, --0.00091862218687, --0.00132635701448, --0.00174694834277, --0.00217548245564, --0.00260676839389, --0.00303528923541, --0.00345493946224, --0.00385913741775, --0.00424182694405, --0.00459594465792, --0.00491465069354, --0.00519145652652, --0.00541948433965, --0.00559201091528, --0.00570259056985, --0.00574458623305, --0.00571426097304, --0.00560342334211, --0.00540914759040, --0.00512683158740, --0.00475297635421, --0.00428478466347, --0.00372032052837, --0.00305867753923, --0.00229951413348, --0.00144354603253, --0.00049266568385, -0.00055068987422, -0.00168289500289, -0.00289928726852, -0.00419431505725, -0.00556147377938, -0.00699351215735, -0.00848235655576, -0.01001896336675, -0.01159386243671, -0.01319687161595, -0.01481730863452, -0.01644404232502, -0.01806553266943, -0.01967016234994, -0.02124618366361, -0.02278177253902, -0.02426535822451, -0.02568554319441, -0.02703126519918, -0.02829195372760, -0.02945766039193, -0.03051890246570, -0.03146736323833, -0.03229522705078, -0.03299576789141, -0.03356324881315, -0.03399298712611, -0.03428143635392, -0.03442628309131, -0.03442628309131, -0.03428143635392, -0.03399298712611, -0.03356324881315, -0.03299576789141, -0.03229522705078, -0.03146736323833, -0.03051890246570, -0.02945766039193, -0.02829195372760, -0.02703126519918, -0.02568554319441, -0.02426535822451, -0.02278177253902, -0.02124618366361, -0.01967016234994, -0.01806553266943, -0.01644404232502, -0.01481730863452, -0.01319687161595, -0.01159386243671, -0.01001896336675, -0.00848235655576, -0.00699351215735, -0.00556147377938, -0.00419431505725, -0.00289928726852, -0.00168289500289, -0.00055068987422, --0.00049266568385, --0.00144354603253, --0.00229951413348, --0.00305867753923, --0.00372032052837, --0.00428478466347, --0.00475297635421, --0.00512683158740, --0.00540914759040, --0.00560342334211, --0.00571426097304, --0.00574458623305, --0.00570259056985, --0.00559201091528, --0.00541948433965, --0.00519145652652, --0.00491465069354, --0.00459594465792, --0.00424182694405, --0.00385913741775, --0.00345493946224, --0.00303528923541, --0.00260676839389, --0.00217548245564, --0.00174694834277, --0.00132635701448, --0.00091862218687, --0.00052769453032, --0.00015771533072, -0.00018855913368, -0.00050782406470, -0.00079780723900, -0.00105668208562, -0.00128322700039, -0.00147714314517, -0.00163768627681, -0.00176518992521, -0.00186084536836, -0.00192521407735, -0.00195937906392, -0.00196531717665, -0.00194506184198, -0.00189900479745, -0.00183808000293, -0.00175017165020, -0.00164810777642, -0.00153207418043, -0.00140469032340, -0.00126854737755, -0.00112581404392, -0.00097943725996, -0.00083093711874, -0.00068422866752, -0.00053928449051, -0.00039945056778, -0.00026649952633, -0.00014135583478, -0.00002508115722, --0.00008430792514, --0.00018248900597, --0.00026866336702, --0.00034301576670, --0.00040612387238, --0.00045777999912, --0.00049731286708, --0.00052537227748, --0.00054488552269, --0.00055432377849, --0.00055472925305, --0.00054783461383, --0.00053276919061, --0.00051135791000, --0.00048466061708, --0.00045358928037, --0.00042499689152, --0.00036942670704, --0.00033926189644, --0.00030001782579, --0.00025986303808, --0.00021972040122, --0.00018116166757, --0.00014691354590, --0.00011279431783, --0.00008079566032, --0.00005339706695, --0.00002610587035, --0.00000166573534, -0.00001853294270, -0.00003561532503, -0.00004988881119, -0.00005629632869, -0.00005827044151, -0.00006228515122, -0.00007020850899, -0.00007485075184, -0.00007612784975, -0.00007308147178, -0.00006830695202, -0.00006446454790, -0.00006414738891, -0.00006174868031, -0.00005426778807, -0.00004713382441, -0.00004292758240, -0.00003947730875, -0.00003634074528, -0.00002968751687, -0.00004978773723, -0.00004157788862, -0.00003386474418, -0.00002653474803, -0.00001984130540, -0.00001478948616, -0.00001313118355, -0.00000991988691, -0.00004858558168, -0.00004604394780, -0.00004533784522, -0.00004157561489, -0.00003696891872, -0.00003230232323, -0.00002780561954, -0.00002353085074, -0.00000181119538, --0.00000057168614, --0.00000154329177, --0.00000263366292, --0.00000417120236, --0.00000792127867, --0.00001050293486, --0.00000916228237, --0.00000629902070, --0.00000727012593, --0.00001198405243, --0.00001734808211, --0.00001990710552, --0.00002134877286, --0.00002196196510, --0.00001220357626, --0.00001084099222, -0.00000046299544, -0.00000052588763, -0.00000027792686, --0.00000023649704, --0.00000108977838, --0.00000091714480, --0.00000052268200, --0.00000703029718, --0.00000638942583, --0.00000461924219, --0.00000325697420, --0.00000231086847, --0.00000143337536, --0.00000060053890, -0.00001183861787, --0.00001051678282, --0.00000001266038, --0.00000003530856, --0.00000003226247, -0.00000004440057, -0.00000042005411, -0.00000080604229, -0.00000058336207 -}; - -#endif - diff --git a/src/atrac/atrac3plus_pqf/tools/plot/main.py b/src/atrac/atrac3plus_pqf/tools/plot/main.py deleted file mode 100644 index 2296196..0000000 --- a/src/atrac/atrac3plus_pqf/tools/plot/main.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import argparse - -import numpy as np -import matplotlib.pyplot as plt -import scipy.fftpack - -import pqf - -SAMPLES = pqf.frame_sz -RUNS = 3 -SAMPLERATE = 44100 - -def show_proto(): - proto = pqf.prototype() - fig = plt.figure() - - yf = scipy.fftpack.fft(proto[:len(proto)]) - - fig.add_subplot(111).plot(10 * np.log10(np.abs(yf[:len(proto)//2]))) - fig.add_subplot(222).plot(proto) - plt.show() - - -def do_an(ctx, time, data, shift): - data_slice = data[shift : SAMPLES + shift] - time_slice = time[shift : SAMPLES + shift] - - res = ctx.do(data_slice); - - fig = plt.figure() - - a = fig.add_subplot(111) - a.plot(time_slice, res) - a.set_title("output") - b = fig.add_subplot(222) - b.plot(time_slice, data_slice) - b.set_title("input"); - plt.show() - - -def process_freq(freq): - ctx = pqf.AnalyzeCtx() - - time = np.arange(0, SAMPLES * RUNS, 1) - amplitude = 0.01 * np.sin(2 * np.pi * freq * time / SAMPLERATE).astype(np.float32) - - do_an(ctx, time, amplitude, 0); - do_an(ctx, time, amplitude, SAMPLES); - - -def main(): - parser = argparse.ArgumentParser() - - parser.add_argument('--freq', type=int, help="generate sine with given frequency", action='store') - parser.add_argument('--proto', help="show filter prototype", action='store_true') - - args = parser.parse_args() - - if (args.proto): - show_proto() - else: - process_freq(args.freq) - - -if __name__ == "__main__": - main() diff --git a/src/atrac/atrac3plus_pqf/tools/plot/pqf/pqf_binding.c b/src/atrac/atrac3plus_pqf/tools/plot/pqf/pqf_binding.c deleted file mode 100644 index 8ddf5ee..0000000 --- a/src/atrac/atrac3plus_pqf/tools/plot/pqf/pqf_binding.c +++ /dev/null @@ -1,187 +0,0 @@ -#include <Python.h> -#include <structmember.h> - -#include <stdio.h> - - -#include <atrac3plus_pqf.h> - -typedef struct { - PyObject_HEAD; - at3plus_pqf_a_ctx_t ctx; -} AnalyzeCtxObject; - -static PyObject * -AnalyzeCtx_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - AnalyzeCtxObject *self; - self = (AnalyzeCtxObject*)type->tp_alloc(type, 0); - if (self == NULL) { - fprintf(stderr, "Unable to allocate analyze context\n"); - return NULL; - } - return (PyObject*)self; -} - -static int -AnalyzeCtx_init(AnalyzeCtxObject *self, PyObject *args, PyObject *kwds) -{ - self->ctx = at3plus_pqf_create_a_ctx(); - return 0; -} - -static void -AnalyzeCtx_dealloc(AnalyzeCtxObject *self) -{ - at3plus_pqf_free_a_ctx(self->ctx); -} - -static PyObject* prototype(PyObject* self, PyObject* unused) -{ - int i; - const float* proto = at3plus_pqf_get_proto(); - - PyObject *my_list = PyList_New(0); - if(my_list == NULL) { - return NULL; - } - - for (i = 0; i < at3plus_pqf_proto_sz; i++) { - PyObject *o = Py_BuildValue("f", proto[i]); - if(PyList_Append(my_list, o) == -1) { - return NULL; - } - } - - return my_list; -} - -static PyObject* analyzectx_do(PyObject* self, PyObject* args) -{ - int i = 0; - int len = 0; - float* in; - float* out; - - AnalyzeCtxObject* ctx; - PyObject *seq; - - if (!PyArg_ParseTuple(args, "O", &seq)) { - return NULL; - } - - seq = PySequence_Fast(seq, "argument must be iterable"); - - if (!seq) { - return NULL; - } - - len = PySequence_Fast_GET_SIZE(seq); - - if (len != at3plus_pqf_frame_sz) { - fprintf(stderr, "wrong frame size, expected: %d, got: %d", (int)at3plus_pqf_frame_sz, len); - return NULL; - } - - in = (float*)malloc(len * sizeof(float)); - if(!in) { - Py_DECREF(seq); - return PyErr_NoMemory( ); - } - - for (i = 0; i < len; i++) { - PyObject *fitem; - PyObject *item = PySequence_Fast_GET_ITEM(seq, i); - if(!item) { - Py_DECREF(seq); - free(in); - return NULL; - } - fitem = PyNumber_Float(item); - if(!fitem) { - Py_DECREF(seq); - free(in); - PyErr_SetString(PyExc_TypeError, "all items must be numbers"); - return NULL; - } - in[i] = PyFloat_AS_DOUBLE(fitem); - Py_DECREF(fitem); - } - - PyObject *my_list = PyList_New(0); - if(my_list == NULL) { - Py_DECREF(seq); - free(in); - return NULL; - } - - out = (float*)calloc(at3plus_pqf_frame_sz, sizeof(float)); - if (out == NULL) { - Py_DECREF(seq); - free(in); - return NULL; - } - - ctx = (AnalyzeCtxObject*)self; - - at3plus_pqf_do_analyse(ctx->ctx, in, out); - - for (i = 0; i < len; i++) { - PyObject *o = Py_BuildValue("f", out[i]); - if(PyList_Append(my_list, o) == -1) { - Py_DECREF(seq); - free(in); - return NULL; - } - } - - free(in); - return my_list; -} - -static PyMethodDef methods[] = { - { "prototype", prototype, METH_NOARGS, "Show atrac3plus pqf filter prototype"}, - { NULL, NULL, 0, NULL } -}; - -static PyMethodDef AnalyzeCtx_methods[] = { - {"do", (PyCFunction)analyzectx_do, METH_VARARGS, NULL}, - {NULL} -}; - -static PyTypeObject AnalyzeCtxType = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pqf.AnalyzeCtx", - .tp_doc = "AnalyzeCtx", - .tp_basicsize = sizeof(AnalyzeCtxObject), - .tp_itemsize = 0, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_new = AnalyzeCtx_new, - .tp_init = (initproc)AnalyzeCtx_init, - .tp_dealloc = (destructor)AnalyzeCtx_dealloc, - .tp_methods = AnalyzeCtx_methods, -}; - -static struct PyModuleDef module = { - PyModuleDef_HEAD_INIT, - .m_name = "pqf", - .m_doc = "pqf library test binding", - .m_size = -1, - .m_methods = methods -}; - -PyMODINIT_FUNC PyInit_pqf(void) -{ - PyObject *m; - if (PyType_Ready(&AnalyzeCtxType) < 0) - return NULL; - - m = PyModule_Create(&module); - if (m == NULL) - return NULL; - - Py_INCREF(&AnalyzeCtxType); - PyModule_AddObject(m, "AnalyzeCtx", (PyObject*)&AnalyzeCtxType); - PyModule_AddIntConstant(m, "frame_sz", at3plus_pqf_frame_sz); - return m; -} diff --git a/src/atrac/atrac3plus_pqf/tools/plot/pqf/setup.py b/src/atrac/atrac3plus_pqf/tools/plot/pqf/setup.py deleted file mode 100644 index bf2b87f..0000000 --- a/src/atrac/atrac3plus_pqf/tools/plot/pqf/setup.py +++ /dev/null @@ -1,6 +0,0 @@ -from distutils.core import setup, Extension - -setup(name = 'pqf', version = '1.0', \ - ext_modules = [Extension('pqf', \ - sources=['pqf_binding.c', '../../../atrac3plus_pqf.c'], \ - include_dirs=['../../../'])]) diff --git a/src/atrac/atrac3plus_pqf/tools/plot/run.sh b/src/atrac/atrac3plus_pqf/tools/plot/run.sh deleted file mode 100644 index 06e7788..0000000 --- a/src/atrac/atrac3plus_pqf/tools/plot/run.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e - -cd pqf - -python3.7 setup.py build - -cd .. - -export PYTHONPATH=./pqf/build/lib.mingw-3.7/ -./main.py "$@" diff --git a/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c b/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c index 940cf05..85f712d 100644 --- a/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c +++ b/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c @@ -35,116 +35,14 @@ #include "atrac3plusdsp.h" +#include "../atrac3plus_pqf_data.h" + /* lookup table for fast modulo 23 op required for cyclic buffers of the IPQF */ static const int mod23_lut[26] = { 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0 }; -/* First half of the 384-tap IPQF filtering coefficients. */ -static const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16] = { - { -5.8336207e-7, -8.0604229e-7, -4.2005411e-7, -4.4400572e-8, - 3.226247e-8, 3.530856e-8, 1.2660377e-8, 0.000010516783, - -0.000011838618, 6.005389e-7, 0.0000014333754, 0.0000023108685, - 0.0000032569742, 0.0000046192422, 0.0000063894258, 0.0000070302972 }, - { -0.0000091622824, -0.000010502935, -0.0000079212787, -0.0000041712024, - -0.0000026336629, -0.0000015432918, -5.7168614e-7, 0.0000018111954, - 0.000023530851, 0.00002780562, 0.000032302323, 0.000036968919, - 0.000041575615, 0.000045337845, 0.000046043948, 0.000048585582 }, - { -0.000064464548, -0.000068306952, -0.000073081472, -0.00007612785, - -0.000074850752, -0.000070208509, -0.000062285151, -0.000058270442, - -0.000056296329, -0.000049888811, -0.000035615325, -0.000018532943, - 0.0000016657353, 0.00002610587, 0.000053397067, 0.00008079566 }, - { -0.00054488552, -0.00052537228, -0.00049731287, -0.00045778, - -0.00040612387, -0.00034301577, -0.00026866337, -0.00018248901, - -0.000084307925, 0.000025081157, 0.00014135583, 0.00026649953, - 0.00039945057, 0.00053928449, 0.00068422867, 0.00083093712 }, - { -0.0014771431, -0.001283227, -0.0010566821, -0.00079780724, - -0.00050782406, -0.00018855913, 0.00015771533, 0.00052769453, - 0.00091862219, 0.001326357, 0.0017469483, 0.0021754825, - 0.0026067684, 0.0030352892, 0.0034549395, 0.0038591374 }, - { -0.0022995141, -0.001443546, -0.00049266568, 0.00055068987, - 0.001682895, 0.0028992873, 0.0041943151, 0.0055614738, - 0.0069935122, 0.0084823566, 0.010018963, 0.011593862, - 0.013196872, 0.014817309, 0.016444042, 0.018065533 }, - { -0.034426283, -0.034281436, -0.033992987, -0.033563249, - -0.032995768, -0.032295227, -0.031467363, -0.030518902, - -0.02945766, -0.028291954, -0.027031265, -0.025685543, - -0.024265358, -0.022781773, -0.021246184, -0.019670162 }, - { -0.0030586775, -0.0037203205, -0.0042847847, -0.0047529764, - -0.0051268316, -0.0054091476, -0.0056034233, -0.005714261, - -0.0057445862, -0.0057025906, -0.0055920109, -0.0054194843, - -0.0051914565, -0.0049146507, -0.0045959447, -0.0042418269 }, - { -0.0016376863, -0.0017651899, -0.0018608454, -0.0019252141, - -0.0019593791, -0.0019653172, -0.0019450618, -0.0018990048, - -0.00183808, -0.0017501717, -0.0016481078, -0.0015320742, - -0.0014046903, -0.0012685474, -0.001125814, -0.00097943726 }, - { -0.00055432378, -0.00055472925, -0.00054783461, -0.00053276919, - -0.00051135791, -0.00048466062, -0.00045358928, -0.00042499689, - -0.00036942671, -0.0003392619, -0.00030001783, -0.00025986304, - -0.0002197204, -0.00018116167, -0.00014691355, -0.00011279432 }, - { -0.000064147389, -0.00006174868, -0.000054267788, -0.000047133824, - -0.000042927582, -0.000039477309, -0.000036340745, -0.000029687517, - -0.000049787737, -0.000041577889, -0.000033864744, -0.000026534748, - -0.000019841305, -0.000014789486, -0.000013131184, -0.0000099198869 }, - { -0.0000062990207, -0.0000072701259, -0.000011984052, -0.000017348082, - -0.000019907106, -0.000021348773, -0.000021961965, -0.000012203576, - -0.000010840992, 4.6299544e-7, 5.2588763e-7, 2.7792686e-7, - -2.3649704e-7, -0.0000010897784, -9.171448e-7, -5.22682e-7 } -}; - -/* Second half of the 384-tap IPQF filtering coefficients. */ -static const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = { - { 5.22682e-7, 9.171448e-7, 0.0000010897784, 2.3649704e-7, - -2.7792686e-7, -5.2588763e-7, -4.6299544e-7, 0.000010840992, - -0.000012203576, -0.000021961965, -0.000021348773, -0.000019907106, - -0.000017348082, -0.000011984052, -0.0000072701259, -0.0000062990207 }, - { 0.0000099198869, 0.000013131184, 0.000014789486, 0.000019841305, - 0.000026534748, 0.000033864744, 0.000041577889, 0.000049787737, - -0.000029687517, -0.000036340745, -0.000039477309, -0.000042927582, - -0.000047133824, -0.000054267788, -0.00006174868, -0.000064147389 }, - { 0.00011279432, 0.00014691355, 0.00018116167, 0.0002197204, - 0.00025986304, 0.00030001783, 0.0003392619, 0.00036942671, - -0.00042499689, -0.00045358928, -0.00048466062, -0.00051135791, - -0.00053276919, -0.00054783461, -0.00055472925, -0.00055432378 }, - { 0.00097943726, 0.001125814, 0.0012685474, 0.0014046903, - 0.0015320742, 0.0016481078, 0.0017501717, 0.00183808, - -0.0018990048, -0.0019450618, -0.0019653172, -0.0019593791, - -0.0019252141, -0.0018608454, -0.0017651899, -0.0016376863 }, - { 0.0042418269, 0.0045959447, 0.0049146507, 0.0051914565, - 0.0054194843, 0.0055920109, 0.0057025906, 0.0057445862, - -0.005714261, -0.0056034233, -0.0054091476, -0.0051268316, - -0.0047529764, -0.0042847847, -0.0037203205, -0.0030586775 }, - { 0.019670162, 0.021246184, 0.022781773, 0.024265358, - 0.025685543, 0.027031265, 0.028291954, 0.02945766, - -0.030518902, -0.031467363, -0.032295227, -0.032995768, - -0.033563249, -0.033992987, -0.034281436, -0.034426283 }, - { -0.018065533, -0.016444042, -0.014817309, -0.013196872, - -0.011593862, -0.010018963, -0.0084823566, -0.0069935122, - 0.0055614738, 0.0041943151, 0.0028992873, 0.001682895, - 0.00055068987, -0.00049266568, -0.001443546, -0.0022995141 }, - { -0.0038591374, -0.0034549395, -0.0030352892, -0.0026067684, - -0.0021754825, -0.0017469483, -0.001326357, -0.00091862219, - 0.00052769453, 0.00015771533, -0.00018855913, -0.00050782406, - -0.00079780724, -0.0010566821, -0.001283227, -0.0014771431 }, - { -0.00083093712, -0.00068422867, -0.00053928449, -0.00039945057, - -0.00026649953, -0.00014135583, -0.000025081157, 0.000084307925, - -0.00018248901, -0.00026866337, -0.00034301577, -0.00040612387, - -0.00045778, -0.00049731287, -0.00052537228, -0.00054488552 }, - { -0.00008079566, -0.000053397067, -0.00002610587, -0.0000016657353, - 0.000018532943, 0.000035615325, 0.000049888811, 0.000056296329, - -0.000058270442, -0.000062285151, -0.000070208509, -0.000074850752, - -0.00007612785, -0.000073081472, -0.000068306952, -0.000064464548 }, - { -0.000048585582, -0.000046043948, -0.000045337845, -0.000041575615, - -0.000036968919, -0.000032302323, -0.00002780562, -0.000023530851, - 0.0000018111954, -5.7168614e-7, -0.0000015432918, -0.0000026336629, - -0.0000041712024, -0.0000079212787, -0.000010502935, -0.0000091622824 }, - { -0.0000070302972, -0.0000063894258, -0.0000046192422, -0.0000032569742, - -0.0000023108685, -0.0000014333754, -6.005389e-7, 0.000011838618, - 0.000010516783, 1.2660377e-8, 3.530856e-8, 3.226247e-8, - -4.4400572e-8, -4.2005411e-7, -8.0604229e-7, -5.8336207e-7 } -}; - // Just for test static void dct4(float* out, const float* x, int N, float scale) { for (int k = 0; k < N; k++) { @@ -182,10 +80,10 @@ void ff_atrac3p_ipqf(Atrac3pIPQFChannelCtx *hist, const float *in, float *out) for (t = 0; t < ATRAC3P_PQF_FIR_LEN; t++) { for (i = 0; i < 8; i++) { - out[s * 16 + i + 0] += hist->buf1[pos_now][i] * ipqf_coeffs1[t][i] + - hist->buf2[pos_next][i] * ipqf_coeffs2[t][i]; - out[s * 16 + i + 8] += hist->buf1[pos_now][7 - i] * ipqf_coeffs1[t][i + 8] + - hist->buf2[pos_next][7 - i] * ipqf_coeffs2[t][i + 8]; + out[s * 16 + i + 0] += hist->buf1[pos_now][i] * ff_ipqf_coeffs1[t][i] + + hist->buf2[pos_next][i] * ff_ipqf_coeffs2[t][i]; + out[s * 16 + i + 8] += hist->buf1[pos_now][7 - i] * ff_ipqf_coeffs1[t][i + 8] + + hist->buf2[pos_next][7 - i] * ff_ipqf_coeffs2[t][i + 8]; } pos_now = mod23_lut[pos_next + 2]; // pos_now = (pos_now + 2) % 23; pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_next + 2) % 23; diff --git a/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.h b/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.h index af45d92..5418f0a 100644 --- a/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.h +++ b/src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.h @@ -36,6 +36,8 @@ extern "C" { #endif /* __cplusplus */ +extern const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16]; +extern const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16]; void ff_atrac3p_ipqf(Atrac3pIPQFChannelCtx *hist, const float *in, float *out); #ifdef __cplusplus diff --git a/src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp b/src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp index ababfcd..c7eec07 100644 --- a/src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp +++ b/src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp @@ -17,6 +17,8 @@ */ #include "atrac3plusdsp.h" +#include "../atrac3plus_pqf.h" +#include "../atrac3plus_pqf_data.h" #include <gtest/gtest.h> @@ -25,6 +27,8 @@ #include <string.h> #include <math.h> +#include <cstdlib> + #define SAMPLES 8192 static int read_file(FILE* f, float buf[SAMPLES]) { @@ -36,6 +40,14 @@ static int read_file(FILE* f, float buf[SAMPLES]) { return 0; } +static void create_chirp(int sz, float* buf) { + int i = 0; + for(i = 0; i < sz; i++) { + float t = i; + buf[i] = sinf((t + t * t * 0.5 / 2.0) * 2.0 * M_PI/(float)sz); + } +} + TEST(ipqf, CheckOnRefData) { FILE* mr_f = fopen("test_data/ipqftest_pcm_mr.dat", "r"); if (!mr_f) { @@ -74,7 +86,210 @@ TEST(ipqf, CheckOnRefData) { const static float err = 1.0 / (float)(1<<26); for (int i = 0; i < SAMPLES; i++) { - //fprintf(stdout, "%f %f\n", tmp[i], ref_data[i]); EXPECT_NEAR(tmp[i], ref_data[i], err); } } + +TEST(ipqf, CmpEnergy) { + double e1 = 0.0; + double e2 = 0.0; + double e = 0.0; + const static double err = 1.0 / (double)(1ull<<32); + for (int i = 0; i < ATRAC3P_SUBBANDS; i++) { + e1 = 0.0; + e2 = 0.0; + for (int j = 0; j < ATRAC3P_PQF_FIR_LEN; j++) { + e1 += ff_ipqf_coeffs1[j][i] * ff_ipqf_coeffs1[j][i]; + e2 += ff_ipqf_coeffs2[j][i] * ff_ipqf_coeffs2[j][i]; + } + if (i) { + EXPECT_NEAR(e, e1 + e2, err); + } + e = e1 + e2; + } +} + +TEST(pqf, DC_Short) { + int i = 0; + float x[2048] = {0}; + float subbands[2048] = {0}; + for (i = 0; i < 2048; i++) + x[i] = 1; + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + + float tmp[2048] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + + const static float err = 1.0 / (float)(1<<21); + + for (int i = 368; i < 2048; i++) { + EXPECT_NEAR(tmp[i], x[i], err); + } +} + +TEST(pqf, DC_Long) { + int i = 0; + float x[4096] = {0}; + float subbands[4096] = {0}; + for (i = 0; i < 4096; i++) + x[i] = 1; + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + at3plus_pqf_do_analyse(actx, x + 2048, subbands + 2048); + + float tmp[4096] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + ff_atrac3p_ipqf(&sctx, &subbands[2048], &tmp[2048]); + + const static float err = 1.0 / (float)(1<<21); + + for (int i = 368; i < 4096; i++) { + EXPECT_NEAR(tmp[i], x[i-368], err); + } +} + +TEST(pqf, Seq_Short) { + int i = 0; + float x[2048] = {0}; + float subbands[2048] = {0}; + + for (i = 0; i < 2048; i++) + x[i] = i; + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + + float tmp[2048] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + + const static float err = 2048.0 / (float)(1<<22); + + for (int i = 368; i < 2048; i++) { + EXPECT_NEAR(tmp[i], x[i - 368], err); + } +} + +TEST(pqf, Seq_Long) { + int i = 0; + float x[4096] = {0}; + float subbands[4096] = {0}; + for (i = 0; i < 4096; i++) + x[i] = i; + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + at3plus_pqf_do_analyse(actx, x + 2048, subbands + 2048); + + float tmp[4096] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + ff_atrac3p_ipqf(&sctx, &subbands[2048], &tmp[2048]); + + const static float err = 4096.0 / (float)(1<<21); + for (int i = 368; i < 4096; i++) { + EXPECT_NEAR(tmp[i], x[i-368], err); + } +} + +TEST(pqf, Chirp_Short) { + int i = 0; + float x[2048] = {0}; + float subbands[2048] = {0}; + + create_chirp(2048, x); + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + + float tmp[2048] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + + const static float err = 1.0 / (float)(1<<22); + + for (int i = 368; i < 2048; i++) { + EXPECT_NEAR(tmp[i], x[i - 368], err); + } +} + +TEST(pqf, Chirp_Long) { + int i = 0; + float x[4096] = {0}; + float subbands[4096] = {0}; + + create_chirp(4096, x); + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + at3plus_pqf_do_analyse(actx, x + 2048, subbands + 2048); + + float tmp[4096] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + ff_atrac3p_ipqf(&sctx, &subbands[2048], &tmp[2048]); + + const static float err = 4096.0 / (float)(1<<21); + for (int i = 368; i < 4096; i++) { + EXPECT_NEAR(tmp[i], x[i-368], err); + } +} + +TEST(pqf, Noise_Long) { + int i = 0; + float x[4096] = {0}; + float subbands[4096] = {0}; + for (i = 0; i < 4096; i++) + x[i] = (float)rand() / (float)RAND_MAX - 0.5; + + at3plus_pqf_a_ctx_t actx = at3plus_pqf_create_a_ctx(); + + at3plus_pqf_do_analyse(actx, x, subbands); + at3plus_pqf_do_analyse(actx, x + 2048, subbands + 2048); + + float tmp[4096] = {0}; + + Atrac3pIPQFChannelCtx sctx; + memset(&sctx, 0, sizeof(sctx)); + + ff_atrac3p_ipqf(&sctx, &subbands[0], &tmp[0]); + ff_atrac3p_ipqf(&sctx, &subbands[2048], &tmp[2048]); + + const static float err = 1.0 / (float)(1<<21); + for (int i = 368; i < 4096; i++) { + EXPECT_NEAR(tmp[i], x[i-368], err); + } +} + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 807b4ab..adeac52 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,6 +36,7 @@ configure_file( set(at3plus_pqf_ut ../src/atrac/atrac3plus_pqf/ut/ipqf_ut.cpp ../src/atrac/atrac3plus_pqf/ut/atrac3plusdsp.c + ../src/atrac/atrac3plus_pqf/atrac3plus_pqf.c ) add_executable(at3plus_pqf_ut ${at3plus_pqf_ut}) |