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 unsigned int uint32_t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
16 typedef enum pa_sample_format {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
17 PA_SAMPLE_S16LE,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
18 PA_SAMPLE_FLOAT32LE,
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
19 } pa_sample_format_t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
20 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
21 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
22 typedef long long unsigned int pa_usec_t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
23
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
24 #define pa_assert(x) assert(x)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
25 #define pa_assert_not_reached() assert(0)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
26
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
27 #define PA_MAX(a, b) ((a) > (b) ? (a) : (b))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
28
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
29 typedef uint32_t pa_volume_t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
30 #define PA_VOLUME_MUTED ((pa_volume_t) 0U)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
31 #define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX/2)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
32
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
33 #define PA_UNLIKELY(x) (x)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
34 #define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x)))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
35 #define PA_CLAMP_VOLUME(v) (PA_CLAMP_UNLIKELY((v), PA_VOLUME_MUTED, PA_VOLUME_MAX))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
36
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
37 static void pa_log_info(const char *format, ...) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
38 va_list ap;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
39 char buf[1024];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
40 va_start(ap, format);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
41 vsprintf(buf, format, ap);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
42 printf("%s\n", buf);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
43 va_end(ap);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
44 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
45
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
46 #define pa_log_debug pa_log_info
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
47
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
48 static pa_usec_t pa_rtclock_now() {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
49 struct timeval tv;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
50 gettimeofday(&tv, NULL);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
51
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
52 return tv.tv_sec * 1000000ULL + tv.tv_usec;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
53 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
54
|
4
|
55 static void pa_volume_s16ne_c(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
56 unsigned channel;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
57
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
58 length /= sizeof(int16_t);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
59
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
60 for (channel = 0; length; length--) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
61 int32_t t, hi, lo;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
62
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
63 /* Multiplying the 32bit volume factor with the 16bit
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
64 * sample might result in an 48bit value. We want to
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
65 * do without 64 bit integers and hence do the
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
66 * multiplication independently for the HI and LO part
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
67 * of the volume. */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
68
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
69 hi = volumes[channel] >> 16;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
70 lo = volumes[channel] & 0xFFFF;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
71
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
72 t = (int32_t)(*samples);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
73 t = ((t * lo) >> 16) + (t * hi);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
74 t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
75 *samples++ = (int16_t) t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
76
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
77 if (PA_UNLIKELY(++channel >= channels))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
78 channel = 0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
79 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
80 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
81
|
4
|
82 static void pa_volume_float32ne_c(float *samples, const float *volumes, unsigned channels, unsigned length) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
83 unsigned channel;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
84
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
85 length /= sizeof(float);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
86
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
87 for (channel = 0; length; length--) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
88 *samples++ *= volumes[channel];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
89
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
90 if (PA_UNLIKELY(++channel >= channels))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
91 channel = 0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
92 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
93 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
94
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
95 #if defined(__arm__)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
96
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
97 #include "arm_neon.h"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
98
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
99 #define MOD_INC() \
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
100 " subs r0, r6, %2 \n\t" \
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
101 " itt cs \n\t" \
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
102 " addcs r0, %1 \n\t" \
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
103 " movcs r6, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
104
|
4
|
105 static void pa_volume_s16ne_arm(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
106 /* Channels must be at least 4, and always a multiple of the original number.
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
107 * This is also the max amount we overread the volume array, which should
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
108 * have enough padding. */
|
4
|
109 channels = channels == 3 ? 6 : PA_MAX(4U, channels);
|
|
110 const uint32_t *ve = volumes + channels;
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
111
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
112 __asm__ __volatile__ (
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
113 " mov r6, %1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
114 " mov %3, %3, LSR #1 \n\t" /* length /= sizeof (int16_t) */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
115 " tst %3, #1 \n\t" /* check for odd samples */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
116 " beq 2f \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
117
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
118 "1: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
119 " ldr r0, [r6], #4 \n\t" /* odd samples volumes */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
120 " ldrh r2, [%0] \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
121
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
122 " smulwb r0, r0, r2 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
123 " ssat r0, #16, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
124
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
125 " strh r0, [%0], #2 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
126
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
127 MOD_INC()
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
128
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
129 "2: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
130 " mov %3, %3, LSR #1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
131 " tst %3, #1 \n\t" /* check for odd samples */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
132 " beq 4f \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
133
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
134 "3: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
135 " ldrd r2, [r6], #8 \n\t" /* 2 samples at a time */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
136 " ldr r0, [%0] \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
137
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
138 " smulwt r2, r2, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
139 " smulwb r3, r3, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
140
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
141 " ssat r2, #16, r2 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
142 " ssat r3, #16, r3 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
143
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
144 " pkhbt r0, r3, r2, LSL #16 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
145 " str r0, [%0], #4 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
146
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
147 MOD_INC()
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
148
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
149 "4: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
150 " movs %3, %3, LSR #1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
151 " beq 6f \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
152
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
153 "5: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
154 " ldrd r2, [r6], #8 \n\t" /* 4 samples at a time */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
155 " ldrd r4, [r6], #8 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
156 " ldrd r0, [%0] \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
157
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
158 " smulwt r2, r2, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
159 " smulwb r3, r3, r0 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
160 " smulwt r4, r4, r1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
161 " smulwb r5, r5, r1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
162
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
163 " ssat r2, #16, r2 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
164 " ssat r3, #16, r3 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
165 " ssat r4, #16, r4 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
166 " ssat r5, #16, r5 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
167
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
168 " pkhbt r0, r3, r2, LSL #16 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
169 " pkhbt r1, r5, r4, LSL #16 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
170 " strd r0, [%0], #8 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
171
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
172 MOD_INC()
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
173
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
174 " subs %3, %3, #1 \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
175 " bne 5b \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
176 "6: \n\t"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
177
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
178 : "+r" (samples), "+r" (volumes), "+r" (ve), "+r" (length)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
179 :
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
180 : "r6", "r5", "r4", "r3", "r2", "r1", "r0", "cc"
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
181 );
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
182 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
183
|
4
|
184 static inline void vol_s16_neon(const uint32x4_t *vol4, int16_t *samples, unsigned length) {
|
|
185 asm volatile (
|
|
186 "mov %[length], %[length], lsr #2\n\t"
|
|
187 "vld1.s32 {q0}, [%[vol]]\n\t"
|
|
188 "vshl.u32 q3, q0, #16\n\t" /* lo */
|
|
189 "vshrn.s32 d1, q0, #16\n\t" /* hi */
|
|
190 "vshr.u32 q3, q3, #16\n\t"
|
|
191 "1:\n\t"
|
|
192 "vld1.16 {d0}, [%[samples]]\n\t"
|
|
193
|
|
194 "vmull.s16 q1, d0, d1\n\t"
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
195
|
4
|
196 "vmovl.s16 q2, d0\n\t"
|
|
197 "vmul.s32 q2, q2, q3\n\t"
|
|
198
|
|
199 "vsra.s32 q1, q2, #16\n\t"
|
|
200 "vmovn.s32 d0, q1\n\t"
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
201
|
4
|
202 "subs %[length], %[length], #1\n\t"
|
|
203 "vst1.16 {d0}, [%[samples]]!\n\t"
|
|
204 "bgt 1b\n\t"
|
|
205 /* output operands (or input operands that get modified) */
|
|
206 : [samples] "+r" (samples), [length] "+r" (length)
|
|
207 : [vol] "r" (vol4) /* input operands */
|
|
208 : "memory", "cc", "q0", "q1", "q2", "q3" /* clobber list */
|
|
209 );
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
210 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
211
|
4
|
212 static inline void vol_float_neon(const float32x4_t *vol4, float *samples, unsigned length) {
|
|
213 asm volatile (
|
|
214 "mov %[length], %[length], lsr #2\n\t"
|
|
215 "vld1.32 {q1}, [%[vol]]\n\t"
|
|
216 "1:\n\t"
|
|
217 "vld1.32 {q0}, [%[samples]]\n\t"
|
|
218 "vmul.f32 q0, q0, q1\n\t"
|
|
219 "subs %[length], %[length], #1\n\t"
|
|
220 "vst1.32 {q0}, [%[samples]]!\n\t"
|
|
221 "bgt 1b\n\t"
|
|
222 /* output operands (or input operands that get modified) */
|
|
223 : [samples] "+r" (samples), [length] "+r" (length)
|
|
224 : [vol] "r" (vol4) /* input operands */
|
|
225 : "memory", "cc", "q0", "q1" /* clobber list */
|
|
226 );
|
|
227 }
|
|
228
|
|
229 static void pa_volume_s16ne_neon(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
230 unsigned channel = 0, i;
|
4
|
231 uint32x4_t vol4;
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
232
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
233 length /= sizeof(int16_t);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
234
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
235 switch (channels) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
236 case 1:
|
4
|
237 vol4 = vdupq_n_u32(*volumes);
|
|
238 vol_s16_neon(&vol4, samples, length);
|
|
239
|
|
240 for (i = length & ~3; i < length; i++) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
241 int32_t t = samples[i];
|
4
|
242 t = ((int32_t) (t * (*volumes & 0xFFFF)) >> 16) + (t * (*volumes >> 16));
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
243 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
244 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
245 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
246 case 2:
|
4
|
247 vol4 = vcombine_u32(*(uint32x2_t *)volumes, *(uint32x2_t *)volumes);
|
|
248 vol_s16_neon(&vol4, samples, length);
|
|
249
|
|
250 for (i = length & ~3; i < length; i++) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
251 int32_t t = samples[i];
|
4
|
252 uint32_t vol = volumes[(channel++) & 1];
|
|
253 t = ((int32_t) (t * (vol & 0xFFFF)) >> 16) + (t * (vol >> 16));
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
254 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
255 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
256 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
257 case 4:
|
4
|
258 vol4 = *(uint32x4_t *)volumes;
|
|
259 vol_s16_neon(&vol4, samples, length);
|
|
260
|
|
261 for (i = length & ~3; i < length; i++) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
262 int32_t t = samples[i];
|
4
|
263 uint32_t vol = volumes[(channel++) & 3];
|
|
264 t = ((int32_t) (t * (vol & 0xFFFF)) >> 16) + (t * (vol >> 16));
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
265 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
266 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
267 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
268 default:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
269 for (; length; length--) {
|
4
|
270 int32_t t;
|
|
271 uint32_t hi, lo;
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
272
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
273 /* Multiplying the 32bit volume factor with the 16bit
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
274 * sample might result in an 48bit value. We want to
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
275 * do without 64 bit integers and hence do the
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
276 * multiplication independently for the HI and LO part
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
277 * of the volume. */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
278
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
279 hi = volumes[channel] >> 16;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
280 lo = volumes[channel] & 0xFFFF;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
281
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
282 t = (int32_t)(*samples);
|
4
|
283 t = ((int32_t) (t * lo) >> 16) + (t * hi);
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
284 t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
285 *samples++ = (int16_t) t;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
286
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
287 if (PA_UNLIKELY(++channel >= channels))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
288 channel = 0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
289 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
290 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
291 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
292 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
293
|
4
|
294 static void pa_volume_float32ne_neon(float *samples, const float *volumes, unsigned channels, unsigned length) {
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
295 unsigned channel = 0, i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
296 float32x4_t vol4;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
297
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
298 length /= sizeof(float);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
299
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
300 switch (channels) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
301 case 1:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
302 vol4 = vdupq_n_f32(*volumes);
|
4
|
303 vol_float_neon(&vol4, samples, length);
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
304
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
305 for (i = length & ~3; i < length; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
306 samples[i] *= volumes[0];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
307 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
308 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
309 case 2:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
310 vol4 = vcombine_f32(*(float32x2_t *)volumes, *(float32x2_t *)volumes);
|
4
|
311 vol_float_neon(&vol4, samples, length);
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
312
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
313 for (i = length & ~3; i < length; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
314 samples[i] *= volumes[channel];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
315
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
316 if (PA_UNLIKELY(++channel >= channels))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
317 channel = 0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
318 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
319 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
320 case 4:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
321 vol4 = *(float32x4_t *)volumes;
|
4
|
322 vol_float_neon(&vol4, samples, length);
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
323
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
324 for (i = length & ~3; i < length; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
325 samples[i] *= volumes[channel++];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
326 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
327 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
328 default:
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
329 for (; length; length--) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
330 *samples++ *= volumes[channel];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
331
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
332 if (PA_UNLIKELY(++channel >= channels))
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
333 channel = 0;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
334 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
335 break;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
336 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
337 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
338
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
339 #define SAMPLES 1019
|
4
|
340 #define TIMES 50000
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
341 #define CHANNELS 4
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
342 #define PADDING 16
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
343
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
344 static void run_test_float(void) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
345 float floats[SAMPLES];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
346 float floats_ref[SAMPLES];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
347 float floats_orig[SAMPLES];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
348 float volumes[CHANNELS];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
349 unsigned i;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
350 pa_usec_t start, stop;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
351
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
352 pa_log_debug("checking NEON volume_float32ne(%d)", SAMPLES);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
353
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
354 for (i = 0; i < SAMPLES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
355 floats_orig[i] = rand()/(float) RAND_MAX - 0.5f;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
356 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
357 memcpy(floats_ref, floats_orig, sizeof(floats_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
358 memcpy(floats, floats_orig, sizeof(floats_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
359
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
360 for (i = 0; i < CHANNELS; i++)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
361 volumes[i] = 0.5f * rand() / (float) RAND_MAX;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
362
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
363 pa_volume_float32ne_neon(floats, volumes, CHANNELS, sizeof(floats));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
364 pa_volume_float32ne_c(floats_ref, volumes, CHANNELS, sizeof(floats_ref));
|
4
|
365
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
366 for (i = 0; i < SAMPLES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
367 if (fabsf(floats[i] - floats_ref[i]) > 0.00001) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
368 pa_log_debug("%d: %.3f != %.3f (%.3f)", i, floats[i], floats_ref[i],
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
369 floats_orig[i]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
370 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
371 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
372
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
373 start = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
374 for (i = 0; i < TIMES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
375 memcpy(floats, floats_orig, sizeof(floats_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
376 pa_volume_float32ne_neon(floats, volumes, CHANNELS, sizeof(floats));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
377 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
378 stop = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
379 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
380
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
381 start = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
382 for (i = 0; i < TIMES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
383 memcpy(floats_ref, floats_orig, sizeof(floats_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
384 pa_volume_float32ne_c(floats_ref, volumes, CHANNELS, sizeof(floats_ref));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
385 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
386 stop = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
387 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
388 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
389
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
390 static void run_test_s16(void) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
391 int16_t samples[SAMPLES];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
392 int16_t samples_ref[SAMPLES];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
393 int16_t samples_orig[SAMPLES];
|
4
|
394 uint32_t volumes[CHANNELS + PADDING];
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
395 unsigned i, padding;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
396 pa_usec_t start, stop;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
397
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
398 pa_log_debug("checking NEON volume_s16ne(%d)", SAMPLES);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
399
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
400 for (i = 0; i < SAMPLES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
401 samples_orig[i] = rand() - RAND_MAX/2;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
402 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
403 memcpy(samples_ref, samples_orig, sizeof(samples_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
404 memcpy(samples, samples_orig, sizeof(samples_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
405
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
406 for (i = 0; i < CHANNELS; i++)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
407 volumes[i] = PA_CLAMP_VOLUME(rand() >> 15);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
408 for (padding = 0; padding < PADDING; padding++, i++)
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
409 volumes[i] = volumes[padding];
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
410
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
411 pa_volume_s16ne_neon(samples, volumes, CHANNELS, sizeof(samples));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
412 pa_volume_s16ne_c(samples_ref, volumes, CHANNELS, sizeof(samples_ref));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
413
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
414 for (i = 0; i < SAMPLES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
415 if (abs(samples[i] - samples_ref[i]) > 0) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
416 pa_log_debug("%d: %d != %d (%d)", i, samples[i], samples_ref[i],
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
417 samples_orig[i]);
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
418 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
419 }
|
4
|
420 exit(0);
|
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
421 start = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
422 for (i = 0; i < TIMES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
423 memcpy(samples, samples_orig, sizeof(samples_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
424 pa_volume_s16ne_neon(samples, volumes, CHANNELS, sizeof(samples));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
425 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
426 stop = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
427 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
428
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
429 start = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
430 for (i = 0; i < TIMES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
431 memcpy(samples, samples_orig, sizeof(samples_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
432 pa_volume_s16ne_arm(samples, volumes, CHANNELS, sizeof(samples));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
433 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
434 stop = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
435 pa_log_info("ARM: %llu usec.", (long long unsigned int)(stop - start));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
436
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
437 start = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
438 for (i = 0; i < TIMES; i++) {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
439 memcpy(samples_ref, samples_orig, sizeof(samples_orig));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
440 pa_volume_s16ne_c(samples_ref, volumes, CHANNELS, sizeof(samples_ref));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
441 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
442 stop = pa_rtclock_now();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
443 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
444 }
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
445
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
446 #endif /* defined(__arm__) */
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
447
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
448 int main() {
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
449
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
450 run_test_float();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
451 run_test_s16();
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
452
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
453 return EXIT_SUCCESS;
|
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff
changeset
|
454 }
|