RobinSchmidt / RS-MET

Codebase for RS-MET products (Robin Schmidt's Music Engineering Tools)
Other
56 stars 6 forks source link

stepped portamento with variable slide? how would you do it? #143

Open elanhickler opened 6 years ago

elanhickler commented 6 years ago

So, I need to implement stepped portamento as another glide mode. The simplest implementation is simply quantizing the pitch always to the nearest note and pitch changes, but I want to do a kind of "variable quantization / slide" into the note.

So, instead of hard quantization, you would have some sliding going on between pitches.

Hmm... maybe I'd have to pre-generate a graph?

image

How would you do it?

elanhickler commented 6 years ago

I'd want to be able to change smoothing amount PREFERABLY real-time, rather than re-generating the entire graph.

elanhickler commented 6 years ago
double offsetPitchByCurve (double inputPitch, double tension)
{
    double quantizedPitch = floor(inputPitch);
    double normalizedDistanceToQuantizedPitch = inputPitch - quantizedPitch ;
    return quantizedPitch + sigmoidCurve(normalizedDistanceToQuantizedPitch, tension);
}

something like that? How do you create a sigmoid curve math to give you value of 0 to 1? Or what would you use? Hmm, maybe I should use my curve... i forget what you call it. rational curve?

https://www.desmos.com/calculator/zoiuus4nyz

RobinSchmidt commented 6 years ago

yes, rational. a "rational function" is a ratio of two polynomials: https://en.wikipedia.org/wiki/Rational_function, which is what this is. perhaps one could also call it "bilinear" (numerator and denominator are both linear functions of x). hmm...yeah...sounds reasonable to me. my first idea would perhaps have been using a lowpass for smoothing, but maybe a sigmoid function is better. how about making it more flexible by allowing not only integer semitone steps for the quantization but arbitrary (not necessarily equidistant) steps. ...of course, that would make the whole thing a lot more complicated but also musically more useful (you could set up certain allowed intervals)

elanhickler commented 6 years ago

oh yeah I actually need that feature, so you could do chord-based glissandos. The point of this is to emulate fret slides.

If you slide from C3 to C#3, that's easy, just apply a curve. Let's say you only allow Cs. Sliding from C3 to C4, you can't just apply the same curve. How do we solve this? Tension needs to be based on distance between enabled pitches. Maybe we don't need to solve it? Or maybe I just try different tension amounts per pitch distance (distance of 1 get a 0.5 tension, distance of 2 gets a 0.6 tension, distance of 12 gets .99 tension). Oh, actually it should be a tension multiplier so you can dial in the base desired tension.

image

RobinSchmidt commented 6 years ago

i think, you could perhaps let the user not set up the "tension" parameter "t" directly but instead a point in time (on the normalized 0...1 axis) at which, say 90% of the target value should be reached and then solve the equation for t. should be some simple algebra, i can do that for you, if you don't know how

RobinSchmidt commented 6 years ago

for example, set t=-0.8 and you reach 90% at x=0.5 (with the unipolar curve) https://www.desmos.com/calculator/zoiuus4nyz

RobinSchmidt commented 6 years ago

basically, what you have to do is to set y = 0.9 = f(x=0.5) = your function insert, for example, 0.5 for x and 0.9 for y into the formula and solve for t

elanhickler commented 6 years ago

Let me implement the initial idea before we get crazy with the maths.