Skip to content

Commit 7d4a30e

Browse files
bwhitmanclaude
andcommitted
Reset oscs in a synth before loading patch
When reloading a patch on a synth that already has voices allocated, reset each osc of each voice before reallocation so stale osc state doesn't persist into the new patch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2339c88 commit 7d4a30e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/patches.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,18 @@ void patches_load_patch(amy_event *e) {
10711071
(int32_t)e->synth, patch_number, (int32_t)e->num_voices, e->voices[0]);
10721072
}
10731073
return;
1074+
} else {
1075+
// Reset every osc belonging to each voice so stale state doesn't persist
1076+
// before we reallocate and reinitialize them below.
1077+
for (uint8_t v = 0; v < num_voices; v++) {
1078+
if (AMY_IS_SET(voice_to_base_osc[voices[v]])) {
1079+
uint16_t base = voice_to_base_osc[voices[v]];
1080+
for (uint16_t j = 0; j < AMY_OSCS - base; j++) {
1081+
if (osc_to_voice[base + j] != voices[v]) break;
1082+
reset_osc(base + j);
1083+
}
1084+
}
1085+
}
10741086
}
10751087

10761088
// At this point, we have the voices[] array and num_voices set up to be initialized.

0 commit comments

Comments
 (0)