FFmpeg
Loading...
Searching...
No Matches
sbcdsp.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <stddef.h>
20#include <stdint.h>
21#include <string.h>
22
23#include "checkasm.h"
24#include "libavcodec/sbcdsp.h"
26#include "libavutil/macros.h"
28
29enum {
31};
32
33#define randomize_buffer(buf) \
34do { \
35 for (size_t k = 0; k < FF_ARRAY_ELEMS(buf); ++k) \
36 buf[k] = rnd(); \
37} while (0)
38
39static void check_sbc_analyze(SBCDSPContext *sbcdsp)
40{
41 DECLARE_ALIGNED(SBC_ALIGN, int16_t, in)[10 * SBC_MAX_SUBBANDS];
44
45 declare_func(void, const int16_t *in, int32_t *out, const int16_t *consts);
46
47 for (int i = 0; i < 2; ++i) {
48 if (check_func(i ? sbcdsp->sbc_analyze_8 : sbcdsp->sbc_analyze_4, "sbc_analyze_%u", i ? 8 : 4)) {
50 randomize_buffer(out_ref);
51 memcpy(out_new, out_ref, sizeof(out_new));
52
53 // the input is always 16-byte aligned for sbc_analyze_8
54 // for sbc_analyze_4 it can be 0 or 8 mod 16.
55 const int16_t *const inp = i || rnd() & 1 ? in : in + 4;
56 // Use the proper const tables as random ones can cause overflow
57 #define A_CONST(SIZE, ODDEVEN) sbcdsp_analysis_consts_fixed ## SIZE ## _simd_ ## ODDEVEN
58 const int16_t *const consts = rnd() & 1 ? (i ? A_CONST(8, odd) : A_CONST(4, odd))
59 : (i ? A_CONST(8, even) : A_CONST(4, even));
60
61 call_ref(inp, out_ref, consts);
62 call_new(inp, out_new, consts);
63
64 if (memcmp(out_ref, out_new, sizeof(out_new)))
65 fail();
66
67 bench_new(inp, out_new, consts);
68 }
69 }
70 report("sbc_analyze");
71}
72
73static void check_sbc_calc_scalefactors(const SBCDSPContext *const sbcdsp, int blocks)
74{
75 DECLARE_ALIGNED(SBC_ALIGN, int32_t, sb_sample_f)[16][2][8];
76 DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_ref)[2][8];
77 DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_new)[2][8];
78
79 declare_func(void, const int32_t sb_sample_f[16][2][8],
80 uint32_t scale_factor[2][8],
81 int blocks, int channels, int subbands);
82
83 int inited = 0;
84
85 for (int ch = 1; ch <= 2; ++ch) {
86 for (int subbands = 4; subbands <= 8; subbands += 4) {
87 if (!check_func(sbcdsp->sbc_calc_scalefactors, "calc_scalefactors_%dch_%dsubbands", ch, subbands))
88 return;
89
90 if (!inited) {
91 for (size_t i = 0; i < FF_ARRAY_ELEMS(sb_sample_f); ++i)
92 for (size_t j = 0; j < FF_ARRAY_ELEMS(sb_sample_f[0]); ++j)
93 for (size_t k = 0; k < FF_ARRAY_ELEMS(sb_sample_f[0][0]); ++k)
94 sb_sample_f[i][j][k] = rnd();
95 }
96
97 call_ref(sb_sample_f, scale_factor_ref, blocks, ch, subbands);
98 call_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
99 for (int i = 0; i < ch; ++i)
100 for (int j = 0; j < subbands; ++j)
101 if (scale_factor_ref[i][j] != scale_factor_new[i][j])
102 fail();
103
104 bench_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
105 }
106 }
107}
108
110{
111 SBCDSPContext sbcdsp = { 0 };
112 int blocks = ((const int[]){4, 8, 12, 15, 16})[rnd() % 5];
113
114 ff_sbcdsp_init(&sbcdsp);
115
116 check_sbc_analyze(&sbcdsp);
117
118 check_sbc_calc_scalefactors(&sbcdsp, blocks);
119 report("calc_scalefactors");
120}
channels
Definition aptx.h:31
subbands
Definition aptx.h:37
int32_t
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:136
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
av_cold void ff_sbcdsp_init(SBCDSPContext *s)
Definition sbcdsp.c:364
Utility Preprocessor macros.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int even(int64_t layout)
Definition rematrix.c:93
#define SBC_ALIGN
Definition sbc.h:80
SBC basic "building bricks".
miscellaneous SBC tables
#define FF_ARRAY_ELEMS(a)
@ SBC_MAX_SUBBANDS
Definition sbcdsp.c:30
static void check_sbc_calc_scalefactors(const SBCDSPContext *const sbcdsp, int blocks)
Definition sbcdsp.c:73
void checkasm_check_sbcdsp(void)
Definition sbcdsp.c:109
static void check_sbc_analyze(SBCDSPContext *sbcdsp)
Definition sbcdsp.c:39
#define randomize_buffer(buf)
Definition sbcdsp.c:33
#define A_CONST(SIZE, ODDEVEN)
static FILE * out
Definition movenc.c:55