improvements

This commit is contained in:
aprilnightk 2025-09-20 23:53:16 +03:00
parent 58ac740143
commit 9f4fad0707
6 changed files with 120 additions and 70 deletions

View file

@ -1,10 +1,10 @@
s.setup(100)
s.setup(10)
;0 s.left.@setgain(0.7)
;0 s.right.@setgain(0.7)
ns = []
for k in range(0, 100):
for k in range(0, 9):
n = s.node(20)
ns.append(n)
;n->s.left
@ -15,8 +15,12 @@ for k in range(0, 100):
;0 n.setpos(1,1,1)
;0 n.setpin(52, 0.9)
for i in range(0,20):
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
;0-9 ns[4].sine()
;ns[4]->s.left
;ns[4]->s.right
;0-90 ns[4].sine()

View file

@ -5,6 +5,7 @@ OPCODES['create'] = 0
OPCODES['endtick'] = 2
OPCODES['link'] = 1
OPCODES['setpin'] = 3
OPCODES['unlink'] = 8
OPCODES['printstate'] = 9
with open("zigsonnum/activity.zig", 'r') as zigfl:

View file

@ -55,6 +55,16 @@ class SonnumCompiler:
name_src, name_trg = ln[1:].split('->')
ln = f'self.add_activity("link", 0, 0, {name_src}, {name_trg}, [0, 2])'
elif '=/>' in ln:
name_src, name_trg = ln[1:].split('=/>')
ln = f'self.add_activity("unlink", 0, 0, {name_src}, {name_trg}, [0, 1])'
elif '-/>' in ln:
name_src, name_trg = ln[1:].split('-/>')
ln = f'self.add_activity("unlink", 0, 0, {name_src}, {name_trg}, [0, 2])'
else:
ln = ln[1:]

View file

@ -156,9 +156,12 @@ pub fn main() !void {
print("{d}-- ", .{tick/44100});
}
for (soundnodes.items, 0..) |soundnode, i| {
soundnode.nullizeStartTick();
for (a_soundnodes.items, 0..) |soundnode, i| {
//print("TICK {d} I {d} ", .{tick, i});
@memset(soundnode.pins[0..32], 0);
_ = i;
}
if (tick == nextopcodetick) {
@ -272,6 +275,31 @@ pub fn main() !void {
},
8 => {
const src = soundnodes.items[src_node];
const trg = soundnodes.items[trg_node];
//print("Wired nodes at tick {d}\n", .{tick});
const src_pin: usize = @intFromFloat(op1);
const trg_pin: usize = @intFromFloat(op2);
var found: bool = false;
var toremove: u64 = 0;
for (trg.links.items, 0..) |link, j| {
if (link.src_node == src and link.trg_node == trg and link.src_pin == src_pin and link.trg_pin == trg_pin) {
toremove = j;
found = true;
break;
}
}
if (found) {
_ = trg.links.orderedRemove(toremove);
}
},
else => {
const soundnode = soundnodes.items[src_node];
@ -281,6 +309,7 @@ pub fn main() !void {
try soundnode.activities.append(a);
if (soundnode.activities.items.len == 1 and soundnode.active == 0) {
soundnode.active = 1;
try reactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
@ -296,17 +325,21 @@ pub fn main() !void {
}
//All but left and right
if (a_soundnodes.items.len > 2) {
var iter: usize = 1;
//while (iter < 0) {
for (a_soundnodes.items[2..], 0..) |soundnode, i| {
while (iter < a_soundnodes.items.len - 1) {
iter += 1;
const soundnode = a_soundnodes.items[iter];
for (soundnode.links.items, 0..) |link, j| {
if (link.src_node.active == 1 or link.trg_pin == 1) {
link.propagate();
}
_ = j;
}
@ -330,7 +363,12 @@ pub fn main() !void {
var j: usize = toremove.items.len;
if (j == 0) {
soundnode.fab.increment_tick();
}
while (j > 0) {
j -= 1;
const activity_ind = toremove.items[j];
@ -341,13 +379,10 @@ pub fn main() !void {
soundnode.active = 0;
try deactivateSoundNode(&a_soundnodes, &p_soundnodes, soundnode);
//print("DEACTIVATING {d} AT TICK {d} ", .{soundnode.uid, tick});
}
}
soundnode.fab.increment_tick();
_ = i;
}
}
// Incrementing passive ones too
@ -355,11 +390,18 @@ pub fn main() !void {
for (p_soundnodes.items, 0..) |soundnode, i| {
soundnode.fab.increment_tick();
_ = i;
}
//Left and right
for (soundnodes.items[0..2], 0..) |soundnode, i| {
iter = 0;
//while (iter < 0) {
while (iter < 2) {
const soundnode = soundnodes.items[iter];
iter += 1;
for (soundnode.links.items, 0..) |link, jz| {
if (link.src_node.active == 1 or link.trg_pin == 1) {
@ -394,7 +436,6 @@ pub fn main() !void {
_ = soundnode.activities.swapRemove(activity_ind);
}
_ = i;
}
//Calculating and writing output amps
@ -426,6 +467,8 @@ pub fn main() !void {
left.fab.current_tick += 1;
right.fab.current_tick += 1;
tick += 1;
}

View file

@ -36,7 +36,7 @@ pub const SoundNode = struct {
wantprint: bool = false,
fab: FreqAmpBuffer,
active: u8 = 1,
active: u8 = 0,
pub fn create(allocator: Allocator, uid: usize, freq_q: u8) !*SoundNode {
@ -68,7 +68,6 @@ pub const SoundNode = struct {
//Gain and per-freq gains must be initialized as 1
sn.pins[32] = 1;
@memset(sn.pins[112..160], 1);
return sn;
@ -84,13 +83,6 @@ pub const SoundNode = struct {
}
pub fn nullizeStartTick(self: *SoundNode) void {
// Zeroing the first 32 pins (dynamic pins)
@memset(self.pins[0..32], 0);
}
pub fn corrGain(self: *SoundNode, gainmult: f64) f64 {
if (gainmult > 0) {