Skip to content

Commit 179d7db

Browse files
committed
fix possible crash when switching instruments
1 parent 7855e55 commit 179d7db

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,11 @@ static int audioCallback(float **inputBuffer, float **outputBuffer, unsigned lon
17191719

17201720
osc->fp2[k][1] = osc->fp2[k][0];
17211721
osc->fp2[k][0] = n->res;
1722+
1723+
// make sure phase index is randomized and within bounds
1724+
if ((n->previous_volume_l <= 0 && n->previous_volume_r <= 0) || trigger_note_on) {
1725+
osc->phase_index[k] = randf(0, fas_wavetable_size);
1726+
}
17221727
}
17231728
} else if (synthesis_method == FAS_GRANULAR) {
17241729
for (j = s; j < e; j += 1) {
@@ -1943,6 +1948,8 @@ static int audioCallback(float **inputBuffer, float **outputBuffer, unsigned lon
19431948
resetOscillator(osc, k);
19441949

19451950
osc->pvalue[k] = 0.0f;
1951+
1952+
osc->phase_index[k] = randf(0, fas_noise_wavetable_size - 1);
19461953
}
19471954
#endif
19481955
}

0 commit comments

Comments
 (0)