Skip to content

Commit

Permalink
amy.c: Preserve one-frame fade-out.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwe committed Mar 19, 2024
1 parent aa3bc38 commit fe3ad6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,11 @@ void hold_and_modify(uint16_t osc) {
msynth[osc].pan = combine_controls(ctrl_inputs, synth[osc].pan_coefs);
// amp is a special case - coeffs apply in log domain.
// Also, we advance one frame by writing both last_amp and amp (=next amp)
msynth[osc].last_amp = combine_controls_mult(ctrl_inputs, synth[osc].amp_coefs);
float new_last_amp = combine_controls_mult(ctrl_inputs, synth[osc].amp_coefs);
// Prevent hard-off on transition to release by updating last_amp only for nonzero new_last_amp.
if (new_last_amp > 0) {
msynth[osc].last_amp = new_last_amp;
}
ctrl_inputs[COEF_EG0] = S2F(compute_breakpoint_scale(osc, 0, AMY_BLOCK_SIZE));
ctrl_inputs[COEF_EG1] = S2F(compute_breakpoint_scale(osc, 1, AMY_BLOCK_SIZE));
msynth[osc].amp = combine_controls_mult(ctrl_inputs, synth[osc].amp_coefs);
Expand Down
2 changes: 1 addition & 1 deletion src/oscillators.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ SAMPLE render_sine(SAMPLE* buf, uint16_t osc) {
PHASOR step = F2P(freq / (float)AMY_SAMPLE_RATE); // cycles per sec / samples per sec -> cycles per sample
SAMPLE amp = F2S(msynth[osc].amp);
SAMPLE last_amp = F2S(msynth[osc].last_amp);
//fprintf(stderr, "render_sine: time %f osc %d freq %f amp %f\n", total_samples / (float)AMY_SAMPLE_RATE, osc, AMY_SAMPLE_RATE * P2F(step), S2F(amp));
//fprintf(stderr, "render_sine: time %f osc %d freq %f last_amp %f amp %f\n", total_samples / (float)AMY_SAMPLE_RATE, osc, AMY_SAMPLE_RATE * P2F(step), S2F(last_amp), S2F(amp));
SAMPLE max_value;
synth[osc].phase = render_lut(buf, synth[osc].phase, step, last_amp, amp, synth[osc].lut, &max_value);
msynth[osc].last_amp = msynth[osc].amp;
Expand Down
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def main(argv):
#TestSawDownOsc().test()
#TestGuitar().test()
#TestFilter().test()
TestAlgo().test()
#TestAlgo().test()
TestBleep().test()
amy.send(debug=0)
print("tests done.")

Expand Down

0 comments on commit fe3ad6b

Please sign in to comment.