annotate remap_neon.c @ 0:e0040ee59c3c

import
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Thu, 12 Jan 2012 17:27:46 +0100
parents
children b829afbea564
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
1 /*
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
2 * Copyright 2012 Peter Meerwald <p.meerwald@bct-electronic.com>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
3 */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
4
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
5 #include <stdlib.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
6 #include <stdio.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
7 #include <stdarg.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
8 #include <string.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
9 #include <math.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
10 #include <sys/time.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
11 #include <assert.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
12
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
13
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
14 typedef short int16_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
15 typedef enum pa_sample_format {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
16 PA_SAMPLE_S16LE,
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
17 PA_SAMPLE_FLOAT32LE,
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
18 } pa_sample_format_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
19 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
20 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
21 typedef struct {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
22 pa_sample_format_t *format;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
23 } pa_remap_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
24 typedef void (*pa_remap_func_t)(pa_remap_t *m, void *dst, const void *src, unsigned n);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
25 typedef long long unsigned int pa_usec_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
26
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
27 #define pa_assert(x) assert(x)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
28 #define pa_assert_not_reached() assert(0)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
29
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
30 #define PA_CLAMP_UNLIKELY(x, low, high) \
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
31 (((x) < (low)) ? (low) : (((x) > (high)) ? (high) : (x)))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
32
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
33 static void pa_log_info(const char *format, ...) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
34 va_list ap;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
35 char buf[1024];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
36 va_start(ap, format);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
37 vsprintf(buf, format, ap);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
38 printf("%s\n", buf);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
39 va_end(ap);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
40 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
41
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
42 #define pa_log_debug pa_log_info
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
43
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
44 static pa_usec_t pa_rtclock_now() {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
45 struct timeval tv;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
46 gettimeofday(&tv, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
47
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
48 return tv.tv_sec * 1000000ULL + tv.tv_usec;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
49 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
50
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
51 static void remap_mono_to_stereo_c(pa_remap_t *m, void *dst, const void *src, unsigned n) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
52 unsigned i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
53
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
54 switch (*m->format) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
55 case PA_SAMPLE_FLOAT32NE:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
56 {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
57 float *d, *s;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
58
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
59 d = (float *) dst;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
60 s = (float *) src;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
61
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
62 for (i = n >> 2; i; i--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
63 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
64 d[2] = d[3] = s[1];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
65 d[4] = d[5] = s[2];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
66 d[6] = d[7] = s[3];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
67 s += 4;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
68 d += 8;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
69 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
70 for (i = n & 3; i; i--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
71 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
72 s++;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
73 d += 2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
74 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
75 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
76 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
77 case PA_SAMPLE_S16NE:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
78 {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
79 int16_t *d, *s;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
80
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
81 d = (int16_t *) dst;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
82 s = (int16_t *) src;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
83
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
84 for (i = n >> 2; i; i--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
85 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
86 d[2] = d[3] = s[1];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
87 d[4] = d[5] = s[2];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
88 d[6] = d[7] = s[3];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
89 s += 4;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
90 d += 8;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
91 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
92 for (i = n & 3; i; i--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
93 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
94 s++;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
95 d += 2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
96 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
97 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
98 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
99 default:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
100 pa_assert_not_reached();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
101 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
102 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
103
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
104 #if defined(__arm__)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
105
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
106 #include "arm_neon.h"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
107
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
108 void remap_mono_to_stereo_neon(pa_remap_t *m, void *dst, const void *src, unsigned n) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
109 unsigned i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
110 switch (*m->format) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
111 case PA_SAMPLE_FLOAT32NE:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
112 {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
113 float *d = (float *) dst, *s = (float *) src;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
114
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
115 for (i = 0; i < n/4; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
116 float32x4x2_t stereo;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
117 stereo.val[0] = vld1q_f32(s);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
118 stereo.val[1] = stereo.val[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
119 vst2q_f32(d, stereo);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
120 s += 4;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
121 d += 8;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
122 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
123
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
124 for (i = n & ~3; i < n; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
125 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
126 s++;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
127 d += 2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
128 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
129 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
130 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
131 case PA_SAMPLE_S16NE:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
132 {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
133 int16_t *d = (int16_t *) dst, *s = (int16_t *) src;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
134
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
135 for (i = 0; i < n/8; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
136 int16x8x2_t stereo;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
137 stereo.val[0] = vld1q_s16(s);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
138 stereo.val[1] = stereo.val[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
139 vst2q_s16(d, stereo);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
140 s += 8;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
141 d += 16;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
142 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
143
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
144 for (i = n & ~7; i < n; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
145 d[0] = d[1] = s[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
146 s++;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
147 d += 2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
148 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
149 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
150 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
151 default:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
152 pa_assert_not_reached();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
153 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
154 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
155
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
156 #define SAMPLES 1019
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
157 #define TIMES 10000
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
158
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
159 static void run_test_float(void) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
160 float stereo[2*SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
161 float stereo_ref[2*SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
162 float mono[SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
163 int i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
164 pa_usec_t start, stop;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
165 pa_remap_func_t func;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
166 pa_sample_format_t sf;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
167 pa_remap_t remap;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
168
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
169 pa_log_debug("checking NEON remap_mono_to_stereo(float, %d)", SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
170
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
171 memset(stereo_ref, 0, sizeof(stereo_ref));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
172 memset(stereo, 0, sizeof(stereo));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
173
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
174 for (i = 0; i < SAMPLES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
175 mono[i] = rand()/(float) RAND_MAX - 0.5f;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
176 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
177
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
178 sf = PA_SAMPLE_FLOAT32NE;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
179 remap.format = &sf;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
180 func = (pa_remap_func_t) remap_mono_to_stereo_c;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
181 func(&remap, stereo_ref, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
182 remap_mono_to_stereo_neon(&remap, stereo, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
183
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
184 for (i = 0; i < 2*SAMPLES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
185 if (fabsf(stereo[i] - stereo_ref[i]) > 0.00001) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
186 pa_log_debug("%d: %.3f != %.3f (%.3f)", i, stereo[i], stereo_ref[i],
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
187 mono[i/2]);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
188 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
189 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
190
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
191 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
192 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
193 remap_mono_to_stereo_neon(&remap, stereo, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
194 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
195 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
196 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
197
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
198 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
199 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
200 func(&remap, stereo_ref, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
201 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
202 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
203 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
204 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
205
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
206 static void run_test_s16(void) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
207 int16_t stereo[2*SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
208 int16_t stereo_ref[2*SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
209 int16_t mono[SAMPLES];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
210 int i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
211 pa_usec_t start, stop;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
212 pa_remap_func_t func;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
213 pa_sample_format_t sf;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
214 pa_remap_t remap;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
215
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
216 pa_log_debug("checking NEON remap_mono_to_stereo(s16, %d)", SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
217
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
218 memset(stereo_ref, 0, sizeof(stereo_ref));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
219 memset(stereo, 0, sizeof(stereo));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
220
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
221 for (i = 0; i < SAMPLES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
222 mono[i] = rand() - RAND_MAX/2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
223 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
224
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
225 sf = PA_SAMPLE_S16NE;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
226 remap.format = &sf;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
227 func = (pa_remap_func_t) remap_mono_to_stereo_c;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
228 func(&remap, stereo_ref, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
229 remap_mono_to_stereo_neon(&remap, stereo, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
230
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
231 for (i = 0; i < 2*SAMPLES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
232 if (abs(stereo[i] - stereo_ref[i]) > 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
233 pa_log_debug("%d: %d != %d (%d)", i, stereo[i], stereo_ref[i],
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
234 mono[i/2]);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
235 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
236 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
237
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
238 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
239 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
240 remap_mono_to_stereo_neon(&remap, stereo, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
241 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
242 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
243 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
244
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
245 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
246 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
247 func(&remap, stereo_ref, mono, SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
248 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
249 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
250 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
251 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
252
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
253 #endif /* defined(__arm__) */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
254
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
255 int main() {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
256
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
257 run_test_float();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
258 run_test_s16();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
259
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
260 return EXIT_SUCCESS;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
261 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.