Merge branch 'master' of github.com:tildearrow/furnace

This commit is contained in:
tildearrow 2021-12-06 16:52:03 -05:00
commit 145403e7dd
19 changed files with 209 additions and 138 deletions

View file

@ -1,6 +1,8 @@
#ifndef _DISPATCH_H
#define _DISPATCH_H
#include <stdint.h>
#define ONE_SEMITONE 2200
enum DivDispatchCmds {
@ -83,10 +85,12 @@ class DivDispatch {
* the engine shall resample to the output rate.
*/
int rate;
virtual void acquire(int& l, int& r);
virtual void acquire(short* bufL, short* bufR, size_t start, size_t len);
virtual int dispatch(DivCommand c);
virtual void tick();
virtual bool isStereo();
/**
* initialize this DivDispatch.
* @param parent the parent DivEngine.

View file

@ -738,6 +738,10 @@ bool DivEngine::init() {
bbOut[0]=new short[got.bufsize];
bbOut[1]=new short[got.bufsize];
bbIn[0]=new short[32768];
bbIn[1]=new short[32768];
bbInLen=32768;
for (int i=0; i<64; i++) {
vibTable[i]=127*sin(((double)i/64.0)*(2*M_PI));
}

View file

@ -67,7 +67,9 @@ class DivEngine {
short vibTable[64];
blip_buffer_t* bb[2];
size_t bbInLen;
int temp[2], prevSample[2];
short* bbIn[2];
short* bbOut[2];
int dispatchCmd(DivCommand c);
@ -117,6 +119,7 @@ class DivEngine {
cmdsPerSecond(0),
view(DIV_STATUS_PATTERN),
audioEngine(DIV_AUDIO_SDL),
bbInLen(0),
temp{0,0},
prevSample{0,0} {}
};

View file

@ -1,8 +1,6 @@
#include "../dispatch.h"
void DivDispatch::acquire(int& l, int& r) {
l=0;
r=0;
void DivDispatch::acquire(short* bufL, short* bufR, size_t start, size_t len) {
}
void DivDispatch::tick() {
@ -12,6 +10,10 @@ int DivDispatch::dispatch(DivCommand c) {
return 1;
}
bool DivDispatch::isStereo() {
return false;
}
int DivDispatch::init(DivEngine* p, int channels, int sugRate) {
return 0;
}

View file

@ -4,10 +4,11 @@
#define FREQ_BASE 277.0f
void DivPlatformC64::acquire(int& l, int& r) {
void DivPlatformC64::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t i=start; i<start+len; i++) {
sid.clock();
l=sid.output();
r=l;
bufL[i]=sid.output();
}
}
void DivPlatformC64::tick() {

View file

@ -39,7 +39,7 @@ class DivPlatformC64: public DivDispatch {
void updateWave();
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
int init(DivEngine* parent, int channels, int sugRate);

View file

@ -2,16 +2,16 @@
#include <stdio.h>
#include <math.h>
void DivPlatformDummy::acquire(int& l, int& r) {
l=0;
for (unsigned char i=0; i<chans; i++) {
if (chan[i].active) {
l+=((chan[i].pos>=0x8000)?chan[i].vol:-chan[i].vol)*chan[i].amp;
chan[i].pos+=chan[i].freq;
void DivPlatformDummy::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t i=start; i<start+len; i++) {
bufL[i]=0;
for (unsigned char j=0; j<chans; j++) {
if (chan[j].active) {
bufL[i]+=((chan[j].pos>=0x8000)?chan[j].vol:-chan[j].vol)*chan[j].amp;
chan[j].pos+=chan[j].freq;
}
}
}
r=l;
}
void DivPlatformDummy::tick() {

View file

@ -15,7 +15,7 @@ class DivPlatformDummy: public DivDispatch {
Channel chan[17];
unsigned char chans;
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
int init(DivEngine* parent, int channels, int sugRate);

View file

@ -7,10 +7,12 @@
#define FREQ_BASE 8015.85f
void DivPlatformGB::acquire(int& l, int& r) {
void DivPlatformGB::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (int i=start; i<start+len; i++) {
GB_advance_cycles(gb,16);
l=gb->apu_output.final_sample.left<<2;
r=gb->apu_output.final_sample.right<<2;
bufL[i]=gb->apu_output.final_sample.left<<2;
bufR[i]=gb->apu_output.final_sample.right<<2;
}
}
void DivPlatformGB::updateWave() {
@ -268,6 +270,10 @@ int DivPlatformGB::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformGB::isStereo() {
return true;
}
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate) {
parent=p;
rate=262144;

View file

@ -36,9 +36,10 @@ class DivPlatformGB: public DivDispatch {
GB_gameboy_t* gb;
void updateWave();
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
bool isStereo();
int init(DivEngine* parent, int channels, int sugRate);
};

View file

@ -12,10 +12,11 @@ static unsigned char konOffs[6]={
0, 1, 2, 4, 5, 6
};
void DivPlatformGenesis::acquire(int& l, int& r) {
void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t len) {
static short o[2];
static int os[2];
for (size_t h=start; h<start+len; h++) {
if (dacMode && dacSample!=-1) {
dacPeriod-=6;
if (dacPeriod<1) {
@ -58,13 +59,13 @@ void DivPlatformGenesis::acquire(int& l, int& r) {
psgClocks+=223722;
while (psgClocks>=rate) {
psg.acquire(psgOut,psgOut);
psgOut=(psg.acquireOne()*3)>>3;
psgClocks-=rate;
psgOut=(psgOut>>2)+(psgOut>>3);
}
l=(os[0]<<5)+psgOut;
r=(os[1]<<5)+psgOut;
bufL[h]=(os[0]<<5)+psgOut;
bufR[h]=(os[1]<<5)+psgOut;
}
}
void DivPlatformGenesis::tick() {
@ -339,6 +340,10 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformGenesis::isStereo() {
return true;
}
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) {
parent=p;
rate=213068;

View file

@ -48,9 +48,10 @@ class DivPlatformGenesis: public DivDispatch {
int toFreq(int freq);
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
bool isStereo();
int init(DivEngine* parent, int channels, int sugRate);
};
#endif

View file

@ -5,7 +5,8 @@
#define FREQ_BASE 3424.0f
void DivPlatformNES::acquire(int& l, int& r) {
void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t i=start; i<start+len; i++) {
if (dacSample!=-1) {
dacPeriod+=dacRate;
if (dacPeriod>=rate) {
@ -26,9 +27,8 @@ void DivPlatformNES::acquire(int& l, int& r) {
apu.odd_cycle=!apu.odd_cycle;
if (apu.clocked) {
apu.clocked=false;
l=(pulse_output()+tnd_output())*30;
r=l;
//printf("output value: %d\n",l);
}
bufL[i]=(pulse_output()+tnd_output())*30;
}
}

View file

@ -36,7 +36,7 @@ class DivPlatformNES: public DivDispatch {
void updateWave();
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
int init(DivEngine* parent, int channels, int sugRate);

View file

@ -13,7 +13,8 @@
#define FREQ_BASE 1712.0f*2
void DivPlatformPCE::acquire(int& l, int& r) {
void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t h=start; h<start+len; h++) {
// PCM part
for (int i=0; i<6; i++) {
if (chan[i].pcm && chan[i].dacSample!=-1) {
@ -46,8 +47,9 @@ void DivPlatformPCE::acquire(int& l, int& r) {
pce->ResetTS(0);
//printf("tempL: %d tempR: %d\n",tempL,tempR);
l=tempL;
r=tempR;
bufL[h]=tempL;
bufR[h]=tempR;
}
}
void DivPlatformPCE::updateWave(int ch) {
@ -248,6 +250,10 @@ int DivPlatformPCE::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformPCE::isStereo() {
return true;
}
int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate) {
parent=p;
rate=1789773;

View file

@ -50,9 +50,10 @@ class DivPlatformPCE: public DivDispatch {
PCE_PSG* pce;
void updateWave(int ch);
public:
void acquire(int& l, int& r);
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
bool isStereo();
int init(DivEngine* parent, int channels, int sugRate);
};

View file

@ -2,11 +2,14 @@
#include "../engine.h"
#include <math.h>
void DivPlatformSMS::acquire(int& l, int& r) {
void DivPlatformSMS::acquire(short* bufL, short* bufR, size_t start, size_t len) {
sn->sound_stream_update(bufL+start,len);
}
int DivPlatformSMS::acquireOne() {
short v;
sn->sound_stream_update(&v,1);
l=v;
r=v;
return v;
}
void DivPlatformSMS::tick() {

View file

@ -30,7 +30,8 @@ class DivPlatformSMS: public DivDispatch {
bool updateSNMode;
sn76496_device* sn;
public:
void acquire(int& l, int& r);
int acquireOne();
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void tick();
int init(DivEngine* parent, int channels, int sugRate);

View file

@ -604,26 +604,59 @@ void DivEngine::nextTick() {
void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size) {
size_t runtotal=blip_clocks_needed(bb[0],size);
for (size_t i=0; i<runtotal; i++) {
if (--cycles<=0) {
nextTick();
}
dispatch->acquire(temp[0],temp[1]);
if (runtotal>bbInLen) {
delete bbIn[0];
delete bbIn[1];
bbIn[0]=new short[runtotal+256];
bbIn[1]=new short[runtotal+256];
bbInLen=runtotal+256;
}
size_t runLeft=runtotal;
size_t runPos=0;
while (runLeft) {
if (runLeft>=cycles) {
runLeft-=cycles;
dispatch->acquire(bbIn[0],bbIn[1],runPos,cycles);
runPos+=cycles;
nextTick();
} else {
dispatch->acquire(bbIn[0],bbIn[1],runPos,runLeft);
cycles-=runLeft;
break;
}
}
for (size_t i=0; i<runtotal; i++) {
temp[0]=bbIn[0][i];
blip_add_delta(bb[0],i,temp[0]-prevSample[0]);
blip_add_delta(bb[1],i,temp[1]-prevSample[1]);
prevSample[0]=temp[0];
}
if (dispatch->isStereo()) for (size_t i=0; i<runtotal; i++) {
temp[1]=bbIn[1][i];
blip_add_delta(bb[1],i,temp[1]-prevSample[1]);
prevSample[1]=temp[1];
}
blip_end_frame(bb[0],runtotal);
blip_end_frame(bb[1],runtotal);
blip_read_samples(bb[0],bbOut[0],size,0);
blip_read_samples(bb[1],bbOut[1],size,0);
if (dispatch->isStereo()) {
blip_end_frame(bb[1],runtotal);
blip_read_samples(bb[1],bbOut[1],size,0);
}
if (dispatch->isStereo()) {
for (size_t i=0; i<size; i++) {
out[0][i]=(float)bbOut[0][i]/16384.0;
out[1][i]=(float)bbOut[1][i]/16384.0;
}
} else {
for (size_t i=0; i<size; i++) {
out[0][i]=(float)bbOut[0][i]/16384.0;
out[1][i]=(float)bbOut[0][i]/16384.0;
}
}
}