From 2ab3fa79e131ee6d5cfcddeb63a5a0b690742f5d Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 15 May 2024 21:35:03 +0100 Subject: [PATCH] Notes are 1 indexed, not 0 indexed Versions of xmrs below 0.4.1 (unreleased, 0.4.2 is on crates.io but 0.4.1 is in the repo) have a bug where they swap linear and amiga frequencies. This caused all old versions of agb (which were using version 0.3) to use the amiga frequency table rather than the linear one. Technically it sounds slightly wrong but it is kinda hard to tell. Since agb 0.20.0, we are now using xmrs 0.5, which correctly reports the frequency type for the XM file. That pointed out an error in the note_to_speed method for linear frequencies (since those are now being used). It turns out that the formula for calculating the frequency expects a 0 based index for the note, but we were passing a 1 based index for the note. Moving this down a note fixes the issue where things were being played at the wrong frequency. --- tracker/agb-xm-core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/agb-xm-core/src/lib.rs b/tracker/agb-xm-core/src/lib.rs index 8882e148..f3481d4c 100644 --- a/tracker/agb-xm-core/src/lib.rs +++ b/tracker/agb-xm-core/src/lib.rs @@ -482,7 +482,7 @@ fn note_to_speed( } fn note_to_frequency_linear(note: Note, fine_tune: f64, relative_note: i8) -> f64 { - let real_note = (note as usize as f64) + (relative_note as f64); + let real_note = (note as usize as f64) + (relative_note as f64) - 1.0; // notes are 1 indexed but below is 0 indexed let period = 10.0 * 12.0 * 16.0 * 4.0 - real_note * 16.0 * 4.0 - fine_tune / 2.0; 8363.0 * 2.0f64.powf((6.0 * 12.0 * 16.0 * 4.0 - period) / (12.0 * 16.0 * 4.0)) }