add initial pulse width support

This commit is contained in:
2022-03-08 22:52:12 +01:00
parent a15e796489
commit ce18a8a162
4 changed files with 10 additions and 6 deletions

View File

@@ -16,7 +16,7 @@ fn melody(ch: i32, t: i32, T: i32) {
export fn upd() { export fn upd() {
let lazy t = 32!32 / (1000/60); let lazy t = 32!32 / (1000/60);
let lazy T = t / 8; let lazy T = t / 7;
melody(98, t, T - 3); melody(98, t, T - 3);
melody(92, t, T); melody(92, t, T);
@@ -36,10 +36,10 @@ export fn upd() {
data 80 { data 80 {
i8( i8(
0, 128, 0, 128, 0x40, 0xe, 0, 64, 0, 128, 0x40, 0xe,
0, 128, 0, 128, 0x8, 0xc8, 0, 128, 0, 128, 0x8, 0xc8,
0, 128, 0, 128, 0xa, 0xa, 0, 32, 0, 128, 0xa, 0xa,
0, 128, 0, 128, 0xa, 0xa, 0, 64, 0, 128, 0xa, 0xa,
0xf8, 0x85, 0xf8, 0x85,
0xc1, 0xf1, 0, 110, 0, 90 0xc1, 0xf1, 0, 110, 0, 90
) )

Binary file not shown.

View File

@@ -63,6 +63,9 @@ export fn gesSnd(t: i32) -> f32 {
let phase = i32.load16_u(channelState, GesChannelState.Phase) << 8; let phase = i32.load16_u(channelState, GesChannelState.Phase) << 8;
let inline pulseWidth = channelReg?1;
let phaseShift = (pulseWidth - 128) * 255;
i = 0; i = 0;
let wave = ctrl >> 6; let wave = ctrl >> 6;
if wave < 2 { if wave < 2 {
@@ -76,7 +79,8 @@ export fn gesSnd(t: i32) -> f32 {
else else
{ {
loop rectLoop { loop rectLoop {
i!(GesBufferOffset + 128*4) = select(phase & 32768, -32768, 32767); let p = (phase & 65535) + phaseShift;
i!(GesBufferOffset + 128*4) = select(p >= 32768, -32768, 32767);
phase = phase + phaseInc; phase = phase + phaseInc;
branch_if (i := i + 4) < 64*4: rectLoop; branch_if (i := i + 4) < 64*4: rectLoop;
} }

File diff suppressed because one or more lines are too long