swh / ladspa

The SWH Plugins package for the LADSPA plugin system
http://plugin.org.uk/
GNU General Public License v2.0
229 stars 52 forks source link

imp_1199 in stereo / multiple instances #27

Open srtaylor opened 8 years ago

srtaylor commented 8 years ago

Trying to apply your imp_1199 to stereo input I get strange results. Using ecasound as the host, with stereo input "in.wav", if I do

ecasound -i:in.wav -o:out.wav -el:imp,1

then the output has processed audio in ch.2 only, with silence on ch.1. This is strange, because every other 1-in-1-out plugin processes all channels in parallel, e.g.

ecasound -i:in.wav -o:out.wav -el:amp,6

adds +6dB gain to both channels, as expected. If I understand correctly, this runs multiple instances of the plugin, one for each channel. I suspect multiple instances of imp_1199 just don't get along well.

Strangely, I can convolve ch.1 only by silencing ch.2 first, like so:

ecasound -i:in.wav -o:out.wav -chorder:1,0 -el:imp,1

and yet if I manually run one instance of imp_1199 per channel like this:

ecasound -a:L,R -i:in.wav -o:out.wav \ -a:L -chorder:1,0 -el:imp,1 \ -a:R -chorder:0,2 -el:imp,1

then I get silence on ch.1 again. Just changing one instance of "imp" to "amp" (or any other 1-in-1-out plugin) in the above gives non-zero output in both channels; the problem only occurs with two instances of "imp". Somehow the second instance of imp_1199 is clobbering the output of the first.

I looked through the imp_1199 code but can't see anything amiss. Any ideas?

swh commented 8 years ago

It's a while since I looked at that code, but from what I remember it's mono-in, stereo-out, so there's no correct way to process stereo input. You could run two in parallel, one for left, one for right, and combine the left out of instance 1, with the right out of instance 2, but there's zero chance ecasound would be able to figure that out on its own.

srtaylor commented 8 years ago

Thanks for looking at this. I'm working on a project that's stuck until I can implement a FIR filter under ladspa.

analyzeplugin says imp_1199 has only one audio output. But in any case, the following runs two instances in parallel and combines the outputs, as you suggest:

ecasound -z:mixmode,sum -a:all -f:,2 -i:in.wav -o:out.wav \ -a:L -chorder:1,0 -el:imp,1 \ -a:R -chorder:2,0 -el:imp,1 -chorder:0,1

This works with lots of other plugins, both 1-in-1-out and 1-in-2-out. But with imp_1199 it outputs silence on ch.1. Simply eliminating the "R" chain (which itself does nothing to ch.1) restores the ch.1 output. So imp_1199 is doing something weird that other plugins don't.

Looking at the code, I wonder if it's that the fftw structures are declared global in scope instead of within the plugin_data structure?

swh commented 8 years ago

Ah, ok. It's 15 years or so since I wrote it, so not clear on how it works. Can't think why you would only get one channel out. Sounds like a bug, but it's an odd one. Could be FFTW setup, as you say. Why LADSPA, jack based FIR might be easier? LADSPA and FFT FIR is not a great mix - buffer sizes can caused unpredictable CPU load from cycle to cycle.

srtaylor commented 8 years ago

LADSPA because I've built a system around ecasound and some IIR filters I wrote in LADSPA (actually, mods of your biquad filters) for doing crossover/eq of active loudspeakers. Documented here if you're interested.

But now I need to add stereo decorrelation; allpass FIR filters are the best way I know how. I realize LADSPA and FIR isn't a great mix. But the impulses are shortish (512 or 1024 samples) so I figured an fft approach would be doable. Your code has what I want, if I can get it working.

Sorry to bug you about old code! I'll work on it; will let you know here if I find a fix.

swh commented 8 years ago

OK, great. Good luck!