summaryrefslogtreecommitdiff
path: root/tools/audio/soundfont_compiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/audio/soundfont_compiler.c')
-rw-r--r--tools/audio/soundfont_compiler.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/tools/audio/soundfont_compiler.c b/tools/audio/soundfont_compiler.c
index 6a47d643b..4f37baa55 100644
--- a/tools/audio/soundfont_compiler.c
+++ b/tools/audio/soundfont_compiler.c
@@ -199,7 +199,8 @@ calc_tuning(float sample_rate, int basenote, int8_t finetune)
/* 0x7F */ 0.099213f, // PITCH_AF0
};
- float tuning = (sample_rate / playback_sample_rate) * pitch_frequencies[basenote];
+ // Due to the way the lookup table is arranged, the note needs to be reflected about middle C (z64 note value 39)
+ float tuning = (sample_rate / playback_sample_rate) * pitch_frequencies[(78u - (unsigned)basenote) % 128u];
if (finetune == 0)
return tuning;
@@ -1446,10 +1447,10 @@ emit_c_drums(FILE *out, soundfont *sf)
ptr_table[ptr_offset].n = note_offset;
// wrap note on overflow
- int note = drum->base_note + note_offset;
- if (note > 127)
- note -= 128;
-
+ // drum frequencies increase with drum offset, corresponding to a decrease in note number
+ int note = drum->base_note - note_offset;
+ if (note < 0)
+ note += 128;
float tuning = calc_tuning(drum->sample_rate, note, drum->fine_tune);
fprintf(out, " SF%d_%s_ENTRY(" F32_FMT "f),\n", sf->info.index, drum->name, tuning);