diff --git a/vocoder_1337.xml b/vocoder_1337.xml new file mode 100644 index 0000000..4e2db50 --- /dev/null +++ b/vocoder_1337.xml @@ -0,0 +1,214 @@ + + + + + + + + + + #include "config.h" + #include "util/iir.h" + + #define MAX_BANDS 16 /* max 16 bands should be increased */ + #define AMPLIFIER 16.0 + + struct bandpasses + { + LADSPA_Data c[MAX_BANDS], f[MAX_BANDS], att[MAX_BANDS]; + + LADSPA_Data freq[MAX_BANDS]; + LADSPA_Data low1[MAX_BANDS], low2[MAX_BANDS]; + LADSPA_Data mid1[MAX_BANDS], mid2[MAX_BANDS]; + LADSPA_Data high1[MAX_BANDS], high2[MAX_BANDS]; + LADSPA_Data y[MAX_BANDS]; + }; + + struct bands_out{ + LADSPA_Data decay[MAX_BANDS]; + LADSPA_Data oldval[MAX_BANDS]; + LADSPA_Data level[MAX_BANDS]; /* 0.0 - 1.0 level of this output band */ + }; + + const LADSPA_Data decay_table[] = + { + 1/100.0, + 1/100.0, 1/100.0, 1/100.0, + 1/125.0, 1/125.0, 1/125.0, + 1/166.0, 1/166.0, 1/166.0, + 1/200.0, 1/200.0, 1/200.0, + 1/250.0, 1/250.0, 1/250.0 + }; + + /* The port numbers for the plugin: */ + + #define PORT_FORMANT 0 /* the track to "vocodify */ + #define PORT_CARRIER 1 /* the track to control 1st track */ + #define PORT_OUTPUT 2 /* left output */ + #define PORT_OUTPUT2 3 /* right output */ + #define CTRL_BANDCOUNT 4 /* selected # of bands to use */ + #define CTRL_PAN 5 /* stereo balance for outputs */ + #define CTRL_BAND1LVL 6 /* start of bands level */ + + #define PORT_COUNT 6 + MAX_BANDS /* bands level */ + + // vocoder_do_bandpasses /*fold00*/ + void inline vocoder_do_bandpasses(struct bandpasses *bands, LADSPA_Data sample) + { + int i; + for (i=0; i < vocoder->num_bands; i++) + { + bands->high1[i] = sample - bands->f[i] * bands->mid1[i] - bands->low1[i]; + bands->mid1[i] += bands->high1[i] * bands->c[i]; + bands->low1[i] += bands->mid1[i]; + + bands->high2[i] = bands->low1[i] - bands->f[i] * bands->mid2[i] - bands->low2[i]; + bands->mid2[i] += bands->high2[i] * bands->c[i]; + bands->low2[i] += bands->mid2[i]; + bands->y[i] = bands->high2[i] * bands->att[i]; + } + } + + ]]> + + + + Vocoder +

+ + + + + + + + ctrlBandCount); + if (numbands < 1 || numbands > MAX_BANDS) numbands = MAX_BANDS; + + /* initialize bandpass information if num_bands control has changed, + or on first run */ + if (plugin_data->num_bands != numbands) + { + plugin_data->num_bands = numbands; + + memset(&plugin_data->bands_formant, 0, sizeof(struct bandpasses)); + for(i=0; i < numbands; i++) + { + a = 16.0 * i/(double)numbands; // stretch existing bands + + if (a < 4.0) + plugin_data->bands_formant.freq[i] = 150 + 420 * a / 4.0; + else + plugin_data->bands_formant.freq[i] = 600 * pow (1.23, a - 4.0); + + c = plugin_data->bands_formant.freq[i] * 2 * M_PI / plugin_data->SampleRate; + plugin_data->bands_formant.c[i] = c * c; + + plugin_data->bands_formant.f[i] = 0.4/c; + plugin_data->bands_formant.att[i] = + 1/(6.0 + ((exp (plugin_data->bands_formant.freq[i] + / plugin_data->SampleRate) - 1) * 10)); + + plugin_data->bands_out.decay[i] = decay_table[(int)a]; + plugin_data->bands_out.level[i] = + CLAMP (*plugin_data->ctrlBandLevels[i], 0.0, 1.0); + } + memcpy(&plugin_data->bands_carrier, + &plugin_data->bands_formant, sizeof(struct bandpasses)); + + } + else /* get current values of band level controls */ + { + for (i = 0; i < numbands; i++) + plugin_data->bands_out.level[i] = CLAMP (*plugin_data->ctrlBandLevels[i], + 0.0, 1.0); + } + + for (i=0; i < SampleCount; i++) + { + vocoder_do_bandpasses (&(plugin_data->bands_carrier), + plugin_data->portCarrier[i]); + vocoder_do_bandpasses (&(plugin_data->bands_formant), + plugin_data->portFormant[i]); + + LADSPA_Data sample = 0.0; + for (j=0; j < numbands; j++) + { + plugin_data->bands_out.oldval[j] = plugin_data->bands_out.oldval[j] + + (fabs (plugin_data->bands_formant.y[j]) + - plugin_data->bands_out.oldval[j]) + * plugin_data->bands_out.decay[j]; + x = plugin_data->bands_carrier.y[j] * plugin_data->bands_out.oldval[j]; + + sample += x * plugin_data->bands_out.level[j]; + } + /* treat paning + main volume */ + pan = (int)(*plugin_data->ctrlPan); + fl = fr = 1.0f; + if (pan != 0) { /* no paning, don't compute useless values */ + if (pan > 0) { /* reduce left */ + fl = (100.-pan)/100.; + } else { + fr = (100.+pan)/100.; + } + } + /* apply volume and paning */ + plugin_data->portOutput[i] = sample * plugin_data->mainvol * fl; + plugin_data->portOutput2[i] = sample * plugin_data->mainvol * fr; + } + ]]> + + + + LoremIn + + + + + LoremOut + + + + + + + + + + + + + + + + + + + + + + + + + + + +