Skip to content

Commit

Permalink
tweaks to audio menus (#1931)
Browse files Browse the repository at this point in the history
* Do not restart the MIDI player if the current option does not match it.

* Don't use thermo bars for big numbers.

* Apply Ceski patch

Co-authored-by: ceski-1
  • Loading branch information
rfomin authored Oct 2, 2024
1 parent 3592063 commit bc9a876
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 71 deletions.
14 changes: 11 additions & 3 deletions src/i_midimusic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,12 @@ static boolean I_MID_InitMusic(int device)
return true;
}

// MIDI CC#7 volume formula (GM Level 1 Developer Guidelines, page 9).
#define MIDI_DB_TO_GAIN(db) powf(10.0f, (db) / 40.0f)

static void UpdateVolumeFactor(int volume)
{
volume_factor = sqrtf(volume / 15.0f) * midi_gain / 100.0f;
volume_factor = volume / 15.0f * MIDI_DB_TO_GAIN(midi_gain);
}

static void I_MID_SetMusicVolume(int volume)
Expand Down Expand Up @@ -1485,6 +1488,11 @@ static const char **I_MID_DeviceList(void)
return midi_devices;
}

static midiplayertype_t I_MID_MidiPlayerType(void)
{
return midiplayer_native;
}

static void I_MID_BindVariables(void)
{
BIND_NUM_MIDI(midi_complevel, COMP_STANDARD, 0, COMP_NUM - 1,
Expand All @@ -1495,8 +1503,7 @@ static void I_MID_BindVariables(void)
"Delay after reset for native MIDI (-1 = Auto; 0 = None; 1-2000 = Milliseconds)");
BIND_BOOL_MIDI(midi_ctf, true,
"Fix invalid instruments by emulating SC-55 capital tone fallback");
BIND_NUM_MIDI(midi_gain, 100, 0, 100,
"Fine tune native MIDI output level (default 100%)");
BIND_NUM_MIDI(midi_gain, 0, -20, 0, "Native MIDI gain [dB]");
}

music_module_t music_mid_module =
Expand All @@ -1512,4 +1519,5 @@ music_module_t music_mid_module =
I_MID_UnRegisterSong,
I_MID_DeviceList,
I_MID_BindVariables,
I_MID_MidiPlayerType,
};
4 changes: 4 additions & 0 deletions src/i_oalcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "al.h"
#include "alc.h"

#include <math.h>

#include "doomtype.h"

// C doesn't allow casting between function and non-function pointer types, so
Expand All @@ -36,6 +38,8 @@

#define ALFUNC(T, ptr) (ptr = FUNCTION_CAST(T, alGetProcAddress(#ptr)))

#define DB_TO_GAIN(db) powf(10.0f, (db) / 20.0f)

typedef struct oal_system_s
{
ALCdevice *device;
Expand Down
3 changes: 0 additions & 3 deletions src/i_oalequalizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "alc.h"
#include "alext.h"

#include <math.h>

#include "i_oalcommon.h"
#include "i_oalequalizer.h"
#include "i_sound.h"
Expand Down Expand Up @@ -233,7 +231,6 @@ void I_OAL_SetEqualizer(void)
// Gains vary from 0.251 up to 3.981, which means from -12dB attenuation
// up to +12dB amplification, i.e. 20*log10(gain).

#define DB_TO_GAIN(db) powf(10.0f, (db) / 20.0f)
#define EQ_GAIN(db) ((ALfloat)BETWEEN(0.251f, 3.981f, DB_TO_GAIN(db)))
#define LP_GAIN(db) ((ALfloat)BETWEEN(0.063f, 1.0f, DB_TO_GAIN(db)))
#define OCTAVE(x) ((ALfloat)BETWEEN(0.01f, 1.0f, (x) / 100.0f))
Expand Down
27 changes: 21 additions & 6 deletions src/i_oalmusic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdlib.h>

#include "doomtype.h"
#include "i_oalcommon.h"
#include "i_oalstream.h"
#include "i_printf.h"
#include "i_sound.h"
Expand Down Expand Up @@ -308,12 +309,12 @@ static void I_OAL_SetMusicVolume(int volume)

if (active_module == &stream_opl_module)
{
gain *= (ALfloat)opl_gain / 100.0f;
gain *= (ALfloat)DB_TO_GAIN(opl_gain);
}
#if defined(HAVE_FLUIDSYNTH)
else if (active_module == &stream_fl_module)
{
gain *= (ALfloat)mus_gain / 100.0f;
gain *= (ALfloat)DB_TO_GAIN(mus_gain);
}
#endif

Expand Down Expand Up @@ -458,13 +459,26 @@ static const char **I_OAL_DeviceList(void)
return devices;
}

static midiplayertype_t I_OAL_MidiPlayerType(void)
{
#ifdef HAVE_FLUIDSYNTH
if (active_module == &stream_fl_module)
{
return midiplayer_fluidsynth;
}
#endif
if (active_module == &stream_opl_module)
{
return midiplayer_opl;
}
return midiplayer_none;
}

static void I_OAL_BindVariables(void)
{
BIND_NUM_MIDI(opl_gain, 200, 100, 1000,
"Fine tune OPL emulation output level (default 200%)");
BIND_NUM_MIDI(opl_gain, 0, -20, 20, "OPL emulation gain [dB]");
#if defined (HAVE_FLUIDSYNTH)
BIND_NUM_MIDI(mus_gain, 100, 10, 1000,
"Fine tune FluidSynth output level (default 100%)");
BIND_NUM_MIDI(mus_gain, 0, -20, 20, "FluidSynth gain [dB]");
#endif
for (int i = 0; i < arrlen(midi_modules); ++i)
{
Expand All @@ -485,4 +499,5 @@ music_module_t music_oal_module =
I_OAL_UnRegisterSong,
I_OAL_DeviceList,
I_OAL_BindVariables,
I_OAL_MidiPlayerType,
};
11 changes: 10 additions & 1 deletion src/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,15 @@ void I_SetSoundModule(void)
MN_UpdateAdvancedSoundItems(snd_module != SND_MODULE_3D);
}

midiplayertype_t I_MidiPlayerType(void)
{
if (active_module)
{
return active_module->I_MidiPlayerType();
}
return midiplayer_none;
}

void I_SetMidiPlayer(void)
{
if (nomusicparm)
Expand Down Expand Up @@ -745,6 +754,6 @@ void I_BindSoundVariables(void)
"MIDI Player string");
for (int i = 0; i < arrlen(music_modules); ++i)
{
music_modules[i]->BindVariables();
music_modules[i]->I_BindVariables();
}
}
13 changes: 12 additions & 1 deletion src/i_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ int I_SoundID(int handle);
// MUSIC I/O
//

typedef enum
{
midiplayer_none,
midiplayer_native,
midiplayer_fluidsynth,
midiplayer_opl,
} midiplayertype_t;

midiplayertype_t I_MidiPlayerType(void);

typedef struct
{
boolean (*I_InitMusic)(int device);
Expand All @@ -155,7 +165,8 @@ typedef struct
void (*I_StopSong)(void *handle);
void (*I_UnRegisterSong)(void *handle);
const char **(*I_DeviceList)(void);
void (*BindVariables)(void);
void (*I_BindVariables)(void);
midiplayertype_t (*I_MidiPlayerType)(void);
} music_module_t;

extern music_module_t music_oal_module;
Expand Down
1 change: 1 addition & 0 deletions src/mn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ typedef struct setup_menu_s
mrect_t rect;
int lines; // number of lines for rect, always > 0
const char *desc; // overrides default description
const char *append; // string to append to value
} setup_menu_t;

// phares 4/21/98: Moved from m_misc.c so m_menu.c could see it.
Expand Down
Loading

0 comments on commit bc9a876

Please sign in to comment.