From a175de1531acea3b56eef18ebf426c954abfd882 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Thu, 15 Oct 2020 14:24:44 +0300 Subject: [PATCH] The small update at libADLMIDI - Fixed a bug of DMX frequency, accidentally ported from DMX - Removed the useless adlmidi_sequencer.cpp file - Synchronize all files of chipset with OPL3-BE --- thirdparty/adlmidi/adlmidi_opl3.cpp | 8 +- thirdparty/adlmidi/adlmidi_sequencer.cpp | 160 ------------------- thirdparty/adlmidi/chips/common/ptr.hpp | 110 +++++++++++++ thirdparty/adlmidi/chips/dosbox/dbopl.cpp | 11 +- thirdparty/adlmidi/chips/dosbox_opl3.cpp | 5 + thirdparty/adlmidi/chips/dosbox_opl3.h | 1 + thirdparty/adlmidi/chips/java_opl3.cpp | 5 + thirdparty/adlmidi/chips/java_opl3.h | 1 + thirdparty/adlmidi/chips/nuked_opl3.cpp | 5 + thirdparty/adlmidi/chips/nuked_opl3.h | 1 + thirdparty/adlmidi/chips/nuked_opl3_v174.cpp | 5 + thirdparty/adlmidi/chips/nuked_opl3_v174.h | 1 + thirdparty/adlmidi/chips/opal_opl3.cpp | 5 + thirdparty/adlmidi/chips/opal_opl3.h | 1 + thirdparty/adlmidi/chips/opl_chip_base.h | 5 + 15 files changed, 154 insertions(+), 170 deletions(-) delete mode 100644 thirdparty/adlmidi/adlmidi_sequencer.cpp create mode 100644 thirdparty/adlmidi/chips/common/ptr.hpp diff --git a/thirdparty/adlmidi/adlmidi_opl3.cpp b/thirdparty/adlmidi/adlmidi_opl3.cpp index a3ec71b..0a41569 100644 --- a/thirdparty/adlmidi/adlmidi_opl3.cpp +++ b/thirdparty/adlmidi/adlmidi_opl3.cpp @@ -403,14 +403,16 @@ static inline double s_dmxFreq(double tone) int_fast32_t oct = 0; int_fast32_t freqIndex = (noteI << 5) + bendI; +#define MAX_FREQ_IDX 283 // 284 - with the DMX side bug if(freqIndex < 0) freqIndex = 0; - else if(freqIndex >= 284) + else if(freqIndex >= MAX_FREQ_IDX) { - freqIndex -= 284; + freqIndex -= MAX_FREQ_IDX; oct = freqIndex / 384; - freqIndex = (freqIndex % 384) + 284; + freqIndex = (freqIndex % 384) + MAX_FREQ_IDX; } +#undef MAX_FREQ_IDX outHz = s_dmx_freq_table[freqIndex]; diff --git a/thirdparty/adlmidi/adlmidi_sequencer.cpp b/thirdparty/adlmidi/adlmidi_sequencer.cpp deleted file mode 100644 index bf3d86c..0000000 --- a/thirdparty/adlmidi/adlmidi_sequencer.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * libADLMIDI is a free Software MIDI synthesizer library with OPL3 emulation - * - * Original ADLMIDI code: Copyright (c) 2010-2014 Joel Yliluoma - * ADLMIDI Library API: Copyright (c) 2015-2020 Vitaly Novichkov - * - * Library is based on the ADLMIDI, a MIDI player for Linux and Windows with OPL3 emulation: - * http://iki.fi/bisqwit/source/adlmidi.html - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER - -// Rename class to avoid ABI collisions -#define BW_MidiSequencer AdlMidiSequencer -// Inlucde MIDI sequencer class implementation -#include "midi_sequencer_impl.hpp" - -#include "adlmidi_midiplay.hpp" -#include "adlmidi_opl3.hpp" -#include "adlmidi_private.hpp" - -/**************************************************** - * Real-Time MIDI calls proxies * - ****************************************************/ - -static void rtNoteOn(void *userdata, uint8_t channel, uint8_t note, uint8_t velocity) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_NoteOn(channel, note, velocity); -} - -static void rtNoteOff(void *userdata, uint8_t channel, uint8_t note) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_NoteOff(channel, note); -} - -static void rtNoteAfterTouch(void *userdata, uint8_t channel, uint8_t note, uint8_t atVal) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_NoteAfterTouch(channel, note, atVal); -} - -static void rtChannelAfterTouch(void *userdata, uint8_t channel, uint8_t atVal) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_ChannelAfterTouch(channel, atVal); -} - -static void rtControllerChange(void *userdata, uint8_t channel, uint8_t type, uint8_t value) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_Controller(channel, type, value); -} - -static void rtPatchChange(void *userdata, uint8_t channel, uint8_t patch) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_PatchChange(channel, patch); -} - -static void rtPitchBend(void *userdata, uint8_t channel, uint8_t msb, uint8_t lsb) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_PitchBend(channel, msb, lsb); -} - -static void rtSysEx(void *userdata, const uint8_t *msg, size_t size) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_SysEx(msg, size); -} - - -/* NonStandard calls */ -static void rtRawOPL(void *userdata, uint8_t reg, uint8_t value) -{ - MIDIplay *context = reinterpret_cast(userdata); - return context->realTime_rawOPL(reg, value); -} - -static void rtDeviceSwitch(void *userdata, size_t track, const char *data, size_t length) -{ - MIDIplay *context = reinterpret_cast(userdata); - context->realTime_deviceSwitch(track, data, length); -} - -static size_t rtCurrentDevice(void *userdata, size_t track) -{ - MIDIplay *context = reinterpret_cast(userdata); - return context->realTime_currentDevice(track); -} - -static void rtSongBegin(void *userdata) -{ - MIDIplay *context = reinterpret_cast(userdata); - return context->realTime_ResetState(); -} - -/* NonStandard calls End */ - - -void MIDIplay::initSequencerInterface() -{ - BW_MidiRtInterface *seq = new BW_MidiRtInterface; - m_sequencerInterface.reset(seq); - - std::memset(seq, 0, sizeof(BW_MidiRtInterface)); - - seq->onDebugMessage = hooks.onDebugMessage; - seq->onDebugMessage_userData = hooks.onDebugMessage_userData; - - /* MIDI Real-Time calls */ - seq->rtUserData = this; - seq->rt_noteOn = rtNoteOn; - seq->rt_noteOff = rtNoteOff; - seq->rt_noteAfterTouch = rtNoteAfterTouch; - seq->rt_channelAfterTouch = rtChannelAfterTouch; - seq->rt_controllerChange = rtControllerChange; - seq->rt_patchChange = rtPatchChange; - seq->rt_pitchBend = rtPitchBend; - seq->rt_systemExclusive = rtSysEx; - - /* NonStandard calls */ - seq->rt_rawOPL = rtRawOPL; - seq->rt_deviceSwitch = rtDeviceSwitch; - seq->rt_currentDevice = rtCurrentDevice; - - seq->onSongStart = rtSongBegin; - seq->onSongStart_userData = this; - /* NonStandard calls End */ - - m_sequencer->setInterface(seq); -} - -double MIDIplay::Tick(double s, double granularity) -{ - MidiSequencer &seqr = *m_sequencer; - double ret = seqr.Tick(s, granularity); - - s *= seqr.getTempoMultiplier(); - TickIterators(s); - - return ret; -} - -#endif /* ADLMIDI_DISABLE_MIDI_SEQUENCER */ diff --git a/thirdparty/adlmidi/chips/common/ptr.hpp b/thirdparty/adlmidi/chips/common/ptr.hpp new file mode 100644 index 0000000..af37a67 --- /dev/null +++ b/thirdparty/adlmidi/chips/common/ptr.hpp @@ -0,0 +1,110 @@ +/* + * libADLMIDI is a free Software MIDI synthesizer library with OPL3 emulation + * + * Original ADLMIDI code: Copyright (c) 2010-2014 Joel Yliluoma + * ADLMIDI Library API: Copyright (c) 2015-2020 Vitaly Novichkov + * + * Library is based on the ADLMIDI, a MIDI player for Linux and Windows with OPL3 emulation: + * http://iki.fi/bisqwit/source/adlmidi.html + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MY_PTR_HPP_THING +#define MY_PTR_HPP_THING + +#include +#include + +/* + Generic deleters for smart pointers + */ +template +struct My_DefaultDelete +{ + void operator()(T *x) { delete x; } +}; + +template +struct My_DefaultArrayDelete +{ + void operator()(T *x) { delete[] x; } +}; + +struct My_CDelete +{ + void operator()(void *x) { free(x); } +}; + +/* + Safe unique pointer for C++98, non-copyable but swappable. +*/ +template< class T, class Deleter = My_DefaultDelete > +class My_UPtr +{ + T *m_p; +public: + explicit My_UPtr(T *p = NULL) + : m_p(p) {} + ~My_UPtr() + { + reset(); + } + + void reset(T *p = NULL) + { + if(p != m_p) + { + if(m_p) + { + Deleter del; + del(m_p); + } + m_p = p; + } + } + + T *get() const + { + return m_p; + } + + T *release() + { + T *ret = m_p; + m_p = NULL; + return ret; + } + + T &operator*() const + { + return *m_p; + } + + T *operator->() const + { + return m_p; + } + + T &operator[](size_t index) const + { + return m_p[index]; + } + +private: + My_UPtr(const My_UPtr &); + My_UPtr &operator=(const My_UPtr &); +}; + +#endif // MY_PTR_HPP_THING diff --git a/thirdparty/adlmidi/chips/dosbox/dbopl.cpp b/thirdparty/adlmidi/chips/dosbox/dbopl.cpp index 5b4bf53..c5a7024 100644 --- a/thirdparty/adlmidi/chips/dosbox/dbopl.cpp +++ b/thirdparty/adlmidi/chips/dosbox/dbopl.cpp @@ -41,6 +41,7 @@ #include #include "dbopl.h" #include "../common/mutex.hpp" +#include "../common/ptr.hpp" #if defined(__GNUC__) && __GNUC__ > 3 #define INLINE inline __attribute__((__always_inline__)) @@ -1353,11 +1354,7 @@ static const CacheEntry &ComputeRateDependent( Bit32u rate ) double original = OPLRATE; double scale = original / (double)rate; -#if __cplusplus >= 201103L - std::unique_ptr entry(new CacheEntry); -#else - std::auto_ptr entry(new CacheEntry); -#endif + My_UPtr entry(new CacheEntry); entry->rate = rate; Bit32u *freqMul = entry->freqMul; Bit32u *linearRates = entry->linearRates; @@ -1438,8 +1435,8 @@ static const CacheEntry &ComputeRateDependent( Bit32u rate ) } MutexHolder lock( cache.mutex ); - if (const CacheEntry *entry = CacheLookupRateDependent( rate )) - return *entry; + if (const CacheEntry *e = CacheLookupRateDependent( rate )) + return *e; cache.entries.push_back(entry.get()); return *entry.release(); diff --git a/thirdparty/adlmidi/chips/dosbox_opl3.cpp b/thirdparty/adlmidi/chips/dosbox_opl3.cpp index a3d5351..6d94eac 100644 --- a/thirdparty/adlmidi/chips/dosbox_opl3.cpp +++ b/thirdparty/adlmidi/chips/dosbox_opl3.cpp @@ -83,3 +83,8 @@ const char *DosBoxOPL3::emulatorName() { return "DOSBox 0.74-r4111 OPL3"; } + +OPLChipBase::ChipType DosBoxOPL3::chipType() +{ + return CHIPTYPE_OPL3; +} diff --git a/thirdparty/adlmidi/chips/dosbox_opl3.h b/thirdparty/adlmidi/chips/dosbox_opl3.h index ca3269c..58082b4 100644 --- a/thirdparty/adlmidi/chips/dosbox_opl3.h +++ b/thirdparty/adlmidi/chips/dosbox_opl3.h @@ -41,6 +41,7 @@ public: void nativePostGenerate() override {} void nativeGenerateN(int16_t *output, size_t frames) override; const char *emulatorName() override; + ChipType chipType() override; }; #endif // DOSBOX_OPL3_H diff --git a/thirdparty/adlmidi/chips/java_opl3.cpp b/thirdparty/adlmidi/chips/java_opl3.cpp index ec8c6c7..5acd6e5 100644 --- a/thirdparty/adlmidi/chips/java_opl3.cpp +++ b/thirdparty/adlmidi/chips/java_opl3.cpp @@ -110,3 +110,8 @@ const char *JavaOPL3::emulatorName() { return "Java 1.0.6 OPL3"; } + +OPLChipBase::ChipType JavaOPL3::chipType() +{ + return CHIPTYPE_OPL3; +} diff --git a/thirdparty/adlmidi/chips/java_opl3.h b/thirdparty/adlmidi/chips/java_opl3.h index edadd88..ccaa4de 100644 --- a/thirdparty/adlmidi/chips/java_opl3.h +++ b/thirdparty/adlmidi/chips/java_opl3.h @@ -39,6 +39,7 @@ public: void nativePostGenerate() override {} void nativeGenerateN(int16_t *output, size_t frames) override; const char *emulatorName() override; + ChipType chipType() override; }; #endif // JAVA_OPL3_H diff --git a/thirdparty/adlmidi/chips/nuked_opl3.cpp b/thirdparty/adlmidi/chips/nuked_opl3.cpp index ad379eb..a83ef8c 100644 --- a/thirdparty/adlmidi/chips/nuked_opl3.cpp +++ b/thirdparty/adlmidi/chips/nuked_opl3.cpp @@ -73,3 +73,8 @@ const char *NukedOPL3::emulatorName() { return "Nuked OPL3 (v 1.8)"; } + +OPLChipBase::ChipType NukedOPL3::chipType() +{ + return CHIPTYPE_OPL3; +} diff --git a/thirdparty/adlmidi/chips/nuked_opl3.h b/thirdparty/adlmidi/chips/nuked_opl3.h index d9c0e76..8764dd0 100644 --- a/thirdparty/adlmidi/chips/nuked_opl3.h +++ b/thirdparty/adlmidi/chips/nuked_opl3.h @@ -39,6 +39,7 @@ public: void nativePostGenerate() override {} void nativeGenerate(int16_t *frame) override; const char *emulatorName() override; + ChipType chipType() override; }; #endif // NUKED_OPL3_H diff --git a/thirdparty/adlmidi/chips/nuked_opl3_v174.cpp b/thirdparty/adlmidi/chips/nuked_opl3_v174.cpp index a15e1ef..a3fb023 100644 --- a/thirdparty/adlmidi/chips/nuked_opl3_v174.cpp +++ b/thirdparty/adlmidi/chips/nuked_opl3_v174.cpp @@ -73,3 +73,8 @@ const char *NukedOPL3v174::emulatorName() { return "Nuked OPL3 (v 1.7.4)"; } + +OPLChipBase::ChipType NukedOPL3v174::chipType() +{ + return CHIPTYPE_OPL3; +} diff --git a/thirdparty/adlmidi/chips/nuked_opl3_v174.h b/thirdparty/adlmidi/chips/nuked_opl3_v174.h index bba7afd..63abb15 100644 --- a/thirdparty/adlmidi/chips/nuked_opl3_v174.h +++ b/thirdparty/adlmidi/chips/nuked_opl3_v174.h @@ -39,6 +39,7 @@ public: void nativePostGenerate() override {} void nativeGenerate(int16_t *frame) override; const char *emulatorName() override; + ChipType chipType() override; }; #endif // NUKED_OPL3174_H diff --git a/thirdparty/adlmidi/chips/opal_opl3.cpp b/thirdparty/adlmidi/chips/opal_opl3.cpp index 3c1cbb7..260743f 100644 --- a/thirdparty/adlmidi/chips/opal_opl3.cpp +++ b/thirdparty/adlmidi/chips/opal_opl3.cpp @@ -79,3 +79,8 @@ const char *OpalOPL3::emulatorName() { return "Opal OPL3"; } + +OPLChipBase::ChipType OpalOPL3::chipType() +{ + return CHIPTYPE_OPL3; +} diff --git a/thirdparty/adlmidi/chips/opal_opl3.h b/thirdparty/adlmidi/chips/opal_opl3.h index ca14f3a..0ff07c5 100644 --- a/thirdparty/adlmidi/chips/opal_opl3.h +++ b/thirdparty/adlmidi/chips/opal_opl3.h @@ -39,6 +39,7 @@ public: void nativePostGenerate() override {} void nativeGenerate(int16_t *frame) override; const char *emulatorName() override; + ChipType chipType() override; }; #endif // NUKED_OPL3_H diff --git a/thirdparty/adlmidi/chips/opl_chip_base.h b/thirdparty/adlmidi/chips/opl_chip_base.h index 006e222..980e23b 100644 --- a/thirdparty/adlmidi/chips/opl_chip_base.h +++ b/thirdparty/adlmidi/chips/opl_chip_base.h @@ -39,6 +39,10 @@ class OPLChipBase { public: enum { nativeRate = 49716 }; + enum ChipType + { + CHIPTYPE_OPL3 = 0, CHIPTYPE_OPL2 = 1 + }; protected: uint32_t m_id; uint32_t m_rate; @@ -74,6 +78,7 @@ public: virtual void generateAndMix32(int32_t *output, size_t frames) = 0; virtual const char* emulatorName() = 0; + virtual ChipType chipType() = 0; private: OPLChipBase(const OPLChipBase &c); OPLChipBase &operator=(const OPLChipBase &c);