Linear interpolating wavetable lookup oscillator with frequency modulation input.
osc = T("osc", wave="sin", freq=440, mul=1, add=0);
// wave [String / Function / Float32Array]
// freq [Object] Frequency
// mul [Number] Multiply the output (default is 1)
// add [Number] and add the output (default is 0)
osc.play();
osc.wave // [String / Function / Float32Array]
osc.freq // [Object] Frequency
osc.phase // [Number] Initial phase offset
osc.mul // [Number] Output will be multiplied by this value
osc.add // [Number] and will be added to the output
// Reset phase
osc.bang();
wave = ["sin", "tri", "saw", "pulse", "fami"][(Math.random()*5)|0];
T("osc", wave, 660, 0.5).play();
// The oscillator class has some aliases.
T("sin"), T("tri"), T("saw"), T("pulse"), T("fami");
// It's same as the above code.
T(wave, 1320, 0.5).play();
// (push [bang] button to change the wave)
// Define custom wavetable from a function
func = function(x) { return x * x * x; };
T("osc", func, 880).play();
// From an array (PWM25%)
T("osc", [ -1, +1, +1, +1 ], 880);
// Directly set
T("osc", new Float32Array(1024), 880);
// Register a wavetable and use it
T("osc").setWavetable("myosc", function(x) {
return Math.random() - 0.5;
});
T("osc", "myosc", 1340).play();
// Get a wavetable
// (push [bang] button and see the result at WebConsole)
T("osc").getWavetable("myosc"); // Float32Array(1024)
T("*", T("tri", 880, 0.25),
T("+sin", 8).kr()).play();
// kr() method switches to processing mode 'Control Rate'
// Control rate are used for low frequency or slowly chaning control signal.
// T("+sin") generate signals between 0.0 and 1.0.
// It's convenient to control amplitude.
// T("+sin"), T("+saw"), T("+tri") or T("+pulse")
T("tri", T("tri", 2, 30, 880).kr(), 0.25).play();
synth = T("fami", T("glide", msec=150, freq.value=880), 0.25).play();
// push [bang] button to execute the below code
cnt = 0;
synth.onbang = function() {
synth.freq.value = [880, 1320, 1100, 660][++cnt % 4]
};