1 /******************************************************************************
2 *
3 * Copyright 2022 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22
23 #include "simd32.h"
24
25 /* -------------------------------------------------------------------------- */
26
27 #define TEST_ARM
28 #include <ltpf.c>
29
lc3_put_bits_generic(lc3_bits_t * a,unsigned b,int c)30 void lc3_put_bits_generic(lc3_bits_t *a, unsigned b, int c)
31 { (void)a, (void)b, (void)c; }
32
lc3_get_bits_generic(struct lc3_bits * a,int b)33 unsigned lc3_get_bits_generic(struct lc3_bits *a, int b)
34 { return (void)a, (void)b, 0; }
35
36 /* -------------------------------------------------------------------------- */
37
check_resampler()38 static int check_resampler()
39 {
40 int16_t __x[60+480], *x = __x + 60;
41 for (int i = -60; i < 480; i++)
42 x[i] = rand() & 0xffff;
43
44 struct lc3_ltpf_hp50_state hp50 = { 0 }, hp50_arm = { 0 };
45 int16_t y[128], y_arm[128];
46
47 resample_8k_12k8(&hp50, x, y, 128);
48 arm_resample_8k_12k8(&hp50_arm, x, y_arm, 128);
49 if (memcmp(y, y_arm, 128 * sizeof(*y)) != 0)
50 return -1;
51
52 resample_16k_12k8(&hp50, x, y, 128);
53 arm_resample_16k_12k8(&hp50_arm, x, y_arm, 128);
54 if (memcmp(y, y_arm, 128 * sizeof(*y)) != 0)
55 return -1;
56
57 resample_24k_12k8(&hp50, x, y, 128);
58 arm_resample_24k_12k8(&hp50_arm, x, y_arm, 128);
59 if (memcmp(y, y_arm, 128 * sizeof(*y)) != 0)
60 return -1;
61
62 resample_32k_12k8(&hp50, x, y, 128);
63 arm_resample_32k_12k8(&hp50_arm, x, y_arm, 128);
64 if (memcmp(y, y_arm, 128 * sizeof(*y)) != 0)
65 return -1;
66
67 resample_48k_12k8(&hp50, x, y, 128);
68 arm_resample_48k_12k8(&hp50_arm, x, y_arm, 128);
69 if (memcmp(y, y_arm, 128 * sizeof(*y)) != 0)
70 return -1;
71
72 return 0;
73 }
74
check_correlate()75 static int check_correlate()
76 {
77 int16_t alignas(4) a[500], b[500];
78 float y[100], y_arm[100];
79
80 for (int i = 0; i < 500; i++) {
81 a[i] = rand() & 0xffff;
82 b[i] = rand() & 0xffff;
83 }
84
85 correlate(a, b+200, 128, y, 100);
86 arm_correlate(a, b+200, 128, y_arm, 100);
87 if (memcmp(y, y_arm, 100 * sizeof(*y)) != 0)
88 return -1;
89
90 correlate(a, b+199, 128, y, 99);
91 arm_correlate(a, b+199, 128, y_arm, 99);
92 if (memcmp(y, y_arm, 99 * sizeof(*y)) != 0)
93 return -1;
94
95 correlate(a, b+199, 128, y, 100);
96 arm_correlate(a, b+199, 128, y_arm, 100);
97 if (memcmp(y, y_arm, 100 * sizeof(*y)) != 0)
98 return -1;
99
100 return 0;
101 }
102
check_ltpf(void)103 int check_ltpf(void)
104 {
105 int ret;
106
107 if ((ret = check_resampler()) < 0)
108 return ret;
109
110 if ((ret = check_correlate()) < 0)
111 return ret;
112
113 return 0;
114 }
115