From 8c9f402c31963290867337a65c9635036acbb49f Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Tue, 29 Sep 2020 12:46:27 +0300 Subject: [PATCH] ADLMIDI: Set the different gain per volume model Different volume models were means louder or quiter sounding of the rest of notes in the song. And to avoid the mess between volume models, let's use different gain factor for each volume model? --- .../mididevices/music_adlmidi_mididevice.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/source/mididevices/music_adlmidi_mididevice.cpp b/source/mididevices/music_adlmidi_mididevice.cpp index 8eaa85c..7ffb42c 100644 --- a/source/mididevices/music_adlmidi_mididevice.cpp +++ b/source/mididevices/music_adlmidi_mididevice.cpp @@ -47,6 +47,7 @@ ADLConfig adlConfig; class ADLMIDIDevice : public SoftSynthMIDIDevice { struct ADL_MIDIPlayer *Renderer; + float OutputGainFactor; public: ADLMIDIDevice(const ADLConfig *config); ~ADLMIDIDevice(); @@ -86,6 +87,7 @@ ADLMIDIDevice::ADLMIDIDevice(const ADLConfig *config) :SoftSynthMIDIDevice(44100) { Renderer = adl_init(44100); // todo: make it configurable + OutputGainFactor = 3.5f; if (Renderer != nullptr) { adl_switchEmulator(Renderer, config->adl_emulator_id); @@ -95,6 +97,34 @@ ADLMIDIDevice::ADLMIDIDevice(const ADLConfig *config) adl_setNumChips(Renderer, config->adl_chips_count); adl_setVolumeRangeModel(Renderer, config->adl_volume_model); adl_setSoftPanEnabled(Renderer, config->adl_fullpan); + // TODO: Please tune the factor for each volume model to avoid too loud or too silent sounding + switch (adl_getVolumeRangeModel(Renderer)) + { + // Louder models + case ADLMIDI_VolumeModel_Generic: + case ADLMIDI_VolumeModel_9X: + case ADLMIDI_VolumeModel_9X_GENERIC_FM: + OutputGainFactor = 2.0f; + break; + // Middle volume models + case ADLMIDI_VolumeModel_HMI: + case ADLMIDI_VolumeModel_HMI_OLD: + OutputGainFactor = 2.5f; + break; + default: + // Quite models + case ADLMIDI_VolumeModel_DMX: + case ADLMIDI_VolumeModel_DMX_Fixed: + case ADLMIDI_VolumeModel_APOGEE: + case ADLMIDI_VolumeModel_APOGEE_Fixed: + case ADLMIDI_VolumeModel_AIL: + OutputGainFactor = 3.5f; + break; + // Quiter models + case ADLMIDI_VolumeModel_NativeOPL3: + OutputGainFactor = 3.8f; + break; + } } else throw std::runtime_error("Failed to create ADL MIDI renderer."); } @@ -222,7 +252,7 @@ void ADLMIDIDevice::ComputeOutput(float *buffer, int len) auto result = adl_generateFormat(Renderer, len * 2, left, right, &audio_output_format); for(int i=0; i < result; i++) { - buffer[i] *= 3.5f; + buffer[i] *= OutputGainFactor; } }