From 9ea510c351732ec226bc1d2fcf8549095fb1b7b3 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 13 Feb 2022 17:49:24 -0500 Subject: [PATCH] SAA1099: implement SAASound core option --- src/engine/dispatchContainer.cpp | 6 ++- src/engine/platform/saa.cpp | 74 +++++++++++++++++++++++++++++++- src/engine/platform/saa.h | 4 ++ src/gui/gui.cpp | 15 ++++++- src/gui/gui.h | 2 + 5 files changed, 96 insertions(+), 5 deletions(-) diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 173f8a337..e7bf89673 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -173,9 +173,13 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do case DIV_SYSTEM_TIA: dispatch=new DivPlatformTIA; break; - case DIV_SYSTEM_SAA1099: + case DIV_SYSTEM_SAA1099: { + int saaCore=eng->getConfInt("saaCore",0); + if (saaCore<0 || saaCore>2) saaCore=0; dispatch=new DivPlatformSAA1099; + ((DivPlatformSAA1099*)dispatch)->setCore((DivSAACores)saaCore); break; + } default: logW("this system is not supported yet! using dummy platform.\n"); dispatch=new DivPlatformDummy; diff --git a/src/engine/platform/saa.cpp b/src/engine/platform/saa.cpp index 4b4ae70bf..c69821d78 100644 --- a/src/engine/platform/saa.cpp +++ b/src/engine/platform/saa.cpp @@ -37,7 +37,7 @@ const char** DivPlatformSAA1099::getRegisterSheet() { return regCheatSheetSAA; } -void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformSAA1099::acquire_mame(short* bufL, short* bufR, size_t start, size_t len) { if (saaBufLenWriteAddressData(w.addr,w.val); + writes.pop(); + } + saa_saaSound->GenerateMany((unsigned char*)saaBuf[0],len); + for (size_t i=0; i>4))/15)|(((vol*(pan&15))/15)<<4); } @@ -301,7 +335,16 @@ void* DivPlatformSAA1099::getChanState(int ch) { void DivPlatformSAA1099::reset() { while (!writes.empty()) writes.pop(); - saa=saa1099_device(); + switch (core) { + case DIV_SAA_CORE_MAME: + saa=saa1099_device(); + break; + case DIV_SAA_CORE_SAASOUND: + saa_saaSound->Clear(); + break; + case DIV_SAA_CORE_E: + break; + } for (int i=0; i<6; i++) { chan[i]=DivPlatformSAA1099::Channel(); chan[i].vol=0x0f; @@ -356,6 +399,19 @@ void DivPlatformSAA1099::setFlags(unsigned int flags) { chipClock=8000000; } rate=chipClock/32; + + switch (core) { + case DIV_SAA_CORE_MAME: + break; + case DIV_SAA_CORE_SAASOUND: + saa_saaSound->SetClockRate(chipClock); + saa_saaSound->SetSampleRate(rate); + + printf("rate: %ld bytes %d params %lx\n",saa_saaSound->GetCurrentSampleRate(),saa_saaSound->GetCurrentBytesPerSample(),saa_saaSound->GetCurrentSoundParameters()); + break; + case DIV_SAA_CORE_E: + break; + } } void DivPlatformSAA1099::poke(unsigned int addr, unsigned short val) { @@ -366,13 +422,23 @@ void DivPlatformSAA1099::poke(std::vector& wlist) { for (DivRegWrite& i: wlist) rWrite(i.addr,i.val); } +void DivPlatformSAA1099::setCore(DivSAACores c) { + core=c; +} + int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, unsigned int flags) { parent=p; dumpWrites=false; skipRegisterWrites=false; + saa_saaSound=NULL; for (int i=0; i<6; i++) { isMuted[i]=false; } + if (core==DIV_SAA_CORE_SAASOUND) { + saa_saaSound=CreateCSAASound(); + saa_saaSound->SetOversample(1); + saa_saaSound->SetSoundParameters(SAAP_NOFILTER|SAAP_16BIT|SAAP_STEREO); + } setFlags(flags); saaBufLen=65536; for (int i=0; i<2; i++) saaBuf[i]=new short[saaBufLen]; @@ -381,5 +447,9 @@ int DivPlatformSAA1099::init(DivEngine* p, int channels, int sugRate, unsigned i } void DivPlatformSAA1099::quit() { + if (saa_saaSound!=NULL) { + DestroyCSAASound(saa_saaSound); + saa_saaSound=NULL; + } for (int i=0; i<2; i++) delete[] saaBuf[i]; } diff --git a/src/engine/platform/saa.h b/src/engine/platform/saa.h index 9a73f90a0..3acfad4fa 100644 --- a/src/engine/platform/saa.h +++ b/src/engine/platform/saa.h @@ -4,6 +4,7 @@ #include "../macroInt.h" #include #include "sound/saa1099.h" +#include "../../../../extern/SAASound/src/SAASound.h" enum DivSAACores { DIV_SAA_CORE_MAME=0, @@ -33,7 +34,9 @@ class DivPlatformSAA1099: public DivDispatch { QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {} }; std::queue writes; + DivSAACores core; saa1099_device saa; + CSAASound* saa_saaSound; unsigned char lastBusy; bool dacMode; @@ -67,6 +70,7 @@ class DivPlatformSAA1099: public DivDispatch { void forceIns(); void tick(); void muteChannel(int ch, bool mute); + void setCore(DivSAACores core); void setFlags(unsigned int flags); bool isStereo(); int getPortaFloor(int ch); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6cab7b757..5a5f1f59f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3648,6 +3648,11 @@ const char* ym2612Cores[]={ "ymfm" }; +const char* saaCores[]={ + "MAME", + "SAASound" +}; + #define SAMPLE_RATE_SELECTABLE(x) \ if (ImGui::Selectable(#x,settings.audioRate==x)) { \ settings.audioRate=x; \ @@ -3810,14 +3815,18 @@ void FurnaceGUI::drawSettings() { ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Emulation")) { - ImGui::Text("Arcade core"); + ImGui::Text("Arcade/YM2151 core"); ImGui::SameLine(); ImGui::Combo("##ArcadeCore",&settings.arcadeCore,arcadeCores,2); - ImGui::Text("Genesis core"); + ImGui::Text("Genesis/YM2612 core"); ImGui::SameLine(); ImGui::Combo("##YM2612Core",&settings.ym2612Core,ym2612Cores,2); + ImGui::Text("SAA1099 core"); + ImGui::SameLine(); + ImGui::Combo("##SAACore",&settings.saaCore,saaCores,2); + ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Appearance")) { @@ -4220,6 +4229,7 @@ void FurnaceGUI::syncSettings() { settings.audioRate=e->getConfInt("audioRate",44100); settings.arcadeCore=e->getConfInt("arcadeCore",0); settings.ym2612Core=e->getConfInt("ym2612Core",0); + settings.saaCore=e->getConfInt("saaCore",0); settings.mainFont=e->getConfInt("mainFont",0); settings.patFont=e->getConfInt("patFont",0); settings.mainFontPath=e->getConfString("mainFontPath",""); @@ -4408,6 +4418,7 @@ void FurnaceGUI::commitSettings() { e->setConf("audioRate",settings.audioRate); e->setConf("arcadeCore",settings.arcadeCore); e->setConf("ym2612Core",settings.ym2612Core); + e->setConf("saaCore",settings.saaCore); e->setConf("mainFont",settings.mainFont); e->setConf("patFont",settings.patFont); e->setConf("mainFontPath",settings.mainFontPath); diff --git a/src/gui/gui.h b/src/gui/gui.h index e8a06c3b2..05ce4334e 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -381,6 +381,7 @@ class FurnaceGUI { int audioQuality; int arcadeCore; int ym2612Core; + int saaCore; int mainFont; int patFont; int audioRate; @@ -416,6 +417,7 @@ class FurnaceGUI { audioQuality(0), arcadeCore(0), ym2612Core(0), + saaCore(0), mainFont(0), patFont(0), audioRate(44100),