Previous 199869 Revisions Next

r29534 Friday 11th April, 2014 at 09:47:08 UTC by Fabio Priuli
cem3394: updated to use delegates and inline configs. nw.
[src/emu/sound]cem3394.c cem3394.h
[src/mame/drivers]balsente.c
[src/mame/includes]balsente.h
[src/mame/machine]balsente.c

trunk/src/emu/sound/cem3394.c
r29533r29534
116116cem3394_device::cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
117117   : device_t(mconfig, CEM3394, "CEM3394", tag, owner, clock, "cem3394", __FILE__),
118118      device_sound_interface(mconfig, *this),
119      m_external(NULL),
120119      m_stream(NULL),
121120      m_vco_zero_freq(0.0),
122121      m_filter_zero_freq(0.0),
r29533r29534
154153   int i;
155154
156155   /* external volume is effectively 0 if no external function */
157   if (!m_external || !ENABLE_EXTERNAL)
156   if (m_ext_cb.isnull() || !ENABLE_EXTERNAL)
158157      ext_volume = 0;
159158
160159   /* adjust the volume for the filter */
r29533r29534
175174      INT16 last_ext = m_last_ext;
176175
177176      /* fetch the external data */
178      (*m_external)(this, samples, m_external_buffer);
177      m_ext_cb(samples, m_external_buffer);
179178
180179      /* compute the modulation depth, and adjust fstep to the maximum frequency */
181180      /* we lop off 13 bits of depth so that we can multiply by stepadjust, below, */
r29533r29534
325324
326325void cem3394_device::device_start()
327326{
328   const cem3394_interface *intf = (const cem3394_interface *)static_config();
329
330327   /* copy global parameters */
331328   m_sample_rate = CEM3394_SAMPLE_RATE;
332329   m_inv_sample_rate = 1.0 / (double)m_sample_rate;
333330
334331   /* allocate stream channels, 1 per chip */
335332   m_stream = stream_alloc(0, 1, m_sample_rate);
336   m_external = intf->external;
337   m_vco_zero_freq = intf->vco_zero_freq;
338   m_filter_zero_freq = intf->filter_zero_freq;
339333
334   m_ext_cb.bind_relative_to(*owner());
335
340336   /* allocate memory for a mixer buffer and external buffer (1 second should do it!) */
341337   m_mixer_buffer = auto_alloc_array(machine(), INT16, m_sample_rate);
342338   m_external_buffer = auto_alloc_array(machine(), INT16, m_sample_rate);
trunk/src/emu/sound/cem3394.h
r29533r29534
55
66#define CEM3394_SAMPLE_RATE     (44100*4)
77
8
9// interface
10struct cem3394_interface
11{
12   double vco_zero_freq;                    /* frequency at 0V for VCO */
13   double filter_zero_freq;                 /* frequency at 0V for filter */
14   void (*external)(device_t*, int, short*);/* external input source */
15};
16
178// inputs
189enum
1910{
r29533r29534
2718   CEM3394_FINAL_GAIN
2819};
2920
21typedef device_delegate<void (int count, short *buffer)> cem3394_ext_input_delegate;
3022
23#define CEM3394_EXT_INPUT(_name) void _name(int count, short *buffer)
24
3125//**************************************************************************
3226//  INTERFACE CONFIGURATION MACROS
3327//**************************************************************************
r29533r29534
3731#define MCFG_CEM3394_REPLACE(_tag, _clock) \
3832   MCFG_DEVICE_REPLACE(_tag, CEM3394, _clock)
3933
34#define MCFG_CEM3394_EXT_INPUT_CB(_class, _method) \
35   cem3394_device::set_ext_input_callback(*device, cem3394_ext_input_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
4036
37#define MCFG_CEM3394_VCO_ZERO(_freq) \
38   cem3394_device::set_vco_zero_freq(*device, _freq);
4139
40#define MCFG_CEM3394_FILTER_ZERO(_freq) \
41   cem3394_device::set_filter_zero_freq(*device, _freq);
42
43
4244class cem3394_device : public device_t,
4345                  public device_sound_interface
4446{
r29533r29534
4648   cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
4749   ~cem3394_device() { }
4850
51   static void set_ext_input_callback(device_t &device, cem3394_ext_input_delegate callback) { downcast<cem3394_device &>(device).m_ext_cb = callback; }
52   static void set_vco_zero_freq(device_t &device, double freq) { downcast<cem3394_device &>(device).m_vco_zero_freq = freq; }
53   static void set_filter_zero_freq(device_t &device, double freq) { downcast<cem3394_device &>(device).m_filter_zero_freq = freq; }
54
4955protected:
5056   // device-level overrides
5157   virtual void device_start();
r29533r29534
7379   UINT32 compute_db_volume(double voltage);
7480
7581private:
76   void (*m_external)(device_t*, int, short*);/* callback to generate external samples */
82   cem3394_ext_input_delegate m_ext_cb; /* callback to generate external samples */
7783
7884   sound_stream *m_stream;           /* our stream */
7985   double m_vco_zero_freq;           /* frequency of VCO at 0.0V */
trunk/src/mame/includes/balsente.h
r29533r29534
215215   void update_grudge_steering();
216216   void expand_roms(UINT8 cd_rom_mask);
217217   inline void config_shooter_adc(UINT8 shooter, UINT8 adc_shift);
218   inline void noise_gen_chip(int chip, int count, short *buffer);
219   CEM3394_EXT_INPUT(noise_gen_0);
220   CEM3394_EXT_INPUT(noise_gen_1);
221   CEM3394_EXT_INPUT(noise_gen_2);
222   CEM3394_EXT_INPUT(noise_gen_3);
223   CEM3394_EXT_INPUT(noise_gen_4);
224   CEM3394_EXT_INPUT(noise_gen_5);
218225   required_device<cpu_device> m_maincpu;
219226   required_device<cpu_device> m_audiocpu;
220227   optional_device<cpu_device> m_68k;
trunk/src/mame/drivers/balsente.c
r29533r29534
11771177INPUT_PORTS_END
11781178
11791179
1180
11811180/*************************************
11821181 *
1183 *  Sound definitions
1184 *
1185 *************************************/
1186
1187static const cem3394_interface cem_interface =
1188{
1189   431.894,
1190   1300.0,
1191   balsente_noise_gen
1192};
1193
1194
1195
1196/*************************************
1197 *
11981182 *  Machine driver
11991183 *
12001184 *************************************/
r29533r29534
12331217   MCFG_SPEAKER_STANDARD_MONO("mono")
12341218
12351219   MCFG_CEM3394_ADD("cem1", 0)
1236   MCFG_SOUND_CONFIG(cem_interface)
1220   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_0)
1221   MCFG_CEM3394_VCO_ZERO(431.894)
1222   MCFG_CEM3394_FILTER_ZERO(1300.0)
12371223   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12381224
12391225   MCFG_CEM3394_ADD("cem2", 0)
1240   MCFG_SOUND_CONFIG(cem_interface)
1226   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_1)
1227   MCFG_CEM3394_VCO_ZERO(431.894)
1228   MCFG_CEM3394_FILTER_ZERO(1300.0)
12411229   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12421230
12431231   MCFG_CEM3394_ADD("cem3", 0)
1244   MCFG_SOUND_CONFIG(cem_interface)
1232   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_2)
1233   MCFG_CEM3394_VCO_ZERO(431.894)
1234   MCFG_CEM3394_FILTER_ZERO(1300.0)
12451235   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12461236
12471237   MCFG_CEM3394_ADD("cem4", 0)
1248   MCFG_SOUND_CONFIG(cem_interface)
1238   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_3)
1239   MCFG_CEM3394_VCO_ZERO(431.894)
1240   MCFG_CEM3394_FILTER_ZERO(1300.0)
12491241   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12501242
12511243   MCFG_CEM3394_ADD("cem5", 0)
1252   MCFG_SOUND_CONFIG(cem_interface)
1244   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_4)
1245   MCFG_CEM3394_VCO_ZERO(431.894)
1246   MCFG_CEM3394_FILTER_ZERO(1300.0)
12531247   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12541248
12551249   MCFG_CEM3394_ADD("cem6", 0)
1256   MCFG_SOUND_CONFIG(cem_interface)
1250   MCFG_CEM3394_EXT_INPUT_CB(balsente_state, noise_gen_5)
1251   MCFG_CEM3394_VCO_ZERO(431.894)
1252   MCFG_CEM3394_FILTER_ZERO(1300.0)
12571253   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90)
12581254MACHINE_CONFIG_END
12591255
trunk/src/mame/machine/balsente.c
r29533r29534
206206}
207207
208208
209void balsente_noise_gen(device_t *device, int count, short *buffer)
209inline void balsente_state::noise_gen_chip(int chip, int count, short *buffer)
210210{
211   balsente_state *state = device->machine().driver_data<balsente_state>();
212   int chip;
213   UINT32 step, noise_counter;
214
215   /* find the chip we are referring to */
216   for (chip = 0; chip < ARRAY_LENGTH(state->m_cem_device); chip++)
217      if (device == state->m_cem_device[chip])
218         break;
219   assert(chip < ARRAY_LENGTH(state->m_cem_device));
220
221211   /* noise generator runs at 100kHz */
222   step = (100000 << 14) / CEM3394_SAMPLE_RATE;
223   noise_counter = state->m_noise_position[chip];
224
212   UINT32 step = (100000 << 14) / CEM3394_SAMPLE_RATE;
213   UINT32 noise_counter = m_noise_position[chip];
214   
225215   while (count--)
226216   {
227      *buffer++ = state->m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12;
217      *buffer++ = m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12;
228218      noise_counter += step;
229219   }
230
220   
231221   /* remember the noise position */
232   state->m_noise_position[chip] = noise_counter;
222   m_noise_position[chip] = noise_counter;
233223}
234224
225CEM3394_EXT_INPUT(balsente_state::noise_gen_0) { noise_gen_chip(0, count, buffer); }
226CEM3394_EXT_INPUT(balsente_state::noise_gen_1) { noise_gen_chip(1, count, buffer); }
227CEM3394_EXT_INPUT(balsente_state::noise_gen_2) { noise_gen_chip(2, count, buffer); }
228CEM3394_EXT_INPUT(balsente_state::noise_gen_3) { noise_gen_chip(3, count, buffer); }
229CEM3394_EXT_INPUT(balsente_state::noise_gen_4) { noise_gen_chip(4, count, buffer); }
230CEM3394_EXT_INPUT(balsente_state::noise_gen_5) { noise_gen_chip(5, count, buffer); }
235231
236232
237233/*************************************
r29533r29534
930926   /* bit D0 enables/disables audio */
931927   if (diff_counter_control & 0x01)
932928   {
933      int ch;
934      for (ch = 0; ch < 6; ch++)
929      for (int ch = 0; ch < 6; ch++)
935930         m_cem_device[ch]->set_output_gain(0, (data & 0x01) ? 1.0 : 0);
936931   }
937932

Previous 199869 Revisions Next


© 1997-2024 The MAME Team