aboutsummaryrefslogtreecommitdiffstats
path: root/meta-multimedia/recipes-multimedia/fluidsynth/fluidsynth/0002-fluid_synth_nwrite_float-Allow-zero-pointer-for-left.patch
blob: f7debc5ad47a02f7460711b7b24c087c69dc319e (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
From 300977537b6056bdbbba9df9100fa6e891ca1f44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Mon, 17 Dec 2018 14:08:45 +0100
Subject: [PATCH 2/2] fluid_synth_nwrite_float: Allow zero pointer for
 left/right and zero pointer in arrays
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With this modification a client can define exactly what it wants to get into
buffers to avoid useless copying of data. On weak machines this leads to measurable
performance wins.

Upstream-Status: Submitted [1]

[1] https://github.com/FluidSynth/fluidsynth/pull/490

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
---
 src/synth/fluid_synth.c | 69 ++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 21 deletions(-)

diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c
index 1eb5d737..6c876efa 100644
--- a/src/synth/fluid_synth.c
+++ b/src/synth/fluid_synth.c
@@ -3628,10 +3628,10 @@ fluid_synth_program_reset(fluid_synth_t *synth)
  *
  * @param synth FluidSynth instance
  * @param len Count of audio frames to synthesize
- * @param left Array of float buffers to store left channel of planar audio (as many as \c synth.audio-channels buffers, each of \c len in size)
- * @param right Array of float buffers to store right channel of planar audio (size: dito)
- * @param fx_left Since 1.1.7: If not \c NULL, array of float buffers to store left effect channels (as many as \c synth.effects-channels buffers, each of \c len in size)
- * @param fx_right Since 1.1.7: If not \c NULL, array of float buffers to store right effect channels (size: dito)
+ * @param left Array of float buffers to store left channel of planar audio (as many as \c synth.audio-channels buffers, each of \c len in size). Since 2.0.3: NULL allowed / NULL allowed for array entry
+ * @param right Array of float buffers to store right channel of planar audio (size: dito). Since 2.0.3: NULL allowed / NULL allowed for array entry
+ * @param fx_left Since 1.1.7: If not \c NULL, array of float buffers to store left effect channels (as many as \c synth.effects-channels buffers, each of \c len in size). Since 2.0.3: NULL allowed for array entry
+ * @param fx_right Since 1.1.7: If not \c NULL, array of float buffers to store right effect channels (size: dito). Since 2.0.3: NULL allowed for array entry
  * @return #FLUID_OK on success, #FLUID_FAILED otherwise
  *
  * First effect channel used by reverb, second for chorus.
@@ -3719,15 +3719,27 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
         for(i = 0; i < synth->audio_channels; i++)
         {
 #ifdef WITH_FLOAT
-            FLUID_MEMCPY(left[i], &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
-            FLUID_MEMCPY(right[i], &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
+            if(left != NULL && left[i] != NULL)
+            {
+                FLUID_MEMCPY(left[i], &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
+            }
+            if(right != NULL && right[i] != NULL)
+            {
+                FLUID_MEMCPY(right[i], &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
+            }
 #else //WITH_FLOAT
             int j;
 
             for(j = 0; j < num; j++)
             {
-                left[i][j] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
-                right[i][j] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
+                if(left != NULL && left[i] != NULL)
+                {
+                    left[i][j] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
+                }
+                if(right != NULL && right[i] != NULL)
+                {
+                    right[i][j] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
+                }
             }
 
 #endif //WITH_FLOAT
@@ -3737,12 +3749,12 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
         {
 #ifdef WITH_FLOAT
 
-            if(fx_left != NULL)
+            if(fx_left != NULL && fx_left[i] != NULL)
             {
                 FLUID_MEMCPY(fx_left[i], &fx_left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
             }
 
-            if(fx_right != NULL)
+            if(fx_right != NULL && fx_right[i] != NULL)
             {
                 FLUID_MEMCPY(fx_right[i], &fx_right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
             }
@@ -3750,7 +3762,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
 #else //WITH_FLOAT
             int j;
 
-            if(fx_left != NULL)
+            if(fx_left != NULL && fx_left[i] != NULL)
             {
                 for(j = 0; j < num; j++)
                 {
@@ -3758,7 +3770,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
                 }
             }
 
-            if(fx_right != NULL)
+            if(fx_right != NULL && fx_right[i] != NULL)
             {
                 for(j = 0; j < num; j++)
                 {
@@ -3789,15 +3801,30 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
         for(i = 0; i < synth->audio_channels; i++)
         {
 #ifdef WITH_FLOAT
-            FLUID_MEMCPY(left[i] + count, &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
-            FLUID_MEMCPY(right[i] + count, &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
+            if(left != NULL && left[i] != NULL)
+            {
+                FLUID_MEMCPY(left[i] + count, &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
+            }
+            if(right != NULL && right[i] != NULL)
+            {
+                FLUID_MEMCPY(right[i] + count, &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
+            }
 #else //WITH_FLOAT
             int j;
 
-            for(j = 0; j < num; j++)
+            if(left != NULL && left[i] != NULL)
+            {
+                for(j = 0; j < num; j++)
+                {
+                    left[i][j + count] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
+                }
+            }
+            if(right != NULL && right[i] != NULL)
             {
-                left[i][j + count] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
-                right[i][j + count] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
+                for(j = 0; j < num; j++)
+                {
+                    right[i][j + count] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
+                }
             }
 
 #endif //WITH_FLOAT
@@ -3807,12 +3834,12 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
         {
 #ifdef WITH_FLOAT
 
-            if(fx_left != NULL)
+            if(fx_left != NULL && fx_left[i] != NULL)
             {
                 FLUID_MEMCPY(fx_left[i] + count, &fx_left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
             }
 
-            if(fx_right != NULL)
+            if(fx_right != NULL && fx_right[i] != NULL)
             {
                 FLUID_MEMCPY(fx_right[i] + count, &fx_right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
             }
@@ -3820,7 +3847,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
 #else //WITH_FLOAT
             int j;
 
-            if(fx_left != NULL)
+            if(fx_left != NULL && fx_left[i] != NULL)
             {
                 for(j = 0; j < num; j++)
                 {
@@ -3828,7 +3855,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
                 }
             }
 
-            if(fx_right != NULL)
+            if(fx_right != NULL && fx_right[i] != NULL)
             {
                 for(j = 0; j < num; j++)
                 {
-- 
2.14.5