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
|
Description: Fix for Pd64
LADSPA (as used by us) only supports single-precision float,
so we need to convert...
Author: IOhannes m zmölnig
Origin: Debian
Forwarded: no
Last-Update: 2024-07-18
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
@@ -73,7 +73,7 @@
assert (plugin_tilde_class != NULL);
/* Let's be explicit in not converting the signals in any way */
- assert (sizeof (float) == sizeof (t_float));
+ //assert (sizeof (float) == sizeof (t_float));
assert (sizeof (float) == sizeof (LADSPA_Data));
@@ -157,6 +157,8 @@
x->dsp_vec_length = x->num_audio_inputs + x->num_audio_outputs + 2;
x->dsp_vec = (t_int*)calloc (x->dsp_vec_length, sizeof (t_int));
+ x->dsp_floatbuf = (float**)calloc (x->num_audio_inputs + x->num_audio_outputs, sizeof(float*));
+
if(NULL==x->dsp_vec)return NULL;
return x;
}
@@ -202,6 +204,10 @@
}
}
+
+static t_int*plugin_tilde_sample2float_perform(t_int*w);
+static t_int*plugin_tilde_float2sample_perform(t_int*w);
+
static void plugin_tilde_dsp (Pd_Plugin_Tilde* x, t_signal** sp)
{
unsigned i = 0;
@@ -213,8 +219,20 @@
x->dsp_vec[0] = (t_int)x;
x->dsp_vec[1] = (t_int)num_samples;
/* Inputs are before outputs; ignore the first "null" input */
- for (i = 2; i < x->dsp_vec_length; i++) {
- x->dsp_vec[i] = (t_int)(sp[i - 1]->s_vec);
+ if(sizeof(float) != sizeof(t_sample)) {
+ /* double precision */
+ for (i = 0; i < x->num_audio_inputs + x->num_audio_outputs; i++) {
+ x->dsp_floatbuf[i] = realloc(x->dsp_floatbuf[i], num_samples * sizeof(float));
+ x->dsp_vec[i+2] = (t_int)(x->dsp_floatbuf[i]);
+ }
+ for (i = 0; i < x->num_audio_inputs; i++) {
+ dsp_add(plugin_tilde_sample2float_perform, 3, sp[i+1]->s_vec, x->dsp_floatbuf[i], num_samples);
+ }
+ } else {
+ /* single precision */
+ for (i = 2; i < x->dsp_vec_length; i++) {
+ x->dsp_vec[i] = (t_int)(sp[i - 1]->s_vec);
+ }
}
/* Connect audio ports with buffers (this is only done when DSP
@@ -226,23 +244,47 @@
/* add DSP routine to Pd's DSP chain */
dsp_addv (plugin_tilde_perform, x->dsp_vec_length, x->dsp_vec);
+
+ if(sizeof(float) != sizeof(t_sample)) {
+ /* double precision */
+ for (i = x->num_audio_inputs; i < x->num_audio_outputs + x->num_audio_inputs; i++) {
+ dsp_add(plugin_tilde_float2sample_perform, 3, x->dsp_floatbuf[i], sp[i+1]->s_vec, num_samples);
+ }
+ }
+}
+
+static t_int*plugin_tilde_sample2float_perform(t_int*w) {
+ t_sample *in = (t_sample *)(w[1]);
+ float *out = (float *)(w[2]);
+ int n = (int)w[3];
+ while(n--)
+ *out++ = *in++;
+ return (w+4);
+}
+static t_int*plugin_tilde_float2sample_perform(t_int*w) {
+ float *in = (float *)(w[1]);
+ t_sample *out = (t_sample *)(w[2]);
+ int n = (int)w[3];
+ while(n--)
+ *out++ = *in++;
+ return (w+4);
}
static t_int* plugin_tilde_perform (t_int* w)
{
Pd_Plugin_Tilde* x = NULL;
- t_float** audio_inputs = NULL;
- t_float** audio_outputs = NULL;
+ float** audio_inputs = NULL;
+ float** audio_outputs = NULL;
int num_samples = 0;
/* precondition(s) */
assert (w != NULL);
-
+
/* Unpack DSP parameter vector */
x = (Pd_Plugin_Tilde*)(w[1]);
num_samples = (int)(w[2]);
- audio_inputs = (t_float**)(&w[3]);
- audio_outputs = (t_float**)(&w[3 + x->num_audio_inputs]);
+ audio_inputs = (float**)(&w[3]);
+ audio_outputs = (float**)(&w[3 + x->num_audio_inputs]);
/* Call the LADSPA/VST plugin */
plugin_tilde_apply_plugin (x);
return w + (x->dsp_vec_length + 1);
@@ -1004,16 +1046,16 @@
{
unsigned i = 0;
- x->plugin.ladspa.outofplace_audio_outputs = (t_float**)
- calloc (x->num_audio_outputs, sizeof (t_float*));
+ x->plugin.ladspa.outofplace_audio_outputs = (float**)
+ calloc (x->num_audio_outputs, sizeof (float*));
if (x->plugin.ladspa.outofplace_audio_outputs == NULL) {
return 1; /* error */
}
for (i = 0; i < x->num_audio_outputs; i++)
{
- x->plugin.ladspa.outofplace_audio_outputs[i] = (t_float*)
- calloc (buflen, sizeof (t_float));
+ x->plugin.ladspa.outofplace_audio_outputs[i] = (float*)
+ calloc (buflen, sizeof (float));
if (x->plugin.ladspa.outofplace_audio_outputs[i] == NULL) {
/* FIXME free got buffers? */
return 1; /* error */
@@ -55,6 +55,9 @@
unsigned dsp_vec_length;
unsigned dsp_active;
+ /* LADSPA only uses single-precision float */
+ float** dsp_floatbuf;
+
} Pd_Plugin_Tilde;
/* Object construction and destruction */
|