diff --git a/src/emu/sound/cem3394.c b/src/emu/sound/cem3394.c index cf5624125e3..117fa0f003c 100644 --- a/src/emu/sound/cem3394.c +++ b/src/emu/sound/cem3394.c @@ -116,7 +116,6 @@ const device_type CEM3394 = &device_creator; cem3394_device::cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, CEM3394, "CEM3394", tag, owner, clock, "cem3394", __FILE__), device_sound_interface(mconfig, *this), - m_external(NULL), m_stream(NULL), m_vco_zero_freq(0.0), m_filter_zero_freq(0.0), @@ -154,7 +153,7 @@ void cem3394_device::sound_stream_update(sound_stream &stream, stream_sample_t * int i; /* external volume is effectively 0 if no external function */ - if (!m_external || !ENABLE_EXTERNAL) + if (m_ext_cb.isnull() || !ENABLE_EXTERNAL) ext_volume = 0; /* adjust the volume for the filter */ @@ -175,7 +174,7 @@ void cem3394_device::sound_stream_update(sound_stream &stream, stream_sample_t * INT16 last_ext = m_last_ext; /* fetch the external data */ - (*m_external)(this, samples, m_external_buffer); + m_ext_cb(samples, m_external_buffer); /* compute the modulation depth, and adjust fstep to the maximum frequency */ /* we lop off 13 bits of depth so that we can multiply by stepadjust, below, */ @@ -325,17 +324,14 @@ void cem3394_device::sound_stream_update(sound_stream &stream, stream_sample_t * void cem3394_device::device_start() { - const cem3394_interface *intf = (const cem3394_interface *)static_config(); - /* copy global parameters */ m_sample_rate = CEM3394_SAMPLE_RATE; m_inv_sample_rate = 1.0 / (double)m_sample_rate; /* allocate stream channels, 1 per chip */ m_stream = stream_alloc(0, 1, m_sample_rate); - m_external = intf->external; - m_vco_zero_freq = intf->vco_zero_freq; - m_filter_zero_freq = intf->filter_zero_freq; + + m_ext_cb.bind_relative_to(*owner()); /* allocate memory for a mixer buffer and external buffer (1 second should do it!) */ m_mixer_buffer = auto_alloc_array(machine(), INT16, m_sample_rate); diff --git a/src/emu/sound/cem3394.h b/src/emu/sound/cem3394.h index 0581df78a94..9ba4154a7b2 100644 --- a/src/emu/sound/cem3394.h +++ b/src/emu/sound/cem3394.h @@ -5,15 +5,6 @@ #define CEM3394_SAMPLE_RATE (44100*4) - -// interface -struct cem3394_interface -{ - double vco_zero_freq; /* frequency at 0V for VCO */ - double filter_zero_freq; /* frequency at 0V for filter */ - void (*external)(device_t*, int, short*);/* external input source */ -}; - // inputs enum { @@ -27,6 +18,9 @@ enum CEM3394_FINAL_GAIN }; +typedef device_delegate cem3394_ext_input_delegate; + +#define CEM3394_EXT_INPUT(_name) void _name(int count, short *buffer) //************************************************************************** // INTERFACE CONFIGURATION MACROS @@ -37,6 +31,14 @@ enum #define MCFG_CEM3394_REPLACE(_tag, _clock) \ MCFG_DEVICE_REPLACE(_tag, CEM3394, _clock) +#define MCFG_CEM3394_EXT_INPUT_CB(_class, _method) \ + cem3394_device::set_ext_input_callback(*device, cem3394_ext_input_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner))); + +#define MCFG_CEM3394_VCO_ZERO(_freq) \ + cem3394_device::set_vco_zero_freq(*device, _freq); + +#define MCFG_CEM3394_FILTER_ZERO(_freq) \ + cem3394_device::set_filter_zero_freq(*device, _freq); class cem3394_device : public device_t, @@ -46,6 +48,10 @@ public: cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); ~cem3394_device() { } + static void set_ext_input_callback(device_t &device, cem3394_ext_input_delegate callback) { downcast(device).m_ext_cb = callback; } + static void set_vco_zero_freq(device_t &device, double freq) { downcast(device).m_vco_zero_freq = freq; } + static void set_filter_zero_freq(device_t &device, double freq) { downcast(device).m_filter_zero_freq = freq; } + protected: // device-level overrides virtual void device_start(); @@ -73,7 +79,7 @@ private: UINT32 compute_db_volume(double voltage); private: - void (*m_external)(device_t*, int, short*);/* callback to generate external samples */ + cem3394_ext_input_delegate m_ext_cb; /* callback to generate external samples */ sound_stream *m_stream; /* our stream */ double m_vco_zero_freq; /* frequency of VCO at 0.0V */ diff --git a/src/mame/drivers/balsente.c b/src/mame/drivers/balsente.c index 1b342b446c4..26dbcf270e8 100644 --- a/src/mame/drivers/balsente.c +++ b/src/mame/drivers/balsente.c @@ -1177,22 +1177,6 @@ static INPUT_PORTS_START( shrike ) INPUT_PORTS_END - -/************************************* - * - * Sound definitions - * - *************************************/ - -static const cem3394_interface cem_interface = -{ - 431.894, - 1300.0, - balsente_noise_gen -}; - - - /************************************* * * Machine driver @@ -1233,27 +1217,39 @@ static MACHINE_CONFIG_START( balsente, balsente_state ) MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_CEM3394_ADD("cem1", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_0) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MCFG_CEM3394_ADD("cem2", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_1) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MCFG_CEM3394_ADD("cem3", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_2) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MCFG_CEM3394_ADD("cem4", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_3) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MCFG_CEM3394_ADD("cem5", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_4) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MCFG_CEM3394_ADD("cem6", 0) - MCFG_SOUND_CONFIG(cem_interface) + MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_5) + MCFG_CEM3394_VCO_ZERO(431.894) + MCFG_CEM3394_FILTER_ZERO(1300.0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) MACHINE_CONFIG_END diff --git a/src/mame/includes/balsente.h b/src/mame/includes/balsente.h index 2bc4de8a0a9..6e0b9dbefd0 100644 --- a/src/mame/includes/balsente.h +++ b/src/mame/includes/balsente.h @@ -215,6 +215,13 @@ public: void update_grudge_steering(); void expand_roms(UINT8 cd_rom_mask); inline void config_shooter_adc(UINT8 shooter, UINT8 adc_shift); + inline void noise_gen_chip(int chip, int count, short *buffer); + CEM3394_EXT_INPUT(noise_gen_0); + CEM3394_EXT_INPUT(noise_gen_1); + CEM3394_EXT_INPUT(noise_gen_2); + CEM3394_EXT_INPUT(noise_gen_3); + CEM3394_EXT_INPUT(noise_gen_4); + CEM3394_EXT_INPUT(noise_gen_5); required_device m_maincpu; required_device m_audiocpu; optional_device m_68k; diff --git a/src/mame/machine/balsente.c b/src/mame/machine/balsente.c index 00cee9dc665..ed867be3642 100644 --- a/src/mame/machine/balsente.c +++ b/src/mame/machine/balsente.c @@ -206,32 +206,28 @@ void balsente_state::poly17_init() } -void balsente_noise_gen(device_t *device, int count, short *buffer) +inline void balsente_state::noise_gen_chip(int chip, int count, short *buffer) { - balsente_state *state = device->machine().driver_data(); - int chip; - UINT32 step, noise_counter; - - /* find the chip we are referring to */ - for (chip = 0; chip < ARRAY_LENGTH(state->m_cem_device); chip++) - if (device == state->m_cem_device[chip]) - break; - assert(chip < ARRAY_LENGTH(state->m_cem_device)); - /* noise generator runs at 100kHz */ - step = (100000 << 14) / CEM3394_SAMPLE_RATE; - noise_counter = state->m_noise_position[chip]; - + UINT32 step = (100000 << 14) / CEM3394_SAMPLE_RATE; + UINT32 noise_counter = m_noise_position[chip]; + while (count--) { - *buffer++ = state->m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; + *buffer++ = m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; noise_counter += step; } - + /* remember the noise position */ - state->m_noise_position[chip] = noise_counter; + m_noise_position[chip] = noise_counter; } +CEM3394_EXT_INPUT(balsente_state::noise_gen_0) { noise_gen_chip(0, count, buffer); } +CEM3394_EXT_INPUT(balsente_state::noise_gen_1) { noise_gen_chip(1, count, buffer); } +CEM3394_EXT_INPUT(balsente_state::noise_gen_2) { noise_gen_chip(2, count, buffer); } +CEM3394_EXT_INPUT(balsente_state::noise_gen_3) { noise_gen_chip(3, count, buffer); } +CEM3394_EXT_INPUT(balsente_state::noise_gen_4) { noise_gen_chip(4, count, buffer); } +CEM3394_EXT_INPUT(balsente_state::noise_gen_5) { noise_gen_chip(5, count, buffer); } /************************************* @@ -930,8 +926,7 @@ WRITE8_MEMBER(balsente_state::balsente_counter_control_w) /* bit D0 enables/disables audio */ if (diff_counter_control & 0x01) { - int ch; - for (ch = 0; ch < 6; ch++) + for (int ch = 0; ch < 6; ch++) m_cem_device[ch]->set_output_gain(0, (data & 0x01) ? 1.0 : 0); }