aboutsummaryrefslogtreecommitdiffstats
path: root/meta-multimedia/recipes-multimedia/fluidsynth/fluidsynth/0003-Use-ARM-NEON-accelaration-for-float-multithreaded-se.patch
blob: ead099545df75d5fdf2cbbef1c510a3be59ac02e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
From 947f79f97a5fa6547d99bff282606026632e010b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Sat, 13 Oct 2018 23:01:11 +0200
Subject: [PATCH] Use ARM-NEON accelaration for float-multithreaded setups

Profiling shows a considerable performance win. See estimated number of voices:
They increase from ~471 to ~513 which makes a ~9% win:

*******************************************************************************
WITHOUT ARM NEON:
*******************************************************************************

morona@raspberrypi3:~$ fluidsynth -o synth.cpu-cores=4 -o synth.chorus.active=0 -o synth.reverb.active=0 /usr/share/sf2/fluidr3gm.sf2
> prof_set_print 1
> prof_set_notes 10
> prof_start 3 10000
Generating 10 notes, generated voices:20
Number of measures(n_prof):3, duration of one mesure(dur):10000ms

Profiling time(mm:ss): Total=0:30  Remainder=0:30, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    112.00|    118.96|    206.00|   4.461
 synth_one_block ---------->|    20|    109.00|    116.44|    196.00|   4.367
 synth_one_block:clear ---->|    20|      1.00|      1.67|     18.00|   0.063
 synth_one_block:one voice->|     1|     11.00|     12.36|     58.00|   0.463
 synth_one_block:all voices>|    20|    107.00|    113.47|    187.00|   4.255
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.461|    4.461|     0.000|    0.000|    0.213|              470

Profiling time(mm:ss): Total=0:30  Remainder=0:20, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    112.00|    118.42|    216.00|   4.441
 synth_one_block ---------->|    20|    109.00|    115.91|    205.00|   4.347
 synth_one_block:clear ---->|    20|      1.00|      1.65|     18.00|   0.062
 synth_one_block:one voice->|     1|     11.00|     12.30|     58.00|   0.461
 synth_one_block:all voices>|    20|    107.00|    112.98|    197.00|   4.237
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.441|    4.441|     0.000|    0.000|    0.212|              472

Profiling time(mm:ss): Total=0:30  Remainder=0:10, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    112.00|    118.64|    244.00|   4.449
 synth_one_block ---------->|    20|    109.00|    116.12|    234.00|   4.355
 synth_one_block:clear ---->|    20|      1.00|      1.67|     37.00|   0.062
 synth_one_block:one voice->|     1|     11.00|     12.31|     63.00|   0.462
 synth_one_block:all voices>|    20|    107.00|    113.18|    214.00|   4.244
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.449|    4.449|     0.000|    0.000|    0.212|              471
Stopping 20 voices...voices stopped.
> quit
cheers!
JackTemporaryException : now quits...
Jack main caught signal 2
fluid_profiling_print
fluidsynth: Estimated times: min/avg/max (micro seconds)
fluidsynth: synth_write_* ------------>: 112.000/118.636/244.000
fluidsynth: synth_one_block ---------->: 109.000/116.124/234.000
fluidsynth: synth_one_block:clear ---->: 1.000/1.665/37.000
fluidsynth: synth_one_block:one voice->: 11.000/12.309/63.000
fluidsynth: synth_one_block:all voices>: 107.000/113.180/214.000

*******************************************************************************
WITH ARM NEON:
*******************************************************************************

morona@raspberrypi3:~$ fluidsynth -o synth.cpu-cores=4 -o synth.chorus.active=0 -o synth.reverb.active=0 /usr/share/sf2/fluidr3gm.sf2
> prof_set_print 1
> prof_set_notes 10
> prof_start 3 10000
Generating 10 notes, generated voices:20
Number of measures(n_prof):3, duration of one mesure(dur):10000ms

Profiling time(mm:ss): Total=0:30  Remainder=0:30, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    102.00|    109.21|    213.00|   4.095
 synth_one_block ---------->|    20|     99.00|    106.68|    201.00|   4.001
 synth_one_block:clear ---->|    20|      1.00|      1.64|     18.00|   0.062
 synth_one_block:one voice->|     1|     11.00|     12.30|     54.00|   0.461
 synth_one_block:all voices>|    20|     97.00|    103.71|    188.00|   3.889
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.095|    4.095|     0.000|    0.000|    0.194|              514

Profiling time(mm:ss): Total=0:30  Remainder=0:20, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    102.00|    109.46|    278.00|   4.105
 synth_one_block ---------->|    20|     99.00|    106.91|    265.00|   4.009
 synth_one_block:clear ---->|    20|      1.00|      1.67|     22.00|   0.062
 synth_one_block:one voice->|     1|     11.00|     12.30|     54.00|   0.461
 synth_one_block:all voices>|    20|     97.00|    103.94|    251.00|   3.898
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.105|    4.105|     0.000|    0.000|    0.195|              513

Profiling time(mm:ss): Total=0:30  Remainder=0:10, press <ENTER> to cancel
 ------------------------------------------------------------------------------
 Duration(microsecond) and cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond)
 ------------------------------------------------------------------------------
 Code under profiling       |Voices|       Duration (microsecond)   |  Load(%)
                            |   nbr|       min|       avg|       max|
 ---------------------------|------|--------------------------------|----------
 synth_write_* ------------>|    20|    102.00|    109.22|    278.00|   4.096
 synth_one_block ---------->|    20|     99.00|    106.65|    265.00|   3.999
 synth_one_block:clear ---->|    20|      1.00|      1.67|     22.00|   0.062
 synth_one_block:one voice->|     1|     11.00|     12.31|     57.00|   0.462
 synth_one_block:all voices>|    20|     97.00|    103.68|    251.00|   3.888
 synth_one_block:reverb --->| no profiling available
 synth_one_block:chorus --->| no profiling available
 voice:note --------------->| no profiling available
 voice:release ------------>| no profiling available
 ------------------------------------------------------------------------------
 Cpu loads(%) (sr: 48000 Hz, sp: 20.83 microsecond) and maximum voices
 ------------------------------------------------------------------------------
 nVoices| total(%)|voices(%)| reverb(%)|chorus(%)| voice(%)|estimated maxVoices
 -------|---------|---------|----------|---------|---------|-------------------
      20|    4.096|    4.096|     0.000|    0.000|    0.194|              514
Stopping 20 voices...voices stopped.
> quit
cheers!
JackTemporaryException : now quits...
Jack main caught signal 2
fluid_profiling_print
fluidsynth: Estimated times: min/avg/max (micro seconds)
fluidsynth: synth_write_* ------------>: 102.000/109.216/278.000
fluidsynth: synth_one_block ---------->: 99.000/106.649/265.000
fluidsynth: synth_one_block:clear ---->: 1.000/1.666/22.000
fluidsynth: synth_one_block:one voice->: 11.000/12.307/57.000
fluidsynth: synth_one_block:all voices>: 97.000/103.681/251.000

Upstream-Status: Inappropriate [embedded-specific]

---
 src/rvoice/fluid_rvoice_mixer.c | 55 ++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c
index af0ef75d..07a357c7 100644
--- a/src/rvoice/fluid_rvoice_mixer.c
+++ b/src/rvoice/fluid_rvoice_mixer.c
@@ -27,6 +27,9 @@
 #include "fluid_ladspa.h"
 #include "fluid_synth.h"
 
+#if defined(__ARM_NEON__)
+#include "arm_neon.h"
+#endif
 
 // If less than x voices, the thread overhead is larger than the gain,
 // so don't activate the thread(s).
@@ -1053,9 +1056,15 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
     int i, j;
     int scount = current_blockcount * FLUID_BUFSIZE;
     int minbuf;
+#if defined(__ARM_NEON__) && defined(WITH_FLOAT)
+    fluid_real_t *FLUID_RESTRICT base_src_left;
+    fluid_real_t *FLUID_RESTRICT base_src_right;
+    fluid_real_t *FLUID_RESTRICT base_dst_left;
+    fluid_real_t *FLUID_RESTRICT base_dst_right;
+#else
     fluid_real_t *FLUID_RESTRICT base_src;
     fluid_real_t *FLUID_RESTRICT base_dst;
-
+#endif
     minbuf = dst->buf_count;
 
     if(minbuf > src->buf_count)
@@ -1063,6 +1072,27 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
         minbuf = src->buf_count;
     }
 
+#if defined(__ARM_NEON__) && defined(WITH_FLOAT)
+    base_src_left = fluid_align_ptr(src->left_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_dst_left = fluid_align_ptr(dst->left_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_src_right = fluid_align_ptr(src->right_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_dst_right = fluid_align_ptr(dst->right_buf, FLUID_DEFAULT_ALIGNMENT);
+
+    for(i = 0; i < minbuf; i++)
+    {
+        for(j = 0; j < scount; j+=4)
+        {
+            int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
+
+            float32x4_t vleft = vld1q_f32(&base_dst_left[dsp_i]);
+            float32x4_t vright = vld1q_f32(&base_dst_right[dsp_i]);
+            vleft = vaddq_f32(vleft, vld1q_f32(&base_src_left[dsp_i]));
+            vright = vaddq_f32(vright, vld1q_f32(&base_src_right[dsp_i]));
+            vst1q_f32(&base_dst_left[dsp_i], vleft);
+            vst1q_f32(&base_dst_right[dsp_i], vright);
+        }
+    }
+#else
     base_src = fluid_align_ptr(src->left_buf, FLUID_DEFAULT_ALIGNMENT);
     base_dst = fluid_align_ptr(dst->left_buf, FLUID_DEFAULT_ALIGNMENT);
 
@@ -1090,6 +1120,7 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
             base_dst[dsp_i] += base_src[dsp_i];
         }
     }
+#endif
 
     minbuf = dst->fx_buf_count;
 
@@ -1098,6 +1129,27 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
         minbuf = src->fx_buf_count;
     }
 
+#if defined(__ARM_NEON__) && defined(WITH_FLOAT)
+    base_src_left = fluid_align_ptr(src->fx_left_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_dst_left = fluid_align_ptr(dst->fx_left_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_src_right = fluid_align_ptr(src->fx_right_buf, FLUID_DEFAULT_ALIGNMENT);
+    base_dst_right = fluid_align_ptr(dst->fx_right_buf, FLUID_DEFAULT_ALIGNMENT);
+
+    for(i = 0; i < minbuf; i++)
+    {
+        for(j = 0; j < scount; j+=4)
+        {
+            int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
+
+            float32x4_t vleft = vld1q_f32(&base_dst_left[dsp_i]);
+            float32x4_t vright = vld1q_f32(&base_dst_right[dsp_i]);
+            vleft = vaddq_f32(vleft, vld1q_f32(&base_src_left[dsp_i]));
+            vright = vaddq_f32(vright, vld1q_f32(&base_src_right[dsp_i]));
+            vst1q_f32(&base_dst_left[dsp_i], vleft);
+            vst1q_f32(&base_dst_right[dsp_i], vright);
+        }
+    }
+#else
     base_src = fluid_align_ptr(src->fx_left_buf, FLUID_DEFAULT_ALIGNMENT);
     base_dst = fluid_align_ptr(dst->fx_left_buf, FLUID_DEFAULT_ALIGNMENT);
 
@@ -1125,6 +1177,7 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
             base_dst[dsp_i] += base_src[dsp_i];
         }
     }
+#endif
 }
 
 
-- 
2.20.1