TGrains family Ugen and pitch

Hello,
First of all thanks a lot for providing the TGrain UGen, it is a lot of fun working with them.

As my maths are gone a long time ago, I was wondering if someone could explain me how to set the pitch of a grain to the nearest pitch value in in a scale. Maybe clearer :
A potentiometer is sending a value in [0,1],
(Pot_Value * 4) - 2 brings the interval to [-2,2] so with Tgrain, its means the value applied to “rate” can shift the pitch of the grain from “reversed” 2 octaves higher to 2 octaves higher.
Now, I would like to round these values to the nearest semi-tone, how can I achieve this ( if values is for example 1.2456… what is the nearest note pitch)?

Thank you for help ( I am sure the anser is trivial but I can’t get it )

A useful thing for modulating “rate” style parameters to musically sensible intervals is the midiratio method. This converts a MIDI interval in semitones to a ratio that can be used directly to change the rate of playback to produce this interval:

TGrains.ar(
    // ...
    rate: -3.midiratio // pitch down by 3 semitones
);

modulator = SinOsc.kr(1/10);
TGrains.ar(
    // ...
    rate: modulator.range(-10, 10).round(3).midiratio // scale to +-10 semitones, and round
);

Hello,
Thank you a lot for your help. I am not sure I understand well ; The rate in TGrain Ugen is not very clear to me. My understanding is :
1 = Actual value of the pitch,
0.5 = 1 octave lower
2 = 1 Octave higher ( this is what the helpfile says)

So I suppose that 0.25 is 2 octaves lower and 0.125 is 3 octaves lower ( somehow , this is also what I hear). In that case how can “midiratio” apply as the intervals are not linear but a power of 2 ?

Or am I totally wrong ?

x.midiratio = 2 ** (x/12)

Edit: rate is a multiplier for frequency – so the exponential conversion is appropriate.

hjh

1 Like