adsr + basicsynths fix
This commit is contained in:
parent
68a3024cfe
commit
1981f243ed
6 changed files with 151 additions and 90 deletions
|
|
@ -8,12 +8,22 @@ sn = s.node(1)
|
|||
;0 sn.@setfreq(0, 4)
|
||||
;0-10 sn.sine()
|
||||
|
||||
sn2 = s.node(1)
|
||||
sn2 = s.node(2)
|
||||
|
||||
;sn:0 >> sn2:10
|
||||
|
||||
;0 sn>sn2.link(0, 10)
|
||||
;0 sn2.@wire_lr()
|
||||
;0 sn2.@setfreq(0,440)
|
||||
;0-10 sn2.rerange(10, 64, -1, 1, 400, 500)
|
||||
;0 sn2.@setfreq(0,400)
|
||||
;0 sn2.@setfreq(1,800)
|
||||
|
||||
;0-10 sn2.triangle()
|
||||
;0-10 sn2:10:-1/1 ::> fp(0):396/404
|
||||
;0-10 sn2:10:-1/1 ::> fp(1):795/806
|
||||
|
||||
;0 sn2.setpin(40, 0.9)
|
||||
;0 sn2.setpin(41, 0.4)
|
||||
|
||||
;0-10 sn2:10:-1/1 ::> 35:0.1/0.9
|
||||
;0-10 sn2.adsr(sec(0.1), sec(0.2), sec(0.3), sec(0.4), sec(0.5))
|
||||
|
||||
;0-10 sn2.triangle(0.5)
|
||||
;0-10 sn2.sine(0.5)
|
||||
|
|
@ -65,6 +65,40 @@ class SonnumCompiler:
|
|||
name_src, name_trg = ln[1:].split('-/>')
|
||||
ln = f'self.add_activity("unlink", 0, 0, {name_src}, {name_trg}, [0, 2])'
|
||||
|
||||
elif '>>' in ln:
|
||||
|
||||
name_src, name_trg = ln[1:].split('>>')
|
||||
name_src, pin_src = name_src.split(':')
|
||||
name_trg, pin_trg = name_trg.split(':')
|
||||
ln = f'self.add_activity("link", 0, 0, {name_src}, {name_trg}, [{pin_src}, {pin_trg}])'
|
||||
|
||||
elif '::>' in ln:
|
||||
tickdata, cmd = ln[1:].split(' ',1)
|
||||
|
||||
if '-' in tickdata:
|
||||
starttick, endtick = tickdata.split('-', 1)
|
||||
else:
|
||||
starttick = tickdata
|
||||
endtick = starttick
|
||||
name_src, name_trg = cmd.split('::>')
|
||||
name_src, pin_src, rangepair_src = name_src.split(':')
|
||||
pin_trg, rangepair_trg = name_trg.split(':')
|
||||
from_src, from_trg = rangepair_src.split('/')
|
||||
to_src, to_trg = rangepair_trg.split('/')
|
||||
ln = f'self.add_activity("rerange", sec({starttick}), sec({endtick}), {name_src}, {name_src}, [{pin_src}, {pin_trg}, {from_src}, {from_trg}, {to_src}, {to_trg}])'
|
||||
|
||||
elif ':>' in ln:
|
||||
tickdata, cmd = ln[1:].split(' ',1)
|
||||
|
||||
if '-' in tickdata:
|
||||
starttick, endtick = tickdata.split('-', 1)
|
||||
else:
|
||||
starttick = tickdata
|
||||
endtick = starttick
|
||||
name_src, pin_trg = cmd.split(':>')
|
||||
name_src, pin_src = name_src.split(':')
|
||||
ln = f'self.add_activity("copy", sec({starttick}), sec({endtick}), {name_src}, None, [{pin_src}, {pin_trg}])'
|
||||
|
||||
else:
|
||||
|
||||
ln = ln[1:]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,15 @@ def gainpin(freq_no):
|
|||
def shiftpin(freq_no):
|
||||
return 160+freq_no
|
||||
|
||||
def fp(freq_no):
|
||||
return 64+freq_no
|
||||
|
||||
def gp(freq_no):
|
||||
return 112+freq_no
|
||||
|
||||
def sp(freq_no):
|
||||
return 160+freq_no
|
||||
|
||||
def sec(seconds):
|
||||
return seconds * 44100
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub fn sine(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 144];
|
||||
|
|
@ -27,7 +28,7 @@ pub fn sine(self: *Activity) void {
|
|||
|
||||
const amp = math.sin(utility.corrected_tau * self.soundnode.pins[freq_pin] * current_tick - totalphase * utility.tau);
|
||||
final_amp += maingain * gain * amp;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
|
@ -45,6 +46,7 @@ pub fn triangle(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 144];
|
||||
|
|
@ -56,7 +58,7 @@ pub fn triangle(self: *Activity) void {
|
|||
|
||||
const amp = @abs(2 * (2 * ( tp - @floor(tp + 0.5) ) )) - 1;
|
||||
final_amp += maingain * gain * amp;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
|
@ -74,6 +76,7 @@ pub fn square(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 144];
|
||||
|
|
@ -87,6 +90,7 @@ pub fn square(self: *Activity) void {
|
|||
} else {
|
||||
final_amp += -(maingain * gain);
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
||||
|
|
@ -105,6 +109,7 @@ pub fn sawtooth(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 144];
|
||||
|
|
@ -116,7 +121,7 @@ pub fn sawtooth(self: *Activity) void {
|
|||
|
||||
const amp = 2 * (tp - @floor(0.5+tp));
|
||||
final_amp += maingain * gain * amp;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
|
@ -137,6 +142,7 @@ pub fn skewsine(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 144];
|
||||
|
|
@ -160,7 +166,7 @@ pub fn skewsine(self: *Activity) void {
|
|||
final_amp += maingain * gain * (1/skew) * math.atan(sincos);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
|
@ -181,6 +187,7 @@ pub fn pulse(self: *Activity) void {
|
|||
const max_freq_pin = 64 + self.soundnode.freq_q;
|
||||
for (64..max_freq_pin) |freq_pin| {
|
||||
|
||||
if (self.soundnode.pins[freq_pin] > 0) {
|
||||
const gain = self.soundnode.pins[freq_pin + 48];
|
||||
const shift = self.soundnode.pins[freq_pin + 96];
|
||||
const phase = self.soundnode.pins[freq_pin + 114];
|
||||
|
|
@ -195,7 +202,7 @@ pub fn pulse(self: *Activity) void {
|
|||
const amp_detract = 2 * (tp_detract - @floor(0.5+tp_detract));
|
||||
|
||||
final_amp += maingain * gain * (amp - amp_detract);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self.soundnode.add_r_amp(final_amp);
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ pub fn singenN(self: *Activity) void {
|
|||
}
|
||||
|
||||
// Generates a linear ADSR envelope (range 0) to GAIN
|
||||
// Takes attack gain from OUT8
|
||||
// Takes sustain gain from OUT9
|
||||
// Takes attack gain from pin 40
|
||||
// Takes sustain gain from pin 41
|
||||
// Tick count starts from 0, as if start_tick was 0
|
||||
pub fn adsr(self: *Activity) void {
|
||||
|
||||
|
|
@ -40,8 +40,8 @@ pub fn adsr(self: *Activity) void {
|
|||
const start_tick: f64 = @floatFromInt(self.start_tick);
|
||||
const current_tick = real_current_tick - start_tick;
|
||||
|
||||
var adsrgain = self.soundnode.out8;
|
||||
const adsrsustain = self.soundnode.out9;
|
||||
var adsrgain = self.soundnode.pins[40];
|
||||
var adsrsustain = self.soundnode.pins[41];
|
||||
|
||||
const attack_tick = self.operands[0];
|
||||
const hold_tick = self.operands[1];
|
||||
|
|
@ -52,6 +52,7 @@ pub fn adsr(self: *Activity) void {
|
|||
|
||||
if (gainmult > 0) {
|
||||
adsrgain *= gainmult;
|
||||
adsrsustain *= gainmult;
|
||||
}
|
||||
|
||||
var gain: f64 = 0;
|
||||
|
|
@ -68,6 +69,6 @@ pub fn adsr(self: *Activity) void {
|
|||
gain = (adsrsustain * (current_tick - sustain_tick) / (sustain_tick - release_tick)) + adsrsustain;
|
||||
}
|
||||
|
||||
self.soundnode.gain = gain;
|
||||
self.soundnode.pins[32] = gain;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ pub const Activity = struct {
|
|||
56 => { basicsynths.whitenoise(self); },
|
||||
|
||||
//100 => { generators.singenN(self); },
|
||||
//150 => { generators.adsr(self); },
|
||||
150 => { generators.adsr(self); },
|
||||
//ENDOPCODES
|
||||
else => {},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue