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 "../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();
Buf32 = new Bit32s[buflen*2];
zdoom = JavaOPLCreate(false);
this->SetEmulator(emulator);
_op1offset[1] = 0x0;
_op1offset[2] = 0x1;
_op1offset[3] = 0x2;
@ -33,32 +36,21 @@ Hiopl::Hiopl(int buflen) {
}
}
void Hiopl::Generate(int length, short* buffer) {
adlib->Generate(length, Buf32);
for (int i = 0; i < length; i++) {
buffer[i] = (short)(Buf32[i]);
}
void Hiopl::SetEmulator(Emulator emulator) {
this->emulator = emulator;
}
void Hiopl::Generate(int length, float* buffer) {
// This would be better done using Juce's built in audio format conversion.
adlib->Generate(length, Buf32);
for (int i = 0; i < length; i++) {
buffer[i] = (float)(Buf32[i])/32768.0f;
if (DOSBOX == emulator) {
adlib->Generate(length, Buf32);
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) {
@ -69,7 +61,11 @@ void Hiopl::_WriteReg(Bit32u reg, Bit8u value, Bit8u mask) {
if (mask > 0) {
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;
}

View file

@ -2,6 +2,7 @@
#include "adlib.h"
#include "dbopl.h"
#include "zdopl.h"
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
};
enum Emulator
{
DOSBOX=0, ZDOOM=1
};
class Hiopl {
public:
static const int CHANNELS = 9;
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, float* buffer);
void SetSampleRate(int hz);
@ -51,7 +59,9 @@ class Hiopl {
void _ClearRegBits(Bit32u reg, Bit8u mask);
~Hiopl();
private:
Emulator emulator;
Adlib::Handler *adlib;
OPLEmul *zdoom;
Bit8u regCache[256];
Bit32s *Buf32;
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