improvements and freq modulation fix
This commit is contained in:
parent
9f4fad0707
commit
68a3024cfe
6 changed files with 76 additions and 31 deletions
|
|
@ -3,24 +3,17 @@ s.setup(10)
|
||||||
;0 s.left.@setgain(0.7)
|
;0 s.left.@setgain(0.7)
|
||||||
;0 s.right.@setgain(0.7)
|
;0 s.right.@setgain(0.7)
|
||||||
|
|
||||||
ns = []
|
sn = s.node(1)
|
||||||
for k in range(0, 9):
|
|
||||||
n = s.node(20)
|
|
||||||
ns.append(n)
|
|
||||||
;n->s.left
|
|
||||||
;n->s.right
|
|
||||||
|
|
||||||
;0 n.@setgain(0.04)
|
;0 sn.@setfreq(0, 4)
|
||||||
|
;0-10 sn.sine()
|
||||||
|
|
||||||
;0 n.setpos(1,1,1)
|
sn2 = s.node(1)
|
||||||
;0 n.setpin(52, 0.9)
|
|
||||||
|
|
||||||
for i in range(0,40):
|
|
||||||
;0 n.@setfreq(i, s.note("C3")*(i+1))
|
|
||||||
;0 n.@setfreqgain(i, 1/float(i+1))
|
|
||||||
;n-/>s.left
|
|
||||||
;n-/>s.right
|
|
||||||
|
|
||||||
;ns[4]->s.left
|
;0 sn>sn2.link(0, 10)
|
||||||
;ns[4]->s.right
|
;0 sn2.@wire_lr()
|
||||||
;0-90 ns[4].sine()
|
;0 sn2.@setfreq(0,440)
|
||||||
|
;0-10 sn2.rerange(10, 64, -1, 1, 400, 500)
|
||||||
|
|
||||||
|
;0-10 sn2.triangle()
|
||||||
|
|
@ -42,6 +42,14 @@ class SoundNode:
|
||||||
def act(self, *args):
|
def act(self, *args):
|
||||||
self.c.add_activity(*args)
|
self.c.add_activity(*args)
|
||||||
|
|
||||||
|
def wire_lr(self, *args):
|
||||||
|
self.act("link", 0, 0, self, self.s.left, [0, 1])
|
||||||
|
self.act("link", 0, 0, self, self.s.right, [0, 1])
|
||||||
|
|
||||||
|
def air_lr(self, *args):
|
||||||
|
self.act("link", 0, 0, self, self.s.left, [0, 2])
|
||||||
|
self.act("link", 0, 0, self, self.s.right, [0, 2])
|
||||||
|
|
||||||
def setfreq(self, starttick, endtick, args):
|
def setfreq(self, starttick, endtick, args):
|
||||||
freq_no = args[0]
|
freq_no = args[0]
|
||||||
freq = args[1]
|
freq = args[1]
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ pub fn sine(self: *Activity) void {
|
||||||
|
|
||||||
const gain = self.soundnode.pins[freq_pin + 48];
|
const gain = self.soundnode.pins[freq_pin + 48];
|
||||||
const shift = self.soundnode.pins[freq_pin + 96];
|
const shift = self.soundnode.pins[freq_pin + 96];
|
||||||
const phase = self.soundnode.pins[freq_pin + 114];
|
const phase = self.soundnode.pins[freq_pin + 144];
|
||||||
|
|
||||||
const totalphase = self.soundnode.pins[33] + shift + phase;
|
const totalphase = self.soundnode.pins[33] + shift + phase;
|
||||||
|
|
||||||
const amp = math.sin(utility.corrected_tau * self.soundnode.pins[freq_pin] * current_tick - totalphase * utility.tau);
|
const amp = math.sin(utility.corrected_tau * self.soundnode.pins[freq_pin] * current_tick - totalphase * utility.tau);
|
||||||
|
|
@ -46,7 +47,7 @@ pub fn triangle(self: *Activity) void {
|
||||||
|
|
||||||
const gain = self.soundnode.pins[freq_pin + 48];
|
const gain = self.soundnode.pins[freq_pin + 48];
|
||||||
const shift = self.soundnode.pins[freq_pin + 96];
|
const shift = self.soundnode.pins[freq_pin + 96];
|
||||||
const phase = self.soundnode.pins[freq_pin + 114];
|
const phase = self.soundnode.pins[freq_pin + 144];
|
||||||
|
|
||||||
const totalphase = self.soundnode.pins[33] + shift + phase;
|
const totalphase = self.soundnode.pins[33] + shift + phase;
|
||||||
|
|
||||||
|
|
@ -75,7 +76,7 @@ pub fn square(self: *Activity) void {
|
||||||
|
|
||||||
const gain = self.soundnode.pins[freq_pin + 48];
|
const gain = self.soundnode.pins[freq_pin + 48];
|
||||||
const shift = self.soundnode.pins[freq_pin + 96];
|
const shift = self.soundnode.pins[freq_pin + 96];
|
||||||
const phase = self.soundnode.pins[freq_pin + 114];
|
const phase = self.soundnode.pins[freq_pin + 144];
|
||||||
|
|
||||||
const totalphase = self.soundnode.pins[33] + shift + phase;
|
const totalphase = self.soundnode.pins[33] + shift + phase;
|
||||||
|
|
||||||
|
|
@ -106,7 +107,7 @@ pub fn sawtooth(self: *Activity) void {
|
||||||
|
|
||||||
const gain = self.soundnode.pins[freq_pin + 48];
|
const gain = self.soundnode.pins[freq_pin + 48];
|
||||||
const shift = self.soundnode.pins[freq_pin + 96];
|
const shift = self.soundnode.pins[freq_pin + 96];
|
||||||
const phase = self.soundnode.pins[freq_pin + 114];
|
const phase = self.soundnode.pins[freq_pin + 144];
|
||||||
|
|
||||||
const totalphase = self.soundnode.pins[33] + shift + phase;
|
const totalphase = self.soundnode.pins[33] + shift + phase;
|
||||||
|
|
||||||
|
|
@ -138,7 +139,7 @@ pub fn skewsine(self: *Activity) void {
|
||||||
|
|
||||||
const gain = self.soundnode.pins[freq_pin + 48];
|
const gain = self.soundnode.pins[freq_pin + 48];
|
||||||
const shift = self.soundnode.pins[freq_pin + 96];
|
const shift = self.soundnode.pins[freq_pin + 96];
|
||||||
const phase = self.soundnode.pins[freq_pin + 114];
|
const phase = self.soundnode.pins[freq_pin + 144];
|
||||||
|
|
||||||
const totalphase = self.soundnode.pins[33] + shift + phase;
|
const totalphase = self.soundnode.pins[33] + shift + phase;
|
||||||
|
|
||||||
|
|
@ -172,9 +173,8 @@ pub fn pulse(self: *Activity) void {
|
||||||
|
|
||||||
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
||||||
|
|
||||||
const maingain = self.soundnode.corrGain(self.operands[0]);
|
const pulse_shift = self.soundnode.pins[@intFromFloat(self.operands[0])];
|
||||||
|
const maingain = self.soundnode.corrGain(self.operands[1]);
|
||||||
const pulse_shift = self.soundnode.pins[@intFromFloat(self.operands[1])];
|
|
||||||
|
|
||||||
var final_amp: f64 = 0;
|
var final_amp: f64 = 0;
|
||||||
|
|
||||||
|
|
@ -209,8 +209,8 @@ pub fn whitenoise(self: *Activity) void {
|
||||||
|
|
||||||
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
||||||
|
|
||||||
const seed = self.soundnode.pins[@intFromFloat(self.operands[1])];
|
const seed = self.soundnode.pins[@intFromFloat(self.operands[0])];
|
||||||
const maingain = self.soundnode.corrGain(self.operands[0]);
|
const maingain = self.soundnode.corrGain(self.operands[1]);
|
||||||
|
|
||||||
const w = (seed*current_tick) / math.sin(current_tick);
|
const w = (seed*current_tick) / math.sin(current_tick);
|
||||||
const amp = (2 * (w - @floor(w))) - 1;
|
const amp = (2 * (w - @floor(w))) - 1;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ pub const Activity = struct {
|
||||||
4 => { self.relay(); },
|
4 => { self.relay(); },
|
||||||
5 => { self.copy(); },
|
5 => { self.copy(); },
|
||||||
6 => { self.mute(); },
|
6 => { self.mute(); },
|
||||||
|
7 => { self.rerange(); },
|
||||||
|
|
||||||
10 => { spatial.setpos(self); },
|
10 => { spatial.setpos(self); },
|
||||||
|
|
||||||
|
|
@ -96,6 +97,48 @@ pub const Activity = struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rerange(self: *Activity) void {
|
||||||
|
|
||||||
|
const from_pin: usize = @intFromFloat(self.operands[0]);
|
||||||
|
const to_pin: usize = @intFromFloat(self.operands[1]);
|
||||||
|
|
||||||
|
const from_lo = self.operands[2];
|
||||||
|
const from_hi = self.operands[3];
|
||||||
|
const to_lo = self.operands[4];
|
||||||
|
const to_hi = self.operands[5];
|
||||||
|
|
||||||
|
// Special case: setting freq results in setting calculating new phase too
|
||||||
|
if (to_pin >= 64 and to_pin < 112) {
|
||||||
|
|
||||||
|
const freq_no = to_pin - 64;
|
||||||
|
|
||||||
|
const fcurrent_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
||||||
|
const prevphase = self.soundnode.pins[208 + freq_no];
|
||||||
|
const prevfreq = self.soundnode.pins[to_pin];
|
||||||
|
|
||||||
|
//const newfreq = self.soundnode.pins[from_pin];
|
||||||
|
|
||||||
|
const share = (self.soundnode.pins[from_pin] - from_lo) / (from_hi - from_lo);
|
||||||
|
const newfreq = to_lo + ((to_hi - to_lo) * share);
|
||||||
|
//print("ORIG {d} SHARE {d} NEWFREQ {d} ", .{self.soundnode.pins[from_pin], share, newfreq});
|
||||||
|
|
||||||
|
self.soundnode.pins[to_pin] = newfreq;
|
||||||
|
|
||||||
|
const c = fcurrent_tick / 44100;
|
||||||
|
const pp = prevphase + c * (newfreq - prevfreq) + @floor(c * prevfreq - prevphase);
|
||||||
|
|
||||||
|
//print("OLDPHASE {d} NEWPHASE {d} :: ", .{self.soundnode.pins[208 + freq_no], pp - @floor(pp)});
|
||||||
|
self.soundnode.pins[208 + freq_no] = pp - @floor(pp);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const share = (self.soundnode.pins[from_pin] - from_lo) / (from_hi - from_lo);
|
||||||
|
self.soundnode.pins[to_pin] = to_lo + ((to_hi - to_lo) * share);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mute(self: *Activity) void {
|
pub fn mute(self: *Activity) void {
|
||||||
|
|
||||||
self.soundnode.fab.set_r_amp(0);
|
self.soundnode.fab.set_r_amp(0);
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,7 @@ pub fn main() !void {
|
||||||
const freq_q: u8 = @truncate(trg_node);
|
const freq_q: u8 = @truncate(trg_node);
|
||||||
|
|
||||||
const sn = try SoundNode.create(allocator, uid, freq_q);
|
const sn = try SoundNode.create(allocator, uid, freq_q);
|
||||||
|
sn.pins[32]=1;
|
||||||
|
|
||||||
//print("Added node {s} at tick {d}\n", .{nodename, tick});
|
//print("Added node {s} at tick {d}\n", .{nodename, tick});
|
||||||
try soundnodes.append(sn);
|
try soundnodes.append(sn);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ pub const SoundNode = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
//Gain and per-freq gains must be initialized as 1
|
//Gain and per-freq gains must be initialized as 1
|
||||||
|
sn.pins[32] = 1;
|
||||||
@memset(sn.pins[112..160], 1);
|
@memset(sn.pins[112..160], 1);
|
||||||
|
|
||||||
return sn;
|
return sn;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue