2020-01-02 16:52:30 +00:00
|
|
|
/*
|
Update libADLMIDI up to 1.5.0
## 1.5.0 2020-09-28
* Drum note length expanding is now supported in real-time mode (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!)
* Channels manager has been improved (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!)
* Nuked OPL3 1.8 emulator got some optimizations ported from 1.7 where they are was applied previously (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!)
* Reworked rhythm-mode percussions system, WOPL banks with rhythm-mode percussions
* Added Public Domain Opal OPL3 emulator made by Reality (a team who originally made the Reality Adlib Tracker) (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!)
* Added LGPL licensed JavaOPL3 emulator made by Robson Cozendey in Java and later rewritten into C++ for GZDoom (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!)
* Fully rewritten an embedded bank database format, embedded banks now supports a wider set (more than 127:127 instruments in one bank)
* Improved accuracy of the DMX volume model, include the buggy AM interpretation
* Improved accuracy of Apogee volume model, include the bug of AM instruments
* Improved accuracy of the Win9X volume model
* Removed C++ extras. C++-bounded instruments tester is useless since a real-time MIDI API can completely replace it
* Added AIL volume model
* Added Generic FM variant of Win9X volume model
* Fixed an incorrect work of CC-121 (See https://github.com/Wohlstand/libADLMIDI/issues/227 for details)
* Added HMI volume model (Thanks to [Alexey Khokholov](https://github.com/nukeykt) for help with research!)
* Added frequency models, assigned to every volume model: AIL, HMI, DMX, Apogee, 9X, and the Generic formula
2020-09-28 18:17:46 +00:00
|
|
|
* Copyright (c) 2017-2020 Vitaly Novichkov (Wohlstand)
|
2020-01-02 16:52:30 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ONP_CHIP_BASE_H
|
|
|
|
#define ONP_CHIP_BASE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#if !defined(_MSC_VER) && (__cplusplus <= 199711L)
|
|
|
|
#define final
|
|
|
|
#define override
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ADLMIDI_ENABLE_HQ_RESAMPLER)
|
|
|
|
class VResampler;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ADLMIDI_AUDIO_TICK_HANDLER)
|
|
|
|
extern void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class OPLChipBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { nativeRate = 49716 };
|
2020-10-15 11:24:44 +00:00
|
|
|
enum ChipType
|
|
|
|
{
|
|
|
|
CHIPTYPE_OPL3 = 0, CHIPTYPE_OPL2 = 1
|
|
|
|
};
|
2020-01-02 16:52:30 +00:00
|
|
|
protected:
|
|
|
|
uint32_t m_id;
|
|
|
|
uint32_t m_rate;
|
|
|
|
public:
|
|
|
|
OPLChipBase();
|
|
|
|
virtual ~OPLChipBase();
|
|
|
|
|
|
|
|
uint32_t chipId() const { return m_id; }
|
|
|
|
void setChipId(uint32_t id) { m_id = id; }
|
|
|
|
|
|
|
|
virtual bool canRunAtPcmRate() const = 0;
|
|
|
|
virtual bool isRunningAtPcmRate() const = 0;
|
|
|
|
virtual bool setRunningAtPcmRate(bool r) = 0;
|
|
|
|
#if defined(ADLMIDI_AUDIO_TICK_HANDLER)
|
|
|
|
virtual void setAudioTickHandlerInstance(void *instance) = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void setRate(uint32_t rate) = 0;
|
|
|
|
virtual uint32_t effectiveRate() const = 0;
|
|
|
|
virtual void reset() = 0;
|
|
|
|
virtual void writeReg(uint16_t addr, uint8_t data) = 0;
|
|
|
|
|
|
|
|
// extended
|
|
|
|
virtual void writePan(uint16_t addr, uint8_t data) { (void)addr; (void)data; }
|
|
|
|
|
|
|
|
virtual void nativePreGenerate() = 0;
|
|
|
|
virtual void nativePostGenerate() = 0;
|
|
|
|
virtual void nativeGenerate(int16_t *frame) = 0;
|
|
|
|
|
|
|
|
virtual void generate(int16_t *output, size_t frames) = 0;
|
|
|
|
virtual void generateAndMix(int16_t *output, size_t frames) = 0;
|
|
|
|
virtual void generate32(int32_t *output, size_t frames) = 0;
|
|
|
|
virtual void generateAndMix32(int32_t *output, size_t frames) = 0;
|
|
|
|
|
|
|
|
virtual const char* emulatorName() = 0;
|
2020-10-15 11:24:44 +00:00
|
|
|
virtual ChipType chipType() = 0;
|
2020-01-02 16:52:30 +00:00
|
|
|
private:
|
|
|
|
OPLChipBase(const OPLChipBase &c);
|
|
|
|
OPLChipBase &operator=(const OPLChipBase &c);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A base class providing F-bounded generic and efficient implementations,
|
|
|
|
// supporting resampling of chip outputs
|
|
|
|
template <class T>
|
|
|
|
class OPLChipBaseT : public OPLChipBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OPLChipBaseT();
|
|
|
|
virtual ~OPLChipBaseT();
|
|
|
|
|
|
|
|
bool isRunningAtPcmRate() const override;
|
|
|
|
bool setRunningAtPcmRate(bool r) override;
|
|
|
|
#if defined(ADLMIDI_AUDIO_TICK_HANDLER)
|
|
|
|
void setAudioTickHandlerInstance(void *instance);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void setRate(uint32_t rate) override;
|
|
|
|
uint32_t effectiveRate() const override;
|
|
|
|
virtual void reset() override;
|
|
|
|
void generate(int16_t *output, size_t frames) override;
|
|
|
|
void generateAndMix(int16_t *output, size_t frames) override;
|
|
|
|
void generate32(int32_t *output, size_t frames) override;
|
|
|
|
void generateAndMix32(int32_t *output, size_t frames) override;
|
|
|
|
private:
|
|
|
|
bool m_runningAtPcmRate;
|
|
|
|
#if defined(ADLMIDI_AUDIO_TICK_HANDLER)
|
|
|
|
void *m_audioTickHandlerInstance;
|
|
|
|
#endif
|
|
|
|
void nativeTick(int16_t *frame);
|
|
|
|
void setupResampler(uint32_t rate);
|
|
|
|
void resetResampler();
|
|
|
|
void resampledGenerate(int32_t *output);
|
|
|
|
#if defined(ADLMIDI_ENABLE_HQ_RESAMPLER)
|
|
|
|
VResampler *m_resampler;
|
|
|
|
#else
|
|
|
|
int32_t m_oldsamples[2];
|
|
|
|
int32_t m_samples[2];
|
|
|
|
int32_t m_samplecnt;
|
|
|
|
int32_t m_rateratio;
|
|
|
|
enum { rsm_frac = 10 };
|
|
|
|
#endif
|
|
|
|
// amplitude scale factors in and out of resampler, varying for chips;
|
|
|
|
// values are OK to "redefine", the static polymorphism will accept it.
|
|
|
|
enum { resamplerPreAmplify = 1, resamplerPostAttenuate = 1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
// A base class which provides frame-by-frame interfaces on emulations which
|
|
|
|
// don't have a routine for it. It produces outputs in fixed size buffers.
|
|
|
|
// Fast register updates will suffer some latency because of buffering.
|
|
|
|
template <class T, unsigned Buffer = 256>
|
|
|
|
class OPLChipBaseBufferedT : public OPLChipBaseT<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OPLChipBaseBufferedT()
|
|
|
|
: OPLChipBaseT<T>(), m_bufferIndex(0) {}
|
|
|
|
virtual ~OPLChipBaseBufferedT()
|
|
|
|
{}
|
|
|
|
public:
|
|
|
|
void reset() override;
|
|
|
|
void nativeGenerate(int16_t *frame) override;
|
|
|
|
protected:
|
|
|
|
virtual void nativeGenerateN(int16_t *output, size_t frames) = 0;
|
|
|
|
private:
|
|
|
|
unsigned m_bufferIndex;
|
|
|
|
int16_t m_buffer[2 * Buffer];
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "opl_chip_base.tcc"
|
|
|
|
|
|
|
|
#endif // ONP_CHIP_BASE_H
|