trunk/src/emu/sound/cem3394.c
| r29533 | r29534 | |
| 116 | 116 | cem3394_device::cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 117 | 117 | : device_t(mconfig, CEM3394, "CEM3394", tag, owner, clock, "cem3394", __FILE__), |
| 118 | 118 | device_sound_interface(mconfig, *this), |
| 119 | | m_external(NULL), |
| 120 | 119 | m_stream(NULL), |
| 121 | 120 | m_vco_zero_freq(0.0), |
| 122 | 121 | m_filter_zero_freq(0.0), |
| r29533 | r29534 | |
| 154 | 153 | int i; |
| 155 | 154 | |
| 156 | 155 | /* external volume is effectively 0 if no external function */ |
| 157 | | if (!m_external || !ENABLE_EXTERNAL) |
| 156 | if (m_ext_cb.isnull() || !ENABLE_EXTERNAL) |
| 158 | 157 | ext_volume = 0; |
| 159 | 158 | |
| 160 | 159 | /* adjust the volume for the filter */ |
| r29533 | r29534 | |
| 175 | 174 | INT16 last_ext = m_last_ext; |
| 176 | 175 | |
| 177 | 176 | /* fetch the external data */ |
| 178 | | (*m_external)(this, samples, m_external_buffer); |
| 177 | m_ext_cb(samples, m_external_buffer); |
| 179 | 178 | |
| 180 | 179 | /* compute the modulation depth, and adjust fstep to the maximum frequency */ |
| 181 | 180 | /* we lop off 13 bits of depth so that we can multiply by stepadjust, below, */ |
| r29533 | r29534 | |
| 325 | 324 | |
| 326 | 325 | void cem3394_device::device_start() |
| 327 | 326 | { |
| 328 | | const cem3394_interface *intf = (const cem3394_interface *)static_config(); |
| 329 | | |
| 330 | 327 | /* copy global parameters */ |
| 331 | 328 | m_sample_rate = CEM3394_SAMPLE_RATE; |
| 332 | 329 | m_inv_sample_rate = 1.0 / (double)m_sample_rate; |
| 333 | 330 | |
| 334 | 331 | /* allocate stream channels, 1 per chip */ |
| 335 | 332 | 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; |
| 339 | 333 | |
| 334 | m_ext_cb.bind_relative_to(*owner()); |
| 335 | |
| 340 | 336 | /* allocate memory for a mixer buffer and external buffer (1 second should do it!) */ |
| 341 | 337 | m_mixer_buffer = auto_alloc_array(machine(), INT16, m_sample_rate); |
| 342 | 338 | m_external_buffer = auto_alloc_array(machine(), INT16, m_sample_rate); |
trunk/src/emu/sound/cem3394.h
| r29533 | r29534 | |
| 5 | 5 | |
| 6 | 6 | #define CEM3394_SAMPLE_RATE (44100*4) |
| 7 | 7 | |
| 8 | | |
| 9 | | // interface |
| 10 | | struct 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 | | |
| 17 | 8 | // inputs |
| 18 | 9 | enum |
| 19 | 10 | { |
| r29533 | r29534 | |
| 27 | 18 | CEM3394_FINAL_GAIN |
| 28 | 19 | }; |
| 29 | 20 | |
| 21 | typedef device_delegate<void (int count, short *buffer)> cem3394_ext_input_delegate; |
| 30 | 22 | |
| 23 | #define CEM3394_EXT_INPUT(_name) void _name(int count, short *buffer) |
| 24 | |
| 31 | 25 | //************************************************************************** |
| 32 | 26 | // INTERFACE CONFIGURATION MACROS |
| 33 | 27 | //************************************************************************** |
| r29533 | r29534 | |
| 37 | 31 | #define MCFG_CEM3394_REPLACE(_tag, _clock) \ |
| 38 | 32 | MCFG_DEVICE_REPLACE(_tag, CEM3394, _clock) |
| 39 | 33 | |
| 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))); |
| 40 | 36 | |
| 37 | #define MCFG_CEM3394_VCO_ZERO(_freq) \ |
| 38 | cem3394_device::set_vco_zero_freq(*device, _freq); |
| 41 | 39 | |
| 40 | #define MCFG_CEM3394_FILTER_ZERO(_freq) \ |
| 41 | cem3394_device::set_filter_zero_freq(*device, _freq); |
| 42 | |
| 43 | |
| 42 | 44 | class cem3394_device : public device_t, |
| 43 | 45 | public device_sound_interface |
| 44 | 46 | { |
| r29533 | r29534 | |
| 46 | 48 | cem3394_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 47 | 49 | ~cem3394_device() { } |
| 48 | 50 | |
| 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 | |
| 49 | 55 | protected: |
| 50 | 56 | // device-level overrides |
| 51 | 57 | virtual void device_start(); |
| r29533 | r29534 | |
| 73 | 79 | UINT32 compute_db_volume(double voltage); |
| 74 | 80 | |
| 75 | 81 | private: |
| 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 */ |
| 77 | 83 | |
| 78 | 84 | sound_stream *m_stream; /* our stream */ |
| 79 | 85 | double m_vco_zero_freq; /* frequency of VCO at 0.0V */ |
trunk/src/mame/includes/balsente.h
| r29533 | r29534 | |
| 215 | 215 | void update_grudge_steering(); |
| 216 | 216 | void expand_roms(UINT8 cd_rom_mask); |
| 217 | 217 | 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); |
| 218 | 225 | required_device<cpu_device> m_maincpu; |
| 219 | 226 | required_device<cpu_device> m_audiocpu; |
| 220 | 227 | optional_device<cpu_device> m_68k; |
trunk/src/mame/drivers/balsente.c
| r29533 | r29534 | |
| 1177 | 1177 | INPUT_PORTS_END |
| 1178 | 1178 | |
| 1179 | 1179 | |
| 1180 | | |
| 1181 | 1180 | /************************************* |
| 1182 | 1181 | * |
| 1183 | | * Sound definitions |
| 1184 | | * |
| 1185 | | *************************************/ |
| 1186 | | |
| 1187 | | static const cem3394_interface cem_interface = |
| 1188 | | { |
| 1189 | | 431.894, |
| 1190 | | 1300.0, |
| 1191 | | balsente_noise_gen |
| 1192 | | }; |
| 1193 | | |
| 1194 | | |
| 1195 | | |
| 1196 | | /************************************* |
| 1197 | | * |
| 1198 | 1182 | * Machine driver |
| 1199 | 1183 | * |
| 1200 | 1184 | *************************************/ |
| r29533 | r29534 | |
| 1233 | 1217 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 1234 | 1218 | |
| 1235 | 1219 | 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) |
| 1237 | 1223 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1238 | 1224 | |
| 1239 | 1225 | 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) |
| 1241 | 1229 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1242 | 1230 | |
| 1243 | 1231 | 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) |
| 1245 | 1235 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1246 | 1236 | |
| 1247 | 1237 | 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) |
| 1249 | 1241 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1250 | 1242 | |
| 1251 | 1243 | 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) |
| 1253 | 1247 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1254 | 1248 | |
| 1255 | 1249 | 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) |
| 1257 | 1253 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.90) |
| 1258 | 1254 | MACHINE_CONFIG_END |
| 1259 | 1255 | |
trunk/src/mame/machine/balsente.c
| r29533 | r29534 | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
| 209 | | void balsente_noise_gen(device_t *device, int count, short *buffer) |
| 209 | inline void balsente_state::noise_gen_chip(int chip, int count, short *buffer) |
| 210 | 210 | { |
| 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 | | |
| 221 | 211 | /* 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 | |
| 225 | 215 | while (count--) |
| 226 | 216 | { |
| 227 | | *buffer++ = state->m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; |
| 217 | *buffer++ = m_poly17[(noise_counter >> 14) & POLY17_SIZE] << 12; |
| 228 | 218 | noise_counter += step; |
| 229 | 219 | } |
| 230 | | |
| 220 | |
| 231 | 221 | /* remember the noise position */ |
| 232 | | state->m_noise_position[chip] = noise_counter; |
| 222 | m_noise_position[chip] = noise_counter; |
| 233 | 223 | } |
| 234 | 224 | |
| 225 | CEM3394_EXT_INPUT(balsente_state::noise_gen_0) { noise_gen_chip(0, count, buffer); } |
| 226 | CEM3394_EXT_INPUT(balsente_state::noise_gen_1) { noise_gen_chip(1, count, buffer); } |
| 227 | CEM3394_EXT_INPUT(balsente_state::noise_gen_2) { noise_gen_chip(2, count, buffer); } |
| 228 | CEM3394_EXT_INPUT(balsente_state::noise_gen_3) { noise_gen_chip(3, count, buffer); } |
| 229 | CEM3394_EXT_INPUT(balsente_state::noise_gen_4) { noise_gen_chip(4, count, buffer); } |
| 230 | CEM3394_EXT_INPUT(balsente_state::noise_gen_5) { noise_gen_chip(5, count, buffer); } |
| 235 | 231 | |
| 236 | 232 | |
| 237 | 233 | /************************************* |
| r29533 | r29534 | |
| 930 | 926 | /* bit D0 enables/disables audio */ |
| 931 | 927 | if (diff_counter_control & 0x01) |
| 932 | 928 | { |
| 933 | | int ch; |
| 934 | | for (ch = 0; ch < 6; ch++) |
| 929 | for (int ch = 0; ch < 6; ch++) |
| 935 | 930 | m_cem_device[ch]->set_output_gain(0, (data & 0x01) ? 1.0 : 0); |
| 936 | 931 | } |
| 937 | 932 | |