diff options
Diffstat (limited to 'src/mame/audio/segasnd.cpp')
-rw-r--r-- | src/mame/audio/segasnd.cpp | 153 |
1 files changed, 75 insertions, 78 deletions
diff --git a/src/mame/audio/segasnd.cpp b/src/mame/audio/segasnd.cpp index 5f81c3d2281..ba9d4d86728 100644 --- a/src/mame/audio/segasnd.cpp +++ b/src/mame/audio/segasnd.cpp @@ -9,12 +9,15 @@ ***************************************************************************/ #include "emu.h" -#include "sound/sp0250.h" #include "segasnd.h" +#include "sound/sp0250.h" + +#include <cmath> + #define VERBOSE 0 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) +#include "logmacro.h" /*************************************************************************** @@ -37,24 +40,23 @@ INLINE FUNCTIONS ***************************************************************************/ -static inline void configure_filter(g80_filter_state *state, double r, double c) +inline void usb_sound_device::g80_filter_state::configure(double r, double c) { - state->capval = 0; - state->exponent = 1.0 - exp(-1.0 / (r * c * SAMPLE_RATE)); + capval = 0.0; + exponent = 1.0 - std::exp(-1.0 / (r * c * SAMPLE_RATE)); } -static inline double step_rc_filter(g80_filter_state *state, double input) +inline double usb_sound_device::g80_filter_state::step_rc(double input) { - state->capval += (input - state->capval) * state->exponent; - return state->capval; + return capval += (input - capval) * exponent; } -static inline double step_cr_filter(g80_filter_state *state, double input) +inline double usb_sound_device::g80_filter_state::step_cr(double input) { - double result = (input - state->capval); - state->capval += (input - state->capval) * state->exponent; + double const result = input - capval; + capval += result * exponent; return result; } @@ -64,10 +66,10 @@ static inline double step_cr_filter(g80_filter_state *state, double input) SPEECH BOARD ***************************************************************************/ -const device_type SEGASPEECH = device_creator<speech_sound_device>; +DEFINE_DEVICE_TYPE(SEGASPEECH, speech_sound_device, "sega_speech_sound", "Sega Speech Sound Board") -speech_sound_device::speech_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, SEGASPEECH, "Sega Speech Sound Board", tag, owner, clock, "sega_speech_sound", __FILE__), +speech_sound_device::speech_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, SEGASPEECH, tag, owner, clock), device_sound_interface(mconfig, *this), m_drq(0), m_latch(0), @@ -155,7 +157,7 @@ WRITE_LINE_MEMBER(speech_sound_device::drq_w) TIMER_CALLBACK_MEMBER( speech_sound_device::delayed_speech_w ) { int data = param; - uint8_t old = m_latch; + u8 old = m_latch; /* all 8 bits are latched */ m_latch = data; @@ -177,7 +179,7 @@ WRITE8_MEMBER( speech_sound_device::data_w ) WRITE8_MEMBER( speech_sound_device::control_w ) { - LOG(("Speech control = %X\n", data)); + LOG("Speech control = %X\n", data); } @@ -238,10 +240,10 @@ MACHINE_CONFIG_END UNIVERSAL SOUND BOARD ***************************************************************************/ -const device_type SEGAUSB = device_creator<usb_sound_device>; +DEFINE_DEVICE_TYPE(SEGAUSB, usb_sound_device, "segausb", "Sega Universal Sound Board") -usb_sound_device::usb_sound_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, uint32_t clock, const char *shortname, const char *source) - : device_t(mconfig, type, name, tag, owner, clock, shortname, source), +usb_sound_device::usb_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, type, tag, owner, clock), device_sound_interface(mconfig, *this), m_ourcpu(*this, "ourcpu"), m_stream(nullptr), @@ -259,12 +261,8 @@ usb_sound_device::usb_sound_device(const machine_config &mconfig, device_type ty { } -usb_sound_device::usb_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, SEGAUSB, "Sega Universal Sound Board", tag, owner, clock, "segausb", __FILE__), - device_sound_interface(mconfig, *this), - m_ourcpu(*this, "ourcpu"), - m_program_ram(*this, "pgmram"), - m_work_ram(*this, "workram") +usb_sound_device::usb_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : usb_sound_device(mconfig, SEGAUSB, tag, owner, clock) { } @@ -287,31 +285,30 @@ void usb_sound_device::device_start() /* initialize state */ m_noise_shift = 0x15555; - for (tgroup = 0; tgroup < 3; tgroup++) + for (timer8253 &g : m_timer_group) { - timer8253 *g = &m_timer_group[tgroup]; - configure_filter(&g->chan_filter[0], 10e3, 1e-6); - configure_filter(&g->chan_filter[1], 10e3, 1e-6); - configure_filter(&g->gate1, 100e3, 0.01e-6); - configure_filter(&g->gate2, 2 * 100e3, 0.01e-6); + g.chan_filter[0].configure(10e3, 1e-6); + g.chan_filter[1].configure(10e3, 1e-6); + g.gate1.configure(100e3, 0.01e-6); + g.gate2.configure(2 * 100e3, 0.01e-6); } - configure_filter(&temp, 100e3, 0.01e-6); + temp.configure(100e3, 0.01e-6); m_gate_rc1_exp[0] = temp.exponent; - configure_filter(&temp, 1e3, 0.01e-6); + temp.configure(1e3, 0.01e-6); m_gate_rc1_exp[1] = temp.exponent; - configure_filter(&temp, 2 * 100e3, 0.01e-6); + temp.configure(2 * 100e3, 0.01e-6); m_gate_rc2_exp[0] = temp.exponent; - configure_filter(&temp, 2 * 1e3, 0.01e-6); + temp.configure(2 * 1e3, 0.01e-6); m_gate_rc2_exp[1] = temp.exponent; - configure_filter(&m_noise_filters[0], 2.7e3 + 2.7e3, 1.0e-6); - configure_filter(&m_noise_filters[1], 2.7e3 + 1e3, 0.30e-6); - configure_filter(&m_noise_filters[2], 2.7e3 + 270, 0.15e-6); - configure_filter(&m_noise_filters[3], 2.7e3 + 0, 0.082e-6); - configure_filter(&m_noise_filters[4], 33e3, 0.1e-6); + m_noise_filters[0].configure(2.7e3 + 2.7e3, 1.0e-6); + m_noise_filters[1].configure(2.7e3 + 1e3, 0.30e-6); + m_noise_filters[2].configure(2.7e3 + 270, 0.15e-6); + m_noise_filters[3].configure(2.7e3 + 0, 0.082e-6); + m_noise_filters[4].configure(33e3, 0.1e-6); - configure_filter(&m_final_filter, 100e3, 4.7e-6); + m_final_filter.configure(100e3, 4.7e-6); /* register for save states */ save_item(NAME(m_in_latch)); @@ -325,7 +322,7 @@ void usb_sound_device::device_start() timer8253 *group = &m_timer_group[tgroup]; for (tchan = 0; tchan < 3; tchan++) { - timer8253_channel *channel = &group->chan[tchan]; + timer8253::channel *channel = &group->chan[tchan]; save_item(NAME(channel->holding), tgroup * 3 + tchan); save_item(NAME(channel->latchmode), tgroup * 3 + tchan); save_item(NAME(channel->latchtoggle), tgroup * 3 + tchan); @@ -392,7 +389,7 @@ TIMER_DEVICE_CALLBACK_MEMBER( usb_sound_device::increment_t1_clock_timer_cb ) READ8_MEMBER( usb_sound_device::status_r ) { - LOG(("%04X:usb_data_r = %02X\n", m_maincpu->safe_pc(), (m_out_latch & 0x81) | (m_in_latch & 0x7e))); + LOG("%04X:usb_data_r = %02X\n", m_maincpu->safe_pc(), (m_out_latch & 0x81) | (m_in_latch & 0x7e)); m_maincpu->execute().adjust_icount(-200); @@ -420,7 +417,7 @@ TIMER_CALLBACK_MEMBER( usb_sound_device::delayed_usb_data_w ) WRITE8_MEMBER( usb_sound_device::data_w ) { - LOG(("%04X:usb_data_w = %02X\n", m_maincpu->safe_pc(), data)); + LOG("%04X:usb_data_w = %02X\n", m_maincpu->safe_pc(), data); space.machine().scheduler().synchronize(timer_expired_delegate(FUNC(usb_sound_device::delayed_usb_data_w), this), data); /* boost the interleave so that sequences can be sent */ @@ -439,7 +436,7 @@ WRITE8_MEMBER( usb_sound_device::ram_w ) if (m_in_latch & 0x80) m_program_ram[offset] = data; else - LOG(("%04X:sega_usb_ram_w(%03X) = %02X while /LOAD disabled\n", m_maincpu->safe_pc(), offset, data)); + LOG("%04X:sega_usb_ram_w(%03X) = %02X while /LOAD disabled\n", m_maincpu->safe_pc(), offset, data); } @@ -454,7 +451,7 @@ READ8_MEMBER( usb_sound_device::p1_r ) { /* bits 0-6 are inputs and map to bits 0-6 of the input latch */ if ((m_in_latch & 0x7f) != 0) - LOG(("%03X: P1 read = %02X\n", m_maincpu->safe_pc(), m_in_latch & 0x7f)); + LOG("%03X: P1 read = %02X\n", m_maincpu->safe_pc(), m_in_latch & 0x7f); return m_in_latch & 0x7f; } @@ -463,13 +460,13 @@ WRITE8_MEMBER( usb_sound_device::p1_w ) { /* bit 7 maps to bit 0 on the output latch */ m_out_latch = (m_out_latch & 0xfe) | (data >> 7); - LOG(("%03X: P1 write = %02X\n", m_maincpu->safe_pc(), data)); + LOG("%03X: P1 write = %02X\n", m_maincpu->safe_pc(), data); } WRITE8_MEMBER( usb_sound_device::p2_w ) { - uint8_t old = m_last_p2_value; + u8 old = m_last_p2_value; m_last_p2_value = data; /* low 2 bits control the bank of work RAM we are addressing */ @@ -485,7 +482,7 @@ WRITE8_MEMBER( usb_sound_device::p2_w ) if ((old & 0x80) && !(data & 0x80)) m_t1_clock = 0; - LOG(("%03X: P2 write -> bank=%d ready=%d clock=%d\n", m_maincpu->safe_pc(), data & 3, (data >> 6) & 1, (data >> 7) & 1)); + LOG("%03X: P2 write -> bank=%d ready=%d clock=%d\n", m_maincpu->safe_pc(), data & 3, (data >> 6) & 1, (data >> 7) & 1); } @@ -504,41 +501,41 @@ READ_LINE_MEMBER( usb_sound_device::t1_r ) * *************************************/ -static inline void clock_channel(timer8253_channel *ch) +inline void usb_sound_device::timer8253::channel::clock() { - uint8_t lastgate = ch->lastgate; + u8 const old_lastgate = lastgate; /* update the gate */ - ch->lastgate = ch->gate; + lastgate = gate; /* if we're holding, skip */ - if (ch->holding) + if (holding) return; /* switch off the clock mode */ - switch (ch->clockmode) + switch (clockmode) { /* oneshot; waits for trigger to restart */ case 1: - if (!lastgate && ch->gate) + if (!old_lastgate && gate) { - ch->output = 0; - ch->remain = ch->count; + output = 0; + remain = count; } else { - if (--ch->remain == 0) - ch->output = 1; + if (--remain == 0) + output = 1; } break; /* square wave: counts down by 2 and toggles output */ case 3: - ch->remain = (ch->remain - 1) & ~1; - if (ch->remain == 0) + remain = (remain - 1) & ~1; + if (remain == 0) { - ch->output ^= 1; - ch->remain = ch->count; + output ^= 1; + remain = count; } break; } @@ -551,10 +548,10 @@ static inline void clock_channel(timer8253_channel *ch) * *************************************/ -void usb_sound_device::timer_w(int which, uint8_t offset, uint8_t data) +void usb_sound_device::timer_w(int which, u8 offset, u8 data) { timer8253 *g = &m_timer_group[which]; - timer8253_channel *ch; + timer8253::channel *ch; int was_holding; m_stream->update(); @@ -620,7 +617,7 @@ void usb_sound_device::timer_w(int which, uint8_t offset, uint8_t data) } -void usb_sound_device::env_w(int which, uint8_t offset, uint8_t data) +void usb_sound_device::env_w(int which, u8 offset, u8 data) { timer8253 *g = &m_timer_group[which]; @@ -725,7 +722,7 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t /* final output goes through a CR filter; the scaling factor is arbitrary to get the noise to the */ /* correct relative volume */ - noiseval = step_cr_filter(&m_noise_filters[4], noiseval); + noiseval = m_noise_filters[4].step_cr(noiseval); noiseval *= 0.075; /* there are 3 identical groups of circuits, each with its own 8253 */ @@ -748,12 +745,12 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t { g->chan[0].subcount = USB_2MHZ_CLOCK / USB_PCS_CLOCK; g->chan[0].gate = 1; - clock_channel(&g->chan[0]); + g->chan[0].clock(); } g->chan[0].subcount -= step; /* channel 0 is mixed in with a resistance of 100k */ - chan0 = step_cr_filter(&g->chan_filter[0], g->chan[0].output) * g->env[0] * (1.0/100.0); + chan0 = g->chan_filter[0].step_cr(g->chan[0].output) * g->env[0] * (1.0/100.0); /*------------- @@ -769,12 +766,12 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t { g->chan[1].subcount = USB_2MHZ_CLOCK / USB_PCS_CLOCK; g->chan[1].gate = 1; - clock_channel(&g->chan[1]); + g->chan[1].clock(); } g->chan[1].subcount -= step; /* channel 1 is mixed in with a resistance of 100k */ - chan1 = step_cr_filter(&g->chan_filter[1], g->chan[1].output) * g->env[1] * (1.0/100.0); + chan1 = g->chan_filter[1].step_cr(g->chan[1].output) * g->env[1] * (1.0/100.0); /*------------- @@ -802,7 +799,7 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t g->chan[2].subcount = USB_2MHZ_CLOCK / USB_GOS_CLOCK / 2 - 1; g->chan[2].gate = !g->chan[2].gate; } - clock_channel(&g->chan[2]); + g->chan[2].clock(); } /* the exponents for the gate filters are determined by channel 2's output */ @@ -812,14 +809,14 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t /* based on the envelope mode, we do one of two things with source 2 */ if (g->config == 0) { - chan2 = step_rc_filter(&g->gate2, step_rc_filter(&g->gate1, noiseval)) * -1.56 * g->env[2] * (1.0/33.0); + chan2 = g->gate2.step_rc(g->gate1.step_rc(noiseval)) * -1.56 * g->env[2] * (1.0/33.0); mix = chan0 + chan1 + chan2; } else { chan2 = -noiseval * g->env[2] * (1.0/33.0); mix = chan0 + chan1 + chan2; - mix = step_rc_filter(&g->gate2, step_rc_filter(&g->gate1, -mix)) * 1.56; + mix = g->gate2.step_rc(g->gate1.step_rc(-mix)) * 1.56; } /* accumulate the sample */ @@ -836,7 +833,7 @@ void usb_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t WEIGHT */ - *dest++ = 4000 * step_cr_filter(&m_final_filter, sample); + *dest++ = 4000 * m_final_filter.step_cr(sample); } } @@ -881,10 +878,10 @@ machine_config_constructor usb_sound_device::device_mconfig_additions() const return MACHINE_CONFIG_NAME( segausb ); } -const device_type SEGAUSBROM = device_creator<usb_rom_sound_device>; +DEFINE_DEVICE_TYPE(SEGAUSBROM, usb_rom_sound_device, "segausbrom", "Sega Universal Sound Board with ROM") -usb_rom_sound_device::usb_rom_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : usb_sound_device(mconfig, SEGAUSBROM, "Sega Universal Sound Board with ROM", tag, owner, clock, "segausbrom", __FILE__) +usb_rom_sound_device::usb_rom_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : usb_sound_device(mconfig, SEGAUSBROM, tag, owner, clock) { } |