ported steady on tim as a sound test

This commit is contained in:
2022-03-04 23:38:27 +01:00
parent 85240599e8
commit 9063e872d3
2 changed files with 27 additions and 8 deletions

View File

@@ -1,8 +0,0 @@
include "../include/microw8-api.cwa"
export fn snd(index: i32) -> f32 {
let inline saw = index;
let inline env = (-index #>> 9);
let inline sample = saw & env;
(sample & 255) as f32 / 255 as f32 - 0.5
}

View File

@@ -0,0 +1,27 @@
// Steady On Tim, It's Only A Budget Game
// by Gasman / Hooy-Program
// ported to MicroW8 by exoticorn/icebird
include "../include/microw8-api.cwa"
fn melody(t: i32, T: i32) -> i32 {
let lazy b=(T&31)-16;
if b < 0 {
b = -b;
}
let lazy K = 1.0 + ((1-((T>>5)&3))%2-1) as f32 / 6.0;
let inline arpeggio = ((t as f32 * pow(2.0, ((((0x85>>(t/2000%3*4)) & 15) - 1) as f32 / 12.0 + K))) as i32 & 128) * (!!(T>>8) * (12-T%12)) / 12;
let inline melody = (t as f32 * pow(2.0, K+(b/5) as f32 - (((5514>>(b%select(T>>9, 4, 5)*4)&15) as f32) / 12.0))) as i32 & 128;
arpeggio +
melody
}
export fn snd(sample: i32) -> f32 {
let lazy t = sample / 2;
let lazy T = t/5000;
let inline mel_arp = melody(t, T)/3 + melody(t, T-3)/5;
let inline bass = !!(T>>7) * ((t as f32 * pow(2.0, ((!!(T & 4) * ((T & 7) - 1)) as f32 / 6.0 - 4.0))) as i32 & 63) * ((197 >> (T % 8)) & 1);
let inline snare_ish = (random() & 31) * (8 - (T + 4) % 8) / 8;
let inline sample = mel_arp + bass + snare_ish;
(sample & 255) as f32 / 255 as f32 - 0.5
}