NES: puNES acquireDirect(), part 3
reduce CPU usage a bit
This commit is contained in:
parent
08e7112d85
commit
007ef91e84
|
@ -108,15 +108,11 @@ void DivPlatformNES::doWrite(int ts, unsigned short addr, unsigned char data) {
|
|||
void DivPlatformNES::acquire_puNES(blip_buffer_t** bb, size_t len) {
|
||||
for (int i=0; i<5; i++) {
|
||||
oscBuf[i]->begin(len);
|
||||
nes->oscBuf[i]=oscBuf[i];
|
||||
}
|
||||
|
||||
nes->timestamp=0;
|
||||
nes->bb=bb[0];
|
||||
nes->S1.oscBuf=oscBuf[0];
|
||||
nes->S2.oscBuf=oscBuf[1];
|
||||
nes->TR.oscBuf=oscBuf[2];
|
||||
nes->NS.oscBuf=oscBuf[3];
|
||||
nes->DMC.oscBuf=oscBuf[4];
|
||||
|
||||
for (size_t i=0; i<len; i++) {
|
||||
// heuristic
|
||||
|
|
|
@ -220,6 +220,7 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
square_output(a->S1, 0)
|
||||
a->S1.frequency = (a->S1.timer + 1) << 1;
|
||||
a->S1.sequencer = (a->S1.sequencer + 1) & 0x07;
|
||||
a->oscBuf[0]->putSample(a->timestamp,a->muted[0]?0:(a->S1.output<<11));
|
||||
}
|
||||
|
||||
// SQUARE 2 TICK
|
||||
|
@ -227,6 +228,7 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
square_output(a->S2, 0)
|
||||
a->S2.frequency = (a->S2.timer + 1) << 1;
|
||||
a->S2.sequencer = (a->S2.sequencer + 1) & 0x07;
|
||||
a->oscBuf[1]->putSample(a->timestamp,a->muted[1]?0:(a->S2.output<<11));
|
||||
}
|
||||
|
||||
// TRIANGLE TICK
|
||||
|
@ -235,6 +237,7 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
if (a->TR.length.value && a->TR.linear.value) {
|
||||
a->TR.sequencer = (a->TR.sequencer + 1) & 0x1F;
|
||||
triangle_output()
|
||||
a->oscBuf[2]->putSample(a->timestamp,a->muted[2]?0:(a->TR.output<<11));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,6 +251,7 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
a->NS.shift &= 0x7FFF;
|
||||
noise_output()
|
||||
a->NS.frequency = noise_timer[a->apu.type][a->NS.timer];
|
||||
a->oscBuf[3]->putSample(a->timestamp,a->muted[3]?0:(a->NS.output<<11));
|
||||
}
|
||||
|
||||
// DMC TICK
|
||||
|
@ -276,6 +280,7 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
}
|
||||
}
|
||||
a->DMC.frequency = dmc_rate[a->apu.type][a->DMC.rate_index];
|
||||
a->oscBuf[4]->putSample(a->timestamp,a->muted[4]?0:(a->DMC.output<<8));
|
||||
}
|
||||
if (a->DMC.empty && a->DMC.remain) {
|
||||
BYTE tick = 4;
|
||||
|
@ -324,12 +329,6 @@ void apu_tick(struct NESAPU* a, int len) {
|
|||
blip_add_delta(a->bb,a->timestamp,sample-a->lastSample);
|
||||
a->lastSample=sample;
|
||||
}
|
||||
// output chan osc
|
||||
a->S1.oscBuf->putSample(a->timestamp,a->muted[0]?0:(a->S1.output<<11));
|
||||
a->S2.oscBuf->putSample(a->timestamp,a->muted[1]?0:(a->S2.output<<11));
|
||||
a->TR.oscBuf->putSample(a->timestamp,a->muted[2]?0:(a->TR.output<<11));
|
||||
a->NS.oscBuf->putSample(a->timestamp,a->muted[3]?0:(a->NS.output<<11));
|
||||
a->DMC.oscBuf->putSample(a->timestamp,a->muted[4]?0:(a->DMC.output<<8));
|
||||
|
||||
rem-=advance;
|
||||
a->timestamp++;
|
||||
|
|
|
@ -342,8 +342,6 @@ typedef struct _apuSquare {
|
|||
_length_counter length;
|
||||
/* output */
|
||||
SWORD output;
|
||||
/* Furnace: chan osc buffer */
|
||||
DivDispatchOscBuffer* oscBuf;
|
||||
} _apuSquare;
|
||||
typedef struct _apuTriangle {
|
||||
/* timer */
|
||||
|
@ -358,8 +356,6 @@ typedef struct _apuTriangle {
|
|||
BYTE sequencer;
|
||||
/* output */
|
||||
SWORD output;
|
||||
/* Furnace: chan osc buffer */
|
||||
DivDispatchOscBuffer* oscBuf;
|
||||
} _apuTriangle;
|
||||
typedef struct _apuNoise {
|
||||
/* timer */
|
||||
|
@ -380,8 +376,6 @@ typedef struct _apuNoise {
|
|||
BYTE sequencer;
|
||||
/* output */
|
||||
SWORD output;
|
||||
/* Furnace: chan osc buffer */
|
||||
DivDispatchOscBuffer* oscBuf;
|
||||
} _apuNoise;
|
||||
typedef struct _apuDMC {
|
||||
/* ogni quanti cicli devo generare un output */
|
||||
|
@ -411,9 +405,6 @@ typedef struct _apuDMC {
|
|||
|
||||
/* misc */
|
||||
BYTE tick_type;
|
||||
|
||||
/* Furnace: chan osc buffer */
|
||||
DivDispatchOscBuffer* oscBuf;
|
||||
} _apuDMC;
|
||||
|
||||
struct _nla_table {
|
||||
|
@ -438,6 +429,7 @@ struct NESAPU {
|
|||
int timestamp;
|
||||
int lastSample;
|
||||
unsigned char muted[5];
|
||||
DivDispatchOscBuffer* oscBuf[5];
|
||||
};
|
||||
|
||||
/* apuPeriod[mode][type][cycles] */
|
||||
|
|
|
@ -202,6 +202,7 @@ INLINE static void apu_wr_reg(struct NESAPU* a, int ts, WORD address, BYTE value
|
|||
} else {
|
||||
a->DMC.counter = a->DMC.output = value;
|
||||
}
|
||||
a->oscBuf[4]->putSample(a->timestamp,a->muted[4]?0:(a->DMC.output<<8));
|
||||
|
||||
a->r4011.cycles = a->r4011.frames = 0;
|
||||
a->r4011.value = value;
|
||||
|
|
Loading…
Reference in a new issue