1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2005-2021 Joël Krähemann
3 *
4 * This file is part of GSequencer.
5 *
6 * GSequencer is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GSequencer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GSequencer. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * FluidSynth - A Software Synthesizer
20 *
21 * Copyright (C) 2003 Peter Hanappe and others.
22 *
23 * This library is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU Lesser General Public License
25 * as published by the Free Software Foundation; either version 2.1 of
26 * the License, or (at your option) any later version.
27 *
28 * This library is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public
34 * License along with this library; if not, write to the Free
35 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 * 02110-1301, USA
37 */
38
39 #include <ags/audio/ags_fluid_interpolate_4th_order_util.h>
40
41 #include <ags/audio/ags_fluid_util.h>
42
43 /* 4th Order interpolation table (2 coefficients centered on 1st) */
44 gboolean interp_coeff_4th_order_initialized = FALSE;
45
46 gdouble interp_coeff_4th_order[AGS_FLUID_INTERP_MAX][4];
47
48 GMutex interp_coeff_4th_order_mutex;
49
50 /**
51 * SECTION:ags_fluid_interpolate_4th_order_util
52 * @short_description: util functions to fluid interpolate 4th order
53 * @title: AgsFluidInterpolate4thOrderUtil
54 * @section_id:
55 * @include: ags/audio/ags_fluid_interpolate_4th_order_util.h
56 *
57 * These utility functions allow you to fill fluid interpolated
58 * 4th order data.
59 */
60
61 GType
ags_fluid_interpolate_4th_order_util_get_type(void)62 ags_fluid_interpolate_4th_order_util_get_type(void)
63 {
64 static volatile gsize g_define_type_id__volatile = 0;
65
66 if(g_once_init_enter (&g_define_type_id__volatile)){
67 GType ags_type_fluid_interpolate_4th_order_util = 0;
68
69 ags_type_fluid_interpolate_4th_order_util =
70 g_boxed_type_register_static("AgsFluidInterpolate4thOrderUtil",
71 (GBoxedCopyFunc) ags_fluid_interpolate_4th_order_util_copy,
72 (GBoxedFreeFunc) ags_fluid_interpolate_4th_order_util_free);
73
74 g_once_init_leave(&g_define_type_id__volatile, ags_type_fluid_interpolate_4th_order_util);
75 }
76
77 return g_define_type_id__volatile;
78 }
79
80 /* Initializes interpolation tables */
81 void
ags_fluid_interpolate_4th_order_util_config()82 ags_fluid_interpolate_4th_order_util_config()
83 {
84 gdouble x;
85 gint i;
86
87 g_mutex_lock(&interp_coeff_4th_order_mutex);
88
89 if(interp_coeff_4th_order_initialized){
90 g_mutex_unlock(&interp_coeff_4th_order_mutex);
91
92 return;
93 }
94
95 for(i = 0; i < AGS_FLUID_INTERP_MAX; i++){
96 x = (double) i / (double) AGS_FLUID_INTERP_MAX;
97
98 interp_coeff_4th_order[i][0] = (x * (-0.5 + x * (1 - 0.5 * x)));
99 interp_coeff_4th_order[i][1] = (1.0 + x * x * (1.5 * x - 2.5));
100 interp_coeff_4th_order[i][2] = (x * (0.5 + x * (2.0 - 1.5 * x)));
101 interp_coeff_4th_order[i][3] = (0.5 * x * x * (x - 1.0));
102 }
103
104 interp_coeff_4th_order_initialized = TRUE;
105
106 g_mutex_unlock(&interp_coeff_4th_order_mutex);
107 }
108
109 /**
110 * ags_fluid_interpolate_4th_order_util_alloc:
111 *
112 * Allocate #AgsFluidInterpolate4thOrderUtil-struct.
113 *
114 * Returns: the newly allocated #AgsFluidInterpolate4thOrderUtil-struct
115 *
116 * Since: 3.9.6
117 */
118 AgsFluidInterpolate4thOrderUtil*
ags_fluid_interpolate_4th_order_util_alloc()119 ags_fluid_interpolate_4th_order_util_alloc()
120 {
121 AgsFluidInterpolate4thOrderUtil *ptr;
122
123 ptr = (AgsFluidInterpolate4thOrderUtil *) g_new(AgsFluidInterpolate4thOrderUtil,
124 1);
125
126 ptr->source = NULL;
127 ptr->source_stride = 1;
128
129 ptr->destination = NULL;
130 ptr->destination_stride = 1;
131
132 ptr->buffer_length = 0;
133 ptr->format = AGS_SOUNDCARD_DEFAULT_FORMAT;
134 ptr->samplerate = AGS_SOUNDCARD_DEFAULT_SAMPLERATE;
135
136 ptr->phase_increment = 0.0;
137
138 return(ptr);
139 }
140
141 /**
142 * ags_fluid_interpolate_4th_order_util_copy:
143 * @ptr: the original #AgsFluidInterpolate4thOrderUtil-struct
144 *
145 * Create a copy of @ptr.
146 *
147 * Returns: a pointer of the new #AgsFluidInterpolate4thOrderUtil-struct
148 *
149 * Since: 3.9.6
150 */
151 gpointer
ags_fluid_interpolate_4th_order_util_copy(AgsFluidInterpolate4thOrderUtil * ptr)152 ags_fluid_interpolate_4th_order_util_copy(AgsFluidInterpolate4thOrderUtil *ptr)
153 {
154 AgsFluidInterpolate4thOrderUtil *new_ptr;
155
156 new_ptr = (AgsFluidInterpolate4thOrderUtil *) g_new(AgsFluidInterpolate4thOrderUtil,
157 1);
158
159 new_ptr->destination = ptr->destination;
160 new_ptr->destination_stride = ptr->destination_stride;
161
162 new_ptr->source = ptr->source;
163 new_ptr->source_stride = ptr->source_stride;
164
165 new_ptr->buffer_length = ptr->buffer_length;
166 new_ptr->format = ptr->format;
167 new_ptr->samplerate = ptr->samplerate;
168
169 new_ptr->phase_increment = ptr->phase_increment;
170
171 return(new_ptr);
172 }
173
174 /**
175 * ags_fluid_interpolate_4th_order_util_free:
176 * @ptr: the #AgsFluidInterpolate4thOrderUtil-struct
177 *
178 * Free the memory of @ptr.
179 *
180 * Since: 3.9.6
181 */
182 void
ags_fluid_interpolate_4th_order_util_free(AgsFluidInterpolate4thOrderUtil * ptr)183 ags_fluid_interpolate_4th_order_util_free(AgsFluidInterpolate4thOrderUtil *ptr)
184 {
185 g_free(ptr->destination);
186
187 if(ptr->destination != ptr->source){
188 g_free(ptr->source);
189 }
190
191 g_free(ptr);
192 }
193
194 /**
195 * ags_fluid_interpolate_4th_order_util_get_destination:
196 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
197 *
198 * Get destination buffer of @fluid_interpolate_4th_order_util.
199 *
200 * Returns: the destination buffer
201 *
202 * Since: 3.9.6
203 */
204 gpointer
ags_fluid_interpolate_4th_order_util_get_destination(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)205 ags_fluid_interpolate_4th_order_util_get_destination(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
206 {
207 if(fluid_interpolate_4th_order_util == NULL){
208 return(NULL);
209 }
210
211 return(fluid_interpolate_4th_order_util->destination);
212 }
213
214 /**
215 * ags_fluid_interpolate_4th_order_util_set_destination:
216 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
217 * @destination: the destination buffer
218 *
219 * Set @destination buffer of @fluid_interpolate_4th_order_util.
220 *
221 * Since: 3.9.6
222 */
223 void
ags_fluid_interpolate_4th_order_util_set_destination(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,gpointer destination)224 ags_fluid_interpolate_4th_order_util_set_destination(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
225 gpointer destination)
226 {
227 if(fluid_interpolate_4th_order_util == NULL){
228 return;
229 }
230
231 fluid_interpolate_4th_order_util->destination = destination;
232 }
233
234 /**
235 * ags_fluid_interpolate_4th_order_util_get_destination_stride:
236 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
237 *
238 * Get destination stride of @fluid_interpolate_4th_order_util.
239 *
240 * Returns: the destination buffer stride
241 *
242 * Since: 3.9.6
243 */
244 guint
ags_fluid_interpolate_4th_order_util_get_destination_stride(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)245 ags_fluid_interpolate_4th_order_util_get_destination_stride(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
246 {
247 if(fluid_interpolate_4th_order_util == NULL){
248 return(0);
249 }
250
251 return(fluid_interpolate_4th_order_util->destination_stride);
252 }
253
254 /**
255 * ags_fluid_interpolate_4th_order_util_set_destination_stride:
256 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
257 * @destination_stride: the destination buffer stride
258 *
259 * Set @destination stride of @fluid_interpolate_4th_order_util.
260 *
261 * Since: 3.9.6
262 */
263 void
ags_fluid_interpolate_4th_order_util_set_destination_stride(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,guint destination_stride)264 ags_fluid_interpolate_4th_order_util_set_destination_stride(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
265 guint destination_stride)
266 {
267 if(fluid_interpolate_4th_order_util == NULL){
268 return;
269 }
270
271 fluid_interpolate_4th_order_util->destination_stride = destination_stride;
272 }
273
274 /**
275 * ags_fluid_interpolate_4th_order_util_get_source:
276 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
277 *
278 * Get source buffer of @fluid_interpolate_4th_order_util.
279 *
280 * Returns: the source buffer
281 *
282 * Since: 3.9.6
283 */
284 gpointer
ags_fluid_interpolate_4th_order_util_get_source(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)285 ags_fluid_interpolate_4th_order_util_get_source(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
286 {
287 if(fluid_interpolate_4th_order_util == NULL){
288 return(NULL);
289 }
290
291 return(fluid_interpolate_4th_order_util->source);
292 }
293
294 /**
295 * ags_fluid_interpolate_4th_order_util_set_source:
296 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
297 * @source: the source buffer
298 *
299 * Set @source buffer of @fluid_interpolate_4th_order_util.
300 *
301 * Since: 3.9.6
302 */
303 void
ags_fluid_interpolate_4th_order_util_set_source(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,gpointer source)304 ags_fluid_interpolate_4th_order_util_set_source(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
305 gpointer source)
306 {
307 if(fluid_interpolate_4th_order_util == NULL){
308 return;
309 }
310
311 fluid_interpolate_4th_order_util->source = source;
312 }
313
314 /**
315 * ags_fluid_interpolate_4th_order_util_get_source_stride:
316 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
317 *
318 * Get source stride of @fluid_interpolate_4th_order_util.
319 *
320 * Returns: the source buffer stride
321 *
322 * Since: 3.9.6
323 */
324 guint
ags_fluid_interpolate_4th_order_util_get_source_stride(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)325 ags_fluid_interpolate_4th_order_util_get_source_stride(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
326 {
327 if(fluid_interpolate_4th_order_util == NULL){
328 return(0);
329 }
330
331 return(fluid_interpolate_4th_order_util->source_stride);
332 }
333
334 /**
335 * ags_fluid_interpolate_4th_order_util_set_source_stride:
336 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
337 * @source_stride: the source buffer stride
338 *
339 * Set @source stride of @fluid_interpolate_4th_order_util.
340 *
341 * Since: 3.9.6
342 */
343 void
ags_fluid_interpolate_4th_order_util_set_source_stride(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,guint source_stride)344 ags_fluid_interpolate_4th_order_util_set_source_stride(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
345 guint source_stride)
346 {
347 if(fluid_interpolate_4th_order_util == NULL){
348 return;
349 }
350
351 fluid_interpolate_4th_order_util->source_stride = source_stride;
352 }
353
354 /**
355 * ags_fluid_interpolate_4th_order_util_get_buffer_length:
356 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
357 *
358 * Get buffer length of @fluid_interpolate_4th_order_util.
359 *
360 * Returns: the buffer length
361 *
362 * Since: 3.9.6
363 */
364 guint
ags_fluid_interpolate_4th_order_util_get_buffer_length(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)365 ags_fluid_interpolate_4th_order_util_get_buffer_length(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
366 {
367 if(fluid_interpolate_4th_order_util == NULL){
368 return(0);
369 }
370
371 return(fluid_interpolate_4th_order_util->buffer_length);
372 }
373
374 /**
375 * ags_fluid_interpolate_4th_order_util_set_buffer_length:
376 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
377 * @buffer_length: the buffer length
378 *
379 * Set @buffer_length of @fluid_interpolate_4th_order_util.
380 *
381 * Since: 3.9.6
382 */
383 void
ags_fluid_interpolate_4th_order_util_set_buffer_length(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,guint buffer_length)384 ags_fluid_interpolate_4th_order_util_set_buffer_length(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
385 guint buffer_length)
386 {
387 if(fluid_interpolate_4th_order_util == NULL){
388 return;
389 }
390
391 fluid_interpolate_4th_order_util->buffer_length = buffer_length;
392 }
393
394 /**
395 * ags_fluid_interpolate_4th_order_util_get_format:
396 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
397 *
398 * Get format of @fluid_interpolate_4th_order_util.
399 *
400 * Returns: the format
401 *
402 * Since: 3.9.6
403 */
404 guint
ags_fluid_interpolate_4th_order_util_get_format(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)405 ags_fluid_interpolate_4th_order_util_get_format(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
406 {
407 if(fluid_interpolate_4th_order_util == NULL){
408 return(0);
409 }
410
411 return(fluid_interpolate_4th_order_util->format);
412 }
413
414 /**
415 * ags_fluid_interpolate_4th_order_util_set_format:
416 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
417 * @format: the format
418 *
419 * Set @format of @fluid_interpolate_4th_order_util.
420 *
421 * Since: 3.9.6
422 */
423 void
ags_fluid_interpolate_4th_order_util_set_format(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,guint format)424 ags_fluid_interpolate_4th_order_util_set_format(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
425 guint format)
426 {
427 if(fluid_interpolate_4th_order_util == NULL){
428 return;
429 }
430
431 fluid_interpolate_4th_order_util->format = format;
432 }
433
434 /**
435 * ags_fluid_interpolate_4th_order_util_get_samplerate:
436 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
437 *
438 * Get samplerate of @fluid_interpolate_4th_order_util.
439 *
440 * Returns: the samplerate
441 *
442 * Since: 3.9.6
443 */
444 guint
ags_fluid_interpolate_4th_order_util_get_samplerate(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)445 ags_fluid_interpolate_4th_order_util_get_samplerate(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
446 {
447 if(fluid_interpolate_4th_order_util == NULL){
448 return(0);
449 }
450
451 return(fluid_interpolate_4th_order_util->samplerate);
452 }
453
454 /**
455 * ags_fluid_interpolate_4th_order_util_set_samplerate:
456 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
457 * @samplerate: the samplerate
458 *
459 * Set @samplerate of @fluid_interpolate_4th_order_util.
460 *
461 * Since: 3.9.6
462 */
463 void
ags_fluid_interpolate_4th_order_util_set_samplerate(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,guint samplerate)464 ags_fluid_interpolate_4th_order_util_set_samplerate(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
465 guint samplerate)
466 {
467 if(fluid_interpolate_4th_order_util == NULL){
468 return;
469 }
470
471 fluid_interpolate_4th_order_util->samplerate = samplerate;
472 }
473
474 /**
475 * ags_fluid_interpolate_4th_order_util_get_fluid_interpolate_4th_order:
476 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
477 *
478 * Get phase_increment of @fluid_interpolate_4th_order_util.
479 *
480 * Returns: the phase_increment
481 *
482 * Since: 3.9.6
483 */
484 gdouble
ags_fluid_interpolate_4th_order_util_get_phase_increment(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)485 ags_fluid_interpolate_4th_order_util_get_phase_increment(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
486 {
487 if(fluid_interpolate_4th_order_util == NULL){
488 return(0.0);
489 }
490
491 return(fluid_interpolate_4th_order_util->phase_increment);
492 }
493
494 /**
495 * ags_fluid_interpolate_4th_order_util_set_phase_increment:
496 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
497 * @phase_increment: the phase increment
498 *
499 * Set @phase_increment of @fluid_interpolate_4th_order_util.
500 *
501 * Since: 3.9.6
502 */
503 void
ags_fluid_interpolate_4th_order_util_set_phase_increment(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util,gdouble phase_increment)504 ags_fluid_interpolate_4th_order_util_set_phase_increment(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util,
505 gdouble phase_increment)
506 {
507 if(fluid_interpolate_4th_order_util == NULL){
508 return;
509 }
510
511 fluid_interpolate_4th_order_util->phase_increment = phase_increment;
512 }
513
514 /**
515 * ags_fluid_interpolate_4th_order_util_pitch_s8:
516 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
517 *
518 * Pitch @fluid_interpolate_4th_order_util of signed 8 bit data.
519 *
520 * Since: 3.9.6
521 */
522 void
ags_fluid_interpolate_4th_order_util_pitch_s8(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)523 ags_fluid_interpolate_4th_order_util_pitch_s8(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
524 {
525 gint8 *destination, *source;
526
527 guint destination_stride, source_stride;
528 guint buffer_length;
529 gdouble phase_incr;
530 guint64 dsp_phase;
531 guint64 dsp_phase_incr;
532 guint dsp_i;
533 guint dsp_phase_index;
534 guint start_index, end_index;
535 gdouble start_point, end_point1, end_point2;
536 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
537
538 if(fluid_interpolate_4th_order_util == NULL ||
539 fluid_interpolate_4th_order_util->destination == NULL ||
540 fluid_interpolate_4th_order_util->source == NULL){
541 return;
542 }
543
544 destination = fluid_interpolate_4th_order_util->destination;
545 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
546
547 source = fluid_interpolate_4th_order_util->source;
548 source_stride = fluid_interpolate_4th_order_util->source_stride;
549
550 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
551
552 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
553
554 ags_fluid_interpolate_4th_order_util_config();
555
556 dsp_phase = 0;
557
558 /* Convert playback "speed" floating point value to phase index/fract */
559 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
560
561 end_index = buffer_length - 1;
562
563 start_index = 0;
564 start_point = source[0];
565
566 end_point1 = source[end_index * source_stride];
567 end_point2 = end_point1;
568
569 dsp_i = 0;
570
571 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
572
573 /* interpolate first sample point (start or loop start) if needed */
574 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
575 gint row;
576
577 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
578
579 g_mutex_lock(&interp_coeff_4th_order_mutex);
580
581 coeffs_0 = interp_coeff_4th_order[row][0];
582 coeffs_1 = interp_coeff_4th_order[row][1];
583 coeffs_2 = interp_coeff_4th_order[row][2];
584 coeffs_3 = interp_coeff_4th_order[row][3];
585
586 g_mutex_unlock(&interp_coeff_4th_order_mutex);
587
588 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
589 + coeffs_1 * source[dsp_phase_index * source_stride]
590 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
591 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
592
593 /* increment phase */
594 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
595 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
596 }
597
598 /* interpolate the sequence of sample points */
599 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
600 {
601 gint row;
602
603 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
604
605 g_mutex_lock(&interp_coeff_4th_order_mutex);
606
607 coeffs_0 = interp_coeff_4th_order[row][0];
608 coeffs_1 = interp_coeff_4th_order[row][1];
609 coeffs_2 = interp_coeff_4th_order[row][2];
610 coeffs_3 = interp_coeff_4th_order[row][3];
611
612 g_mutex_unlock(&interp_coeff_4th_order_mutex);
613
614 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
615 + coeffs_1 * source[dsp_phase_index * source_stride]
616 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
617 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
618
619 /* increment phase */
620 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
621 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
622 }
623 }
624
625 /**
626 * ags_fluid_interpolate_4th_order_util_pitch_s16:
627 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
628 *
629 * Pitch @fluid_interpolate_4th_order_util of signed 16 bit data.
630 *
631 * Since: 3.9.6
632 */
633 void
ags_fluid_interpolate_4th_order_util_pitch_s16(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)634 ags_fluid_interpolate_4th_order_util_pitch_s16(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
635 {
636 gint16 *destination, *source;
637
638 guint destination_stride, source_stride;
639 guint buffer_length;
640 gdouble phase_incr;
641 guint64 dsp_phase;
642 guint64 dsp_phase_incr;
643 guint dsp_i;
644 guint dsp_phase_index;
645 guint start_index, end_index;
646 gdouble start_point, end_point1, end_point2;
647 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
648
649 if(fluid_interpolate_4th_order_util == NULL ||
650 fluid_interpolate_4th_order_util->destination == NULL ||
651 fluid_interpolate_4th_order_util->source == NULL){
652 return;
653 }
654
655 destination = fluid_interpolate_4th_order_util->destination;
656 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
657
658 source = fluid_interpolate_4th_order_util->source;
659 source_stride = fluid_interpolate_4th_order_util->source_stride;
660
661 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
662
663 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
664
665 ags_fluid_interpolate_4th_order_util_config();
666
667 dsp_phase = 0;
668
669 /* Convert playback "speed" floating point value to phase index/fract */
670 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
671
672 end_index = buffer_length - 1;
673
674 start_index = 0;
675 start_point = source[0];
676
677 end_point1 = source[end_index * source_stride];
678 end_point2 = end_point1;
679
680 dsp_i = 0;
681
682 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
683
684 /* interpolate first sample point (start or loop start) if needed */
685 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
686 gint row;
687
688 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
689
690 g_mutex_lock(&interp_coeff_4th_order_mutex);
691
692 coeffs_0 = interp_coeff_4th_order[row][0];
693 coeffs_1 = interp_coeff_4th_order[row][1];
694 coeffs_2 = interp_coeff_4th_order[row][2];
695 coeffs_3 = interp_coeff_4th_order[row][3];
696
697 g_mutex_unlock(&interp_coeff_4th_order_mutex);
698
699 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
700 + coeffs_1 * source[dsp_phase_index * source_stride]
701 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
702 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
703
704 /* increment phase */
705 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
706 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
707 }
708
709 /* interpolate the sequence of sample points */
710 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
711 {
712 gint row;
713
714 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
715
716 g_mutex_lock(&interp_coeff_4th_order_mutex);
717
718 coeffs_0 = interp_coeff_4th_order[row][0];
719 coeffs_1 = interp_coeff_4th_order[row][1];
720 coeffs_2 = interp_coeff_4th_order[row][2];
721 coeffs_3 = interp_coeff_4th_order[row][3];
722
723 g_mutex_unlock(&interp_coeff_4th_order_mutex);
724
725 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
726 + coeffs_1 * source[dsp_phase_index * source_stride]
727 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
728 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
729
730 /* increment phase */
731 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
732 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
733 }
734 }
735
736 /**
737 * ags_fluid_interpolate_4th_order_util_pitch_s24:
738 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
739 *
740 * Pitch @fluid_interpolate_4th_order_util of signed 24 bit data.
741 *
742 * Since: 3.9.6
743 */
744 void
ags_fluid_interpolate_4th_order_util_pitch_s24(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)745 ags_fluid_interpolate_4th_order_util_pitch_s24(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
746 {
747 gint32 *destination, *source;
748
749 guint destination_stride, source_stride;
750 guint buffer_length;
751 gdouble phase_incr;
752 guint64 dsp_phase;
753 guint64 dsp_phase_incr;
754 guint dsp_i;
755 guint dsp_phase_index;
756 guint start_index, end_index;
757 gdouble start_point, end_point1, end_point2;
758 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
759
760 if(fluid_interpolate_4th_order_util == NULL ||
761 fluid_interpolate_4th_order_util->destination == NULL ||
762 fluid_interpolate_4th_order_util->source == NULL){
763 return;
764 }
765
766 destination = fluid_interpolate_4th_order_util->destination;
767 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
768
769 source = fluid_interpolate_4th_order_util->source;
770 source_stride = fluid_interpolate_4th_order_util->source_stride;
771
772 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
773
774 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
775
776 ags_fluid_interpolate_4th_order_util_config();
777
778 dsp_phase = 0;
779
780 /* Convert playback "speed" floating point value to phase index/fract */
781 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
782
783 end_index = buffer_length - 1;
784
785 start_index = 0;
786 start_point = source[0];
787
788 end_point1 = source[end_index * source_stride];
789 end_point2 = end_point1;
790
791 dsp_i = 0;
792
793 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
794
795 /* interpolate first sample point (start or loop start) if needed */
796 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
797 gint row;
798
799 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
800
801 g_mutex_lock(&interp_coeff_4th_order_mutex);
802
803 coeffs_0 = interp_coeff_4th_order[row][0];
804 coeffs_1 = interp_coeff_4th_order[row][1];
805 coeffs_2 = interp_coeff_4th_order[row][2];
806 coeffs_3 = interp_coeff_4th_order[row][3];
807
808 g_mutex_unlock(&interp_coeff_4th_order_mutex);
809
810 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
811 + coeffs_1 * source[dsp_phase_index * source_stride]
812 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
813 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
814
815 /* increment phase */
816 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
817 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
818 }
819
820 /* interpolate the sequence of sample points */
821 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
822 {
823 gint row;
824
825 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
826
827 g_mutex_lock(&interp_coeff_4th_order_mutex);
828
829 coeffs_0 = interp_coeff_4th_order[row][0];
830 coeffs_1 = interp_coeff_4th_order[row][1];
831 coeffs_2 = interp_coeff_4th_order[row][2];
832 coeffs_3 = interp_coeff_4th_order[row][3];
833
834 g_mutex_unlock(&interp_coeff_4th_order_mutex);
835
836 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
837 + coeffs_1 * source[dsp_phase_index * source_stride]
838 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
839 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
840
841 /* increment phase */
842 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
843 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
844 }
845 }
846
847 /**
848 * ags_fluid_interpolate_4th_order_util_pitch_s32:
849 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
850 *
851 * Pitch @fluid_interpolate_4th_order_util of signed 32 bit data.
852 *
853 * Since: 3.9.6
854 */
855 void
ags_fluid_interpolate_4th_order_util_pitch_s32(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)856 ags_fluid_interpolate_4th_order_util_pitch_s32(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
857 {
858 gint32 *destination, *source;
859
860 guint destination_stride, source_stride;
861 guint buffer_length;
862 gdouble phase_incr;
863 guint64 dsp_phase;
864 guint64 dsp_phase_incr;
865 guint dsp_i;
866 guint dsp_phase_index;
867 guint start_index, end_index;
868 gdouble start_point, end_point1, end_point2;
869 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
870
871 if(fluid_interpolate_4th_order_util == NULL ||
872 fluid_interpolate_4th_order_util->destination == NULL ||
873 fluid_interpolate_4th_order_util->source == NULL){
874 return;
875 }
876
877 destination = fluid_interpolate_4th_order_util->destination;
878 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
879
880 source = fluid_interpolate_4th_order_util->source;
881 source_stride = fluid_interpolate_4th_order_util->source_stride;
882
883 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
884
885 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
886
887 ags_fluid_interpolate_4th_order_util_config();
888
889 dsp_phase = 0;
890
891 /* Convert playback "speed" floating point value to phase index/fract */
892 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
893
894 end_index = buffer_length - 1;
895
896 start_index = 0;
897 start_point = source[0];
898
899 end_point1 = source[end_index * source_stride];
900 end_point2 = end_point1;
901
902 dsp_i = 0;
903
904 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
905
906 /* interpolate first sample point (start or loop start) if needed */
907 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
908 gint row;
909
910 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
911
912 g_mutex_lock(&interp_coeff_4th_order_mutex);
913
914 coeffs_0 = interp_coeff_4th_order[row][0];
915 coeffs_1 = interp_coeff_4th_order[row][1];
916 coeffs_2 = interp_coeff_4th_order[row][2];
917 coeffs_3 = interp_coeff_4th_order[row][3];
918
919 g_mutex_unlock(&interp_coeff_4th_order_mutex);
920
921 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
922 + coeffs_1 * source[dsp_phase_index * source_stride]
923 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
924 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
925
926 /* increment phase */
927 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
928 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
929 }
930
931 /* interpolate the sequence of sample points */
932 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
933 {
934 gint row;
935
936 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
937
938 g_mutex_lock(&interp_coeff_4th_order_mutex);
939
940 coeffs_0 = interp_coeff_4th_order[row][0];
941 coeffs_1 = interp_coeff_4th_order[row][1];
942 coeffs_2 = interp_coeff_4th_order[row][2];
943 coeffs_3 = interp_coeff_4th_order[row][3];
944
945 g_mutex_unlock(&interp_coeff_4th_order_mutex);
946
947 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
948 + coeffs_1 * source[dsp_phase_index * source_stride]
949 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
950 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
951
952 /* increment phase */
953 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
954 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
955 }
956 }
957
958 /**
959 * ags_fluid_interpolate_4th_order_util_pitch_s64:
960 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
961 *
962 * Pitch @fluid_interpolate_4th_order_util of signed 64 bit data.
963 *
964 * Since: 3.9.6
965 */
966 void
ags_fluid_interpolate_4th_order_util_pitch_s64(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)967 ags_fluid_interpolate_4th_order_util_pitch_s64(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
968 {
969 gint64 *destination, *source;
970
971 guint destination_stride, source_stride;
972 guint buffer_length;
973 gdouble phase_incr;
974 guint64 dsp_phase;
975 guint64 dsp_phase_incr;
976 guint dsp_i;
977 guint dsp_phase_index;
978 guint start_index, end_index;
979 gdouble start_point, end_point1, end_point2;
980 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
981
982 if(fluid_interpolate_4th_order_util == NULL ||
983 fluid_interpolate_4th_order_util->destination == NULL ||
984 fluid_interpolate_4th_order_util->source == NULL){
985 return;
986 }
987
988 destination = fluid_interpolate_4th_order_util->destination;
989 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
990
991 source = fluid_interpolate_4th_order_util->source;
992 source_stride = fluid_interpolate_4th_order_util->source_stride;
993
994 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
995
996 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
997
998 ags_fluid_interpolate_4th_order_util_config();
999
1000 dsp_phase = 0;
1001
1002 /* Convert playback "speed" floating point value to phase index/fract */
1003 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1004
1005 end_index = buffer_length - 1;
1006
1007 start_index = 0;
1008 start_point = source[0];
1009
1010 end_point1 = source[end_index * source_stride];
1011 end_point2 = end_point1;
1012
1013 dsp_i = 0;
1014
1015 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1016
1017 /* interpolate first sample point (start or loop start) if needed */
1018 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1019 gint row;
1020
1021 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1022
1023 g_mutex_lock(&interp_coeff_4th_order_mutex);
1024
1025 coeffs_0 = interp_coeff_4th_order[row][0];
1026 coeffs_1 = interp_coeff_4th_order[row][1];
1027 coeffs_2 = interp_coeff_4th_order[row][2];
1028 coeffs_3 = interp_coeff_4th_order[row][3];
1029
1030 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1031
1032 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
1033 + coeffs_1 * source[dsp_phase_index * source_stride]
1034 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1035 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1036
1037 /* increment phase */
1038 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1039 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1040 }
1041
1042 /* interpolate the sequence of sample points */
1043 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1044 {
1045 gint row;
1046
1047 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1048
1049 g_mutex_lock(&interp_coeff_4th_order_mutex);
1050
1051 coeffs_0 = interp_coeff_4th_order[row][0];
1052 coeffs_1 = interp_coeff_4th_order[row][1];
1053 coeffs_2 = interp_coeff_4th_order[row][2];
1054 coeffs_3 = interp_coeff_4th_order[row][3];
1055
1056 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1057
1058 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
1059 + coeffs_1 * source[dsp_phase_index * source_stride]
1060 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1061 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1062
1063 /* increment phase */
1064 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1065 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1066 }
1067 }
1068
1069 /**
1070 * ags_fluid_interpolate_4th_order_util_pitch_float:
1071 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
1072 *
1073 * Pitch @fluid_interpolate_4th_order_util of floating point data.
1074 *
1075 * Since: 3.9.6
1076 */
1077 void
ags_fluid_interpolate_4th_order_util_pitch_float(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)1078 ags_fluid_interpolate_4th_order_util_pitch_float(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
1079 {
1080 gfloat *destination, *source;
1081
1082 guint destination_stride, source_stride;
1083 guint buffer_length;
1084 gdouble phase_incr;
1085 guint64 dsp_phase;
1086 guint64 dsp_phase_incr;
1087 guint dsp_i;
1088 guint dsp_phase_index;
1089 guint start_index, end_index;
1090 gdouble start_point, end_point1, end_point2;
1091 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1092
1093 if(fluid_interpolate_4th_order_util == NULL ||
1094 fluid_interpolate_4th_order_util->destination == NULL ||
1095 fluid_interpolate_4th_order_util->source == NULL){
1096 return;
1097 }
1098
1099 destination = fluid_interpolate_4th_order_util->destination;
1100 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
1101
1102 source = fluid_interpolate_4th_order_util->source;
1103 source_stride = fluid_interpolate_4th_order_util->source_stride;
1104
1105 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
1106
1107 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
1108
1109 ags_fluid_interpolate_4th_order_util_config();
1110
1111 dsp_phase = 0;
1112
1113 /* Convert playback "speed" floating point value to phase index/fract */
1114 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1115
1116 end_index = buffer_length - 1;
1117
1118 start_index = 0;
1119 start_point = source[0];
1120
1121 end_point1 = source[end_index * source_stride];
1122 end_point2 = end_point1;
1123
1124 dsp_i = 0;
1125
1126 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1127
1128 /* interpolate first sample point (start or loop start) if needed */
1129 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1130 gint row;
1131
1132 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1133
1134 g_mutex_lock(&interp_coeff_4th_order_mutex);
1135
1136 coeffs_0 = interp_coeff_4th_order[row][0];
1137 coeffs_1 = interp_coeff_4th_order[row][1];
1138 coeffs_2 = interp_coeff_4th_order[row][2];
1139 coeffs_3 = interp_coeff_4th_order[row][3];
1140
1141 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1142
1143 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
1144 + coeffs_1 * source[dsp_phase_index * source_stride]
1145 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1146 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1147
1148 /* increment phase */
1149 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1150 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1151 }
1152
1153 /* interpolate the sequence of sample points */
1154 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1155 {
1156 gint row;
1157
1158 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1159
1160 g_mutex_lock(&interp_coeff_4th_order_mutex);
1161
1162 coeffs_0 = interp_coeff_4th_order[row][0];
1163 coeffs_1 = interp_coeff_4th_order[row][1];
1164 coeffs_2 = interp_coeff_4th_order[row][2];
1165 coeffs_3 = interp_coeff_4th_order[row][3];
1166
1167 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1168
1169 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
1170 + coeffs_1 * source[dsp_phase_index * source_stride]
1171 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1172 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1173
1174 /* increment phase */
1175 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1176 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1177 }
1178 }
1179
1180 /**
1181 * ags_fluid_interpolate_4th_order_util_pitch_double:
1182 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
1183 *
1184 * Pitch @fluid_interpolate_4th_order_util of double precision floating point data.
1185 *
1186 * Since: 3.9.6
1187 */
1188 void
ags_fluid_interpolate_4th_order_util_pitch_double(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)1189 ags_fluid_interpolate_4th_order_util_pitch_double(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
1190 {
1191 gdouble *destination, *source;
1192
1193 guint destination_stride, source_stride;
1194 guint buffer_length;
1195 gdouble phase_incr;
1196 guint64 dsp_phase;
1197 guint64 dsp_phase_incr;
1198 guint dsp_i;
1199 guint dsp_phase_index;
1200 guint start_index, end_index;
1201 gdouble start_point, end_point1, end_point2;
1202 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1203
1204 if(fluid_interpolate_4th_order_util == NULL ||
1205 fluid_interpolate_4th_order_util->destination == NULL ||
1206 fluid_interpolate_4th_order_util->source == NULL){
1207 return;
1208 }
1209
1210 destination = fluid_interpolate_4th_order_util->destination;
1211 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
1212
1213 source = fluid_interpolate_4th_order_util->source;
1214 source_stride = fluid_interpolate_4th_order_util->source_stride;
1215
1216 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
1217
1218 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
1219
1220 ags_fluid_interpolate_4th_order_util_config();
1221
1222 dsp_phase = 0;
1223
1224 /* Convert playback "speed" floating point value to phase index/fract */
1225 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1226
1227 end_index = buffer_length - 1;
1228
1229 start_index = 0;
1230 start_point = source[0];
1231
1232 end_point1 = source[end_index * source_stride];
1233 end_point2 = end_point1;
1234
1235 dsp_i = 0;
1236
1237 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1238
1239 /* interpolate first sample point (start or loop start) if needed */
1240 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1241 gint row;
1242
1243 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1244
1245 g_mutex_lock(&interp_coeff_4th_order_mutex);
1246
1247 coeffs_0 = interp_coeff_4th_order[row][0];
1248 coeffs_1 = interp_coeff_4th_order[row][1];
1249 coeffs_2 = interp_coeff_4th_order[row][2];
1250 coeffs_3 = interp_coeff_4th_order[row][3];
1251
1252 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1253
1254 destination[dsp_i * destination_stride] = (coeffs_0 * start_point
1255 + coeffs_1 * source[dsp_phase_index * source_stride]
1256 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1257 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1258
1259 /* increment phase */
1260 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1261 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1262 }
1263
1264 /* interpolate the sequence of sample points */
1265 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1266 {
1267 gint row;
1268
1269 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1270
1271 g_mutex_lock(&interp_coeff_4th_order_mutex);
1272
1273 coeffs_0 = interp_coeff_4th_order[row][0];
1274 coeffs_1 = interp_coeff_4th_order[row][1];
1275 coeffs_2 = interp_coeff_4th_order[row][2];
1276 coeffs_3 = interp_coeff_4th_order[row][3];
1277
1278 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1279
1280 destination[dsp_i * destination_stride] = (coeffs_0 * source[(dsp_phase_index - 1) * source_stride]
1281 + coeffs_1 * source[dsp_phase_index * source_stride]
1282 + coeffs_2 * source[(dsp_phase_index + 1) * source_stride]
1283 + coeffs_3 * source[(dsp_phase_index + 2) * source_stride]);
1284
1285 /* increment phase */
1286 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1287 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1288 }
1289 }
1290
1291 /**
1292 * ags_fluid_interpolate_4th_order_util_pitch_complex:
1293 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
1294 *
1295 * Pitch @fluid_interpolate_4th_order_util of complex data.
1296 *
1297 * Since: 3.9.6
1298 */
1299 void
ags_fluid_interpolate_4th_order_util_pitch_complex(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)1300 ags_fluid_interpolate_4th_order_util_pitch_complex(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
1301 {
1302 AgsComplex *destination, *source;
1303
1304 guint destination_stride, source_stride;
1305 guint buffer_length;
1306 gdouble phase_incr;
1307 guint64 dsp_phase;
1308 guint64 dsp_phase_incr;
1309 guint dsp_i;
1310 guint dsp_phase_index;
1311 guint start_index, end_index;
1312 double _Complex start_point, end_point1, end_point2;
1313 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1314
1315 if(fluid_interpolate_4th_order_util == NULL ||
1316 fluid_interpolate_4th_order_util->destination == NULL ||
1317 fluid_interpolate_4th_order_util->source == NULL){
1318 return;
1319 }
1320
1321 destination = fluid_interpolate_4th_order_util->destination;
1322 destination_stride = fluid_interpolate_4th_order_util->destination_stride;
1323
1324 source = fluid_interpolate_4th_order_util->source;
1325 source_stride = fluid_interpolate_4th_order_util->source_stride;
1326
1327 buffer_length = fluid_interpolate_4th_order_util->buffer_length;
1328
1329 phase_incr = fluid_interpolate_4th_order_util->phase_increment;
1330
1331 ags_fluid_interpolate_4th_order_util_config();
1332
1333 dsp_phase = 0;
1334
1335 /* Convert playback "speed" floating point value to phase index/fract */
1336 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1337
1338 end_index = buffer_length - 1;
1339
1340 start_index = 0;
1341 start_point = ags_complex_get(source);
1342
1343 end_point1 = ags_complex_get(source + (end_index * source_stride));
1344 end_point2 = end_point1;
1345
1346 dsp_i = 0;
1347
1348 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1349
1350 /* interpolate first sample point (start or loop start) if needed */
1351 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1352 gint row;
1353
1354 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1355
1356 g_mutex_lock(&interp_coeff_4th_order_mutex);
1357
1358 coeffs_0 = interp_coeff_4th_order[row][0];
1359 coeffs_1 = interp_coeff_4th_order[row][1];
1360 coeffs_2 = interp_coeff_4th_order[row][2];
1361 coeffs_3 = interp_coeff_4th_order[row][3];
1362
1363 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1364
1365 ags_complex_set(destination + (dsp_i * destination_stride),
1366 (coeffs_0 * start_point
1367 + coeffs_1 * ags_complex_get(source + (dsp_phase_index * source_stride))
1368 + coeffs_2 * ags_complex_get(source + ((dsp_phase_index + 1) * source_stride))
1369 + coeffs_3 * ags_complex_get(source + ((dsp_phase_index + 2) * source_stride))));
1370
1371 /* increment phase */
1372 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1373 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1374 }
1375
1376 /* interpolate the sequence of sample points */
1377 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1378 {
1379 gint row;
1380
1381 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1382
1383 g_mutex_lock(&interp_coeff_4th_order_mutex);
1384
1385 coeffs_0 = interp_coeff_4th_order[row][0];
1386 coeffs_1 = interp_coeff_4th_order[row][1];
1387 coeffs_2 = interp_coeff_4th_order[row][2];
1388 coeffs_3 = interp_coeff_4th_order[row][3];
1389
1390 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1391
1392 ags_complex_set(destination + (dsp_i * destination_stride),
1393 (coeffs_0 * ags_complex_get(source + ((dsp_phase_index - 1) * source_stride))
1394 + coeffs_1 * ags_complex_get(source + (dsp_phase_index * source_stride))
1395 + coeffs_2 * ags_complex_get(source + ((dsp_phase_index + 1) * source_stride))
1396 + coeffs_3 * ags_complex_get(source + ((dsp_phase_index + 2) * source_stride))));
1397
1398 /* increment phase */
1399 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1400 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1401 }
1402 }
1403
1404 /**
1405 * ags_fluid_interpolate_4th_order_util_pitch:
1406 * @fluid_interpolate_4th_order_util: the #AgsFluidInterpolate4thOrderUtil-struct
1407 *
1408 * Pitch @fluid_interpolate_4th_order_util.
1409 *
1410 * Since: 3.9.6
1411 */
1412 void
ags_fluid_interpolate_4th_order_util_pitch(AgsFluidInterpolate4thOrderUtil * fluid_interpolate_4th_order_util)1413 ags_fluid_interpolate_4th_order_util_pitch(AgsFluidInterpolate4thOrderUtil *fluid_interpolate_4th_order_util)
1414 {
1415 if(fluid_interpolate_4th_order_util == NULL ||
1416 fluid_interpolate_4th_order_util->destination == NULL ||
1417 fluid_interpolate_4th_order_util->source == NULL){
1418 return;
1419 }
1420
1421 switch(fluid_interpolate_4th_order_util->format){
1422 case AGS_SOUNDCARD_SIGNED_8_BIT:
1423 {
1424 ags_fluid_interpolate_4th_order_util_pitch_s8(fluid_interpolate_4th_order_util);
1425 }
1426 break;
1427 case AGS_SOUNDCARD_SIGNED_16_BIT:
1428 {
1429 ags_fluid_interpolate_4th_order_util_pitch_s16(fluid_interpolate_4th_order_util);
1430 }
1431 break;
1432 case AGS_SOUNDCARD_SIGNED_24_BIT:
1433 {
1434 ags_fluid_interpolate_4th_order_util_pitch_s24(fluid_interpolate_4th_order_util);
1435 }
1436 break;
1437 case AGS_SOUNDCARD_SIGNED_32_BIT:
1438 {
1439 ags_fluid_interpolate_4th_order_util_pitch_s32(fluid_interpolate_4th_order_util);
1440 }
1441 break;
1442 case AGS_SOUNDCARD_SIGNED_64_BIT:
1443 {
1444 ags_fluid_interpolate_4th_order_util_pitch_s64(fluid_interpolate_4th_order_util);
1445 }
1446 break;
1447 case AGS_SOUNDCARD_FLOAT:
1448 {
1449 ags_fluid_interpolate_4th_order_util_pitch_float(fluid_interpolate_4th_order_util);
1450 }
1451 break;
1452 case AGS_SOUNDCARD_DOUBLE:
1453 {
1454 ags_fluid_interpolate_4th_order_util_pitch_double(fluid_interpolate_4th_order_util);
1455 }
1456 break;
1457 case AGS_SOUNDCARD_COMPLEX:
1458 {
1459 ags_fluid_interpolate_4th_order_util_pitch_complex(fluid_interpolate_4th_order_util);
1460 }
1461 break;
1462 default:
1463 g_warning("unknown format");
1464 }
1465 }
1466
1467 /**
1468 * ags_fluid_interpolate_4th_order_util_fill_s8:
1469 * @destination: the destination audio buffer
1470 * @source: the source audio buffer
1471 * @buffer_length: the buffer length
1472 * @phase_incr: the phase increment
1473 *
1474 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1475 *
1476 * Since: 3.8.12
1477 */
1478 void
ags_fluid_interpolate_4th_order_util_fill_s8(gint8 * destination,gint8 * source,guint buffer_length,gdouble phase_incr)1479 ags_fluid_interpolate_4th_order_util_fill_s8(gint8 *destination,
1480 gint8 *source,
1481 guint buffer_length,
1482 gdouble phase_incr)
1483 {
1484 guint64 dsp_phase;
1485 guint64 dsp_phase_incr;
1486 guint dsp_i;
1487 guint dsp_phase_index;
1488 guint start_index, end_index;
1489 gdouble start_point, end_point1, end_point2;
1490 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1491
1492 if(destination == NULL ||
1493 source == NULL ||
1494 buffer_length == 0){
1495 return;
1496 }
1497
1498 ags_fluid_interpolate_4th_order_util_config();
1499
1500 dsp_phase = 0;
1501
1502 /* Convert playback "speed" floating point value to phase index/fract */
1503 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1504
1505 end_index = buffer_length - 1;
1506
1507 start_index = 0;
1508 start_point = source[0];
1509
1510 end_point1 = source[end_index];
1511 end_point2 = end_point1;
1512
1513 dsp_i = 0;
1514
1515 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1516
1517 /* interpolate first sample point (start or loop start) if needed */
1518 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1519 gint row;
1520
1521 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1522
1523 g_mutex_lock(&interp_coeff_4th_order_mutex);
1524
1525 coeffs_0 = interp_coeff_4th_order[row][0];
1526 coeffs_1 = interp_coeff_4th_order[row][1];
1527 coeffs_2 = interp_coeff_4th_order[row][2];
1528 coeffs_3 = interp_coeff_4th_order[row][3];
1529
1530 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1531
1532 destination[dsp_i] = (coeffs_0 * start_point
1533 + coeffs_1 * source[dsp_phase_index]
1534 + coeffs_2 * source[dsp_phase_index + 1]
1535 + coeffs_3 * source[dsp_phase_index + 2]);
1536
1537 /* increment phase */
1538 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1539 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1540 }
1541
1542 /* interpolate the sequence of sample points */
1543 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1544 {
1545 gint row;
1546
1547 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1548
1549 g_mutex_lock(&interp_coeff_4th_order_mutex);
1550
1551 coeffs_0 = interp_coeff_4th_order[row][0];
1552 coeffs_1 = interp_coeff_4th_order[row][1];
1553 coeffs_2 = interp_coeff_4th_order[row][2];
1554 coeffs_3 = interp_coeff_4th_order[row][3];
1555
1556 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1557
1558 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
1559 + coeffs_1 * source[dsp_phase_index]
1560 + coeffs_2 * source[dsp_phase_index + 1]
1561 + coeffs_3 * source[dsp_phase_index + 2]);
1562
1563 /* increment phase */
1564 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1565 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1566 }
1567 }
1568
1569 /**
1570 * ags_fluid_interpolate_4th_order_util_fill_s16:
1571 * @destination: the destination audio buffer
1572 * @source: the source audio buffer
1573 * @buffer_length: the buffer length
1574 * @phase_incr: the phase increment
1575 *
1576 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1577 *
1578 * Since: 3.8.12
1579 */
1580 void
ags_fluid_interpolate_4th_order_util_fill_s16(gint16 * destination,gint16 * source,guint buffer_length,gdouble phase_incr)1581 ags_fluid_interpolate_4th_order_util_fill_s16(gint16 *destination,
1582 gint16 *source,
1583 guint buffer_length,
1584 gdouble phase_incr)
1585 {
1586 guint64 dsp_phase;
1587 guint64 dsp_phase_incr;
1588 guint dsp_i;
1589 guint dsp_phase_index;
1590 guint start_index, end_index;
1591 gdouble start_point, end_point1, end_point2;
1592 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1593
1594 if(destination == NULL ||
1595 source == NULL ||
1596 buffer_length == 0){
1597 return;
1598 }
1599
1600 ags_fluid_interpolate_4th_order_util_config();
1601
1602 dsp_phase = 0;
1603
1604 /* Convert playback "speed" floating point value to phase index/fract */
1605 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1606
1607 end_index = buffer_length - 1;
1608
1609 start_index = 0;
1610 start_point = source[0];
1611
1612 end_point1 = source[end_index];
1613 end_point2 = end_point1;
1614
1615 dsp_i = 0;
1616
1617 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1618
1619 /* interpolate first sample point (start or loop start) if needed */
1620 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1621 gint row;
1622
1623 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1624
1625 g_mutex_lock(&interp_coeff_4th_order_mutex);
1626
1627 coeffs_0 = interp_coeff_4th_order[row][0];
1628 coeffs_1 = interp_coeff_4th_order[row][1];
1629 coeffs_2 = interp_coeff_4th_order[row][2];
1630 coeffs_3 = interp_coeff_4th_order[row][3];
1631
1632 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1633
1634 destination[dsp_i] = (coeffs_0 * start_point
1635 + coeffs_1 * source[dsp_phase_index]
1636 + coeffs_2 * source[dsp_phase_index + 1]
1637 + coeffs_3 * source[dsp_phase_index + 2]);
1638
1639 /* increment phase */
1640 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1641 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1642 }
1643
1644 /* interpolate the sequence of sample points */
1645 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1646 {
1647 gint row;
1648
1649 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1650
1651 g_mutex_lock(&interp_coeff_4th_order_mutex);
1652
1653 coeffs_0 = interp_coeff_4th_order[row][0];
1654 coeffs_1 = interp_coeff_4th_order[row][1];
1655 coeffs_2 = interp_coeff_4th_order[row][2];
1656 coeffs_3 = interp_coeff_4th_order[row][3];
1657
1658 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1659
1660 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
1661 + coeffs_1 * source[dsp_phase_index]
1662 + coeffs_2 * source[dsp_phase_index + 1]
1663 + coeffs_3 * source[dsp_phase_index + 2]);
1664
1665 /* increment phase */
1666 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1667 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1668 }
1669 }
1670
1671 /**
1672 * ags_fluid_interpolate_4th_order_util_fill_s24:
1673 * @destination: the destination audio buffer
1674 * @source: the source audio buffer
1675 * @buffer_length: the buffer length
1676 * @phase_incr: the phase increment
1677 *
1678 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1679 *
1680 * Since: 3.8.12
1681 */
1682 void
ags_fluid_interpolate_4th_order_util_fill_s24(gint32 * destination,gint32 * source,guint buffer_length,gdouble phase_incr)1683 ags_fluid_interpolate_4th_order_util_fill_s24(gint32 *destination,
1684 gint32 *source,
1685 guint buffer_length,
1686 gdouble phase_incr)
1687 {
1688 guint64 dsp_phase;
1689 guint64 dsp_phase_incr;
1690 guint dsp_i;
1691 guint dsp_phase_index;
1692 guint start_index, end_index;
1693 gdouble start_point, end_point1, end_point2;
1694 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1695
1696 if(destination == NULL ||
1697 source == NULL ||
1698 buffer_length == 0){
1699 return;
1700 }
1701
1702 ags_fluid_interpolate_4th_order_util_config();
1703
1704 dsp_phase = 0;
1705
1706 /* Convert playback "speed" floating point value to phase index/fract */
1707 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1708
1709 end_index = buffer_length - 1;
1710
1711 start_index = 0;
1712 start_point = source[0];
1713
1714 end_point1 = source[end_index];
1715 end_point2 = end_point1;
1716
1717 dsp_i = 0;
1718
1719 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1720
1721 /* interpolate first sample point (start or loop start) if needed */
1722 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1723 gint row;
1724
1725 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1726
1727 g_mutex_lock(&interp_coeff_4th_order_mutex);
1728
1729 coeffs_0 = interp_coeff_4th_order[row][0];
1730 coeffs_1 = interp_coeff_4th_order[row][1];
1731 coeffs_2 = interp_coeff_4th_order[row][2];
1732 coeffs_3 = interp_coeff_4th_order[row][3];
1733
1734 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1735
1736 destination[dsp_i] = (coeffs_0 * start_point
1737 + coeffs_1 * source[dsp_phase_index]
1738 + coeffs_2 * source[dsp_phase_index + 1]
1739 + coeffs_3 * source[dsp_phase_index + 2]);
1740
1741 /* increment phase */
1742 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1743 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1744 }
1745
1746 /* interpolate the sequence of sample points */
1747 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1748 {
1749 gint row;
1750
1751 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1752
1753 g_mutex_lock(&interp_coeff_4th_order_mutex);
1754
1755 coeffs_0 = interp_coeff_4th_order[row][0];
1756 coeffs_1 = interp_coeff_4th_order[row][1];
1757 coeffs_2 = interp_coeff_4th_order[row][2];
1758 coeffs_3 = interp_coeff_4th_order[row][3];
1759
1760 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1761
1762 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
1763 + coeffs_1 * source[dsp_phase_index]
1764 + coeffs_2 * source[dsp_phase_index + 1]
1765 + coeffs_3 * source[dsp_phase_index + 2]);
1766
1767 /* increment phase */
1768 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1769 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1770 }
1771 }
1772
1773 /**
1774 * ags_fluid_interpolate_4th_order_util_fill_s32:
1775 * @destination: the destination audio buffer
1776 * @source: the source audio buffer
1777 * @buffer_length: the buffer length
1778 * @phase_incr: the phase increment
1779 *
1780 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1781 *
1782 * Since: 3.8.12
1783 */
1784 void
ags_fluid_interpolate_4th_order_util_fill_s32(gint32 * destination,gint32 * source,guint buffer_length,gdouble phase_incr)1785 ags_fluid_interpolate_4th_order_util_fill_s32(gint32 *destination,
1786 gint32 *source,
1787 guint buffer_length,
1788 gdouble phase_incr)
1789 {
1790 guint64 dsp_phase;
1791 guint64 dsp_phase_incr;
1792 guint dsp_i;
1793 guint dsp_phase_index;
1794 guint start_index, end_index;
1795 gdouble start_point, end_point1, end_point2;
1796 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1797
1798 if(destination == NULL ||
1799 source == NULL ||
1800 buffer_length == 0){
1801 return;
1802 }
1803
1804 ags_fluid_interpolate_4th_order_util_config();
1805
1806 dsp_phase = 0;
1807
1808 /* Convert playback "speed" floating point value to phase index/fract */
1809 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1810
1811 end_index = buffer_length - 1;
1812
1813 start_index = 0;
1814 start_point = source[0];
1815
1816 end_point1 = source[end_index];
1817 end_point2 = end_point1;
1818
1819 dsp_i = 0;
1820
1821 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1822
1823 /* interpolate first sample point (start or loop start) if needed */
1824 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1825 gint row;
1826
1827 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1828
1829 g_mutex_lock(&interp_coeff_4th_order_mutex);
1830
1831 coeffs_0 = interp_coeff_4th_order[row][0];
1832 coeffs_1 = interp_coeff_4th_order[row][1];
1833 coeffs_2 = interp_coeff_4th_order[row][2];
1834 coeffs_3 = interp_coeff_4th_order[row][3];
1835
1836 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1837
1838 destination[dsp_i] = (coeffs_0 * start_point
1839 + coeffs_1 * source[dsp_phase_index]
1840 + coeffs_2 * source[dsp_phase_index + 1]
1841 + coeffs_3 * source[dsp_phase_index + 2]);
1842
1843 /* increment phase */
1844 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1845 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1846 }
1847
1848 /* interpolate the sequence of sample points */
1849 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1850 {
1851 gint row;
1852
1853 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1854
1855 g_mutex_lock(&interp_coeff_4th_order_mutex);
1856
1857 coeffs_0 = interp_coeff_4th_order[row][0];
1858 coeffs_1 = interp_coeff_4th_order[row][1];
1859 coeffs_2 = interp_coeff_4th_order[row][2];
1860 coeffs_3 = interp_coeff_4th_order[row][3];
1861
1862 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1863
1864 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
1865 + coeffs_1 * source[dsp_phase_index]
1866 + coeffs_2 * source[dsp_phase_index + 1]
1867 + coeffs_3 * source[dsp_phase_index + 2]);
1868
1869 /* increment phase */
1870 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1871 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1872 }
1873 }
1874
1875 /**
1876 * ags_fluid_interpolate_4th_order_util_fill_s64:
1877 * @destination: the destination audio buffer
1878 * @source: the source audio buffer
1879 * @buffer_length: the buffer length
1880 * @phase_incr: the phase increment
1881 *
1882 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1883 *
1884 * Since: 3.8.12
1885 */
1886 void
ags_fluid_interpolate_4th_order_util_fill_s64(gint64 * destination,gint64 * source,guint buffer_length,gdouble phase_incr)1887 ags_fluid_interpolate_4th_order_util_fill_s64(gint64 *destination,
1888 gint64 *source,
1889 guint buffer_length,
1890 gdouble phase_incr)
1891 {
1892 guint64 dsp_phase;
1893 guint64 dsp_phase_incr;
1894 guint dsp_i;
1895 guint dsp_phase_index;
1896 guint start_index, end_index;
1897 gdouble start_point, end_point1, end_point2;
1898 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
1899
1900 if(destination == NULL ||
1901 source == NULL ||
1902 buffer_length == 0){
1903 return;
1904 }
1905
1906 ags_fluid_interpolate_4th_order_util_config();
1907
1908 dsp_phase = 0;
1909
1910 /* Convert playback "speed" floating point value to phase index/fract */
1911 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
1912
1913 end_index = buffer_length - 1;
1914
1915 start_index = 0;
1916 start_point = source[0];
1917
1918 end_point1 = source[end_index];
1919 end_point2 = end_point1;
1920
1921 dsp_i = 0;
1922
1923 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1924
1925 /* interpolate first sample point (start or loop start) if needed */
1926 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
1927 gint row;
1928
1929 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1930
1931 g_mutex_lock(&interp_coeff_4th_order_mutex);
1932
1933 coeffs_0 = interp_coeff_4th_order[row][0];
1934 coeffs_1 = interp_coeff_4th_order[row][1];
1935 coeffs_2 = interp_coeff_4th_order[row][2];
1936 coeffs_3 = interp_coeff_4th_order[row][3];
1937
1938 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1939
1940 destination[dsp_i] = (coeffs_0 * start_point
1941 + coeffs_1 * source[dsp_phase_index]
1942 + coeffs_2 * source[dsp_phase_index + 1]
1943 + coeffs_3 * source[dsp_phase_index + 2]);
1944
1945 /* increment phase */
1946 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1947 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1948 }
1949
1950 /* interpolate the sequence of sample points */
1951 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
1952 {
1953 gint row;
1954
1955 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
1956
1957 g_mutex_lock(&interp_coeff_4th_order_mutex);
1958
1959 coeffs_0 = interp_coeff_4th_order[row][0];
1960 coeffs_1 = interp_coeff_4th_order[row][1];
1961 coeffs_2 = interp_coeff_4th_order[row][2];
1962 coeffs_3 = interp_coeff_4th_order[row][3];
1963
1964 g_mutex_unlock(&interp_coeff_4th_order_mutex);
1965
1966 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
1967 + coeffs_1 * source[dsp_phase_index]
1968 + coeffs_2 * source[dsp_phase_index + 1]
1969 + coeffs_3 * source[dsp_phase_index + 2]);
1970
1971 /* increment phase */
1972 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
1973 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
1974 }
1975 }
1976
1977 /**
1978 * ags_fluid_interpolate_4th_order_util_fill_float:
1979 * @destination: the destination audio buffer
1980 * @source: the source audio buffer
1981 * @buffer_length: the buffer length
1982 * @phase_incr: the phase increment
1983 *
1984 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
1985 *
1986 * Since: 3.8.12
1987 */
1988 void
ags_fluid_interpolate_4th_order_util_fill_float(gfloat * destination,gfloat * source,guint buffer_length,gdouble phase_incr)1989 ags_fluid_interpolate_4th_order_util_fill_float(gfloat *destination,
1990 gfloat *source,
1991 guint buffer_length,
1992 gdouble phase_incr)
1993 {
1994 guint64 dsp_phase;
1995 guint64 dsp_phase_incr;
1996 guint dsp_i;
1997 guint dsp_phase_index;
1998 guint start_index, end_index;
1999 gdouble start_point, end_point1, end_point2;
2000 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
2001
2002 if(destination == NULL ||
2003 source == NULL ||
2004 buffer_length == 0){
2005 return;
2006 }
2007
2008 ags_fluid_interpolate_4th_order_util_config();
2009
2010 dsp_phase = 0;
2011
2012 /* Convert playback "speed" floating point value to phase index/fract */
2013 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
2014
2015 end_index = buffer_length - 1;
2016
2017 start_index = 0;
2018 start_point = source[0];
2019
2020 end_point1 = source[end_index];
2021 end_point2 = end_point1;
2022
2023 dsp_i = 0;
2024
2025 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2026
2027 /* interpolate first sample point (start or loop start) if needed */
2028 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
2029 gint row;
2030
2031 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2032
2033 g_mutex_lock(&interp_coeff_4th_order_mutex);
2034
2035 coeffs_0 = interp_coeff_4th_order[row][0];
2036 coeffs_1 = interp_coeff_4th_order[row][1];
2037 coeffs_2 = interp_coeff_4th_order[row][2];
2038 coeffs_3 = interp_coeff_4th_order[row][3];
2039
2040 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2041
2042 destination[dsp_i] = (coeffs_0 * start_point
2043 + coeffs_1 * source[dsp_phase_index]
2044 + coeffs_2 * source[dsp_phase_index + 1]
2045 + coeffs_3 * source[dsp_phase_index + 2]);
2046
2047 /* increment phase */
2048 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2049 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2050 }
2051
2052 /* interpolate the sequence of sample points */
2053 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
2054 {
2055 gint row;
2056
2057 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2058
2059 g_mutex_lock(&interp_coeff_4th_order_mutex);
2060
2061 coeffs_0 = interp_coeff_4th_order[row][0];
2062 coeffs_1 = interp_coeff_4th_order[row][1];
2063 coeffs_2 = interp_coeff_4th_order[row][2];
2064 coeffs_3 = interp_coeff_4th_order[row][3];
2065
2066 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2067
2068 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
2069 + coeffs_1 * source[dsp_phase_index]
2070 + coeffs_2 * source[dsp_phase_index + 1]
2071 + coeffs_3 * source[dsp_phase_index + 2]);
2072
2073 /* increment phase */
2074 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2075 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2076 }
2077 }
2078
2079 /**
2080 * ags_fluid_interpolate_4th_order_util_fill_double:
2081 * @destination: the destination audio buffer
2082 * @source: the source audio buffer
2083 * @buffer_length: the buffer length
2084 * @phase_incr: the phase increment
2085 *
2086 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
2087 *
2088 * Since: 3.8.12
2089 */
2090 void
ags_fluid_interpolate_4th_order_util_fill_double(gdouble * destination,gdouble * source,guint buffer_length,gdouble phase_incr)2091 ags_fluid_interpolate_4th_order_util_fill_double(gdouble *destination,
2092 gdouble *source,
2093 guint buffer_length,
2094 gdouble phase_incr)
2095 {
2096 guint64 dsp_phase;
2097 guint64 dsp_phase_incr;
2098 guint dsp_i;
2099 guint dsp_phase_index;
2100 guint start_index, end_index;
2101 gdouble start_point, end_point1, end_point2;
2102 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
2103
2104 if(destination == NULL ||
2105 source == NULL ||
2106 buffer_length == 0){
2107 return;
2108 }
2109
2110 ags_fluid_interpolate_4th_order_util_config();
2111
2112 dsp_phase = 0;
2113
2114 /* Convert playback "speed" floating point value to phase index/fract */
2115 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
2116
2117 end_index = buffer_length - 1;
2118
2119 start_index = 0;
2120 start_point = source[0];
2121
2122 end_point1 = source[end_index];
2123 end_point2 = end_point1;
2124
2125 dsp_i = 0;
2126
2127 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2128
2129 /* interpolate first sample point (start or loop start) if needed */
2130 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
2131 gint row;
2132
2133 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2134
2135 g_mutex_lock(&interp_coeff_4th_order_mutex);
2136
2137 coeffs_0 = interp_coeff_4th_order[row][0];
2138 coeffs_1 = interp_coeff_4th_order[row][1];
2139 coeffs_2 = interp_coeff_4th_order[row][2];
2140 coeffs_3 = interp_coeff_4th_order[row][3];
2141
2142 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2143
2144 destination[dsp_i] = (coeffs_0 * start_point
2145 + coeffs_1 * source[dsp_phase_index]
2146 + coeffs_2 * source[dsp_phase_index + 1]
2147 + coeffs_3 * source[dsp_phase_index + 2]);
2148
2149 /* increment phase */
2150 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2151 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2152 }
2153
2154 /* interpolate the sequence of sample points */
2155 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
2156 {
2157 gint row;
2158
2159 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2160
2161 g_mutex_lock(&interp_coeff_4th_order_mutex);
2162
2163 coeffs_0 = interp_coeff_4th_order[row][0];
2164 coeffs_1 = interp_coeff_4th_order[row][1];
2165 coeffs_2 = interp_coeff_4th_order[row][2];
2166 coeffs_3 = interp_coeff_4th_order[row][3];
2167
2168 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2169
2170 destination[dsp_i] = (coeffs_0 * source[dsp_phase_index - 1]
2171 + coeffs_1 * source[dsp_phase_index]
2172 + coeffs_2 * source[dsp_phase_index + 1]
2173 + coeffs_3 * source[dsp_phase_index + 2]);
2174
2175 /* increment phase */
2176 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2177 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2178 }
2179 }
2180
2181 /**
2182 * ags_fluid_interpolate_4th_order_util_fill_complex:
2183 * @destination: the destination audio buffer
2184 * @source: the source audio buffer
2185 * @buffer_length: the buffer length
2186 * @phase_incr: the phase increment
2187 *
2188 * Perform fluid interpolate 4th order on @buffer and return the result in @output_buffer.
2189 *
2190 * Since: 3.8.12
2191 */
2192 void
ags_fluid_interpolate_4th_order_util_fill_complex(AgsComplex * destination,AgsComplex * source,guint buffer_length,gdouble phase_incr)2193 ags_fluid_interpolate_4th_order_util_fill_complex(AgsComplex *destination,
2194 AgsComplex *source,
2195 guint buffer_length,
2196 gdouble phase_incr)
2197 {
2198 guint64 dsp_phase;
2199 guint64 dsp_phase_incr;
2200 guint dsp_i;
2201 guint dsp_phase_index;
2202 guint start_index, end_index;
2203 double _Complex start_point, end_point1, end_point2;
2204 gdouble coeffs_0, coeffs_1, coeffs_2, coeffs_3;
2205
2206 if(destination == NULL ||
2207 source == NULL ||
2208 buffer_length == 0){
2209 return;
2210 }
2211
2212 ags_fluid_interpolate_4th_order_util_config();
2213
2214 dsp_phase = 0;
2215
2216 /* Convert playback "speed" floating point value to phase index/fract */
2217 ags_fluid_phase_set_float(dsp_phase_incr, phase_incr);
2218
2219 end_index = buffer_length - 1;
2220
2221 start_index = 0;
2222 start_point = ags_complex_get(source);
2223
2224 end_point1 = ags_complex_get(source + end_index);
2225 end_point2 = end_point1;
2226
2227 dsp_i = 0;
2228
2229 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2230
2231 /* interpolate first sample point (start or loop start) if needed */
2232 for(; dsp_phase_index == start_index && dsp_i < buffer_length; dsp_i++){
2233 gint row;
2234
2235 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2236
2237 g_mutex_lock(&interp_coeff_4th_order_mutex);
2238
2239 coeffs_0 = interp_coeff_4th_order[row][0];
2240 coeffs_1 = interp_coeff_4th_order[row][1];
2241 coeffs_2 = interp_coeff_4th_order[row][2];
2242 coeffs_3 = interp_coeff_4th_order[row][3];
2243
2244 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2245
2246 ags_complex_set(destination + dsp_i, (coeffs_0 * start_point
2247 + coeffs_1 * ags_complex_get(source + dsp_phase_index)
2248 + coeffs_2 * ags_complex_get(source + dsp_phase_index + 1),
2249 + coeffs_3 * ags_complex_get(source + dsp_phase_index + 2)));
2250
2251 /* increment phase */
2252 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2253 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2254 }
2255
2256 /* interpolate the sequence of sample points */
2257 for(; dsp_i < buffer_length && dsp_phase_index <= end_index; dsp_i++)
2258 {
2259 gint row;
2260
2261 row = ags_fluid_phase_fract_to_tablerow(dsp_phase);
2262
2263 g_mutex_lock(&interp_coeff_4th_order_mutex);
2264
2265 coeffs_0 = interp_coeff_4th_order[row][0];
2266 coeffs_1 = interp_coeff_4th_order[row][1];
2267 coeffs_2 = interp_coeff_4th_order[row][2];
2268 coeffs_3 = interp_coeff_4th_order[row][3];
2269
2270 g_mutex_unlock(&interp_coeff_4th_order_mutex);
2271
2272 ags_complex_set(destination + dsp_i, (coeffs_0 * ags_complex_get(source + dsp_phase_index - 1)
2273 + coeffs_1 * ags_complex_get(source + dsp_phase_index)
2274 + coeffs_2 * ags_complex_get(source + dsp_phase_index + 1)
2275 + coeffs_3 * ags_complex_get(source + dsp_phase_index + 2)));
2276
2277 /* increment phase */
2278 ags_fluid_phase_incr(dsp_phase, dsp_phase_incr);
2279 dsp_phase_index = ags_fluid_phase_index(dsp_phase);
2280 }
2281 }
2282