Skip to content

Commit

Permalink
simple #playtest demo v3
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed May 3, 2024
1 parent 3ee0009 commit c485312
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
5 changes: 4 additions & 1 deletion zss/device/pcspeaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ onblasterready(() => {
drumindex++,
range(1, 16).map((i) => (i % 2) * 1600 + 1600 + (i % 4) * 1600),
)
// empty 'cause 3 is taken
loadchipdrum(drumindex++, [])
loadchipdrum(
drumindex++,
range(1, 14).map(() => randomInteger(0, 5000) + 500),
Expand Down Expand Up @@ -128,9 +130,10 @@ function soundupdate(delta: number) {

// read next tone
const tone = pcspeaker.buffer[pcspeaker.bufferpos++]
// reset
playchipfreq(0)
if (tone === 0) {
// rest
playchipfreq(0)
} else if (tone < 240) {
// doot
playchipfreq(soundfreqtable[tone])
Expand Down
45 changes: 35 additions & 10 deletions zss/gadget/audio/blaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ const chipblaster = {
drum: '',
}

function nm(key: string, alt: string): { key: string } {
return { key: `${key}:${alt}` }
}

function cl(key: string, input: any) {
return el.max(nm(key, 'max'), 0, el.min(nm(key, 'min'), 1, input))
}

function rendersq(key: string, freq: any) {
// round & mul for the nice classic sound
return el.mul(el.square(freq), 0.1)
const sq = el.square(nm(key, 'sq'), freq)
const ssq = el.mul(nm(key, 'sqm'), sq, 32)
const cssq = cl(nm(key, 'cl').key, ssq)
return cssq
}

function drumname(i: number) {
return `drum${i}`
return nm('drum', `${i}`).key
}

const drumvalues: Record<string, number[]> = {}
Expand All @@ -29,31 +40,45 @@ function renderblaster() {
const voices: any[] = []

// add doot
const doot = 'doot'
voices.push(
el.mul(el.ge(chipblaster.freq, 0), rendersq('doot', chipblaster.freq)),
el.mul(
nm(doot, 'mul'),
el.ge(chipblaster.freq, 0),
rendersq(nm(doot, 'voice').key, chipblaster.freq),
),
)

// add drums
const drums = Object.keys(drumvalues)
voices.push(
...drums.map((name) => {
const active = name === chipblaster.drum
const active = name === chipblaster.drum ? 1 : 0
return el.mul(
1, // active ? 1 : 0,
nm(name, 'mul'),
el.const({ ...nm(name, 'gate'), value: active }),
rendersq(
name,
nm(name, 'voice').key,
el.seq2(
{ seq: drumvalues[name], offset: 0 },
el.train(500),
active ? 1 : 0,
{
...nm(name, 'seq'),
loop: false,
seq: drumvalues[name],
},
el.train(1000),
el.const({ ...nm(name, 'reset'), value: active }),
),
),
)
}),
)

// render output
const out = el.add(...voices)
const out = el.mul(
nm('mixer', 'gate'),
0.5,
el.add(nm('mixer', 'add'), ...voices),
)
core.render(out, out).catch((e) => console.error(e))
}

Expand Down

0 comments on commit c485312

Please sign in to comment.