From 7306ab5e074dd262d332fc6fa0d9528e42365348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20H=C3=BClsmann?= Date: Thu, 7 Apr 2022 19:50:27 +0200 Subject: [PATCH] Allocate memory during instantiation, fixing segfaults in a few plugins. allpass, comb and delay should also not set the buffer size based on the max_delay control, which is now deprecated. --- plugins/allpass-swh.lv2/plugin.xml | 84 +++++++++------------- plugins/bandpass_a_iir-swh.lv2/plugin.xml | 4 +- plugins/bandpass_iir-swh.lv2/plugin.xml | 8 +-- plugins/butterworth-swh.lv2/plugin.xml | 12 ++-- plugins/comb-swh.lv2/plugin.xml | 88 +++++++++-------------- plugins/delay-swh.lv2/plugin.xml | 84 +++++++++------------- plugins/highpass_iir-swh.lv2/plugin.xml | 4 +- plugins/lowpass_iir-swh.lv2/plugin.xml | 4 +- plugins/revdelay-swh.lv2/plugin.xml | 12 +++- 9 files changed, 126 insertions(+), 174 deletions(-) diff --git a/plugins/allpass-swh.lv2/plugin.xml b/plugins/allpass-swh.lv2/plugin.xml index 31127b1..4df714e 100644 --- a/plugins/allpass-swh.lv2/plugin.xml +++ b/plugins/allpass-swh.lv2/plugin.xml @@ -42,28 +42,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(float)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(float)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -225,28 +219,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(float)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(float)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -363,28 +351,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(float)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(float)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

diff --git a/plugins/bandpass_a_iir-swh.lv2/plugin.xml b/plugins/bandpass_a_iir-swh.lv2/plugin.xml index 0b9f0db..86ad999 100644 --- a/plugins/bandpass_a_iir-swh.lv2/plugin.xml +++ b/plugins/bandpass_a_iir-swh.lv2/plugin.xml @@ -19,6 +19,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); + iirf = init_iirf_t(gt); calc_2polebandpass(iirf, gt, center, width, sample_rate); @@ -26,8 +28,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); calc_2polebandpass(iirf, plugin_data->gt, *(plugin_data->center), *(plugin_data->width), sample_rate); diff --git a/plugins/bandpass_iir-swh.lv2/plugin.xml b/plugins/bandpass_iir-swh.lv2/plugin.xml index 415290e..9575336 100644 --- a/plugins/bandpass_iir-swh.lv2/plugin.xml +++ b/plugins/bandpass_iir-swh.lv2/plugin.xml @@ -21,6 +21,10 @@ sample_rate = s_rate; + first = init_iir_stage(IIR_STAGE_LOWPASS,10,3,2); + second = init_iir_stage(IIR_STAGE_HIGHPASS,10,3,2); + gt = init_iir_stage(IIR_STAGE_BANDPASS,20,3,2); + iirf = init_iirf_t(gt); ufc = (center + width*0.5f)/(float)sample_rate; @@ -34,10 +38,6 @@ plugin_data->ufc = (*(plugin_data->center) + *(plugin_data->width)*0.5f)/(float)sample_rate; plugin_data->lfc = (*(plugin_data->center) - *(plugin_data->width)*0.5f)/(float)sample_rate; - plugin_data->first = init_iir_stage(IIR_STAGE_LOWPASS,10,3,2); - plugin_data->second = init_iir_stage(IIR_STAGE_HIGHPASS,10,3,2); - plugin_data->gt = init_iir_stage(IIR_STAGE_BANDPASS,20,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); chebyshev(plugin_data->iirf, plugin_data->first, 2*CLAMP((int)(*(plugin_data->stages)),1,10), IIR_STAGE_LOWPASS, plugin_data->ufc, 0.5f); chebyshev(plugin_data->iirf, plugin_data->second, 2*CLAMP((int)(*(plugin_data->stages)),1,10), IIR_STAGE_HIGHPASS, plugin_data->lfc, 0.5f); combine_iir_stages(IIR_STAGE_BANDPASS, plugin_data->gt, plugin_data->first, plugin_data->second,0,0); diff --git a/plugins/butterworth-swh.lv2/plugin.xml b/plugins/butterworth-swh.lv2/plugin.xml index c1d8d6b..79ffabe 100644 --- a/plugins/butterworth-swh.lv2/plugin.xml +++ b/plugins/butterworth-swh.lv2/plugin.xml @@ -19,6 +19,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); + iirf = init_iirf_t(gt); butterworth_stage(gt, 0, cutoff, resonance, sample_rate); @@ -27,8 +29,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); butterworth_stage(plugin_data->gt, 0, *(plugin_data->cutoff), *(plugin_data->resonance), sample_rate); @@ -74,6 +74,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); + iirf = init_iirf_t(gt); butterworth_stage(gt, 0, cutoff, resonance, sample_rate); @@ -81,8 +83,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); butterworth_stage(plugin_data->gt, 0, *(plugin_data->cutoff), *(plugin_data->resonance), sample_rate); @@ -124,6 +124,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); + iirf = init_iirf_t(gt); butterworth_stage(gt, 1, cutoff, resonance, sample_rate); @@ -131,8 +133,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_LOWPASS,1,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); butterworth_stage(plugin_data->gt, 1, *(plugin_data->cutoff), *(plugin_data->resonance), sample_rate); diff --git a/plugins/comb-swh.lv2/plugin.xml b/plugins/comb-swh.lv2/plugin.xml index 8d653bc..4271901 100644 --- a/plugins/comb-swh.lv2/plugin.xml +++ b/plugins/comb-swh.lv2/plugin.xml @@ -39,28 +39,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -219,28 +213,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -357,28 +345,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

diff --git a/plugins/delay-swh.lv2/plugin.xml b/plugins/delay-swh.lv2/plugin.xml index 94415d5..ea79908 100644 --- a/plugins/delay-swh.lv2/plugin.xml +++ b/plugins/delay-swh.lv2/plugin.xml @@ -25,28 +25,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -153,28 +147,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

@@ -269,28 +257,24 @@ - - max_delay && *plugin_data->max_delay > 0) - minsize = sample_rate * *plugin_data->max_delay; - else if (plugin_data->delay_time) - minsize = sample_rate * *plugin_data->delay_time; - else - minsize = sample_rate; /* 1 second default */ + minsize = sample_rate * 10; /* 10 seconds buffer */ size = 1; while (size < minsize) size <<= 1; /* calloc sets the buffer to zero. */ - plugin_data->buffer = calloc(size, sizeof(LADSPA_Data)); - if (plugin_data->buffer) - plugin_data->buffer_mask = size - 1; + buffer = calloc(size, sizeof(LADSPA_Data)); + if (buffer) + buffer_mask = size - 1; else - plugin_data->buffer_mask = 0; - plugin_data->write_phase = 0; + buffer_mask = 0; + write_phase = 0; + ]]> + + buffer, 0, (plugin_data->buffer_mask + 1) * sizeof(LADSPA_Data)); ]]> Max Delay (s)

- Maximum delay. Used to set the delay buffer size upon activation. Cannot - be modulated. Note that if you do not connect to this port before - activation, it will default to 1 second. + This has no effect and is left in for interface backwards compatibility.

diff --git a/plugins/highpass_iir-swh.lv2/plugin.xml b/plugins/highpass_iir-swh.lv2/plugin.xml index 3a238d5..acb2656 100644 --- a/plugins/highpass_iir-swh.lv2/plugin.xml +++ b/plugins/highpass_iir-swh.lv2/plugin.xml @@ -21,6 +21,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_HIGHPASS,10,3,2); + iirf = init_iirf_t(gt); chebyshev(iirf, gt, 2*CLAMP((int)stages,1,10), IIR_STAGE_HIGHPASS, cutoff/(float)sample_rate, 0.5f); @@ -28,8 +30,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_HIGHPASS,10,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); chebyshev(plugin_data->iirf, plugin_data->gt, 2*CLAMP((int)(*(plugin_data->stages)),1,10), IIR_STAGE_HIGHPASS, *(plugin_data->cutoff)/(float)sample_rate, 0.5f); diff --git a/plugins/lowpass_iir-swh.lv2/plugin.xml b/plugins/lowpass_iir-swh.lv2/plugin.xml index a5e0c31..ba5fad0 100644 --- a/plugins/lowpass_iir-swh.lv2/plugin.xml +++ b/plugins/lowpass_iir-swh.lv2/plugin.xml @@ -22,6 +22,8 @@ sample_rate = s_rate; + gt = init_iir_stage(IIR_STAGE_LOWPASS,10,3,2); + iirf = init_iirf_t(gt); chebyshev(iirf, gt, 2*CLAMP((int)stages,1,10), IIR_STAGE_LOWPASS, cutoff/(float)sample_rate, 0.5f); @@ -29,8 +31,6 @@ - plugin_data->gt = init_iir_stage(IIR_STAGE_LOWPASS,10,3,2); - plugin_data->iirf = init_iirf_t(plugin_data->gt); chebyshev(plugin_data->iirf, plugin_data->gt, 2*CLAMP(f_round(*(plugin_data->stages)),1,10), IIR_STAGE_LOWPASS, *(plugin_data->cutoff)/(float)sample_rate, 0.5f); diff --git a/plugins/revdelay-swh.lv2/plugin.xml b/plugins/revdelay-swh.lv2/plugin.xml index 70547a9..3c242ce 100644 --- a/plugins/revdelay-swh.lv2/plugin.xml +++ b/plugins/revdelay-swh.lv2/plugin.xml @@ -32,15 +32,21 @@ delay_samples = 0; last_delay_time = 0; write_phase = 0; + + unsigned int size; + + size = sample_rate * 5 * 2; /* 5 second maximum */ + + /* calloc sets the buffer to zero. */ + buffer = calloc(size, sizeof(LADSPA_Data)); ]]>
buffer = calloc(size, sizeof(LADSPA_Data)); + memset(plugin_data->buffer, 0, size * sizeof(LADSPA_Data)); plugin_data->buffer_size = size; plugin_data->write_phase = 0;