aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt35
-rw-r--r--utils/gen_adldata/measurer.cpp99
2 files changed, 82 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2228353..7db29ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,13 +99,42 @@ endif()
if(WITH_EMBEDDED_BANKS)
if(WITH_GENADLDATA)
- add_executable(gen_adldata
+ set(GEN_ADLDATA_SRC)
+ list(APPEND GEN_ADLDATA_SRC
${libADLMIDI_SOURCE_DIR}/utils/gen_adldata/gen_adldata.cc
${libADLMIDI_SOURCE_DIR}/utils/gen_adldata/progs_cache.cpp
${libADLMIDI_SOURCE_DIR}/utils/gen_adldata/measurer.cpp
${libADLMIDI_SOURCE_DIR}/utils/gen_adldata/ini/ini_processing.cpp
- ${libADLMIDI_SOURCE_DIR}/src/nukedopl3.c
- ${libADLMIDI_SOURCE_DIR}/src/dbopl.cpp
+ )
+
+ list(APPEND GEN_ADLDATA_SRC
+ ${libADLMIDI_SOURCE_DIR}/src/chips/opl_chip_base.cpp
+ )
+
+ if(USE_DOSBOX_EMULATOR)
+ set(HAS_EMULATOR TRUE)
+ list(APPEND GEN_ADLDATA_SRC
+ ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox_opl3.cpp
+ ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox/dbopl.cpp
+ )
+ else()
+ add_definitions(-DADLMIDI_DISABLE_DOSBOX_EMULATOR)
+ endif()
+
+ if(USE_NUKED_EMULATOR)
+ set(HAS_EMULATOR TRUE)
+ list(APPEND GEN_ADLDATA_SRC
+ ${libADLMIDI_SOURCE_DIR}/src/chips/nuked_opl3.cpp # v 1.8
+ ${libADLMIDI_SOURCE_DIR}/src/chips/nuked/nukedopl3.c
+ ${libADLMIDI_SOURCE_DIR}/src/chips/nuked_opl3_v174.cpp # v 1.7.4
+ ${libADLMIDI_SOURCE_DIR}/src/chips/nuked/nukedopl3_174.c
+ )
+ else()
+ add_definitions(-DADLMIDI_DISABLE_NUKED_EMULATOR)
+ endif()
+
+ add_executable(gen_adldata
+ ${GEN_ADLDATA_SRC}
)
if(NOT MSVC)
target_link_libraries(gen_adldata pthread m stdc++)
diff --git a/utils/gen_adldata/measurer.cpp b/utils/gen_adldata/measurer.cpp
index 7618d7d..7a81379 100644
--- a/utils/gen_adldata/measurer.cpp
+++ b/utils/gen_adldata/measurer.cpp
@@ -1,10 +1,17 @@
#include "measurer.h"
#include <cmath>
-#ifndef ADLMIDI_USE_DOSBOX_OPL
-#include "../../src/nukedopl3.h"
-#else
-#include "../../src/dbopl.h"
+#include "../../src/chips/opl_chip_base.h"
+
+// Nuked OPL3 emulator, Most accurate, but requires the powerful CPU
+#ifndef ADLMIDI_DISABLE_NUKED_EMULATOR
+# include "../../src/chips/nuked_opl3.h"
+# include "../../src/chips/nuked_opl3_v174.h"
+#endif
+
+// DosBox 0.74 OPL3 emulator, Well-accurate and fast
+#ifndef ADLMIDI_DISABLE_DOSBOX_EMULATOR
+# include "../../src/chips/dosbox_opl3.h"
#endif
DurationInfo MeasureDurations(const ins &in)
@@ -40,25 +47,22 @@ DurationInfo MeasureDurations(const ins &in)
: in.notenum >= 128 ? (44 + 128 - in.notenum)
: in.notenum;
-#ifndef ADLMIDI_USE_DOSBOX_OPL
-#define WRITE_REG(key, value) OPL3_WriteReg(&opl, (Bit8u)(key), (Bit8u)(value))
- _opl3_chip opl;
-#else
-#define WRITE_REG(key, value) opl.WriteReg((Bit8u)(key), (Bit8u)(value));
- DBOPL::Handler opl;
-#endif
+ OPLChipBase *opl;
+
+ //DosBoxOPL3 db; opl = &db;
+ //NukedOPL3 nuke; opl = &nuke;
+ NukedOPL3v174 nuke74; opl = &nuke74;
+
+#define WRITE_REG(key, value) opl->writeReg((uint16_t)(key), (uint8_t)(value))
static const short initdata[(2 + 3 + 2 + 2) * 2] =
{
- 0x004, 96, 0x004, 128, // Pulse timer
- 0x105, 0, 0x105, 1, 0x105, 0, // Pulse OPL3 enable, leave disabled
- 0x001, 32, 0x0BD, 0 // Enable wave & melodic
-};
-#ifndef ADLMIDI_USE_DOSBOX_OPL
- OPL3_Reset(&opl, rate);
-#else
- opl.Init(rate);
-#endif
+ 0x004, 96, 0x004, 128, // Pulse timer
+ 0x105, 0, 0x105, 1, 0x105, 0, // Pulse OPL3 enable, leave disabled
+ 0x001, 32, 0x0BD, 0 // Enable wave & melodic
+ };
+ opl->setRate(rate);
+
for(unsigned a = 0; a < 18; a += 2) WRITE_REG(initdata[a], initdata[a + 1]);
const unsigned n_notes = in.insno1 == in.insno2 ? 1 : 2;
@@ -100,32 +104,28 @@ DurationInfo MeasureDurations(const ins &in)
WRITE_REG(0xB0 + n * 3, x[n] >> 8);
}
+ const unsigned max_silent = 6;
const unsigned max_on = 40;
const unsigned max_off = 60;
// For up to 40 seconds, measure mean amplitude.
std::vector<double> amplitudecurve_on;
double highest_sofar = 0;
+ short sound_min = 0, sound_max = 0;
for(unsigned period = 0; period < max_on * interval; ++period)
{
stereoSampleBuf.clear();
stereoSampleBuf.resize(samples_per_interval * 2);
-#ifndef ADLMIDI_USE_DOSBOX_OPL
- OPL3_GenerateStream(&opl, stereoSampleBuf.data(), samples_per_interval);
-#else
- {
- stereoSampleBuf_32.resize(samples_per_interval * 2);
- Bitu samples = samples_per_interval;
- opl.GenerateArr(stereoSampleBuf_32.data(), &samples);
- size_t ssat = 0;
- for(const int32_t &i : stereoSampleBuf_32)
- stereoSampleBuf[ssat++] = (int16_t)i;
- }
-#endif
+ opl->generate(stereoSampleBuf.data(), samples_per_interval);
double mean = 0.0;
for(unsigned long c = 0; c < samples_per_interval; ++c)
- mean += stereoSampleBuf[c * 2];
+ {
+ short s = stereoSampleBuf[c * 2];
+ mean += s;
+ if(sound_min > s) sound_min = s;
+ if(sound_max < s) sound_max = s;
+ }
mean /= samples_per_interval;
double std_deviation = 0;
for(unsigned long c = 0; c < samples_per_interval; ++c)
@@ -138,7 +138,10 @@ DurationInfo MeasureDurations(const ins &in)
if(std_deviation > highest_sofar)
highest_sofar = std_deviation;
- if(period > 6 * interval && std_deviation < highest_sofar * 0.2)
+ if((period > max_silent * interval) &&
+ ((std_deviation < highest_sofar * 0.2)||
+ (sound_min >= -1 && sound_max <= 1))
+ )
break;
}
@@ -152,22 +155,16 @@ DurationInfo MeasureDurations(const ins &in)
{
stereoSampleBuf.clear();
stereoSampleBuf.resize(samples_per_interval * 2);
-#ifndef ADLMIDI_USE_DOSBOX_OPL
- OPL3_GenerateStream(&opl, stereoSampleBuf.data(), samples_per_interval);
-#else
- {
- stereoSampleBuf_32.resize(samples_per_interval * 2);
- Bitu samples = samples_per_interval;
- opl.GenerateArr(stereoSampleBuf_32.data(), &samples);
- size_t ssat = 0;
- for(const int32_t &i : stereoSampleBuf_32)
- stereoSampleBuf[ssat++] = (int16_t)i;
- }
-#endif
+ opl->generate(stereoSampleBuf.data(), samples_per_interval);
double mean = 0.0;
for(unsigned long c = 0; c < samples_per_interval; ++c)
- mean += stereoSampleBuf[c * 2];
+ {
+ short s = stereoSampleBuf[c * 2];
+ mean += s;
+ if(sound_min > s) sound_min = s;
+ if(sound_max < s) sound_max = s;
+ }
mean /= samples_per_interval;
double std_deviation = 0;
for(unsigned long c = 0; c < samples_per_interval; ++c)
@@ -178,7 +175,11 @@ DurationInfo MeasureDurations(const ins &in)
std_deviation = std::sqrt(std_deviation / samples_per_interval);
amplitudecurve_off.push_back(std_deviation);
- if(std_deviation < highest_sofar * 0.2) break;
+ if(std_deviation < highest_sofar * 0.2)
+ break;
+
+ if((period > max_silent * interval) && (sound_min >= -1 && sound_max <= 1))
+ break;
}
/* Analyze the results */
@@ -225,7 +226,7 @@ DurationInfo MeasureDurations(const ins &in)
result.ms_sound_kon = (int64_t)(quarter_amplitude_time * 1000.0 / interval);
result.ms_sound_koff = (int64_t)(keyoff_out_time * 1000.0 / interval);
- result.nosound = (peak_amplitude_value < 0.5);
+ result.nosound = (peak_amplitude_value < 0.5) || ((sound_min >= -1) && (sound_max <= 1));
return result;
}