Reset FM synthesis and PCM state on load

This commit is contained in:
Zachary Hall 2024-10-15 10:05:18 -07:00
parent c188aafb22
commit ba59bb8028
4 changed files with 16 additions and 1 deletions

View file

@ -82,6 +82,14 @@ class ym2151_interface : public ymfm::ymfm_interface {
bool irq() { bool irq() {
return m_irq_status; return m_irq_status;
} }
void reset() {
m_chip.reset();
m_timers[0] = 0;
m_timers[1] = 0;
m_busy_timer = 0;
m_irq_status = false;
opm_out.clear();
}
private: private:
ymfm::ym2151 m_chip; ymfm::ym2151 m_chip;
@ -114,6 +122,9 @@ extern "C" {
void YM_write_reg(uint8_t reg, uint8_t val) { void YM_write_reg(uint8_t reg, uint8_t val) {
if (initialized) opm_iface.write(reg, val); if (initialized) opm_iface.write(reg, val);
} }
void YM_reset() {
opm_iface.reset();
}
uint8_t YM_read_status() { uint8_t YM_read_status() {
if (initialized) if (initialized)

View file

@ -12,7 +12,7 @@ extern "C" {
void YM_stream_update(int16_t* output, uint32_t numsamples); void YM_stream_update(int16_t* output, uint32_t numsamples);
void YM_write_reg(uint8_t reg, uint8_t val); void YM_write_reg(uint8_t reg, uint8_t val);
bool YM_irq(void); bool YM_irq(void);
void YM_reset();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -74,7 +74,9 @@ extern SDL_AudioSpec obtained;
void ZsmBackend::switch_stream(int idx) { void ZsmBackend::switch_stream(int idx) {
YM_Create(YM_FREQ); YM_Create(YM_FREQ);
YM_init(YM_FREQ/64, 60); YM_init(YM_FREQ/64, 60);
YM_reset();
psg_reset(); psg_reset();
pcm_reset();
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
psg_writereg(i * 4 + 2, 0); psg_writereg(i * 4 + 2, 0);
} }

View file

@ -68,6 +68,8 @@ class ZsmBackend : public PlaybackBackend {
DynPtr out_buf; DynPtr out_buf;
DynPtr ym_buf; DynPtr ym_buf;
DynPtr ym_resample_buf; DynPtr ym_resample_buf;
bool ym_recorded = false;
uint8_t ym_data[256];
uint32_t loop_rem; uint32_t loop_rem;
uint32_t pcm_data_offs; uint32_t pcm_data_offs;
uint32_t loop; uint32_t loop;