aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Novichkov <admin@wohlnet.ru>2018-05-31 02:05:58 +0300
committerVitaly Novichkov <admin@wohlnet.ru>2018-05-31 02:05:58 +0300
commit56c0cd7f2439898080df2e0a8129b72d2d85ca70 (patch)
treebe843a7c9a7ca52457d110ba04e79dcc28f67b97
parent30bd206493e8b2dae81e99cffb22266bd3029d3d (diff)
downloadlibADLMIDI-56c0cd7f2439898080df2e0a8129b72d2d85ca70.tar.gz
libADLMIDI-56c0cd7f2439898080df2e0a8129b72d2d85ca70.tar.bz2
libADLMIDI-56c0cd7f2439898080df2e0a8129b72d2d85ca70.zip
Small polishing of volume model and CMF/RSXX tempo
- Removed "Logarithmic volumes" flag as volume models concept successfuly serves this task. "Logarithmic volumes" flag is useless when we have volume models. - Fixed "too fast" tempo while playing CMF and EA-MUS (aka RSXX) files
-rw-r--r--include/adlmidi.h15
-rw-r--r--src/adlmidi.cpp4
-rw-r--r--src/adlmidi_load.cpp11
-rw-r--r--src/adlmidi_midiplay.cpp30
-rw-r--r--src/adlmidi_opl3.cpp7
-rw-r--r--src/adlmidi_private.hpp6
6 files changed, 39 insertions, 34 deletions
diff --git a/include/adlmidi.h b/include/adlmidi.h
index 56626bb..19dd6b2 100644
--- a/include/adlmidi.h
+++ b/include/adlmidi.h
@@ -30,7 +30,7 @@ extern "C" {
#define ADLMIDI_VERSION_MAJOR 1
#define ADLMIDI_VERSION_MINOR 3
-#define ADLMIDI_VERSION_PATCHLEVEL 2
+#define ADLMIDI_VERSION_PATCHLEVEL 3
#define ADLMIDI_TOSTR_I(s) #s
#define ADLMIDI_TOSTR(s) ADLMIDI_TOSTR_I(s)
@@ -58,11 +58,12 @@ typedef short ADL_SInt16;
enum ADLMIDI_VolumeModels
{
ADLMIDI_VolumeModel_AUTO = 0,
- ADLMIDI_VolumeModel_Generic,
- ADLMIDI_VolumeModel_CMF,
- ADLMIDI_VolumeModel_DMX,
- ADLMIDI_VolumeModel_APOGEE,
- ADLMIDI_VolumeModel_9X
+ ADLMIDI_VolumeModel_Generic = 1,
+ ADLMIDI_VolumeModel_NativeOPL3 = 2,
+ ADLMIDI_VolumeModel_CMF = ADLMIDI_VolumeModel_NativeOPL3,
+ ADLMIDI_VolumeModel_DMX = 3,
+ ADLMIDI_VolumeModel_APOGEE = 4,
+ ADLMIDI_VolumeModel_9X = 5
};
enum ADLMIDI_SampleType
@@ -141,7 +142,7 @@ extern void adl_setFullRangeBrightness(struct ADL_MIDIPlayer *device, int fr_bri
/*Enable or disable built-in loop (built-in loop supports 'loopStart' and 'loopEnd' tags to loop specific part)*/
extern void adl_setLoopEnabled(struct ADL_MIDIPlayer *device, int loopEn);
-/*Enable or disable Logariphmic volume changer */
+/* !!!DEPRECATED!!! Enable or disable Logariphmic volume changer */
extern void adl_setLogarithmicVolumes(struct ADL_MIDIPlayer *device, int logvol);
/*Set different volume range model */
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp
index c8eceaf..022a07d 100644
--- a/src/adlmidi.cpp
+++ b/src/adlmidi.cpp
@@ -221,12 +221,14 @@ ADLMIDI_EXPORT void adl_setLoopEnabled(ADL_MIDIPlayer *device, int loopEn)
play->m_setup.loopingIsEnabled = (loopEn != 0);
}
+/* !!!DEPRECATED!!! */
ADLMIDI_EXPORT void adl_setLogarithmicVolumes(struct ADL_MIDIPlayer *device, int logvol)
{
if(!device) return;
MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer);
play->m_setup.LogarithmicVolumes = logvol;
- play->opl.LogarithmicVolumes = play->m_setup.LogarithmicVolumes;
+ if(play->m_setup.LogarithmicVolumes)
+ play->opl.ChangeVolumeRangesModel(ADLMIDI_VolumeModel_NativeOPL3);
}
ADLMIDI_EXPORT void adl_setVolumeRangeModel(struct ADL_MIDIPlayer *device, int volumeModel)
diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp
index 35fba3b..0c2fe48 100644
--- a/src/adlmidi_load.cpp
+++ b/src/adlmidi_load.cpp
@@ -438,10 +438,9 @@ riffskip:
DeltaTicks = (size_t)ticks;
opl.AdlBank = ~0u; // Ignore AdlBank number, use dynamic banks instead
//std::printf("CMF deltas %u ticks %u, basictempo = %u\n", deltas, ticks, basictempo);
- opl.LogarithmicVolumes = true;
opl.AdlPercussionMode = true;
opl.m_musicMode = OPL3::MODE_CMF;
- opl.m_volumeScale = OPL3::VOLUME_CMF;
+ opl.m_volumeScale = OPL3::VOLUME_NATIVE;
}
else
{
@@ -456,10 +455,9 @@ riffskip:
fr.seek(0x7D, SEEK_SET);
TrackCount = 1;
DeltaTicks = 60;
- opl.LogarithmicVolumes = true;
//opl.CartoonersVolumes = true;
opl.m_musicMode = OPL3::MODE_RSXX;
- opl.m_volumeScale = OPL3::VOLUME_CMF;
+ opl.m_volumeScale = OPL3::VOLUME_NATIVE;
}
}
@@ -518,7 +516,10 @@ riffskip:
TrackData.clear();
TrackData.resize(TrackCount, std::vector<uint8_t>());
InvDeltaTicks = fraction<uint64_t>(1, 1000000l * static_cast<uint64_t>(DeltaTicks));
- Tempo = fraction<uint64_t>(1, static_cast<uint64_t>(DeltaTicks) * 2);
+ if(is_CMF || is_RSXX)
+ Tempo = fraction<uint64_t>(1, static_cast<uint64_t>(DeltaTicks));
+ else
+ Tempo = fraction<uint64_t>(1, static_cast<uint64_t>(DeltaTicks) * 2);
static const unsigned char EndTag[4] = {0xFF, 0x2F, 0x00, 0x00};
size_t totalGotten = 0;
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp
index 7919e91..52d8409 100644
--- a/src/adlmidi_midiplay.cpp
+++ b/src/adlmidi_midiplay.cpp
@@ -756,8 +756,8 @@ void MIDIplay::applySetup()
opl.ScaleModulators = m_setup.ScaleModulators < 0 ?
opl.dynamic_bank_setup.scaleModulators :
(bool)m_setup.ScaleModulators;
- opl.LogarithmicVolumes = m_setup.LogarithmicVolumes;
- //opl.CartoonersVolumes = false;
+ if(m_setup.LogarithmicVolumes)
+ opl.ChangeVolumeRangesModel(ADLMIDI_VolumeModel_NativeOPL3);
opl.m_musicMode = OPL3::MODE_MIDI;
opl.ChangeVolumeRangesModel(static_cast<ADLMIDI_VolumeModels>(m_setup.VolumeModel));
if(m_setup.VolumeModel == ADLMIDI_VolumeModel_AUTO)//Use bank default volume model
@@ -1555,8 +1555,8 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
switch(opl.m_volumeScale)
{
+
case OPL3::VOLUME_Generic:
- case OPL3::VOLUME_CMF:
{
volume = vol * Ch[MidCh].volume * Ch[MidCh].expression;
@@ -1569,20 +1569,24 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
*/
//volume = (int)(volume * std::sqrt( (double) ch[c].users.size() ));
- if(opl.LogarithmicVolumes)
- volume = volume * 127 / (127 * 127 * 127) / 2;
- else
- {
- // The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
- volume = volume > 8725 ? static_cast<uint32_t>(std::log(static_cast<double>(volume)) * 11.541561 + (0.5 - 104.22845)) : 0;
- // The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
- //opl.Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
- }
+ // The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
+ volume = volume > 8725 ? static_cast<uint32_t>(std::log(static_cast<double>(volume)) * 11.541561 + (0.5 - 104.22845)) : 0;
+ // The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
+ //opl.Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
+
opl.Touch_Real(c, volume, brightness);
//opl.Touch(c, volume);
}
break;
+ case OPL3::VOLUME_NATIVE:
+ {
+ volume = vol * Ch[MidCh].volume * Ch[MidCh].expression;
+ volume = volume * 127 / (127 * 127 * 127) / 2;
+ opl.Touch_Real(c, volume, brightness);
+ }
+ break;
+
case OPL3::VOLUME_DMX:
{
volume = 2 * ((Ch[MidCh].volume * Ch[MidCh].expression) * 127 / 16129) + 1;
@@ -2588,7 +2592,7 @@ ADLMIDI_EXPORT void AdlInstrumentTester::FindAdlList()
ADLMIDI_EXPORT void AdlInstrumentTester::Touch(unsigned c, unsigned volume) // Volume maxes at 127*127*127
{
OPL3 *opl = P->opl;
- if(opl->LogarithmicVolumes)
+ if(opl->m_volumeScale == OPL3::VOLUME_NATIVE)
opl->Touch_Real(c, volume * 127 / (127 * 127 * 127) / 2);
else
{
diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp
index 279a7d5..143c911 100644
--- a/src/adlmidi_opl3.cpp
+++ b/src/adlmidi_opl3.cpp
@@ -165,8 +165,6 @@ OPL3::OPL3() :
HighTremoloMode(false),
HighVibratoMode(false),
AdlPercussionMode(false),
- LogarithmicVolumes(false),
- //CartoonersVolumes(false),
m_musicMode(MODE_MIDI),
m_volumeScale(VOLUME_Generic)
{}
@@ -476,9 +474,8 @@ void OPL3::ChangeVolumeRangesModel(ADLMIDI_VolumeModels volumeModel)
m_volumeScale = OPL3::VOLUME_Generic;
break;
- case ADLMIDI_VolumeModel_CMF:
- LogarithmicVolumes = true;
- m_volumeScale = OPL3::VOLUME_CMF;
+ case ADLMIDI_VolumeModel_NativeOPL3:
+ m_volumeScale = OPL3::VOLUME_NATIVE;
break;
case ADLMIDI_VolumeModel_DMX:
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp
index e43bd4e..b20a2b4 100644
--- a/src/adlmidi_private.hpp
+++ b/src/adlmidi_private.hpp
@@ -251,8 +251,8 @@ public:
bool AdlPercussionMode;
//! Carriers-only are scaled by default by volume level. This flag will tell to scale modulators too.
bool ScaleModulators;
- //! Required to play CMF files. Can be turned on by using of "CMF" volume model
- bool LogarithmicVolumes;
+ // ! Required to play CMF files. Can be turned on by using of "CMF" volume model
+ //bool LogarithmicVolumes; //[REPLACED WITH "m_volumeScale == VOLUME_NATIVE", DEPRECATED!!!]
// ! Required to play EA-MUS files [REPLACED WITH "m_musicMode", DEPRECATED!!!]
//bool CartoonersVolumes;
enum MusicMode
@@ -268,7 +268,7 @@ public:
enum VolumesScale
{
VOLUME_Generic,
- VOLUME_CMF,
+ VOLUME_NATIVE,
VOLUME_DMX,
VOLUME_APOGEE,
VOLUME_9X