71
71
// a new route to the device
72
72
//-------------------------------------------------
74
void device_sound_interface::static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input)
74
device_sound_interface::sound_route &device_sound_interface::static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input, UINT32 mixoutput)
76
76
// find our sound interface
77
77
device_sound_interface *sound;
202
200
//-------------------------------------------------
201
// set_input_gain - set the gain on the given
202
// input index of the device
203
//-------------------------------------------------
205
void device_sound_interface::set_input_gain(int inputnum, float gain)
208
sound_stream *stream = input_to_stream_input(inputnum, stream_inputnum);
210
stream->set_input_gain(stream_inputnum, gain);
214
//-------------------------------------------------
203
215
// set_output_gain - set the gain on the given
204
216
// output index of the device
205
217
//-------------------------------------------------
229
241
//-------------------------------------------------
242
// inputnum_from_device - return the input number
243
// that is connected to the given device's output
244
//-------------------------------------------------
246
int device_sound_interface::inputnum_from_device(device_t &source_device, int outputnum) const
249
for (sound_stream *stream = m_device.machine().sound().first_stream(); stream != NULL; stream = stream->next())
250
if (&stream->device() == &device())
251
for (int inputnum = 0; inputnum < stream->input_count(); inputnum++, overall++)
252
if (stream->input_source_device(inputnum) == &source_device && stream->input_source_outputnum(inputnum) == outputnum)
258
//-------------------------------------------------
230
259
// interface_validity_check - validation for a
231
260
// device after the configuration has been
358
387
// sound_route - constructor
359
388
//-------------------------------------------------
361
device_sound_interface::sound_route::sound_route(int output, int input, float gain, const char *target)
390
device_sound_interface::sound_route::sound_route(int output, int input, float gain, const char *target, UINT32 mixoutput)
363
392
m_output(output),
394
m_mixoutput(mixoutput),
402
//**************************************************************************
403
// SIMPLE DERIVED MIXER INTERFACE
404
//**************************************************************************
406
//-------------------------------------------------
407
// device_mixer_interface - constructor
408
//-------------------------------------------------
410
device_mixer_interface::device_mixer_interface(const machine_config &mconfig, device_t &device, int outputs)
411
: device_sound_interface(mconfig, device),
418
//-------------------------------------------------
419
// ~device_mixer_interface - destructor
420
//-------------------------------------------------
422
device_mixer_interface::~device_mixer_interface()
427
//-------------------------------------------------
428
// interface_pre_start - perform startup prior
429
// to the device startup
430
//-------------------------------------------------
432
void device_mixer_interface::interface_pre_start()
435
device_sound_interface::interface_pre_start();
437
// no inputs? that's weird
438
if (m_auto_allocated_inputs == 0)
440
logerror("Warning: mixer \"%s\" has no inputs\n", device().tag());
444
// generate the output map
445
m_outputmap.resize(m_auto_allocated_inputs);
447
// iterate through all routes that point to us and note their mixer output
448
sound_interface_iterator iter(m_device.machine().root_device());
449
for (device_sound_interface *sound = iter.first(); sound != NULL; sound = iter.next())
450
for (const sound_route *route = sound->first_route(); route != NULL; route = route->next())
452
// see if we are the target of this route
453
device_t *target_device = sound->device().siblingdevice(route->m_target);
454
if (target_device == &device() && route->m_input < m_auto_allocated_inputs)
456
int count = (route->m_output == ALL_OUTPUTS) ? sound->outputs() : 1;
457
for (int output = 0; output < count; output++)
458
m_outputmap[route->m_input + output] = route->m_mixoutput;
462
// allocate the mixer stream
463
m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate());
467
//-------------------------------------------------
468
// interface_post_load - after we load a save
469
// state be sure to update the mixer stream's
470
// output sample rate
471
//-------------------------------------------------
473
void device_mixer_interface::interface_post_load()
475
m_mixer_stream->set_sample_rate(device().machine().sample_rate());
478
device_sound_interface::interface_post_load();
482
//-------------------------------------------------
483
// mixer_update - mix all inputs to one output
484
//-------------------------------------------------
486
void device_mixer_interface::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
488
// clear output buffers
489
for (int output = 0; output < m_outputs; output++)
490
memset(outputs[output], 0, samples * sizeof(outputs[0][0]));
493
const UINT8 *outmap = &m_outputmap[0];
494
for (int pos = 0; pos < samples; pos++)
496
// for each input, add it to the appropriate output
497
for (int inp = 0; inp < m_auto_allocated_inputs; inp++)
498
outputs[outmap[inp]][pos] += inputs[inp][pos];