all basicsynths so far
This commit is contained in:
parent
f5137de7bb
commit
3ec8cd4704
5 changed files with 52 additions and 10 deletions
|
|
@ -8,10 +8,12 @@ s.pin(m, BASEFREQ, n, IN_BASEFREQ)
|
||||||
m.singenN(0, s.sec(10), 50.4, 0, 0.003, 440)
|
m.singenN(0, s.sec(10), 50.4, 0, 0.003, 440)
|
||||||
|
|
||||||
n.bridge(0, s.sec(10), IN_BASEFREQ, BASEFREQ)
|
n.bridge(0, s.sec(10), IN_BASEFREQ, BASEFREQ)
|
||||||
n.triangle(0, s.sec(10))
|
#n.setpin(0, BASEFREQ, 330)
|
||||||
|
n.setpin(0, OUT8, 0.3)
|
||||||
|
n.pulse(0, s.sec(10))
|
||||||
|
|
||||||
n.printstate(1, 1)
|
n.printstate(30000, 30000)
|
||||||
n.printstate(20000, 20000)
|
n.printstate(30001, 30001)
|
||||||
|
|
||||||
s.wire(n, s.left)
|
s.wire(n, s.left)
|
||||||
s.wire(n, s.right)
|
s.wire(n, s.right)
|
||||||
|
|
@ -14,19 +14,19 @@ OPCODES = {
|
||||||
|
|
||||||
'sine': 50,
|
'sine': 50,
|
||||||
'triangle': 51,
|
'triangle': 51,
|
||||||
|
'square': 52,
|
||||||
|
'sawtooth': 53,
|
||||||
|
'skewsine': 54,
|
||||||
|
'pulse': 55,
|
||||||
|
|
||||||
'singenN': 100,
|
'singenN': 100,
|
||||||
|
|
||||||
'square': 10,
|
|
||||||
'sawtooth': 11,
|
|
||||||
'setskew': 12,
|
'setskew': 12,
|
||||||
'skewsine': 14,
|
|
||||||
'slidebasefreq': 15,
|
'slidebasefreq': 15,
|
||||||
'slidegain': 16,
|
'slidegain': 16,
|
||||||
'slidephase': 17,
|
'slidephase': 17,
|
||||||
'slideskew': 18,
|
'slideskew': 18,
|
||||||
'slidepos': 19,
|
'slidepos': 19,
|
||||||
'pulse': 20,
|
|
||||||
'fmsetup': 21,
|
'fmsetup': 21,
|
||||||
'fm': 22,
|
'fm': 22,
|
||||||
'am': 23,
|
'am': 23,
|
||||||
|
|
|
||||||
|
|
@ -104,4 +104,25 @@ pub fn skewsine(self: *Activity) void {
|
||||||
|
|
||||||
self.soundnode.add_r_amp(final_amp);
|
self.soundnode.add_r_amp(final_amp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Produces a pulse wave to r_amp pin
|
||||||
|
// Uses OUT8 as pulse phase
|
||||||
|
pub fn pulse(self: *Activity) void {
|
||||||
|
|
||||||
|
const current_tick: f64 = @floatFromInt(self.soundnode.fab.current_tick);
|
||||||
|
|
||||||
|
const gain = self.soundnode.corrGain(self.operands[0]);
|
||||||
|
|
||||||
|
const period = 44100 / self.soundnode.basefreq;
|
||||||
|
const tp = (current_tick - (period * self.soundnode.totalPhase())) / period;
|
||||||
|
const tp_detract = (current_tick - (period * (self.soundnode.out8 + self.soundnode.totalPhase()))) / period;
|
||||||
|
|
||||||
|
const amp = 2 * (tp - @floor(0.5 + tp));
|
||||||
|
const amp_detract = 2 * (tp_detract - @floor(0.5+tp_detract));
|
||||||
|
|
||||||
|
const final_amp = gain * (amp - amp_detract);
|
||||||
|
|
||||||
|
self.soundnode.add_r_amp(final_amp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ pub const Activity = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do(self: *Activity) !void {
|
pub fn do(self: *Activity) !void {
|
||||||
|
|
||||||
switch (self.opcode) {
|
switch (self.opcode) {
|
||||||
|
|
||||||
4 => { self.relay(); },
|
4 => { self.relay(); },
|
||||||
5 => { self.bridge(); },
|
5 => { self.bridge(); },
|
||||||
|
|
||||||
|
|
@ -42,11 +44,17 @@ pub const Activity = struct {
|
||||||
|
|
||||||
50 => { basicsynths.sine(self); },
|
50 => { basicsynths.sine(self); },
|
||||||
51 => { basicsynths.triangle(self); },
|
51 => { basicsynths.triangle(self); },
|
||||||
|
52 => { basicsynths.square(self); },
|
||||||
|
53 => { basicsynths.sawtooth(self); },
|
||||||
|
54 => { basicsynths.skewsine(self); },
|
||||||
|
55 => { basicsynths.pulse(self); },
|
||||||
|
|
||||||
100 => { generators.singenN(self); },
|
100 => { generators.singenN(self); },
|
||||||
|
|
||||||
else => {},
|
else => {},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn relay(self: *Activity) void {
|
pub fn relay(self: *Activity) void {
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,6 @@ pub fn main() !void {
|
||||||
|
|
||||||
const sn = soundnodes.items[src_node];
|
const sn = soundnodes.items[src_node];
|
||||||
sn.wantprint = true;
|
sn.wantprint = true;
|
||||||
sn.printState();
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -416,9 +415,21 @@ pub fn main() !void {
|
||||||
left = soundnodes.items[0];
|
left = soundnodes.items[0];
|
||||||
right = soundnodes.items[1];
|
right = soundnodes.items[1];
|
||||||
|
|
||||||
|
if (left.r_amp > 1) {
|
||||||
|
left.r_amp = 1;
|
||||||
|
} else if (left.r_amp < -1) {
|
||||||
|
left.r_amp = -1;
|
||||||
|
}
|
||||||
|
|
||||||
sample = @intFromFloat(left.r_amp * settings.max_amp_multiplier);
|
sample = @intFromFloat(left.r_amp * settings.max_amp_multiplier);
|
||||||
try stdout.writeInt(i24, sample, Endian.little);
|
try stdout.writeInt(i24, sample, Endian.little);
|
||||||
|
|
||||||
|
if (right.r_amp > 1) {
|
||||||
|
right.r_amp = 1;
|
||||||
|
} else if (right.r_amp < -1) {
|
||||||
|
right.r_amp = -1;
|
||||||
|
}
|
||||||
|
|
||||||
sample = @intFromFloat(right.r_amp * settings.max_amp_multiplier);
|
sample = @intFromFloat(right.r_amp * settings.max_amp_multiplier);
|
||||||
try stdout.writeInt(i24, sample, Endian.little);
|
try stdout.writeInt(i24, sample, Endian.little);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue