From a29f36a5dfdd8b47a3cfefc628a9489c154ecb11 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 3 Jan 2023 01:09:46 -0500 Subject: [PATCH] new dispatch, part 1 --- src/engine/dispatchContainer.cpp | 86 ++++++++++++++++---------------- src/engine/engine.cpp | 37 +++++++------- src/engine/engine.h | 13 +++-- src/engine/platform/arcade.cpp | 12 ++--- src/engine/platform/arcade.h | 4 +- src/engine/platform/fds.cpp | 16 +++--- src/engine/platform/fds.h | 4 +- src/engine/platform/ga20.cpp | 2 +- src/engine/platform/gb.cpp | 2 +- src/engine/platform/genesis.cpp | 12 ++--- src/engine/platform/genesis.h | 4 +- src/engine/platform/k007232.cpp | 2 +- src/engine/platform/lynx.cpp | 4 +- src/engine/platform/mmc5.cpp | 2 +- src/engine/platform/msm5232.cpp | 2 +- src/engine/platform/msm6258.cpp | 2 +- src/engine/platform/msm6295.cpp | 2 +- src/engine/platform/n163.cpp | 2 +- src/engine/platform/namcowsg.cpp | 8 +-- src/engine/platform/nes.cpp | 12 ++--- src/engine/platform/nes.h | 4 +- src/engine/platform/opl.cpp | 8 +-- src/engine/platform/opl.h | 4 +- src/engine/platform/opll.cpp | 8 +-- src/engine/platform/opll.h | 4 +- src/engine/platform/pce.cpp | 2 +- src/engine/platform/pcmdac.cpp | 2 +- src/engine/platform/pcspkr.cpp | 28 +++++------ src/engine/platform/pcspkr.h | 8 +-- src/engine/platform/pet.cpp | 4 +- src/engine/platform/pokemini.cpp | 2 +- src/engine/platform/pokey.cpp | 12 ++--- src/engine/platform/pokey.h | 4 +- src/engine/platform/pong.cpp | 2 +- src/engine/platform/qsound.cpp | 2 +- src/engine/platform/rf5c68.cpp | 14 +++--- src/engine/platform/saa.cpp | 12 ++--- src/engine/platform/saa.h | 2 +- src/engine/platform/scc.cpp | 2 +- src/engine/platform/segapcm.cpp | 2 +- src/engine/platform/sms.cpp | 16 +++--- src/engine/platform/sms.h | 4 +- src/engine/platform/snes.cpp | 2 +- src/engine/platform/su.cpp | 2 +- src/engine/platform/swan.cpp | 2 +- src/engine/platform/t6w28.cpp | 2 +- src/engine/platform/tia.cpp | 2 +- src/engine/platform/tx81z.cpp | 2 +- src/engine/platform/vb.cpp | 2 +- src/engine/platform/vera.cpp | 16 +++--- src/engine/platform/vic20.cpp | 2 +- src/engine/platform/vrc6.cpp | 2 +- src/engine/platform/x1_010.cpp | 2 +- src/engine/platform/ym2203.cpp | 12 ++--- src/engine/platform/ym2203.h | 4 +- src/engine/platform/ym2608.cpp | 12 ++--- src/engine/platform/ym2608.h | 4 +- src/engine/platform/ym2610.cpp | 12 ++--- src/engine/platform/ym2610.h | 4 +- src/engine/platform/ym2610b.cpp | 12 ++--- src/engine/platform/ym2610b.h | 4 +- src/engine/platform/ymz280b.cpp | 14 +++--- src/engine/platform/zxbeeper.cpp | 2 +- src/engine/playback.cpp | 10 +++- 64 files changed, 258 insertions(+), 242 deletions(-) diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 5b943332c..fa72b76b9 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -80,8 +80,11 @@ #include "song.h" void DivDispatchContainer::setRates(double gotRate) { - blip_set_rates(bb[0],dispatch->rate,gotRate); - blip_set_rates(bb[1],dispatch->rate,gotRate); + int outs=dispatch->getOutputCount(); + + for (int i=0; irate,gotRate); + } } void DivDispatchContainer::setQuality(bool lowQual) { @@ -90,73 +93,68 @@ void DivDispatchContainer::setQuality(bool lowQual) { void DivDispatchContainer::acquire(size_t offset, size_t count) { int outs=dispatch->getOutputCount(); - for (int i=0; i=outs) { + bbInMapped[i]=NULL; + } else { + bbInMapped[i]=&bbIn[i][offset]; + } } dispatch->acquire(bbInMapped,count); } void DivDispatchContainer::flush(size_t count) { - blip_read_samples(bb[0],bbOut[0],count,0); + int outs=dispatch->getOutputCount(); - if (dispatch->isStereo()) { - blip_read_samples(bb[1],bbOut[1],count,0); + for (int i=0; igetOutputCount(); if (dcOffCompensation && runtotal>0) { dcOffCompensation=false; - prevSample[0]=bbIn[0][0]; - if (dispatch->isStereo()) prevSample[1]=bbIn[1][0]; + for (int i=0; iisStereo()) for (size_t i=0; iisStereo()) for (size_t i=0; i0) { for (size_t i=totalRead; iisStereo()) { - blip_end_frame(bb[1],runtotal); - blip_read_samples(bb[1],bbOut[1]+offset,size,0); - } } void DivDispatchContainer::clear() { - blip_clear(bb[0]); - blip_clear(bb[1]); - temp[0]=0; - temp[1]=0; - prevSample[0]=0; - prevSample[1]=0; + for (int i=0; igetDCOffRequired()) { dcOffCompensation=true; } @@ -463,8 +461,8 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do bbIn[i]=new short[bbInLen]; bbOut[i]=new short[bbInLen]; - memset(bbIn,0,bbInLen*sizeof(short)); - memset(bbOut,0,bbInLen*sizeof(short)); + memset(bbIn[i],0,bbInLen*sizeof(short)); + memset(bbOut[i],0,bbInLen*sizeof(short)); } } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index c75d86fae..b31aff56d 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -897,11 +897,7 @@ void DivEngine::runExportThread() { for (int i=0; iisStereo()) { - si[i].channels=2; - } else { - si[i].channels=1; - } + si[i].channels=disCont[i].dispatch->getOutputCount(); si[i].format=SF_FORMAT_WAV|SF_FORMAT_PCM_16; } @@ -944,11 +940,12 @@ void DivEngine::runExportThread() { if (isFadingOut) { double mul=(1.0-((double)curFadeOutSample/(double)fadeOutSamples)); for (int i=0; iisStereo()) { - sysBuf[i][j]=(double)disCont[i].bbOut[0][j]*mul; - } else { - sysBuf[i][j<<1]=(double)disCont[i].bbOut[0][j]*mul; - sysBuf[i][1+(j<<1)]=(double)disCont[i].bbOut[1][j]*mul; + for (int k=0; k=fadeOutSamples) { @@ -957,11 +954,12 @@ void DivEngine::runExportThread() { } } else { for (int i=0; iisStereo()) { - sysBuf[i][j]=disCont[i].bbOut[0][j]; - } else { - sysBuf[i][j<<1]=disCont[i].bbOut[0][j]; - sysBuf[i][1+(j<<1)]=disCont[i].bbOut[1][j]; + for (int k=0; k-1 && j>=lastLoopPos && totalLoops>=exportLoopCount) { @@ -1904,10 +1902,11 @@ String DivEngine::getPlaybackDebugInfo() { "speed1: %d\n" "speed2: %d\n" "tempoAccum: %d\n" - "totalProcessed: %d\n", + "totalProcessed: %d\n" + "bufferPos: %d\n", curOrder,prevOrder,curRow,prevRow,ticks,subticks,totalLoops,lastLoopPos,nextSpeed,divider,cycles,clockDrift, changeOrd,changePos,totalSeconds,totalTicks,totalTicksR,totalCmds,lastCmds,cmdsPerSecond,globalPitch, - (int)extValue,(int)speed1,(int)speed2,(int)tempoAccum,(int)totalProcessed + (int)extValue,(int)speed1,(int)speed2,(int)tempoAccum,(int)totalProcessed,(int)bufferPos ); } @@ -4311,6 +4310,10 @@ bool DivEngine::init() { if (!haveAudio) { return false; } else { + if (output==NULL) { + logE("output is NULL!"); + return false; + } if (!output->setRun(true)) { logE("error while activating!"); return false; diff --git a/src/engine/engine.h b/src/engine/engine.h index 34f3d8dac..652d71584 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -195,12 +195,12 @@ struct DivDispatchContainer { lastAvail(0), lowQuality(false), dcOffCompensation(false) { - memset(bb,0,DIV_MAX_OUTPUTS*sizeof(void*)); + memset(bb,0,DIV_MAX_OUTPUTS*sizeof(blip_buffer_t*)); memset(temp,0,DIV_MAX_OUTPUTS*sizeof(int)); memset(prevSample,0,DIV_MAX_OUTPUTS*sizeof(int)); - memset(bbIn,0,DIV_MAX_OUTPUTS*sizeof(void*)); - memset(bbInMapped,0,DIV_MAX_OUTPUTS*sizeof(void*)); - memset(bbOut,0,DIV_MAX_OUTPUTS*sizeof(void*)); + memset(bbIn,0,DIV_MAX_OUTPUTS*sizeof(short*)); + memset(bbInMapped,0,DIV_MAX_OUTPUTS*sizeof(short*)); + memset(bbOut,0,DIV_MAX_OUTPUTS*sizeof(short*)); } }; @@ -356,6 +356,7 @@ class DivEngine { int softLockCount; int subticks, ticks, curRow, curOrder, prevRow, prevOrder, remainingLoops, totalLoops, lastLoopPos, exportLoopCount, nextSpeed, elapsedBars, elapsedBeats; size_t curSubSongIndex; + size_t bufferPos; double divider; int cycles; double clockDrift; @@ -905,6 +906,9 @@ class DivEngine { // set metronome volume (1.0 = 100%) void setMetronomeVol(float vol); + // get buffer position + int getBufferPos(); + // halt now void halt(); @@ -1073,6 +1077,7 @@ class DivEngine { elapsedBars(0), elapsedBeats(0), curSubSongIndex(0), + bufferPos(0), divider(60), cycles(0), clockDrift(0), diff --git a/src/engine/platform/arcade.cpp b/src/engine/platform/arcade.cpp index 3912921cc..f9a2e7cb7 100644 --- a/src/engine/platform/arcade.cpp +++ b/src/engine/platform/arcade.cpp @@ -50,10 +50,10 @@ const char** DivPlatformArcade::getRegisterSheet() { return regCheatSheetOPM; } -void DivPlatformArcade::acquire_nuked(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformArcade::acquire_nuked(short** buf, size_t len) { static int o[2]; - for (size_t h=start; hdebug_engine(); - for (size_t h=start; hsnd.main.output; if (sample>32767) sample=32767; if (sample<-32768) sample=-32768; - buf[0][i]=sample; + buf[i]=sample; if (++writeOscBuf>=32) { writeOscBuf=0; oscBuf->data[oscBuf->needle++]=sample<<1; @@ -69,15 +69,15 @@ void DivPlatformFDS::acquire_puNES(short* bufL, short* bufR, size_t start, size_ } } -void DivPlatformFDS::acquire_NSFPlay(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformFDS::acquire_NSFPlay(short* buf, size_t len) { int out[2]; - for (size_t i=start; iTick(1); fds_NP->Render(out); int sample=isMuted[0]?0:(out[0]<<1); if (sample>32767) sample=32767; if (sample<-32768) sample=-32768; - buf[0][i]=sample; + buf[i]=sample; if (++writeOscBuf>=32) { writeOscBuf=0; oscBuf->data[oscBuf->needle++]=sample<<1; @@ -95,9 +95,9 @@ void DivPlatformFDS::doWrite(unsigned short addr, unsigned char data) { void DivPlatformFDS::acquire(short** buf, size_t len) { if (useNP) { - acquire_NSFPlay(bufL,bufR,start,len); + acquire_NSFPlay(buf[0],len); } else { - acquire_puNES(bufL,bufR,start,len); + acquire_puNES(buf[0],len); } } diff --git a/src/engine/platform/fds.h b/src/engine/platform/fds.h index a6e7862e8..7872319b1 100644 --- a/src/engine/platform/fds.h +++ b/src/engine/platform/fds.h @@ -62,8 +62,8 @@ class DivPlatformFDS: public DivDispatch { friend void putDispatchChan(void*,int,int); void doWrite(unsigned short addr, unsigned char data); - void acquire_puNES(short* bufL, short* bufR, size_t start, size_t len); - void acquire_NSFPlay(short* bufL, short* bufR, size_t start, size_t len); + void acquire_puNES(short* buf, size_t len); + void acquire_NSFPlay(short* buf, size_t len); public: void acquire(short** buf, size_t len); diff --git a/src/engine/platform/ga20.cpp b/src/engine/platform/ga20.cpp index 990531b35..c5cbbb61e 100644 --- a/src/engine/platform/ga20.cpp +++ b/src/engine/platform/ga20.cpp @@ -60,7 +60,7 @@ void DivPlatformGA20::acquire(short** buf, size_t len) { } } - for (size_t h=start; hdebug_engine(); - for (size_t h=start; h=0 && chan[i].samplesong.sampleLen) { chan[i].sampleAccum-=chan[i].sampleFreq; @@ -156,7 +156,7 @@ void DivPlatformLynx::acquire(short** buf, size_t len) { } } - mikey->sampleAudio( bufL + h, bufR + h, 1, oscBuf ); + mikey->sampleAudio(buf[0]+h,buf[1]+h,1,oscBuf); } } diff --git a/src/engine/platform/mmc5.cpp b/src/engine/platform/mmc5.cpp index 3e9920683..6e44ea1cb 100644 --- a/src/engine/platform/mmc5.cpp +++ b/src/engine/platform/mmc5.cpp @@ -44,7 +44,7 @@ const char** DivPlatformMMC5::getRegisterSheet() { } void DivPlatformMMC5::acquire(short** buf, size_t len) { - for (size_t i=start; i=rate) { diff --git a/src/engine/platform/msm5232.cpp b/src/engine/platform/msm5232.cpp index 1ed6e5a2e..7405f8d36 100644 --- a/src/engine/platform/msm5232.cpp +++ b/src/engine/platform/msm5232.cpp @@ -46,7 +46,7 @@ const char** DivPlatformMSM5232::getRegisterSheet() { } void DivPlatformMSM5232::acquire(short** buf, size_t len) { - for (size_t h=start; hwrite(w.addr,w.val); diff --git a/src/engine/platform/msm6258.cpp b/src/engine/platform/msm6258.cpp index 4824af90c..af1472af2 100644 --- a/src/engine/platform/msm6258.cpp +++ b/src/engine/platform/msm6258.cpp @@ -35,7 +35,7 @@ void DivPlatformMSM6258::acquire(short** buf, size_t len) { &msmOut, NULL }; - for (size_t h=start; h32767) out=32767; diff --git a/src/engine/platform/namcowsg.cpp b/src/engine/platform/namcowsg.cpp index 58270c0e6..cb4540f5c 100644 --- a/src/engine/platform/namcowsg.cpp +++ b/src/engine/platform/namcowsg.cpp @@ -171,11 +171,11 @@ void DivPlatformNamcoWSG::acquire(short** buf, size_t len) { regPool[w.addr&0x3f]=w.val; writes.pop(); } - for (size_t h=start; hsound_stream_update(buf,1); + namco->sound_stream_update(bufC,1); for (int i=0; idata[oscBuf[i]->needle++]=namco->m_channel_list[i].last_out*chans; } diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index a60eeee47..3af55a0d6 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -100,8 +100,8 @@ void DivPlatformNES::doWrite(unsigned short addr, unsigned char data) { } \ } -void DivPlatformNES::acquire_puNES(short* bufL, short* bufR, size_t start, size_t len) { - for (size_t i=start; iTick(1); @@ -153,9 +153,9 @@ void DivPlatformNES::acquire_NSFPlay(short* bufL, short* bufR, size_t start, siz void DivPlatformNES::acquire(short** buf, size_t len) { if (useNP) { - acquire_NSFPlay(bufL,bufR,start,len); + acquire_NSFPlay(buf,len); } else { - acquire_puNES(bufL,bufR,start,len); + acquire_puNES(buf,len); } } diff --git a/src/engine/platform/nes.h b/src/engine/platform/nes.h index 42758f568..22ccfd913 100644 --- a/src/engine/platform/nes.h +++ b/src/engine/platform/nes.h @@ -68,8 +68,8 @@ class DivPlatformNES: public DivDispatch { void doWrite(unsigned short addr, unsigned char data); unsigned char calcDPCMRate(int inRate); - void acquire_puNES(short* bufL, short* bufR, size_t start, size_t len); - void acquire_NSFPlay(short* bufL, short* bufR, size_t start, size_t len); + void acquire_puNES(short** buf, size_t len); + void acquire_NSFPlay(short** buf, size_t len); public: void acquire(short** buf, size_t len); diff --git a/src/engine/platform/opl.cpp b/src/engine/platform/opl.cpp index 4c993d541..e997a20b5 100644 --- a/src/engine/platform/opl.cpp +++ b/src/engine/platform/opl.cpp @@ -159,12 +159,12 @@ const int orderedOpsL[4]={ #define ADDR_FREQH 0xb0 #define ADDR_LR_FB_ALG 0xc0 -void DivPlatformOPL::acquire_nuked(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformOPL::acquire_nuked(short** buf, size_t len) { static short o[2]; static int os[2]; static ymfm::ymfm_output<2> aOut; - for (size_t h=start; hfreq) pos=freq; @@ -216,8 +216,8 @@ void DivPlatformPCSpeaker::acquire_unfilt(short* bufL, short* bufR, size_t start } } -void DivPlatformPCSpeaker::acquire_cone(short* bufL, short* bufR, size_t start, size_t len) { - for (size_t i=start; ifreq) pos=freq; @@ -243,8 +243,8 @@ void DivPlatformPCSpeaker::acquire_cone(short* bufL, short* bufR, size_t start, } } -void DivPlatformPCSpeaker::acquire_piezo(short* bufL, short* bufR, size_t start, size_t len) { - for (size_t i=start; ifreq) pos=freq; @@ -274,7 +274,7 @@ void DivPlatformPCSpeaker::beepFreq(int freq, int delay) { realQueueLock.lock(); #ifdef __linux__ struct timespec ts; - double addition=1000000000.0*(double)delay/(double)rate; + double addition=1000000000.0*(double)delay/parent->getAudioDescGot().rate; addition+=1500000000.0*((double)parent->getAudioDescGot().bufsize/parent->getAudioDescGot().rate); if (clock_gettime(CLOCK_MONOTONIC,&ts)<0) { ts.tv_sec=0; @@ -294,14 +294,14 @@ void DivPlatformPCSpeaker::beepFreq(int freq, int delay) { realOutCond.notify_one(); } -void DivPlatformPCSpeaker::acquire_real(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformPCSpeaker::acquire_real(short** buf, size_t len) { int out=0; if (lastOn!=on || lastFreq!=freq) { lastOn=on; lastFreq=freq; - beepFreq((on && !isMuted[0])?freq:0,start); + beepFreq((on && !isMuted[0])?freq:0,parent->getBufferPos()); } - for (size_t i=start; ifreq) pos=freq; @@ -324,16 +324,16 @@ void DivPlatformPCSpeaker::acquire_real(short* bufL, short* bufR, size_t start, void DivPlatformPCSpeaker::acquire(short** buf, size_t len) { switch (speakerType) { case 0: - acquire_unfilt(bufL,bufR,start,len); + acquire_unfilt(buf,len); break; case 1: - acquire_cone(bufL,bufR,start,len); + acquire_cone(buf,len); break; case 2: - acquire_piezo(bufL,bufR,start,len); + acquire_piezo(buf,len); break; case 3: - acquire_real(bufL,bufR,start,len); + acquire_real(buf,len); break; } } diff --git a/src/engine/platform/pcspkr.h b/src/engine/platform/pcspkr.h index 953a93b83..554c0d074 100644 --- a/src/engine/platform/pcspkr.h +++ b/src/engine/platform/pcspkr.h @@ -61,10 +61,10 @@ class DivPlatformPCSpeaker: public DivDispatch { void beepFreq(int freq, int delay=0); - void acquire_unfilt(short* bufL, short* bufR, size_t start, size_t len); - void acquire_cone(short* bufL, short* bufR, size_t start, size_t len); - void acquire_piezo(short* bufL, short* bufR, size_t start, size_t len); - void acquire_real(short* bufL, short* bufR, size_t start, size_t len); + void acquire_unfilt(short** buf, size_t len); + void acquire_cone(short** buf, size_t len); + void acquire_piezo(short** buf, size_t len); + void acquire_real(short** buf, size_t len); public: void pcSpeakerThread(); diff --git a/src/engine/platform/pet.cpp b/src/engine/platform/pet.cpp index 7474558e0..7a38de81c 100644 --- a/src/engine/platform/pet.cpp +++ b/src/engine/platform/pet.cpp @@ -62,7 +62,7 @@ void DivPlatformPET::acquire(short** buf, size_t len) { if (!hwSROutput) { reload+=regPool[9]*512; } - for (size_t h=start; hchan[0].cnt) { chan[0].out=(chan[0].sreg&1)*32767; chan[0].sreg=(chan[0].sreg>>1)|((chan[0].sreg&1)<<7); @@ -78,7 +78,7 @@ void DivPlatformPET::acquire(short** buf, size_t len) { if (!hwSROutput) regPool[12]=chan[0].out?0xe0:0xc0; } else { chan[0].out=0; - for (size_t h=start; hdata[oscBuf->needle++]=0; diff --git a/src/engine/platform/pokemini.cpp b/src/engine/platform/pokemini.cpp index 1099e63f8..9b543153c 100644 --- a/src/engine/platform/pokemini.cpp +++ b/src/engine/platform/pokemini.cpp @@ -88,7 +88,7 @@ void DivPlatformPokeMini::rWrite(unsigned char addr, unsigned char val) { void DivPlatformPokeMini::acquire(short** buf, size_t len) { int out=0; - for (size_t i=start; i=2) { oscBufDelay=0; buf[h]=altASAP.sampleAudio(oscBuf); diff --git a/src/engine/platform/pokey.h b/src/engine/platform/pokey.h index 2418ade29..79206a745 100644 --- a/src/engine/platform/pokey.h +++ b/src/engine/platform/pokey.h @@ -59,8 +59,8 @@ class DivPlatformPOKEY: public DivDispatch { friend void putDispatchChan(void*,int,int); public: void acquire(short** buf, size_t len); - void acquireMZ(short* buf, size_t start, size_t len); - void acquireASAP(short* buf, size_t start, size_t len); + void acquireMZ(short* buf, size_t len); + void acquireASAP(short* buf, size_t len); int dispatch(DivCommand c); void* getChanState(int chan); DivMacroInt* getChanMacroInt(int ch); diff --git a/src/engine/platform/pong.cpp b/src/engine/platform/pong.cpp index fe34b3980..27fd76b38 100644 --- a/src/engine/platform/pong.cpp +++ b/src/engine/platform/pong.cpp @@ -25,7 +25,7 @@ void DivPlatformPong::acquire(short** buf, size_t len) { int out=0; - for (size_t i=start; i 0) { @@ -72,7 +74,7 @@ void DivPlatformRF5C68::acquire(short** buf, size_t len) { rf5c68.sound_stream_update(bufPtrs,chBufPtrs,blockLen); for (int i=0; i<8; i++) { for (size_t j=0; jdata[oscBuf[i]->needle++]=buf[i*2][j]+buf[i*2+1][j]; + oscBuf[i]->data[oscBuf[i]->needle++]=bufC[i*2][j]+bufC[i*2+1][j]; } } pos+=blockLen; diff --git a/src/engine/platform/saa.cpp b/src/engine/platform/saa.cpp index 0208a3eb3..924bc73ac 100644 --- a/src/engine/platform/saa.cpp +++ b/src/engine/platform/saa.cpp @@ -56,7 +56,7 @@ const char** DivPlatformSAA1099::getRegisterSheet() { return regCheatSheetSAA; } -void DivPlatformSAA1099::acquire_saaSound(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformSAA1099::acquire_saaSound(short** buf, size_t len) { if (saaBufLenGenerateMany((unsigned char*)saaBuf[0],len,oscBuf); #ifdef TA_BIG_ENDIAN for (size_t i=0; i>8)); - buf[1][i+start]=(short)((((unsigned short)saaBuf[0][i<<1])<<8)|(((unsigned short)saaBuf[0][i<<1])>>8)); + buf[0][i]=(short)((((unsigned short)saaBuf[0][1+(i<<1)])<<8)|(((unsigned short)saaBuf[0][1+(i<<1)])>>8)); + buf[1][i]=(short)((((unsigned short)saaBuf[0][i<<1])<<8)|(((unsigned short)saaBuf[0][i<<1])>>8)); } #else for (size_t i=0; itick(); } diff --git a/src/engine/platform/segapcm.cpp b/src/engine/platform/segapcm.cpp index dd212c3f4..25af42113 100644 --- a/src/engine/platform/segapcm.cpp +++ b/src/engine/platform/segapcm.cpp @@ -29,7 +29,7 @@ void DivPlatformSegaPCM::acquire(short** buf, size_t len) { static int os[2]; - for (size_t h=start; h32767) oR=32767; buf[0][h]=oL; - buf[1][h]=oR; + if (stereo) buf[1][h]=oR; for (int i=0; i<4; i++) { if (isMuted[i]) { oscBuf[i]->data[oscBuf[i]->needle++]=0; @@ -85,7 +85,7 @@ void DivPlatformSMS::acquire_nuked(short* bufL, short* bufR, size_t start, size_ } } -void DivPlatformSMS::acquire_mame(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformSMS::acquire_mame(short** buf, size_t len) { while (!writes.empty()) { QueuedWrite w=writes.front(); if (stereo && (w.addr==1)) @@ -95,10 +95,10 @@ void DivPlatformSMS::acquire_mame(short* bufL, short* bufR, size_t start, size_t } writes.pop(); } - for (size_t h=start; hsound_stream_update(outs,1); for (int i=0; i<4; i++) { @@ -113,9 +113,9 @@ void DivPlatformSMS::acquire_mame(short* bufL, short* bufR, size_t start, size_t void DivPlatformSMS::acquire(short** buf, size_t len) { if (nuked) { - acquire_nuked(bufL,bufR,start,len); + acquire_nuked(buf,len); } else { - acquire_mame(bufL,bufR,start,len); + acquire_mame(buf,len); } } diff --git a/src/engine/platform/sms.h b/src/engine/platform/sms.h index 7358ce91b..cd0a7a1f6 100644 --- a/src/engine/platform/sms.h +++ b/src/engine/platform/sms.h @@ -66,8 +66,8 @@ class DivPlatformSMS: public DivDispatch { double NOTE_SN(int ch, int note); int snCalcFreq(int ch); - void acquire_nuked(short* bufL, short* bufR, size_t start, size_t len); - void acquire_mame(short* bufL, short* bufR, size_t start, size_t len); + void acquire_nuked(short** buf, size_t len); + void acquire_mame(short** buf, size_t len); public: void acquire(short** buf, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/snes.cpp b/src/engine/platform/snes.cpp index 38512d135..6fb942d48 100644 --- a/src/engine/platform/snes.cpp +++ b/src/engine/platform/snes.cpp @@ -68,7 +68,7 @@ const char** DivPlatformSNES::getRegisterSheet() { void DivPlatformSNES::acquire(short** buf, size_t len) { short out[2]; short chOut[16]; - for (size_t h=start; hWrite(w.addr,w.val); diff --git a/src/engine/platform/swan.cpp b/src/engine/platform/swan.cpp index b5d860aea..f5a2dfb9a 100644 --- a/src/engine/platform/swan.cpp +++ b/src/engine/platform/swan.cpp @@ -51,7 +51,7 @@ const char** DivPlatformSwan::getRegisterSheet() { } void DivPlatformSwan::acquire(short** buf, size_t len) { - for (size_t h=start; hdebug_engine(); - for (size_t h=start; hgetSample(chan[16].pcm.sample); while (len>0) { if (s->samples>0) { @@ -98,18 +98,18 @@ void DivPlatformVERA::acquire(short** buf, size_t len) { chan[16].pcm.sample=-1; } int curLen=MIN(len,128); - memset(buf,0,sizeof(buf)); - pcm_render(pcm,buf[2],buf[3],curLen); + memset(whyCallItBuf,0,sizeof(whyCallItBuf)); + pcm_render(pcm,whyCallItBuf[2],whyCallItBuf[3],curLen); for (int i=0; idata[oscBuf[i]->needle++]=psg->channels[i].lastOut<<4; } - int pcmOut=buf[2][i]+buf[3][i]; + int pcmOut=whyCallItBuf[2][i]+whyCallItBuf[3][i]; if (pcmOut<-32768) pcmOut=-32768; if (pcmOut>32767) pcmOut=32767; oscBuf[16]->data[oscBuf[16]->needle++]=pcmOut; diff --git a/src/engine/platform/vic20.cpp b/src/engine/platform/vic20.cpp index d45bf99f5..9564ffa23 100644 --- a/src/engine/platform/vic20.cpp +++ b/src/engine/platform/vic20.cpp @@ -45,7 +45,7 @@ void DivPlatformVIC20::acquire(short** buf, size_t len) { 0b0, 0b10, 0b100, 0b110, 0b1000, 0b1010, 0b1011, 0b1110, 0b10010, 0b10100, 0b10110, 0b11000, 0b11010, 0b100100, 0b101010, 0b101100 }; - for (size_t h=start; hdebug_fm_engine(); @@ -240,7 +240,7 @@ void DivPlatformYM2203::acquire_ymfm(short* bufL, short* bufR, size_t start, siz fmChan[i]=fme->debug_channel(i); } - for (size_t h=start; hdebug_channel(i); } - for (size_t h=start; hdebug_fm_engine(); @@ -424,7 +424,7 @@ void DivPlatformYM2608::acquire_ymfm(short* bufL, short* bufR, size_t start, siz adpcmAChan[i]=aae->debug_channel(i); } - for (size_t h=start; hdebug_channel(i); } - for (size_t h=start; hdebug_fm_engine(); @@ -357,7 +357,7 @@ void DivPlatformYM2610::acquire_ymfm(short* bufL, short* bufR, size_t start, siz adpcmAChan[i]=aae->debug_channel(i); } - for (size_t h=start; hread(0)&0x80)) { diff --git a/src/engine/platform/ym2610.h b/src/engine/platform/ym2610.h index 40d013e1f..a3bf53b46 100644 --- a/src/engine/platform/ym2610.h +++ b/src/engine/platform/ym2610.h @@ -38,8 +38,8 @@ class DivPlatformYM2610: public DivPlatformYM2610Base { friend void putDispatchChip(void*,int); - void acquire_combo(short* bufL, short* bufR, size_t start, size_t len); - void acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len); + void acquire_combo(short** buf, size_t len); + void acquire_ymfm(short** buf, size_t len); public: void acquire(short** buf, size_t len); diff --git a/src/engine/platform/ym2610b.cpp b/src/engine/platform/ym2610b.cpp index 82ebd38f3..c69d28bf9 100644 --- a/src/engine/platform/ym2610b.cpp +++ b/src/engine/platform/ym2610b.cpp @@ -298,13 +298,13 @@ const char** DivPlatformYM2610B::getRegisterSheet() { void DivPlatformYM2610B::acquire(short** buf, size_t len) { if (useCombo) { - acquire_combo(bufL,bufR,start,len); + acquire_combo(buf,len); } else { - acquire_ymfm(bufL,bufR,start,len); + acquire_ymfm(buf,len); } } -void DivPlatformYM2610B::acquire_combo(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformYM2610B::acquire_combo(short** buf, size_t len) { static int os[2]; static short ignored[2]; @@ -319,7 +319,7 @@ void DivPlatformYM2610B::acquire_combo(short* bufL, short* bufR, size_t start, s adpcmAChan[i]=aae->debug_channel(i); } - for (size_t h=start; hdebug_fm_engine(); @@ -423,7 +423,7 @@ void DivPlatformYM2610B::acquire_ymfm(short* bufL, short* bufR, size_t start, si adpcmAChan[i]=aae->debug_channel(i); } - for (size_t h=start; hread(0)&0x80)) { diff --git a/src/engine/platform/ym2610b.h b/src/engine/platform/ym2610b.h index c47967fd7..ca2cb3337 100644 --- a/src/engine/platform/ym2610b.h +++ b/src/engine/platform/ym2610b.h @@ -34,8 +34,8 @@ class DivPlatformYM2610B: public DivPlatformYM2610Base { friend void putDispatchChip(void*,int); - void acquire_combo(short* bufL, short* bufR, size_t start, size_t len); - void acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len); + void acquire_combo(short** buf, size_t len); + void acquire_ymfm(short** buf, size_t len); public: void acquire(short** buf, size_t len); diff --git a/src/engine/platform/ymz280b.cpp b/src/engine/platform/ymz280b.cpp index 1ca327f5d..a5fdf10bd 100644 --- a/src/engine/platform/ymz280b.cpp +++ b/src/engine/platform/ymz280b.cpp @@ -61,12 +61,12 @@ const char** DivPlatformYMZ280B::getRegisterSheet() { } void DivPlatformYMZ280B::acquire(short** buf, size_t len) { - short buf[16][256]; + short why[16][256]; short *bufPtrs[16]={ - buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7], - buf[8],buf[9],buf[10],buf[11],buf[12],buf[13],buf[14],buf[15] + why[0],why[1],why[2],why[3],why[4],why[5],why[6],why[7], + why[8],why[9],why[10],why[11],why[12],why[13],why[14],why[15] }; - size_t pos=start; + size_t pos=0; while (len > 0) { size_t blockLen = MIN(len, 256); ymz280b.sound_stream_update(bufPtrs, blockLen); @@ -74,9 +74,9 @@ void DivPlatformYMZ280B::acquire(short** buf, size_t len) { int dataL=0; int dataR=0; for (int j=0; j<8; j++) { - dataL+=buf[j*2][i]; - dataR+=buf[j*2+1][i]; - oscBuf[j]->data[oscBuf[j]->needle++]=(short)(((int)buf[j*2][i]+buf[j*2+1][i])/2); + dataL+=why[j*2][i]; + dataR+=why[j*2+1][i]; + oscBuf[j]->data[oscBuf[j]->needle++]=(short)(((int)why[j*2][i]+why[j*2+1][i])/2); } buf[0][pos]=(short)(dataL/8); buf[1][pos]=(short)(dataR/8); diff --git a/src/engine/platform/zxbeeper.cpp b/src/engine/platform/zxbeeper.cpp index cf563f27c..7bd992f81 100644 --- a/src/engine/platform/zxbeeper.cpp +++ b/src/engine/platform/zxbeeper.cpp @@ -29,7 +29,7 @@ const char** DivPlatformZXBeeper::getRegisterSheet() { void DivPlatformZXBeeper::acquire(short** buf, size_t len) { bool o=false; - for (size_t h=start; h=0 && curSamplesong.sampleLen) { if (--curSamplePeriod<0) { diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 335da02a9..c1a52bee1 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -1359,6 +1359,10 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) { return ret; } +int DivEngine::getBufferPos() { + return bufferPos>>MASTER_CLOCK_PREC; +} + void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size) { lastLoopPos=-1; @@ -1619,6 +1623,9 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi int attempts=0; int runLeftG=size<getPostAmp(); volR*=disCont[i].dispatch->getPostAmp(); - if (disCont[i].dispatch->isStereo()) { + if (disCont[i].dispatch->getOutputCount()>1) { for (size_t j=0; j