interface RenderFrequencySample { public default double get aka renderFrequencySample(Complex c, double frac); default void subtractPeriodFrom(IAddPlateau audio, DoubleRange period, Frequency f, Complex intensity) { int i1 = ifloor(period.start), i2 = ifloor(period.end); new LPair pairs; for (int i = i1; i < i2; i++) addPair(pairs, doubleRangeWithLength(i, 1), renderPeriodSample(period, f, intensity, i, false)); for (DoubleRange r, double amplitude : unpair concatenateAdjacentDoubleRanges(pairs)) audio.addPlateau(r.start, r.end, amplitude); } default double renderPeriodSample(DoubleRange period, Frequency f, Complex intensity, double t, bool shouldPrint) { double n = l(period); Complex c = div(intensity, n); double t2 = t-period.start; double frac = t2/n; if (shouldPrint) printVars(+f, +t, interval := n, +t, +t2, frac := formatDouble2(frac), c := renderComplexWithAngle(div(c, 32768))); /*if (realOnly) c = complex(c.re()); else if (imagOnly) c = complex(0, c.im());*/ ret renderFrequencySample(c, frac); } public default void addPeriodTo(double[] samples, DoubleRange period, Frequency f, Complex intensity) { if (samples == null) ret; subtractPeriodFrom(new IAddPlateau { public void addPlateau(double start, double end, double intensity) { int i1 = ifloor(start), i2 = ifloor(end); for (int i = i1; i < i2; i++) samples[i] += intensity; } }, period, f, minus(intensity)); } }