hey, ive found this code somewhere in the web for avoiding aliasing when dealing with non linear wave shaping and thought it would be capable of suppressing the alias for extreme horizontal
values (near 0 or 1) for my attempt to write the vector phase shaping synthesis algorithm Phaseshaping Osc Algorithms - #42 by dietcv.
its working really nice on a linear ramp signal which is basically more or less we are dealing with in vector phase shaping (altered version of phase distortion).
is there someone who could help me adjusting the code for avoiding alias to use it for my VPS attempt? I already formatted the code and tried to write it in a more condensed way. Im not so sure about BufRd
and BufWr
because in the VPS attempt im not using any external buffers. any help would be very much appreciated.
Code for avoiding alias:
(
a = Array.interpolation(1000, 0.0, 1.0);
b = Buffer.sendCollection(s, a, 1);
a.plot;
)
//use an envelope with shifting points in order to dynamically change the transfer function
(
{
var bufFrames = BufFrames.ir(b.bufnum);
var sampleDur = SampleDur.ir;
var bufInputFreq = sampleDur * bufFrames;
/*
1.) use these points (modPoints) for the env levels – one extra last one (release node) so that the env loops properly
2.) make an envelope which will result in a warped transfer function
*/
var modPoints = [-1.0, -0.2, -0.5, 0.9, 1.0, 1.0];
// uncomment to replace the points with modulating values
//5.do { |i| modPoints = SinOsc.kr(ExpRand(0.1, 0.8), Rand(0.0, 6.28)).range(-0.9, 0.9)};
var env = Env(modPoints, [0.25, 0.25, 0.25, 0.25, 0.0], [2, -4, 7, -5, 0], 4, 0);
var bufInput = EnvGen.ar(env, timeScale: bufInputFreq);
var freq, sig, thisIndex, pos, playHead, output;
freq = MouseX.kr(20, 1000, 1).poll;
sig = SinOsc.ar(freq, 0, 0.8);
thisIndex = LinLin.ar(sig, -1.0, 1.0, 0.0, bufFrames);
// 3.) write the envelope (bufInput) into the buffer that is being used as the transfer function
pos = Phasor.ar(0, BufRateScale.kr(b.bufnum), 0, bufFrames);
BufWr.ar(bufInput, b.bufnum, pos);
playHead = BufRd.ar(1, b.bufnum, thisIndex, 0, 4);
output = LeakDC.ar(playHead);
output ! 2;
}.scope;
)
VPS attempt (note with this example the value for vertical
can only between two whole numbers like 2.001 and 2.999. im working on that.
(
{
arg freq = 300;
var horizontal = MouseX.kr(0.01,0.99);
var vertical = \vertical.kr(2.5);
var cos, phasor;
phasor = LFSaw.ar(freq/2,1).range(horizontal.neg, 1-horizontal);
phasor = phasor.bilin(0, horizontal.neg, 1-horizontal, vertical, 0, 1);
cos = Select.ar(phasor > vertical.floor,
[
(phasor * 2pi).cos.neg,
((phasor.abs.wrap(0,1)/(vertical-vertical.floor)*pi).cos*(vertical-vertical.floor)).neg-(vertical.ceil-vertical)
]
);
cos!2 * 0.1;
}.scope;
)