An alternative is to construct an empirical test, and observe the result.
Here, we could guess that casting float to int is probably either truncation (1.1 → 1, 1.9 → 1) or rounding (1.1 → 1, 1.9 → 2), because nothing else quite makes sense. If it’s truncation, then breakpoints would be at integer boundaries, so a test range would need to span at least one integer bound. If it’s rounding, then breakpoints are at k + 0.5 (k is int). So if you run numharm between, say, 1.0 and 3.0, then it would cross 1.5 and 2.5 (testing rounding) and 2.0 (testing truncation).
{
var nh = Line.ar(1, 3, 0.1);
[nh, Blip.ar(440, nh)]
}.plot(0.1);
… and then it becomes clear that the waveform changes when nh crosses from < 2.0 to >= 2.0.
So the float → int behavior is truncation (which is the normal behavior in C for int x = someFloat
).
I find it helpful to think in terms of signal ranges.
- Pulse (in theory) ranges from -1 to +1. (In practice, it stabilizes to about -0.5 to +0.5, but, because it’s a band limited oscillator, it’s subject to Gibbs effect wiggling at the corners, so it won’t be exactly ± 0.5.)
- How do I know ± 0.5? Again, empirical testing: plot, and look.
- Frequency modulation of the pulse wave should not affect its amplitude. So you don’t need to worry about that.
- Amplitude modulation (mul) does affect its amplitude.
- MouseY’s inputs specify a range 0 to 1.
- ± 0.5 * 0 = 0 only.
- ± 0.5 * 0.5 = ± 0.25.
- etc… so the pulse now has a minimum amplitude 0, and maximum ~0.5.
- Then,
range
. This depends on Pulse’s signalRange
, which is bipolar (± 1). So that range
instruction translates to “scale ± 1 onto 1–10.”
- ± 1 spans 2 units. 1–10 spans 9 units.
x * 4.5
produces ± 4.5 = the desired 9 unit span.
- This is 5.5 lower than desired, so
x * 4.5 + 5.5
.
-
range
(using linlin
) does this internally for you.
- But the input range is roughly ± 0.5, not ± 1.0. So you’d really get:
[-0.5, 0.5] * 4.5 + 5.5
-> [ 3.25, 7.75 ]
Which, when truncated to integer, means 3 to 7 harmonics.
(Probably Pulse is a typo. For an LFO, LFPulse would be a better choice. But, LFPulse is a unipolar oscillator, so the details of the math would work out differently.)
hjh