From d1f6b7a719a92466142ec44e7082daf5c0bd1424 Mon Sep 17 00:00:00 2001 From: AJR Date: Mon, 26 Jun 2017 09:12:43 -0400 Subject: ym2151: Support dynamic changes to clock frequency --- src/devices/sound/ym2151.cpp | 31 ++++++++++++++++++++----------- src/devices/sound/ym2151.h | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/devices/sound/ym2151.cpp b/src/devices/sound/ym2151.cpp index a86227af86b..3e5df2b1914 100644 --- a/src/devices/sound/ym2151.cpp +++ b/src/devices/sound/ym2151.cpp @@ -382,25 +382,28 @@ void ym2151_device::init_tables() } } + /* calculate noise periods table */ + for (int i=0; i<32; i++) + { + int j = (i!=31 ? i : 30); /* rate 30 and 31 are the same */ + j = 32-j; + j = (65536.0 / (double)(j*32.0)); /* number of samples per one shift of the shift register */ + noise_tab[i] = j * 64; /* number of chip clock cycles per one shift */ + } +} + +void ym2151_device::calculate_timers() +{ /* calculate timers' deltas */ for (int i=0; i<1024; i++) { /* ASG 980324: changed to compute both tim_A_tab and timer_A_time */ - timer_A_time[i] = attotime::from_hz(clock()) * (64 * (1024 - i)); + timer_A_time[i] = clocks_to_attotime(64 * (1024 - i)); } for (int i=0; i<256; i++) { /* ASG 980324: changed to compute both tim_B_tab and timer_B_time */ - timer_B_time[i] = attotime::from_hz(clock()) * (1024 * (256 - i)); - } - - /* calculate noise periods table */ - for (int i=0; i<32; i++) - { - int j = (i!=31 ? i : 30); /* rate 30 and 31 are the same */ - j = 32-j; - j = (65536.0 / (double)(j*32.0)); /* number of samples per one shift of the shift register */ - noise_tab[i] = j * 64; /* number of chip clock cycles per one shift */ + timer_B_time[i] = clocks_to_attotime(1024 * (256 - i)); } } @@ -1020,6 +1023,12 @@ void ym2151_device::device_start() save_item(NAME(connect)); } +void ym2151_device::device_clock_changed() +{ + m_stream->set_sample_rate(clock() / 64); + calculate_timers(); +} + int ym2151_device::op_calc(YM2151Operator * OP, unsigned int env, signed int pm) { diff --git a/src/devices/sound/ym2151.h b/src/devices/sound/ym2151.h index 57b1efb80eb..9ca2f41f4e4 100644 --- a/src/devices/sound/ym2151.h +++ b/src/devices/sound/ym2151.h @@ -81,6 +81,7 @@ protected: virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; virtual void device_post_load() override; + virtual void device_clock_changed() override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; @@ -259,6 +260,7 @@ private: devcb_write8 m_portwritehandler; void init_tables(); + void calculate_timers(); void envelope_KONKOFF(YM2151Operator * op, int v); void set_connect(YM2151Operator *om1, int cha, int v); void advance(); -- cgit v1.2.3