FFmpeg
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 
22 #include "checkasm.h"
23 #include "libavcodec/sbcdsp.h"
24 #include "libavcodec/sbcdsp_data.h"
25 #include "libavutil/macros.h"
26 #include "libavutil/mem_internal.h"
27 
28 enum {
30 };
31 
32 #define randomize_buffer(buf) \
33 do { \
34  for (size_t k = 0; k < FF_ARRAY_ELEMS(buf); ++k) \
35  buf[k] = rnd(); \
36 } while (0)
37 
38 static void check_sbc_analyze(SBCDSPContext *sbcdsp)
39 {
40  DECLARE_ALIGNED(SBC_ALIGN, int16_t, in)[10 * SBC_MAX_SUBBANDS];
43 
44  declare_func(void, const int16_t *in, int32_t *out, const int16_t *consts);
45 
46  for (int i = 0; i < 2; ++i) {
47  if (check_func(i ? sbcdsp->sbc_analyze_8 : sbcdsp->sbc_analyze_4, "sbc_analyze_%u", i ? 8 : 4)) {
48  randomize_buffer(in);
49  randomize_buffer(out_ref);
50  memcpy(out_new, out_ref, sizeof(out_new));
51 
52  // the input is always 16-byte aligned for sbc_analyze_8
53  // for sbc_analyze_4 it can be 0 or 8 mod 16.
54  const int16_t *const inp = i || rnd() & 1 ? in : in + 4;
55  // Use the proper const tables as random ones can cause overflow
56  #define CONST(SIZE, ODDEVEN) sbcdsp_analysis_consts_fixed ## SIZE ## _simd_ ## ODDEVEN
57  const int16_t *const consts = rnd() & 1 ? (i ? CONST(8, odd) : CONST(4, odd))
58  : (i ? CONST(8, even) : CONST(4, even));
59 
60  call_ref(inp, out_ref, consts);
61  call_new(inp, out_new, consts);
62 
63  if (memcmp(out_ref, out_new, sizeof(out_new)))
64  fail();
65 
66  bench_new(inp, out_new, consts);
67  }
68  }
69  report("sbc_analyze");
70 }
71 
72 static void check_sbc_calc_scalefactors(const SBCDSPContext *const sbcdsp)
73 {
74  DECLARE_ALIGNED(SBC_ALIGN, int32_t, sb_sample_f)[16][2][8];
75  DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_ref)[2][8];
76  DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_new)[2][8];
77 
78  declare_func(void, const int32_t sb_sample_f[16][2][8],
79  uint32_t scale_factor[2][8],
80  int blocks, int channels, int subbands);
81 
82  static int blocks = 0;
83  if (!blocks)
84  blocks = ((const int[]){4, 8, 12, 15, 16})[rnd() % 5];
85  int inited = 0;
86 
87  for (int ch = 1; ch <= 2; ++ch) {
88  for (int subbands = 4; subbands <= 8; subbands += 4) {
89  if (!check_func(sbcdsp->sbc_calc_scalefactors, "calc_scalefactors_%dch_%dsubbands", ch, subbands))
90  return;
91 
92  if (!inited) {
93  for (size_t i = 0; i < FF_ARRAY_ELEMS(sb_sample_f); ++i)
94  for (size_t j = 0; j < FF_ARRAY_ELEMS(sb_sample_f[0]); ++j)
95  for (size_t k = 0; k < FF_ARRAY_ELEMS(sb_sample_f[0][0]); ++k)
96  sb_sample_f[i][j][k] = rnd();
97  }
98 
99  call_ref(sb_sample_f, scale_factor_ref, blocks, ch, subbands);
100  call_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
101  for (int i = 0; i < ch; ++i)
102  for (int j = 0; j < subbands; ++j)
103  if (scale_factor_ref[i][j] != scale_factor_new[i][j])
104  fail();
105 
106  bench_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
107  }
108  }
109 }
110 
112 {
113  SBCDSPContext sbcdsp;
114 
115  ff_sbcdsp_init(&sbcdsp);
116 
117  check_sbc_analyze(&sbcdsp);
118 
120  report("calc_scalefactors");
121 }
check_sbc_analyze
static void check_sbc_analyze(SBCDSPContext *sbcdsp)
Definition: sbcdsp.c:38
mem_internal.h
out
static FILE * out
Definition: movenc.c:55
even
Tag MUST be even
Definition: snow.txt:206
check_func
#define check_func(func,...)
Definition: checkasm.h:213
subbands
subbands
Definition: aptx.h:37
call_ref
#define call_ref(...)
Definition: checkasm.h:229
ff_sbcdsp_init
av_cold void ff_sbcdsp_init(SBCDSPContext *s)
Definition: sbcdsp.c:364
macros.h
fail
#define fail()
Definition: checkasm.h:223
CONST
#define CONST(SIZE, ODDEVEN)
checkasm.h
sbcdsp.h
rnd
#define rnd()
Definition: checkasm.h:206
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
channels
channels
Definition: aptx.h:31
call_new
#define call_new(...)
Definition: checkasm.h:237
checkasm_check_sbcdsp
void checkasm_check_sbcdsp(void)
Definition: sbcdsp.c:111
sbcdsp_data.h
SBC_ALIGN
#define SBC_ALIGN
Definition: sbc.h:80
SBC_MAX_SUBBANDS
@ SBC_MAX_SUBBANDS
Definition: sbcdsp.c:29
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
report
#define report
Definition: checkasm.h:226
randomize_buffer
#define randomize_buffer(buf)
Definition: sbcdsp.c:32
bench_new
#define bench_new(...)
Definition: checkasm.h:428
check_sbc_calc_scalefactors
static void check_sbc_calc_scalefactors(const SBCDSPContext *const sbcdsp)
Definition: sbcdsp.c:72
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:218
int32_t
int32_t
Definition: audioconvert.c:56