2
0
Fork 0

Hacked in support for the ZDoom emulator.

This commit is contained in:
bruce 2014-09-24 23:53:40 +09:00
parent b1a16c70cb
commit 24acda92fc
4 changed files with 1946 additions and 26 deletions

View File

@ -3,11 +3,14 @@
#include <assert.h> #include <assert.h>
#include "../JuceLibraryCode/JuceHeader.h" #include "../JuceLibraryCode/JuceHeader.h"
// A higher level wrapper around the DOSBox OPL emulator. // A wrapper around the DOSBox and ZDoom OPL emulators.
Hiopl::Hiopl(int buflen) { Hiopl::Hiopl(int buflen, Emulator emulator) {
adlib = new DBOPL::Handler(); adlib = new DBOPL::Handler();
Buf32 = new Bit32s[buflen*2]; zdoom = JavaOPLCreate(false);
this->SetEmulator(emulator);
_op1offset[1] = 0x0; _op1offset[1] = 0x0;
_op1offset[2] = 0x1; _op1offset[2] = 0x1;
_op1offset[3] = 0x2; _op1offset[3] = 0x2;
@ -33,32 +36,21 @@ Hiopl::Hiopl(int buflen) {
} }
} }
void Hiopl::Generate(int length, short* buffer) { void Hiopl::SetEmulator(Emulator emulator) {
adlib->Generate(length, Buf32); this->emulator = emulator;
for (int i = 0; i < length; i++) {
buffer[i] = (short)(Buf32[i]);
}
} }
void Hiopl::Generate(int length, float* buffer) { void Hiopl::Generate(int length, float* buffer) {
// This would be better done using Juce's built in audio format conversion. // This would be better done using Juce's built in audio format conversion.
adlib->Generate(length, Buf32); if (DOSBOX == emulator) {
for (int i = 0; i < length; i++) { adlib->Generate(length, Buf32);
buffer[i] = (float)(Buf32[i])/32768.0f; for (int i = 0; i < length; i++) {
buffer[i] = (float)(Buf32[i])/32768.0f;
}
} else if (ZDOOM == emulator) {
// ZDoom hacked to write mono samples
zdoom->Update(buffer, length);
} }
/*
AudioData::ConverterInstance<
AudioData::Pointer <AudioData::Int16,
AudioData::NativeEndian,
AudioData::Interleaved,
AudioData::Const>,
AudioData::Pointer <AudioData::Float32,
AudioData::NativeEndian,
AudioData::NonInterleaved,
AudioData::NonConst>
>converter;
converter.convertSamples(buffer, 0, Buf32, 0, length);
*/
} }
void Hiopl::SetSampleRate(int hz) { void Hiopl::SetSampleRate(int hz) {
@ -69,7 +61,11 @@ void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) {
if (mask > 0) { if (mask > 0) {
value = (regCache[reg] & (~mask)) | (value & mask); value = (regCache[reg] & (~mask)) | (value & mask);
} }
adlib->WriteReg(reg, value); if (DOSBOX == emulator) {
adlib->WriteReg(reg, value);
} else if (ZDOOM == emulator) {
zdoom->WriteReg(reg, value);
}
regCache[reg] = value; regCache[reg] = value;
} }

View File

@ -2,6 +2,7 @@
#include "adlib.h" #include "adlib.h"
#include "dbopl.h" #include "dbopl.h"
#include "zdopl.h"
enum Waveform enum Waveform
{ {
@ -13,12 +14,19 @@ enum FreqMultiple
xHALF=0, x1=1, x2=2, x3=3, x4=4, x5=5, x6=6, x7=7, x8=8, x9=9, x10=10, x12=12, x15=15 xHALF=0, x1=1, x2=2, x3=3, x4=4, x5=5, x6=6, x7=7, x8=8, x9=9, x10=10, x12=12, x15=15
}; };
enum Emulator
{
DOSBOX=0, ZDOOM=1
};
class Hiopl { class Hiopl {
public: public:
static const int CHANNELS = 9; static const int CHANNELS = 9;
static const int OSCILLATORS = 2; static const int OSCILLATORS = 2;
Hiopl(int buflen); Hiopl(int buflen, Emulator emulator=ZDOOM);
void Hiopl::SetEmulator(Emulator emulator);
void Generate(int length, short* buffer); void Generate(int length, short* buffer);
void Generate(int length, float* buffer); void Generate(int length, float* buffer);
void SetSampleRate(int hz); void SetSampleRate(int hz);
@ -51,7 +59,9 @@ class Hiopl {
void _ClearRegBits(Bit32u reg, Bit8u mask); void _ClearRegBits(Bit32u reg, Bit8u mask);
~Hiopl(); ~Hiopl();
private: private:
Emulator emulator;
Adlib::Handler *adlib; Adlib::Handler *adlib;
OPLEmul *zdoom;
Bit8u regCache[256]; Bit8u regCache[256];
Bit32s *Buf32; Bit32s *Buf32;
bool _CheckParams(int ch, int osc); bool _CheckParams(int ch, int osc);

1890
Source/zdopl.cpp Normal file

File diff suppressed because it is too large Load Diff

24
Source/zdopl.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef OPL_H
#define OPL_H
// Abstract base class for OPL emulators
class OPLEmul
{
public:
OPLEmul() {}
virtual ~OPLEmul() {}
virtual void Reset() = 0;
virtual void WriteReg(int reg, int v) = 0;
virtual void Update(float *buffer, int length) = 0;
virtual void SetPanning(int c, float left, float right) = 0;
};
OPLEmul *JavaOPLCreate(bool stereo);
#define OPL_SAMPLE_RATE 49716.0
#define CENTER_PANNING_POWER 0.70710678118 /* [RH] volume at center for EQP */
#endif