Skip to content

Commit 9581cfe

Browse files
committed
fix ub
1 parent 0a37553 commit 9581cfe

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

runtime/w4on2.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void w4on2_rt_init(w4on2_rt_t *rt, w4on2_tone_t tone, void *userdata)
6969
void w4on2_rt_tick(w4on2_rt_t *rt)
7070
{
7171
// Play each channel
72-
for (uint8_t ch_i = 0; ch_i < W4ON2_CHANNEL_COUNT; ch_i++) {
72+
for (uint8_t ch_i = 0; ch_i < W4ON2_CHANNEL_COUNT; ch_i++) {
7373
w4on2_channel_t *ch = &rt->channels[ch_i];
7474
if (ch->active_track_i >= W4ON2_TRACK_COUNT) {
7575
continue;
@@ -124,8 +124,10 @@ void w4on2_rt_tick(w4on2_rt_t *rt)
124124
to_pitch += w4on2_triangle((0x3fff + (uint32_t)(porta_ticks + 1) * ((uint32_t)track->vib_speed << 6)) % 0xffff, track->vib_depth << 2);
125125

126126
// Convert from pitch to WASM-4 bent MIDI notes to WASM-4 frequency slope
127-
uint32_t w4_freq_param = (((from_pitch >> 8) | (from_pitch << 8)) & 0xffff) | ((((to_pitch >> 8) | (to_pitch << 8)) & 0xffff) << 16);
128-
127+
uint32_t w4_freq_param =
128+
((((uint32_t)from_pitch >> 8) | ((uint32_t)from_pitch << 8)) & 0xffff)
129+
| (((((uint32_t)to_pitch >> 8) | ((uint32_t)to_pitch << 8)) & 0xffff) << 16);
130+
129131
// Continous linear tone
130132
// Using the Decay part of ADSR is most flexible for playing any linear envelope since peak and sustain are absolute values in WASM-4.
131133
// The downside is WASM-4 defaults peak volume to 100 when it is 0, so we use Attack specifically for that case (since it goes from zero.)

0 commit comments

Comments
 (0)