more optimization
as of now non-stereo sound chips are only processed once
This commit is contained in:
parent
6efcfc2e8a
commit
d6fb6b0bb3
|
@ -85,10 +85,12 @@ class DivDispatch {
|
||||||
* the engine shall resample to the output rate.
|
* the engine shall resample to the output rate.
|
||||||
*/
|
*/
|
||||||
int rate;
|
int rate;
|
||||||
virtual void acquire(short** buf, size_t start, size_t len);
|
virtual void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
virtual int dispatch(DivCommand c);
|
virtual int dispatch(DivCommand c);
|
||||||
virtual void tick();
|
virtual void tick();
|
||||||
|
|
||||||
|
virtual bool isStereo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize this DivDispatch.
|
* initialize this DivDispatch.
|
||||||
* @param parent the parent DivEngine.
|
* @param parent the parent DivEngine.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../dispatch.h"
|
#include "../dispatch.h"
|
||||||
|
|
||||||
void DivDispatch::acquire(short** buf, size_t start, size_t len) {
|
void DivDispatch::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivDispatch::tick() {
|
void DivDispatch::tick() {
|
||||||
|
@ -10,6 +10,10 @@ int DivDispatch::dispatch(DivCommand c) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivDispatch::isStereo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int DivDispatch::init(DivEngine* p, int channels, int sugRate) {
|
int DivDispatch::init(DivEngine* p, int channels, int sugRate) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,10 @@
|
||||||
|
|
||||||
#define FREQ_BASE 277.0f
|
#define FREQ_BASE 277.0f
|
||||||
|
|
||||||
void DivPlatformC64::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformC64::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
for (size_t i=start; i<start+len; i++) {
|
for (size_t i=start; i<start+len; i++) {
|
||||||
sid.clock();
|
sid.clock();
|
||||||
buf[0][i]=sid.output();
|
bufL[i]=sid.output();
|
||||||
buf[1][i]=buf[0][i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class DivPlatformC64: public DivDispatch {
|
||||||
|
|
||||||
void updateWave();
|
void updateWave();
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
|
|
|
@ -2,16 +2,15 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
void DivPlatformDummy::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformDummy::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
for (size_t i=start; i<start+len; i++) {
|
for (size_t i=start; i<start+len; i++) {
|
||||||
buf[0][i]=0;
|
bufL[i]=0;
|
||||||
for (unsigned char j=0; j<chans; j++) {
|
for (unsigned char j=0; j<chans; j++) {
|
||||||
if (chan[j].active) {
|
if (chan[j].active) {
|
||||||
buf[0][i]+=((chan[j].pos>=0x8000)?chan[j].vol:-chan[j].vol)*chan[j].amp;
|
bufL[i]+=((chan[j].pos>=0x8000)?chan[j].vol:-chan[j].vol)*chan[j].amp;
|
||||||
chan[j].pos+=chan[j].freq;
|
chan[j].pos+=chan[j].freq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[1][i]=buf[0][i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class DivPlatformDummy: public DivDispatch {
|
||||||
Channel chan[17];
|
Channel chan[17];
|
||||||
unsigned char chans;
|
unsigned char chans;
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
#define FREQ_BASE 8015.85f
|
#define FREQ_BASE 8015.85f
|
||||||
|
|
||||||
void DivPlatformGB::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformGB::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
for (int i=start; i<start+len; i++) {
|
for (int i=start; i<start+len; i++) {
|
||||||
GB_advance_cycles(gb,16);
|
GB_advance_cycles(gb,16);
|
||||||
buf[0][i]=gb->apu_output.final_sample.left<<2;
|
bufL[i]=gb->apu_output.final_sample.left<<2;
|
||||||
buf[1][i]=gb->apu_output.final_sample.right<<2;
|
bufR[i]=gb->apu_output.final_sample.right<<2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +270,10 @@ int DivPlatformGB::dispatch(DivCommand c) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivPlatformGB::isStereo() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate) {
|
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate) {
|
||||||
parent=p;
|
parent=p;
|
||||||
rate=262144;
|
rate=262144;
|
||||||
|
|
|
@ -36,9 +36,10 @@ class DivPlatformGB: public DivDispatch {
|
||||||
GB_gameboy_t* gb;
|
GB_gameboy_t* gb;
|
||||||
void updateWave();
|
void updateWave();
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
|
bool isStereo();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ static unsigned char konOffs[6]={
|
||||||
0, 1, 2, 4, 5, 6
|
0, 1, 2, 4, 5, 6
|
||||||
};
|
};
|
||||||
|
|
||||||
void DivPlatformGenesis::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
static short o[2];
|
static short o[2];
|
||||||
static int os[2];
|
static int os[2];
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ void DivPlatformGenesis::acquire(short** buf, size_t start, size_t len) {
|
||||||
psgClocks-=rate;
|
psgClocks-=rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[0][h]=(os[0]<<5)+psgOut;
|
bufL[h]=(os[0]<<5)+psgOut;
|
||||||
buf[1][h]=(os[1]<<5)+psgOut;
|
bufR[h]=(os[1]<<5)+psgOut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +340,10 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivPlatformGenesis::isStereo() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) {
|
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) {
|
||||||
parent=p;
|
parent=p;
|
||||||
rate=213068;
|
rate=213068;
|
||||||
|
|
|
@ -48,9 +48,10 @@ class DivPlatformGenesis: public DivDispatch {
|
||||||
int toFreq(int freq);
|
int toFreq(int freq);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
|
bool isStereo();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#define FREQ_BASE 3424.0f
|
#define FREQ_BASE 3424.0f
|
||||||
|
|
||||||
void DivPlatformNES::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
for (size_t i=start; i<start+len; i++) {
|
for (size_t i=start; i<start+len; i++) {
|
||||||
if (dacSample!=-1) {
|
if (dacSample!=-1) {
|
||||||
dacPeriod+=dacRate;
|
dacPeriod+=dacRate;
|
||||||
|
@ -27,10 +27,8 @@ void DivPlatformNES::acquire(short** buf, size_t start, size_t len) {
|
||||||
apu.odd_cycle=!apu.odd_cycle;
|
apu.odd_cycle=!apu.odd_cycle;
|
||||||
if (apu.clocked) {
|
if (apu.clocked) {
|
||||||
apu.clocked=false;
|
apu.clocked=false;
|
||||||
buf[0][i]=(pulse_output()+tnd_output())*30;
|
|
||||||
buf[1][i]=buf[0][i];
|
|
||||||
//printf("output value: %d\n",l);
|
|
||||||
}
|
}
|
||||||
|
bufL[i]=(pulse_output()+tnd_output())*30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DivPlatformNES: public DivDispatch {
|
||||||
|
|
||||||
void updateWave();
|
void updateWave();
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#define FREQ_BASE 1712.0f*2
|
#define FREQ_BASE 1712.0f*2
|
||||||
|
|
||||||
void DivPlatformPCE::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
for (size_t h=start; h<start+len; h++) {
|
for (size_t h=start; h<start+len; h++) {
|
||||||
// PCM part
|
// PCM part
|
||||||
for (int i=0; i<6; i++) {
|
for (int i=0; i<6; i++) {
|
||||||
|
@ -47,8 +47,8 @@ void DivPlatformPCE::acquire(short** buf, size_t start, size_t len) {
|
||||||
pce->ResetTS(0);
|
pce->ResetTS(0);
|
||||||
|
|
||||||
//printf("tempL: %d tempR: %d\n",tempL,tempR);
|
//printf("tempL: %d tempR: %d\n",tempL,tempR);
|
||||||
buf[0][h]=tempL;
|
bufL[h]=tempL;
|
||||||
buf[1][h]=tempR;
|
bufR[h]=tempR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +250,10 @@ int DivPlatformPCE::dispatch(DivCommand c) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivPlatformPCE::isStereo() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate) {
|
int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate) {
|
||||||
parent=p;
|
parent=p;
|
||||||
rate=1789773;
|
rate=1789773;
|
||||||
|
|
|
@ -50,9 +50,10 @@ class DivPlatformPCE: public DivDispatch {
|
||||||
PCE_PSG* pce;
|
PCE_PSG* pce;
|
||||||
void updateWave(int ch);
|
void updateWave(int ch);
|
||||||
public:
|
public:
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
|
bool isStereo();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
void DivPlatformSMS::acquire(short** buf, size_t start, size_t len) {
|
void DivPlatformSMS::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||||
sn->sound_stream_update(buf[0]+start,len);
|
sn->sound_stream_update(bufL+start,len);
|
||||||
memcpy(buf[1]+start,buf[0]+start,sizeof(short)*len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DivPlatformSMS::acquireOne() {
|
int DivPlatformSMS::acquireOne() {
|
||||||
|
|
|
@ -31,7 +31,7 @@ class DivPlatformSMS: public DivDispatch {
|
||||||
sn76496_device* sn;
|
sn76496_device* sn;
|
||||||
public:
|
public:
|
||||||
int acquireOne();
|
int acquireOne();
|
||||||
void acquire(short** buf, size_t start, size_t len);
|
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||||
int dispatch(DivCommand c);
|
int dispatch(DivCommand c);
|
||||||
void tick();
|
void tick();
|
||||||
int init(DivEngine* parent, int channels, int sugRate);
|
int init(DivEngine* parent, int channels, int sugRate);
|
||||||
|
|
|
@ -618,11 +618,11 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
while (runLeft) {
|
while (runLeft) {
|
||||||
if (runLeft>=cycles) {
|
if (runLeft>=cycles) {
|
||||||
runLeft-=cycles;
|
runLeft-=cycles;
|
||||||
dispatch->acquire(bbIn,runPos,cycles);
|
dispatch->acquire(bbIn[0],bbIn[1],runPos,cycles);
|
||||||
runPos+=cycles;
|
runPos+=cycles;
|
||||||
nextTick();
|
nextTick();
|
||||||
} else {
|
} else {
|
||||||
dispatch->acquire(bbIn,runPos,runLeft);
|
dispatch->acquire(bbIn[0],bbIn[1],runPos,runLeft);
|
||||||
cycles-=runLeft;
|
cycles-=runLeft;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -634,20 +634,29 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
prevSample[0]=temp[0];
|
prevSample[0]=temp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i=0; i<runtotal; i++) {
|
if (dispatch->isStereo()) for (size_t i=0; i<runtotal; i++) {
|
||||||
temp[1]=bbIn[1][i];
|
temp[1]=bbIn[1][i];
|
||||||
blip_add_delta(bb[1],i,temp[1]-prevSample[1]);
|
blip_add_delta(bb[1],i,temp[1]-prevSample[1]);
|
||||||
prevSample[1]=temp[1];
|
prevSample[1]=temp[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
blip_end_frame(bb[0],runtotal);
|
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[0],bbOut[0],size,0);
|
||||||
blip_read_samples(bb[1],bbOut[1],size,0);
|
|
||||||
|
|
||||||
for (size_t i=0; i<size; i++) {
|
if (dispatch->isStereo()) {
|
||||||
out[0][i]=(float)bbOut[0][i]/16384.0;
|
blip_end_frame(bb[1],runtotal);
|
||||||
out[1][i]=(float)bbOut[1][i]/16384.0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue