grame-cncm / faustlibraries

The Faust libraries
https://faustlibraries.grame.fr
183 stars 59 forks source link

Adding more mixing functions #162

Closed DBraun closed 9 months ago

DBraun commented 9 months ago

I've added some functions similar to dryWetMixer/dryWetMixerConstantPower. Instead of consuming an FX that creates a dry and wet bus, these new functions consume N buses that already exist. The new functions are called:

These are relevant to wavetable blending. Suppose each wavetable has C channels and there are N wavetables. It's common practice to have a wavetable-position index that helps select any two wavetables and blend between them. An index of 0 selects the 0th wavetable. An index of 1.25 blends between the 1st and 2nd, by 0.75 and 0.25, and so on. This is how I can do it with mixLinearLoop:

N = 4;
C = 2;

// Make N buses of C channels. Each bus has higher pitch than the previous.
sounds = par(i, N*C, int(i/C)*7 + 48 : ba.midikey2hz : os.osc : _*.4);

loopingM = os.phasor(S,freq) : it.remap(0, S, 0, N)
with {
    freq = hslider("Looping Freq", 0., 0., 1., .001);
    S = 1<<15;
};

process = mixLinearLoop(N, C, loopingM, sounds);

What's cool here is that I can seamlessly loop back from the N-1 th wavetable to the 0th. That's why it's called mixLinear*Loop*. In contrast, mixLinearClamp clamps the index so that circular lookups aren't possible.

The other two mixPower* functions use constant-power weights, like dryWetMixerConstantPower already does.

To see this demo, copy this code into the Faust IDE: https://gist.github.com/DBraun/92c1ee2c0c6262c5585f163b5ca75718

I will keep this as a draft PR for a bit in case I missed something. Feedback is very welcome :)

sletz commented 9 months ago

Ready to be merged ?

DBraun commented 9 months ago

Yea I’m ok with the code.

sletz commented 9 months ago

Thanks, merged in https://github.com/grame-cncm/faustlibraries/commit/02634fca827173fb44dd1c4ec44fe8ddd8a2a6e3