SAA1099: implement SAASound core option

This commit is contained in:
tildearrow 2022-02-13 17:49:24 -05:00
parent 2f766553e8
commit 9ea510c351
5 changed files with 96 additions and 5 deletions

View File

@ -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;

View File

@ -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 (saaBufLen<len) {
saaBufLen=len;
for (int i=0; i<2; i++) {
@ -58,6 +58,40 @@ void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t
}
}
void DivPlatformSAA1099::acquire_saaSound(short* bufL, short* bufR, size_t start, size_t len) {
if (saaBufLen<len*2) {
saaBufLen=len*2;
for (int i=0; i<2; i++) {
delete[] saaBuf[i];
saaBuf[i]=new short[saaBufLen];
}
}
while (!writes.empty()) {
QueuedWrite w=writes.front();
saa_saaSound->WriteAddressData(w.addr,w.val);
writes.pop();
}
saa_saaSound->GenerateMany((unsigned char*)saaBuf[0],len);
for (size_t i=0; i<len; i++) {
bufL[i+start]=saaBuf[0][i<<1];
bufR[i+start]=saaBuf[0][1+(i<<1)];
}
}
void DivPlatformSAA1099::acquire(short* bufL, short* bufR, size_t start, size_t len) {
switch (core) {
case DIV_SAA_CORE_MAME:
acquire_mame(bufL,bufR,start,len);
break;
case DIV_SAA_CORE_SAASOUND:
acquire_saaSound(bufL,bufR,start,len);
break;
case DIV_SAA_CORE_E:
//acquire_e(bufL,bufR,start,len);
break;
}
}
inline unsigned char applyPan(unsigned char vol, unsigned char pan) {
return ((vol*(pan>>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<DivRegWrite>& 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];
}

View File

@ -4,6 +4,7 @@
#include "../macroInt.h"
#include <queue>
#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<QueuedWrite> 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);

View File

@ -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);

View File

@ -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),