From 3fe954288be58aa518e17f2ac4df5b8a7fb2d611 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 2 Jan 2021 21:05:16 +0100 Subject: Update utility SynthDefs classes/ZZZ.sc: Add \ZZZVCO with variants for triangle, pulse, saw, sine and sawsine to provide an easy to use VCO (not yet integrated into ZZZDevice) with different waveforms (on demand). Add (still rather experimental) \ZZZCV SynthDef with freqVO, freqHV, midiVO and midiHV variants for input via frequencies or MIDI notes and output to V/O or Hz/V (respectively). The SynthDef is still rather static and probably not really correct (see TODOs). Remove the obsolete SynthDefs \ZZZPerc and \ZZZConstant. They have been superseded by \ZZZClock/\ZZZClockKorg and \ZZZGate. Change all uses of the Out to OffsetOut Ugen for sample accuracy. --- classes/ZZZ.sc | 62 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 22 deletions(-) (limited to 'classes') diff --git a/classes/ZZZ.sc b/classes/ZZZ.sc index 24ba9a0..4d4d506 100644 --- a/classes/ZZZ.sc +++ b/classes/ZZZ.sc @@ -20,38 +20,56 @@ ZZZ{ *initClass{ StartUp.add{ SynthDef(\ZZZGate, {|bus = 0, in = 1.0, out = 0| - Out.ar( + OffsetOut.ar( out, DC.ar(in: in) * In.kr(bus) ); }).add; SynthDef(\ZZZClock, { |out = 0, bus = 0, iphase = 0, width = 0.5, mul = 1.0, add = 0.0| - Out.ar(out, LFPulse.ar(In.kr(bus), iphase, width, mul, add)); + OffsetOut.ar(out, LFPulse.ar(In.kr(bus), iphase, width, mul, add)); }).add; SynthDef(\ZZZClockKorg, { |out = 0, bus = 0, iphase = 0, width = 0.5, mul = 1.0, add = 0.0| - Out.ar(out, LFPulse.ar(In.kr(bus) * 2, iphase, width, mul, add)); + OffsetOut.ar(out, LFPulse.ar(In.kr(bus) * 2, iphase, width, mul, add)); }).add; - // adding SynthDef for constant notes - SynthDef(\ZZZConstant, { |out = 0, mul= 0.0| - Out.ar( + // TODO: revise mapping of ranges and how to shift reference point + // NOTE: https://kentonuk.com/support/midi-to-cv/ + // NOTE: https://soundprogramming.net/file-formats/midi-note-frequencies/ + // NOTE: https://web.archive.org/web/20100409063540/http://www.users.globalnet.co.uk/~concuss/mcvbeg.htm + SynthDef(\ZZZCV, { |out = 0, freq = 1, gate = 1, attackTime = 0.01, susLevel = 1.0, releaseTime = 0.3, midiAmpVO = 0.0, midiAmpHV = 0.0, freqAmpVO = 0.0, freqAmpHV = 0.0| + // midi to V/O (C-1 - G9) + var midiVO = LinLin.kr(in: freq, srclo: 0, srchi: 127, dstlo: -0.1, dsthi: 0.96666) * midiAmpVO, + // midi to Hz/V (C-1 - C5) + midiHV = LinExp.kr(in: freq, srclo: 0, srchi: 72, dstlo: 0.00625, dsthi: 0.8) * midiAmpHV, + // frequency to V/O (C-1 - G9) + freqVO = LinLin.kr(in: freq, srclo: 8.176, srchi: 12543.850, dstlo: -0.1, dsthi: 0.96666) * freqAmpVO, + // frequency to Hz/V (C-1 - C5) + freqHV = LinExp.kr(in: freq, srclo: 8.176, srchi: 523.251, dstlo: 0.00625, dsthi: 0.8) * freqAmpHV; + OffsetOut.ar( out, - Lag.ar( - LFPulse.ar( - 500, - 0, - 1), - 0.1, - mul - ) + // TODO: revise envelope to become more flexible + DC.ar(in: midiVO + midiHV + freqVO + freqHV) * Linen.kr(gate: gate, attackTime: attackTime, susLevel: susLevel, releaseTime: releaseTime, doneAction: Done.freeSelf) ); - }).add; - //adding synth for percussive environments (trigger, gate) - SynthDef(\ZZZPerc, { |out = 0, freq = 20000, amp = 0.0, attack = 0.001, release = 1, time = 1, curve = -4| - var signal, envelope; - envelope = EnvGen.kr(Env.perc(attack, release, amp, curve), doneAction: 2); - signal = SinOsc.ar(freq, 0, envelope); - Out.ar(out, signal); - }).add; + }, variants: ( + freqVO: [\freqAmpVO: 1.0], + freqHV: [\freqAmpHV: 1.0], + midiVO: [\midiAmpVO: 1.0], + midiHV: [\midiAmpHV: 1.0], + )).add; + SynthDef('ZZZVCO', {|out = 0, freq = 440, iphase = 0.0, width = 0.0, mul = 1.0, add = 0.0, triAmp = 0.0, pulseAmp = 0.0, sawAmp = 0.0, sineAmp = 0.0| + var triangle = LFTri.ar(freq: freq, iphase: iphase, mul: mul, add: add) * triAmp, + pulse = LFPulse.ar(freq: freq, iphase: iphase, width: width, mul: mul, add: add) * pulseAmp, + saw = LFSaw.ar(freq: freq, iphase: iphase, mul: mul, add: add) * sawAmp, + sine = SinOsc.ar(freq, 0, 0.5) * sineAmp; + OffsetOut.ar( + out, triangle + pulse + saw + sine + ) + }, variants: ( + triangle: [mul: 0.5, add: 0.0, triAmp: 1.0], + pulse: [width: 0.5, mul: 1.0, add: -0.5, pulseAmp: 1.0], + saw: [mul: 0.5, add: 0.0, sawAmp: 1.0], + sine: [mul: 0.5, add: 0.0, sineAmp: 1.0], + sawsine: [mul: 0.5, add: 0.0, sineAmp: 0.5, sawAmp: 0.5], + )).add; } } -- cgit v1.2.3-70-g09d2