diff options
| author | 2026-02-02 17:36:39 +0100 | |
|---|---|---|
| committer | 2026-02-02 17:36:50 +0100 | |
| commit | 91f494d95169d72a315d6956cf93cd8c38238525 (patch) | |
| tree | 2f2d57c0ed46e895c9abc6591fc839767a20a46a | |
| parent | 5b25c66c0de6866047b2bb483e5f5f5029573cf9 (diff) | |
msm5205: small cleanup
| -rw-r--r-- | src/devices/sound/msm5205.cpp | 101 | ||||
| -rw-r--r-- | src/devices/sound/msm5205.h | 10 |
2 files changed, 55 insertions, 56 deletions
diff --git a/src/devices/sound/msm5205.cpp b/src/devices/sound/msm5205.cpp index ff5c99a6402..83c87adaaf8 100644 --- a/src/devices/sound/msm5205.cpp +++ b/src/devices/sound/msm5205.cpp @@ -1,23 +1,15 @@ // license:BSD-3-Clause // copyright-holders:Aaron Giles /* - * streaming ADPCM driver - * by Aaron Giles - * - * Library to transcode from an ADPCM source to raw PCM. - * Written by Buffoni Mirko in 08/06/97 - * References: various sources and documents. - * - * HJB 08/31/98 - * modified to use an automatically selected oversampling factor - * for the current sample rate - * - * 01/06/99 - * separate MSM5205 emulator form adpcm.c and some fix - * - * 07/29/12 - * added basic support for the MSM6585 - */ + + streaming ADPCM driver + by Aaron Giles + + Library to transcode from an ADPCM source to raw PCM. + Written by Buffoni Mirko in 08/06/97 + References: various sources and documents. + +*/ #include "emu.h" #include "msm5205.h" @@ -56,7 +48,7 @@ TODO: - lowpass filter for MSM6585 - */ +*/ DEFINE_DEVICE_TYPE(MSM5205, msm5205_device, "msm5205", "OKI MSM5205 ADPCM") DEFINE_DEVICE_TYPE(MSM6585, msm6585_device, "msm6585", "OKI MSM6585 ADPCM") @@ -91,15 +83,15 @@ msm6585_device::msm6585_device(const machine_config &mconfig, const char *tag, d void msm5205_device::device_start() { - /* compute the difference tables */ + // compute the difference tables compute_tables(); - /* stream system initialize */ + // stream system initialize m_stream = stream_alloc(0, 1, clock()); m_vck_timer = timer_alloc(FUNC(msm5205_device::toggle_vck), this); m_capture_timer = timer_alloc(FUNC(msm5205_device::update_adpcm), this); - /* register for save states */ + // register for save states save_item(NAME(m_data)); save_item(NAME(m_vck)); save_item(NAME(m_reset)); @@ -116,7 +108,7 @@ void msm5205_device::device_start() void msm5205_device::device_reset() { - /* initialize work */ + // initialize work m_data = 0; m_vck = 0; m_reset = 0; @@ -129,16 +121,17 @@ void msm5205_device::device_reset() * ADPCM lookup table */ -/* step size index shift table */ +// step size index shift table static const int index_shift[8] = { -1, -1, -1, -1, 2, 4, 6, 8 }; + /* * Compute the difference table */ void msm5205_device::compute_tables() { - /* nibble to bit map */ + // nibble to bit map static const int nbl2bit[16][4] = { { 1, 0, 0, 0}, { 1, 0, 0, 1}, { 1, 0, 1, 0}, { 1, 0, 1, 1}, @@ -147,19 +140,17 @@ void msm5205_device::compute_tables() {-1, 1, 0, 0}, {-1, 1, 0, 1}, {-1, 1, 1, 0}, {-1, 1, 1, 1} }; - int step, nib; - - /* loop over all possible steps */ - for (step = 0; step <= 48; step++) + // loop over all possible steps + for (int step = 0; step <= 48; step++) { - /* compute the step value */ + // compute the step value int stepval = floor (16.0 * pow (11.0 / 10.0, (double)step)); - /* loop over all nibbles and compute the difference */ - for (nib = 0; nib < 16; nib++) + // loop over all nibbles and compute the difference + for (int nib = 0; nib < 16; nib++) { m_diff_lookup[step*16 + nib] = nbl2bit[nib][0] * - (stepval * nbl2bit[nib][1] + + (stepval * nbl2bit[nib][1] + stepval/2 * nbl2bit[nib][2] + stepval/4 * nbl2bit[nib][3] + stepval/8); @@ -177,13 +168,12 @@ TIMER_CALLBACK_MEMBER(msm5205_device::toggle_vck) m_vck = !m_vck; m_vck_cb(m_vck); if (!m_vck) - m_capture_timer->adjust(attotime::from_hz(clock() / adpcm_capture_divisor())); + m_capture_timer->adjust(attotime::from_ticks(adpcm_capture_divisor(), clock())); } // timer callback at VCK low edge on MSM5205 (at rising edge on MSM6585) TIMER_CALLBACK_MEMBER(msm5205_device::update_adpcm) { - int val; int new_signal; // callback user handler and latch next data @@ -198,21 +188,25 @@ TIMER_CALLBACK_MEMBER(msm5205_device::update_adpcm) } else { - /* update signal */ - /* !! MSM5205 has internal 12bit decoding, signal width is 0 to 8191 !! */ - val = m_data; + // update signal + // !! MSM5205 has internal 12bit decoding, signal width is 0 to 8191 !! + int val = m_data; new_signal = m_signal + m_diff_lookup[m_step * 16 + (val & 15)]; - if (new_signal > 2047) new_signal = 2047; - else if (new_signal < -2048) new_signal = -2048; + if (new_signal > 2047) + new_signal = 2047; + else if (new_signal < -2048) + new_signal = -2048; m_step += index_shift[val & 7]; - if (m_step > 48) m_step = 48; - else if (m_step < 0) m_step = 0; + if (m_step > 48) + m_step = 48; + else if (m_step < 0) + m_step = 0; } - /* update when signal changed */ + // update when signal changed if (m_signal != new_signal) { m_stream->update(); @@ -221,11 +215,11 @@ TIMER_CALLBACK_MEMBER(msm5205_device::update_adpcm) } - /* * Handle an update of the VCK status of a chip (1 is reset ON, 0 is reset OFF) * This function can use selector = MSM5205_SEX only */ + void msm5205_device::vclk_w(int state) { if (get_prescaler() != 0) @@ -233,11 +227,12 @@ void msm5205_device::vclk_w(int state) else { if (m_vck && !state) - m_capture_timer->adjust(attotime::from_hz(clock()/6)); // 15.6 usec at 384KHz + m_capture_timer->adjust(attotime::from_ticks(6, clock())); // 15.6 usec at 384KHz m_vck = state; } } + /* * Handle an update of the reset status of a chip (1 is reset ON, 0 is reset OFF) */ @@ -247,6 +242,7 @@ void msm5205_device::reset_w(int state) m_reset = state; } + /* * Handle an update of the data to the chip */ @@ -256,7 +252,7 @@ void msm5205_device::data_w(uint8_t data) if (m_bitwidth == 4) m_data = data & 0x0f; else - m_data = (data & 0x07) << 1; /* unknown */ + m_data = (data & 0x07) << 1; // unknown } int msm5205_device::get_prescaler() const @@ -272,22 +268,25 @@ int msm6585_device::get_prescaler() const return (m_s1 ? 20 : 40) * (m_s2 ? 1 : 4); } + /* * Handle a change of the selector */ void msm5205_device::playmode_w(int select) { - int bitwidth = (select & 4) ? 4 : 3; + bool s1 = BIT(select, 0); + bool s2 = BIT(select, 1); + u8 bitwidth = BIT(select, 2) ? 4 : 3; - if ((select & 3) != ((m_s1 << 1) | m_s2)) + if (m_s1 != s1 || m_s2 != s2) { m_stream->update(); - m_s1 = BIT(select, 0); - m_s2 = BIT(select, 1); + m_s1 = s1; + m_s2 = s2; - /* timer set */ + // timer set notify_clock_changed(); } @@ -349,7 +348,7 @@ void msm5205_device::device_clock_changed() void msm5205_device::sound_stream_update(sound_stream &stream) { - /* if this voice is active */ + // if this voice is active if (m_signal) { constexpr sound_stream::sample_t sample_scale = 1.0 / double(1 << 12); diff --git a/src/devices/sound/msm5205.h b/src/devices/sound/msm5205.h index cd68abc6545..528e00a8adc 100644 --- a/src/devices/sound/msm5205.h +++ b/src/devices/sound/msm5205.h @@ -26,7 +26,7 @@ public: { m_s1 = BIT(select, 0); m_s2 = BIT(select, 1); - m_bitwidth = (select & 4) ? 4 : 3; + m_bitwidth = BIT(select, 2) ? 4 : 3; } auto vck_callback() { return m_vck_cb.bind(); } auto vck_legacy_callback() { return m_vck_legacy_cb.bind(); } @@ -34,7 +34,7 @@ public: // reset signal should keep for 2cycle of VCLK void reset_w(int state); - // adpcmata is latched after vclk_interrupt callback + // data is latched after vclk callback void data_w(uint8_t data); // VCLK slave mode option @@ -42,7 +42,7 @@ public: // call vclk_w after data_w and reset_w. void vclk_w(int state); - // option , selected pin selector + // option, sampling pin selector void playmode_w(int select); void s1_w(int state); void s2_w(int state); @@ -63,7 +63,7 @@ protected: void compute_tables(); virtual int get_prescaler() const; - virtual double adpcm_capture_divisor() const { return 6.0; } + virtual int adpcm_capture_divisor() const { return 6; } // internal state sound_stream *m_stream; // number of stream system @@ -98,7 +98,7 @@ public: protected: virtual int get_prescaler() const override; - virtual double adpcm_capture_divisor() const override { return 2.0; } + virtual int adpcm_capture_divisor() const override { return 2; } // sound stream update overrides virtual void sound_stream_update(sound_stream &stream) override; |
