Skip to content

Commit

Permalink
Fixed: Note-off events don't always happen at the end of a track
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Aug 18, 2024
1 parent 934c956 commit 917f424
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 6 additions & 3 deletions audio/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,18 @@ impl Conn {
// Set the initial wav export state.
Self::set_export_state_wav(exportable, &export_state, 0);
let mut synth = synth.lock();
for t in 0..total_samples {
for t in 0..=total_samples {
// Get and send each event at this time.
for event in exportable.events.dequeue(t).iter() {
let _ = synth.send_event(*event);
}
// Set the export state.
Self::set_export_state_wav(exportable, &export_state, t);
let t = t as usize;
(left[t], right[t]) = synth.read_next();
// We are iterating to `total_samples` in order to get events at t=1.
if t < total_samples {
let t = t as usize;
(left[t], right[t]) = synth.read_next();
}
}
// Append decaying silence.
Self::set_export_state(&export_state, ExportState::AppendingDecay);
Expand Down
13 changes: 11 additions & 2 deletions audio/src/decayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Default for Decayer {

impl Decayer {
pub fn decay_shared(&mut self, synth: &SharedSynth, len: usize) {
for sample in self.buffer[0..len].chunks_mut(2) {
for sample in self.buffer[0..Self::get_len(len)].chunks_mut(2) {
let mut synth = synth.lock();
synth.write(sample);
}
Expand All @@ -48,6 +48,15 @@ impl Decayer {
}

fn set_decaying(&mut self, len: usize) {
self.decaying = self.buffer[0..len].iter().any(|s| s.abs() > SILENCE);
self.decaying = self.buffer[0..Self::get_len(len)].iter().any(|s| s.abs() > SILENCE);
}

fn get_len(len: usize) -> usize {
if len <= DECAY_CHUNK_SIZE {
len
}
else {
DECAY_CHUNK_SIZE
}
}
}
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.2.7

- Fixed: Note-off events at the end of a track are sometimes not detected during export
- Fixed: Panic when decaying audio if the output buffer exceeds the length of the decay buffer.
- Allow alphanumeric input in `--events events.txt`.

## 0.2.6
Expand Down

0 comments on commit 917f424

Please sign in to comment.