From 36804d7c9b29724d7cc64918de9b82ddf09c8ae0 Mon Sep 17 00:00:00 2001 From: Zeta Date: Tue, 14 Nov 2023 03:27:03 -0500 Subject: [PATCH] Add an option to round volumes up when applying linear scaling This is secretly a FamiTracker compatibility mode, but it's useful in many other contexts. With upwards rounding, if both the channel and the macro volume are positive, then the computed result is also positive, ie, it will never become 0, which is silent on many chips. Still needs UI changes to expose the setting, and save/load work to persist it to file. --- src/engine/dispatch.h | 2 +- src/engine/song.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 2f6b7c04a..bfdcf6883 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -782,7 +782,7 @@ class DivDispatch { #define NOTE_FNUM_BLOCK(x,bits) parent->calcBaseFreqFNumBlock(chipClock,CHIP_FREQBASE,x,bits) // this is for volume scaling calculation. -#define VOL_SCALE_LINEAR(x,y,range) (((x)*(y))/(range)) +#define VOL_SCALE_LINEAR(x,y,range) ((parent->song.ceilVolumeScaling)?((((x)*(y))+(range-1))/(range)):(((x)*(y))/(range))) #define VOL_SCALE_LOG(x,y,range) (CLAMP(((x)+(y))-(range),0,(range))) #define VOL_SCALE_LINEAR_BROKEN(x,y,range) ((parent->song.newVolumeScaling)?(VOL_SCALE_LINEAR(x,y,range)):(VOL_SCALE_LOG(x,y,range))) #define VOL_SCALE_LOG_BROKEN(x,y,range) ((parent->song.newVolumeScaling)?(VOL_SCALE_LOG(x,y,range)):(VOL_SCALE_LINEAR(x,y,range))) diff --git a/src/engine/song.h b/src/engine/song.h index 7a7e267c2..50435aee1 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -379,6 +379,7 @@ struct DivSong { bool preNoteNoEffect; bool oldDPCM; bool resetArpPhaseOnNewNote; + bool ceilVolumeScaling; std::vector ins; std::vector wave; @@ -500,7 +501,8 @@ struct DivSong { brokenFMOff(false), preNoteNoEffect(false), oldDPCM(false), - resetArpPhaseOnNewNote(false) { + resetArpPhaseOnNewNote(false), + ceilVolumeScaling(false) { // DEBUG: before accepting PR, set this to false! (zeta hasn't touched the UI yet) for (int i=0; i