working bridging, starting generators
This commit is contained in:
parent
1e2f8d78e8
commit
f5137de7bb
7 changed files with 106 additions and 10 deletions
|
|
@ -3,17 +3,15 @@ s.setup(s.sec(10))
|
|||
m = s.node()
|
||||
n = s.node()
|
||||
|
||||
s.pin(m, R_AMP, n, IN_GAIN)
|
||||
s.pin(m, BASEFREQ, n, IN_BASEFREQ)
|
||||
|
||||
m.setpin(0, BASEFREQ, 6)
|
||||
m.singenN(0, s.sec(10), 50.4, 0, 0.003, 440)
|
||||
|
||||
n.bridge(0, s.sec(10), IN_BASEFREQ, BASEFREQ)
|
||||
n.triangle(0, s.sec(10))
|
||||
|
||||
n.setpin(0, BASEFREQ, s.note("D4"))
|
||||
n.bridge(0, s.sec(10), IN_GAIN, GAIN)
|
||||
|
||||
m.sine(0, s.sec(10))
|
||||
n.sine(0, s.sec(10))
|
||||
|
||||
n.printstate(1, 1)
|
||||
n.printstate(20000, 20000)
|
||||
|
||||
s.wire(n, s.left)
|
||||
s.wire(n, s.right)
|
||||
|
|
@ -7,12 +7,15 @@ OPCODES = {
|
|||
'endtick': 2,
|
||||
'setpin': 3,
|
||||
'relay': 4,
|
||||
'bridge': 4,
|
||||
'bridge': 5,
|
||||
'printstate': 9,
|
||||
|
||||
'setpos': 10,
|
||||
|
||||
'sine': 50,
|
||||
'triangle': 51,
|
||||
|
||||
'singenN': 100,
|
||||
|
||||
'square': 10,
|
||||
'sawtooth': 11,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ class SoundNode:
|
|||
def setpin(self, start_tick, pin_no, value):
|
||||
self.act('setpin', start_tick, start_tick, self, None, [pin_no, value])
|
||||
|
||||
def printstate(self, start_tick, end_tick):
|
||||
self.act('printstate', start_tick, end_tick, self, None, [])
|
||||
|
||||
def bridge(self, start_tick, end_tick, in_pin, out_pin):
|
||||
self.act('bridge', start_tick, end_tick, self, None, [in_pin, out_pin])
|
||||
|
||||
|
|
@ -41,6 +44,9 @@ class SoundNode:
|
|||
|
||||
def sawtooth(self, start_tick, end_tick, gainmult = 0.0):
|
||||
self.act('sawtooth', start_tick, end_tick, self, None, [gainmult])
|
||||
|
||||
def singenN(self, start_tick, end_tick, magnitude, phase, freq, ylevel):
|
||||
self.act('singenN', start_tick, end_tick, self, None, [magnitude, phase, freq, ylevel])
|
||||
|
||||
def skewsine(self, start_tick, end_tick, gainmult = 0.0):
|
||||
self.act('skewsine', start_tick, end_tick, self, None, [gainmult])
|
||||
|
|
|
|||
26
zigsonnum/activities/generators.zig
Normal file
26
zigsonnum/activities/generators.zig
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const std = @import("std");
|
||||
const math = std.math;
|
||||
const print = std.debug.print;
|
||||
const Activity = @import ("../activity.zig").Activity;
|
||||
const SoundNode = @import("../soundnode.zig").SoundNode;
|
||||
const utility = @import("../utility.zig");
|
||||
const dbg = utility.dbg;
|
||||
const idbg = utility.idbg;
|
||||
|
||||
|
||||
// Produces a sine wave to r_amp pin
|
||||
pub fn singenN(self: *Activity) void {
|
||||
|
||||
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
||||
const magnitude = self.operands[0];
|
||||
const phase = self.operands[1];
|
||||
const freq = self.operands[2];
|
||||
const ylevel = self.operands[3];
|
||||
|
||||
const y = magnitude * math.sin(current_tick * freq + phase) + ylevel;
|
||||
|
||||
self.soundnode.basefreq = y;
|
||||
self.soundnode.out10 = y;
|
||||
self.soundnode.out11 = y;
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ const utility = @import("utility.zig");
|
|||
|
||||
const basicsynths = @import ("activities/basicsynths.zig");
|
||||
const spatial = @import ("activities/spatial.zig");
|
||||
const generators = @import ("activities/generators.zig");
|
||||
|
||||
pub const Activity = struct {
|
||||
|
||||
|
|
@ -36,9 +37,14 @@ pub const Activity = struct {
|
|||
switch (self.opcode) {
|
||||
4 => { self.relay(); },
|
||||
5 => { self.bridge(); },
|
||||
|
||||
10 => { spatial.setpos(self); },
|
||||
|
||||
50 => { basicsynths.sine(self); },
|
||||
51 => { basicsynths.triangle(self); },
|
||||
|
||||
100 => { generators.singenN(self); },
|
||||
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +96,7 @@ pub const Activity = struct {
|
|||
self.soundnode.basefreq = in_value;
|
||||
const c = fcurrent_tick / 44100;
|
||||
|
||||
const pp = prevphase + c*(self.soundnode.basefreq - prevfreq) + @floor(c * prevfreq - prevphase);
|
||||
const pp = prevphase + c * (self.soundnode.basefreq - prevfreq) + @floor(c * prevfreq - prevphase);
|
||||
|
||||
self.soundnode.phase = pp - @floor(pp);
|
||||
|
||||
|
|
|
|||
|
|
@ -278,6 +278,14 @@ pub fn main() !void {
|
|||
|
||||
},
|
||||
|
||||
9 => {
|
||||
|
||||
const sn = soundnodes.items[src_node];
|
||||
sn.wantprint = true;
|
||||
sn.printState();
|
||||
|
||||
},
|
||||
|
||||
else => {
|
||||
|
||||
const soundnode = soundnodes.items[src_node];
|
||||
|
|
@ -329,6 +337,10 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
if (soundnode.wantprint == true) {
|
||||
soundnode.wantprint = false;
|
||||
soundnode.printState();
|
||||
}
|
||||
|
||||
var j: usize = toremove.items.len;
|
||||
|
||||
|
|
@ -383,6 +395,11 @@ pub fn main() !void {
|
|||
|
||||
}
|
||||
|
||||
if (soundnode.wantprint == true) {
|
||||
soundnode.wantprint = false;
|
||||
soundnode.printState();
|
||||
}
|
||||
|
||||
var j: usize = toremove.items.len;
|
||||
|
||||
while (j > 0) {
|
||||
|
|
|
|||
|
|
@ -62,9 +62,48 @@ pub const SoundNode = struct {
|
|||
y: f32 = 0,
|
||||
z: f32 = 0,
|
||||
|
||||
wantprint: bool = false,
|
||||
|
||||
fab: FreqAmpBuffer,
|
||||
active: u8 = 1,
|
||||
|
||||
pub fn printState(self: *SoundNode) void {
|
||||
const fcurrent_tick: f64 = @floatFromInt(self.current_tick());
|
||||
|
||||
print("\n===SOUNDNODE {d} TICK {d} SECOND {d}===\n", .{self.uid, fcurrent_tick, fcurrent_tick/44100});
|
||||
|
||||
print(">> IN_WIRE = {d}\n", .{self.in_wire});
|
||||
print(">> IN_AIR = {d}\n", .{self.in_air});
|
||||
print(">> IN_GAIN = {d}\n", .{self.in_gain});
|
||||
print(">> IN_BASEPHASE = {d}\n", .{self.in_basephase});
|
||||
print(">> IN_PHASE = {d}\n", .{self.in_phase});
|
||||
print(">> IN_BASEFREQ = {d}\n", .{self.in_basefreq});
|
||||
print(">> IN6 = {d}\n", .{self.in6});
|
||||
print(">> IN7 = {d}\n", .{self.in7});
|
||||
print(">> IN8 = {d}\n", .{self.in8});
|
||||
print(">> IN9 = {d}\n", .{self.in9});
|
||||
print(">> IN10 = {d}\n", .{self.in10});
|
||||
print(">> IN11 = {d}\n", .{self.in11});
|
||||
|
||||
print("-----------------------\n", .{});
|
||||
|
||||
print(">> R_AMP = {d}\n", .{self.r_amp});
|
||||
print(">> OUT1 = {d}\n", .{self.out1});
|
||||
print(">> GAIN = {d}\n", .{self.gain});
|
||||
print(">> BASEPHASE = {d}\n", .{self.basephase});
|
||||
print(">> PHASE = {d}\n", .{self.phase});
|
||||
print(">> BASEFREQ = {d}\n", .{self.basefreq});
|
||||
print(">> OUT6 = {d}\n", .{self.out6});
|
||||
print(">> OUT7 = {d}\n", .{self.out7});
|
||||
print(">> OUT8 = {d}\n", .{self.out8});
|
||||
print(">> OUT9 = {d}\n", .{self.out9});
|
||||
print(">> OUT10 = {d}\n", .{self.out10});
|
||||
print(">> OUT11 = {d}\n", .{self.out11});
|
||||
|
||||
print("======================\n", .{});
|
||||
|
||||
}
|
||||
|
||||
pub fn nullizeStartTick(self: *SoundNode) void {
|
||||
|
||||
self.in_wire = 0;
|
||||
|
|
@ -143,6 +182,7 @@ pub const SoundNode = struct {
|
|||
.x = 0,
|
||||
.y = 0,
|
||||
.z = 0,
|
||||
.wantprint = false,
|
||||
.active = 0,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue