Well, somewhere you would need to loop over the samples…
Functional programming would be to use only “pure” functions that never mutate state. Completely deterministic and predicable. Has huge advantages. These functions are easily testable and once set in stone, can never fail.
But that is only a tiny portion of a plugin. Let’s have the most simple example I can think of right now: a simple gain plugin.
So you write a function that takes the input, mutates it and returns the new output. Great. We wrote a pure function that essentially only multiplies the input with another input.
const float gain (const float input, const float multiplier)
return input * mutiplier;
Now if we use this and we modulate the second input value (the multiplier) we get clicks and crackles. We need to smooth the second input parameter. Where do we put that smoothing? Use a LERP inside the gain? Then it would mutate its own state, thus making it “impure” and not testable anymore.
Outside? OK, then we need an interpolator class that, but that needs to maintain its own state, because it needs to keep track of the “current” multiplier, so it can advance it to the “destination” multiplier.
How do we achieve that in a purely functional way, without modifying state? If we can’t even get a simple gain plugin to work in a purely functional way, how do we expect to do the same with more complicated algorithms? I’m afraid that we’re stuck with mutating data forever. There are recursive algorithms that are impossible to achieve without mutations. So we’re already talking about mixing pure and impure functions. Is that still functional programming?