File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -352,15 +352,21 @@ STATIC int find_channel_with_note(synthio_synth_t *synth, mp_obj_t note) {
352
352
return i ;
353
353
}
354
354
}
355
+ int result = -1 ;
355
356
if (note == SYNTHIO_SILENCE ) {
356
- // we need a victim note that is releasing. simple algorithm: lowest numbered slot
357
- for (int i = 0 ; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS ; i ++ ) {
358
- if (!SYNTHIO_NOTE_IS_PLAYING (synth , i )) {
359
- return i ;
357
+ // replace the releasing note with lowest volume level
358
+ int level = 32768 ;
359
+ for (int chan = 0 ; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS ; chan ++ ) {
360
+ if (!SYNTHIO_NOTE_IS_PLAYING (synth , chan )) {
361
+ synthio_envelope_state_t * state = & synth -> envelope_state [chan ];
362
+ if (state -> level < level ) {
363
+ result = chan ;
364
+ level = state -> level ;
365
+ }
360
366
}
361
367
}
362
368
}
363
- return -1 ;
369
+ return result ;
364
370
}
365
371
366
372
bool synthio_span_change_note (synthio_synth_t * synth , mp_obj_t old_note , mp_obj_t new_note ) {
You can’t perform that action at this time.
0 commit comments