|
@@ -3,65 +3,33 @@
|
|
// SDLPal
|
|
// SDLPal
|
|
//
|
|
//
|
|
// Created by palxex on 14-7-20.
|
|
// Created by palxex on 14-7-20.
|
|
-// Copyright (c) 2014年 Wei Mingzhi. All rights reserved.
|
|
|
|
|
|
+// Copyright (c) 2014 Wei Mingzhi. All rights reserved.
|
|
//
|
|
//
|
|
|
|
|
|
#include "demuopl.h"
|
|
#include "demuopl.h"
|
|
-#include <math.h>
|
|
|
|
-#include <stdlib.h> // rand()
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
-int CDemuopl::channels = 0;
|
|
|
|
-
|
|
|
|
-struct OPLHandler {
|
|
|
|
- virtual void init(int rate) = 0;
|
|
|
|
- virtual void getsample(short *buf,int samples) = 0;
|
|
|
|
- virtual void write(int reg,int val) = 0;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-namespace OPLCore {
|
|
|
|
-#include "dosbox_opl.cpp"
|
|
|
|
- struct DOSBoxOPLHandler : OPLHandler {
|
|
|
|
- void init(int rate) {
|
|
|
|
- adlib_init(rate);
|
|
|
|
- }
|
|
|
|
- void getsample(short *buf, int samples) {
|
|
|
|
- adlib_getsample(buf, samples);
|
|
|
|
- }
|
|
|
|
- void write(int reg, int val) {
|
|
|
|
- adlib_write(reg, val);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+CDemuopl::CDemuopl(int rate, bool bit16, bool usestereo)
|
|
|
|
+ : use16bit(bit16), stereo(usestereo), rate(rate), chip(adlib_init(rate))
|
|
|
|
+{
|
|
|
|
+ currType = TYPE_OPL2;
|
|
}
|
|
}
|
|
|
|
|
|
-namespace OPLCore2 {
|
|
|
|
-#include "dosbox_opl.cpp"
|
|
|
|
- struct DOSBoxOPLHandler : OPLHandler {
|
|
|
|
- void init(int rate) {
|
|
|
|
- adlib_init(rate);
|
|
|
|
- }
|
|
|
|
- void getsample(short *buf, int samples) {
|
|
|
|
- adlib_getsample(buf, samples);
|
|
|
|
- }
|
|
|
|
- void write(int reg, int val) {
|
|
|
|
- adlib_write(reg, val);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+CDemuopl::~CDemuopl()
|
|
|
|
+{
|
|
|
|
+ adlib_release(chip);
|
|
}
|
|
}
|
|
|
|
|
|
-CDemuopl::CDemuopl(int rate, bool bit16, bool usestereo)
|
|
|
|
- :use16bit(bit16), stereo(usestereo)
|
|
|
|
|
|
+void CDemuopl::init()
|
|
{
|
|
{
|
|
- if (channels++ == 0)
|
|
|
|
- pHandler = new OPLCore::DOSBoxOPLHandler;
|
|
|
|
- else
|
|
|
|
- pHandler = new OPLCore2::DOSBoxOPLHandler;
|
|
|
|
- pHandler->init(rate);
|
|
|
|
- currType = TYPE_OPL2;
|
|
|
|
|
|
+ if (chip) adlib_release(chip);
|
|
|
|
+ chip = adlib_init(rate);
|
|
}
|
|
}
|
|
|
|
|
|
void CDemuopl::update(short *buf, int samples)
|
|
void CDemuopl::update(short *buf, int samples)
|
|
{
|
|
{
|
|
|
|
+ if (!chip) return;
|
|
|
|
+
|
|
short *mixbuf1 = NULL;
|
|
short *mixbuf1 = NULL;
|
|
short *outbuf;
|
|
short *outbuf;
|
|
if (use16bit) outbuf = buf;
|
|
if (use16bit) outbuf = buf;
|
|
@@ -69,7 +37,7 @@ void CDemuopl::update(short *buf, int samples)
|
|
mixbuf1 = new short[samples * 2];
|
|
mixbuf1 = new short[samples * 2];
|
|
outbuf = mixbuf1;
|
|
outbuf = mixbuf1;
|
|
}
|
|
}
|
|
- pHandler->getsample(outbuf, samples);
|
|
|
|
|
|
+ adlib_getsample(chip, outbuf, samples);
|
|
if (stereo)
|
|
if (stereo)
|
|
for (int i = samples - 1; i >= 0; i--) {
|
|
for (int i = samples - 1; i >= 0; i--) {
|
|
outbuf[i * 2] = outbuf[i];
|
|
outbuf[i * 2] = outbuf[i];
|
|
@@ -86,5 +54,5 @@ void CDemuopl::update(short *buf, int samples)
|
|
// template methods
|
|
// template methods
|
|
void CDemuopl::write(int reg, int val)
|
|
void CDemuopl::write(int reg, int val)
|
|
{
|
|
{
|
|
- pHandler->write(reg, val);
|
|
|
|
-};
|
|
|
|
|
|
+ if (chip) adlib_write(chip, reg, val);
|
|
|
|
+}
|