blob: 94daa951c6910440f9f329c4bd560368c0d212d1 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 300977537b6056bdbbba9df9100fa6e891ca1f44 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Mon, 17 Dec 2018 14:08:45 +0100
4Subject: [PATCH 2/2] fluid_synth_nwrite_float: Allow zero pointer for
5 left/right and zero pointer in arrays
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10With this modification a client can define exactly what it wants to get into
11buffers to avoid useless copying of data. On weak machines this leads to measurable
12performance wins.
13
14Upstream-Status: Submitted [1]
15
16[1] https://github.com/FluidSynth/fluidsynth/pull/490
17
18Signed-off-by: Andreas MΓΌller <schnitzeltony@gmail.com>
19---
20 src/synth/fluid_synth.c | 69 ++++++++++++++++++++++++++++++++++---------------
21 1 file changed, 48 insertions(+), 21 deletions(-)
22
23diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c
24index 0df620d3..379f8216 100644
25--- a/src/synth/fluid_synth.c
26+++ b/src/synth/fluid_synth.c
27@@ -3306,10 +3306,10 @@ fluid_synth_program_reset(fluid_synth_t *synth)
28 * Synthesize a block of floating point audio to separate audio buffers (multichannel rendering). First effect channel used by reverb, second for chorus.
29 * @param synth FluidSynth instance
30 * @param len Count of audio frames to synthesize
31- * @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)
32- * @param right Array of float buffers to store right channel of planar audio (size: dito)
33- * @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)
34- * @param fx_right Since 1.1.7: If not \c NULL, array of float buffers to store right effect channels (size: dito)
35+ * @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
36+ * @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
37+ * @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
38+ * @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
39 * @return #FLUID_OK on success, #FLUID_FAILED otherwise
40 *
41 * @note Should only be called from synthesis thread.
42@@ -3386,15 +3386,27 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
43 for(i = 0; i < synth->audio_channels; i++)
44 {
45 #ifdef WITH_FLOAT
46- FLUID_MEMCPY(left[i], &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
47- FLUID_MEMCPY(right[i], &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
48+ if(left != NULL && left[i] != NULL)
49+ {
50+ FLUID_MEMCPY(left[i], &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
51+ }
52+ if(right != NULL && right[i] != NULL)
53+ {
54+ FLUID_MEMCPY(right[i], &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
55+ }
56 #else //WITH_FLOAT
57 int j;
58
59 for(j = 0; j < num; j++)
60 {
61- left[i][j] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
62- right[i][j] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
63+ if(left != NULL && left[i] != NULL)
64+ {
65+ left[i][j] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
66+ }
67+ if(right != NULL && right[i] != NULL)
68+ {
69+ right[i][j] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j + synth->cur];
70+ }
71 }
72
73 #endif //WITH_FLOAT
74@@ -3404,12 +3416,12 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
75 {
76 #ifdef WITH_FLOAT
77
78- if(fx_left != NULL)
79+ if(fx_left != NULL && fx_left[i] != NULL)
80 {
81 FLUID_MEMCPY(fx_left[i], &fx_left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
82 }
83
84- if(fx_right != NULL)
85+ if(fx_right != NULL && fx_right[i] != NULL)
86 {
87 FLUID_MEMCPY(fx_right[i], &fx_right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + synth->cur], bytes);
88 }
89@@ -3417,7 +3429,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
90 #else //WITH_FLOAT
91 int j;
92
93- if(fx_left != NULL)
94+ if(fx_left != NULL && fx_left[i] != NULL)
95 {
96 for(j = 0; j < num; j++)
97 {
98@@ -3425,7 +3437,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
99 }
100 }
101
102- if(fx_right != NULL)
103+ if(fx_right != NULL && fx_right[i] != NULL)
104 {
105 for(j = 0; j < num; j++)
106 {
107@@ -3456,15 +3468,30 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
108 for(i = 0; i < synth->audio_channels; i++)
109 {
110 #ifdef WITH_FLOAT
111- FLUID_MEMCPY(left[i] + count, &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
112- FLUID_MEMCPY(right[i] + count, &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
113+ if(left != NULL && left[i] != NULL)
114+ {
115+ FLUID_MEMCPY(left[i] + count, &left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
116+ }
117+ if(right != NULL && right[i] != NULL)
118+ {
119+ FLUID_MEMCPY(right[i] + count, &right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
120+ }
121 #else //WITH_FLOAT
122 int j;
123
124- for(j = 0; j < num; j++)
125+ if(left != NULL && left[i] != NULL)
126+ {
127+ for(j = 0; j < num; j++)
128+ {
129+ left[i][j + count] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
130+ }
131+ }
132+ if(right != NULL && right[i] != NULL)
133 {
134- left[i][j + count] = (float) left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
135- right[i][j + count] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
136+ for(j = 0; j < num; j++)
137+ {
138+ right[i][j + count] = (float) right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT + j];
139+ }
140 }
141
142 #endif //WITH_FLOAT
143@@ -3474,12 +3501,12 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
144 {
145 #ifdef WITH_FLOAT
146
147- if(fx_left != NULL)
148+ if(fx_left != NULL && fx_left[i] != NULL)
149 {
150 FLUID_MEMCPY(fx_left[i] + count, &fx_left_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
151 }
152
153- if(fx_right != NULL)
154+ if(fx_right != NULL && fx_right[i] != NULL)
155 {
156 FLUID_MEMCPY(fx_right[i] + count, &fx_right_in[i * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT], bytes);
157 }
158@@ -3487,7 +3514,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
159 #else //WITH_FLOAT
160 int j;
161
162- if(fx_left != NULL)
163+ if(fx_left != NULL && fx_left[i] != NULL)
164 {
165 for(j = 0; j < num; j++)
166 {
167@@ -3495,7 +3522,7 @@ fluid_synth_nwrite_float(fluid_synth_t *synth, int len,
168 }
169 }
170
171- if(fx_right != NULL)
172+ if(fx_right != NULL && fx_right[i] != NULL)
173 {
174 for(j = 0; j < num; j++)
175 {
176--
1772.14.5
178