AY: prepare for optimization

This commit is contained in:
tildearrow 2025-03-07 19:37:18 -05:00
parent 33aebf29c6
commit cb67527103
6 changed files with 27 additions and 50 deletions

View file

@ -249,13 +249,7 @@ void DivPlatformAY8910::checkWrites() {
} }
void DivPlatformAY8910::acquire_mame(short** buf, size_t len) { void DivPlatformAY8910::acquire_mame(short** buf, size_t len) {
if (ayBufLen<len) { thread_local short ayBuf[3];
ayBufLen=len;
for (int i=0; i<3; i++) {
delete[] ayBuf[i];
ayBuf[i]=new short[ayBufLen];
}
}
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
oscBuf[i]->begin(len); oscBuf[i]->begin(len);
@ -268,7 +262,7 @@ void DivPlatformAY8910::acquire_mame(short** buf, size_t len) {
checkWrites(); checkWrites();
ay->sound_stream_update(ayBuf,1); ay->sound_stream_update(ayBuf,1);
buf[0][i]=ayBuf[0][0]; buf[0][i]=ayBuf[0];
buf[1][i]=buf[0][i]; buf[1][i]=buf[0][i];
oscBuf[0]->putSample(i,CLAMP(sunsoftVolTable[31-(ay->lastIndx&31)]<<3,-32768,32767)); oscBuf[0]->putSample(i,CLAMP(sunsoftVolTable[31-(ay->lastIndx&31)]<<3,-32768,32767));
@ -283,16 +277,16 @@ void DivPlatformAY8910::acquire_mame(short** buf, size_t len) {
ay->sound_stream_update(ayBuf,1); ay->sound_stream_update(ayBuf,1);
if (stereo) { if (stereo) {
buf[0][i]=ayBuf[0][0]+ayBuf[1][0]+((ayBuf[2][0]*stereoSep)>>8); buf[0][i]=ayBuf[0]+ayBuf[1]+((ayBuf[2]*stereoSep)>>8);
buf[1][i]=((ayBuf[0][0]*stereoSep)>>8)+ayBuf[1][0]+ayBuf[2][0]; buf[1][i]=((ayBuf[0]*stereoSep)>>8)+ayBuf[1]+ayBuf[2];
} else { } else {
buf[0][i]=ayBuf[0][0]+ayBuf[1][0]+ayBuf[2][0]; buf[0][i]=ayBuf[0]+ayBuf[1]+ayBuf[2];
buf[1][i]=buf[0][i]; buf[1][i]=buf[0][i];
} }
oscBuf[0]->putSample(i,ayBuf[0][0]<<2); oscBuf[0]->putSample(i,ayBuf[0]<<2);
oscBuf[1]->putSample(i,ayBuf[1][0]<<2); oscBuf[1]->putSample(i,ayBuf[1]<<2);
oscBuf[2]->putSample(i,ayBuf[2][0]<<2); oscBuf[2]->putSample(i,ayBuf[2]<<2);
} }
} }
@ -1185,8 +1179,6 @@ int DivPlatformAY8910::init(DivEngine* p, int channels, int sugRate, const DivCo
} }
ay=NULL; ay=NULL;
setFlags(flags); setFlags(flags);
ayBufLen=65536;
for (int i=0; i<3; i++) ayBuf[i]=new short[ayBufLen];
reset(); reset();
return 3; return 3;
} }
@ -1194,7 +1186,6 @@ int DivPlatformAY8910::init(DivEngine* p, int channels, int sugRate, const DivCo
void DivPlatformAY8910::quit() { void DivPlatformAY8910::quit() {
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
delete oscBuf[i]; delete oscBuf[i];
delete[] ayBuf[i];
} }
if (ay!=NULL) delete ay; if (ay!=NULL) delete ay;
} }

View file

@ -145,8 +145,6 @@ class DivPlatformAY8910: public DivDispatch {
unsigned short ayEnvPeriod; unsigned short ayEnvPeriod;
short ayEnvSlideLow; short ayEnvSlideLow;
short ayEnvSlide; short ayEnvSlide;
short* ayBuf[3];
size_t ayBufLen;
void checkWrites(); void checkWrites();
void updateOutSel(bool immediate=false); void updateOutSel(bool immediate=false);

View file

@ -165,14 +165,7 @@ void DivPlatformAY8930::checkWrites() {
} }
void DivPlatformAY8930::acquire(short** buf, size_t len) { void DivPlatformAY8930::acquire(short** buf, size_t len) {
if (ayBufLen<len) { thread_local short ayBuf[3];
ayBufLen=len;
for (int i=0; i<3; i++) {
delete[] ayBuf[i];
ayBuf[i]=new short[ayBufLen];
}
}
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
oscBuf[i]->begin(len); oscBuf[i]->begin(len);
} }
@ -183,16 +176,16 @@ void DivPlatformAY8930::acquire(short** buf, size_t len) {
ay->sound_stream_update(ayBuf,1); ay->sound_stream_update(ayBuf,1);
if (stereo) { if (stereo) {
buf[0][i]=ayBuf[0][0]+ayBuf[1][0]+((ayBuf[2][0]*stereoSep)>>8); buf[0][i]=ayBuf[0]+ayBuf[1]+((ayBuf[2]*stereoSep)>>8);
buf[1][i]=((ayBuf[0][0]*stereoSep)>>8)+ayBuf[1][0]+ayBuf[2][0]; buf[1][i]=((ayBuf[0]*stereoSep)>>8)+ayBuf[1]+ayBuf[2];
} else { } else {
buf[0][i]=ayBuf[0][0]+ayBuf[1][0]+ayBuf[2][0]; buf[0][i]=ayBuf[0]+ayBuf[1]+ayBuf[2];
buf[1][i]=buf[0][i]; buf[1][i]=buf[0][i];
} }
oscBuf[0]->putSample(i,ayBuf[0][0]<<2); oscBuf[0]->putSample(i,ayBuf[0]<<2);
oscBuf[1]->putSample(i,ayBuf[1][0]<<2); oscBuf[1]->putSample(i,ayBuf[1]<<2);
oscBuf[2]->putSample(i,ayBuf[2][0]<<2); oscBuf[2]->putSample(i,ayBuf[2]<<2);
} }
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
@ -949,8 +942,6 @@ int DivPlatformAY8930::init(DivEngine* p, int channels, int sugRate, const DivCo
setFlags(flags); setFlags(flags);
ay=new ay8930_device(rate,clockSel); ay=new ay8930_device(rate,clockSel);
ay->device_start(); ay->device_start();
ayBufLen=65536;
for (int i=0; i<3; i++) ayBuf[i]=new short[ayBufLen];
reset(); reset();
return 3; return 3;
} }
@ -958,7 +949,6 @@ int DivPlatformAY8930::init(DivEngine* p, int channels, int sugRate, const DivCo
void DivPlatformAY8930::quit() { void DivPlatformAY8930::quit() {
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
delete oscBuf[i]; delete oscBuf[i];
delete[] ayBuf[i];
} }
delete ay; delete ay;
} }

View file

@ -121,8 +121,6 @@ class DivPlatformAY8930: public DivDispatch {
short oldWrites[32]; short oldWrites[32];
short pendingWrites[32]; short pendingWrites[32];
short* ayBuf[3];
size_t ayBufLen;
void runDAC(); void runDAC();
void checkWrites(); void checkWrites();

View file

@ -1035,7 +1035,7 @@ void ay8910_device::ay8910_write_reg(int r, int v)
// sound_stream_update - handle a stream update // sound_stream_update - handle a stream update
//------------------------------------------------- //-------------------------------------------------
void ay8910_device::sound_stream_update(short** outputs, int outLen) void ay8910_device::sound_stream_update(short* outputs, int outLen)
{ {
tone_t *tone; tone_t *tone;
envelope_t *envelope; envelope_t *envelope;
@ -1046,7 +1046,7 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen)
if (!m_ready) if (!m_ready)
{ {
for (int chan = 0; chan < m_streams; chan++) for (int chan = 0; chan < m_streams; chan++)
memset(outputs[chan],0,outLen*sizeof(short)); outputs[chan]=0;
} }
/* The 8910 has three outputs, each output is the mix of one of the three */ /* The 8910 has three outputs, each output is the mix of one of the three */
@ -1162,38 +1162,38 @@ void ay8910_device::sound_stream_update(short** outputs, int outLen)
{ {
env_volume >>= 1; env_volume >>= 1;
if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field
outputs[chan][sampindex]=m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; outputs[chan]=m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0];
else else
outputs[chan][sampindex]=m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]; outputs[chan]=m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0];
} }
else else
{ {
if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field
outputs[chan][sampindex]=m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; outputs[chan]=m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0];
else else
outputs[chan][sampindex]=m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]; outputs[chan]=m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0];
} }
} }
else else
{ {
if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field
outputs[chan][sampindex]=m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]; outputs[chan]=m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0];
else else
outputs[chan][sampindex]=m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]; outputs[chan]=m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0];
} }
} }
else else
{ {
if (is_expanded_mode()) if (is_expanded_mode())
outputs[chan][sampindex]=m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]; outputs[chan]=m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0];
else else
outputs[chan][sampindex]=m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]; outputs[chan]=m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0];
} }
} }
} }
else else
{ {
outputs[0][sampindex]=mix_3D(); outputs[0]=mix_3D();
} }
} }
} }

View file

@ -158,7 +158,7 @@ public:
void device_reset(); void device_reset();
// sound stream update overrides // sound stream update overrides
void sound_stream_update(short** outputs, int outLen); void sound_stream_update(short* outputs, int outLen);
void ay8910_write_ym(int addr, unsigned char data); void ay8910_write_ym(int addr, unsigned char data);
unsigned char ay8910_read_ym(); unsigned char ay8910_read_ym();