summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/disound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/disound.cpp')
-rw-r--r--src/emu/disound.cpp118
1 files changed, 62 insertions, 56 deletions
diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp
index f8931ae6d24..2e16107b996 100644
--- a/src/emu/disound.cpp
+++ b/src/emu/disound.cpp
@@ -22,9 +22,9 @@
//-------------------------------------------------
device_sound_interface::device_sound_interface(const machine_config &mconfig, device_t &device)
- : device_interface(device, "sound"),
- m_outputs(0),
- m_auto_allocated_inputs(0)
+ : device_interface(device, "sound")
+ , m_outputs(0)
+ , m_auto_allocated_inputs(0)
{
}
@@ -39,6 +39,29 @@ device_sound_interface::~device_sound_interface()
//-------------------------------------------------
+// add_route - send sound output to a consumer
+//-------------------------------------------------
+
+void device_sound_interface::add_route(u32 output, const char *target, double gain, u32 input, u32 mixoutput)
+{
+ assert(!device().started());
+ m_route_list.emplace_back(sound_route{ output, input, mixoutput, float(gain), device().mconfig().current_device(), target });
+}
+
+void device_sound_interface::add_route(u32 output, device_sound_interface &target, double gain, u32 input, u32 mixoutput)
+{
+ assert(!device().started());
+ m_route_list.emplace_back(sound_route{ output, input, mixoutput, float(gain), target.device(), DEVICE_SELF });
+}
+
+void device_sound_interface::add_route(u32 output, speaker_device &target, double gain, u32 input, u32 mixoutput)
+{
+ assert(!device().started());
+ m_route_list.emplace_back(sound_route{ output, input, mixoutput, float(gain), target, DEVICE_SELF });
+}
+
+
+//-------------------------------------------------
// stream_alloc - allocate a stream implicitly
// associated with this device
//-------------------------------------------------
@@ -202,17 +225,17 @@ int device_sound_interface::inputnum_from_device(device_t &source_device, int ou
void device_sound_interface::interface_validity_check(validity_checker &valid) const
{
// loop over all the routes
- for (auto &route : routes())
+ for (sound_route const &route : routes())
{
// find a device with the requested tag
- const device_t *target = device().siblingdevice(route->m_target.c_str());
- if (target == nullptr)
- osd_printf_error("Attempting to route sound to non-existent device '%s'\n", route->m_target.c_str());
+ device_t const *const target = route.m_base.get().subdevice(route.m_target.c_str());
+ if (!target)
+ osd_printf_error("Attempting to route sound to non-existent device '%s'\n", route.m_base.get().subtag(route.m_target.c_str()).c_str());
// if it's not a speaker or a sound device, error
- const device_sound_interface *sound;
- if (target != nullptr && target->type() != SPEAKER && !target->interface(sound))
- osd_printf_error("Attempting to route sound to a non-sound device '%s' (%s)\n", route->m_target.c_str(), target->name());
+ device_sound_interface const *sound;
+ if (target && (target->type() != SPEAKER) && !target->interface(sound))
+ osd_printf_error("Attempting to route sound to a non-sound device '%s' (%s)\n", target->tag(), target->name());
}
}
@@ -226,14 +249,14 @@ void device_sound_interface::interface_pre_start()
{
// scan all the sound devices
sound_interface_iterator iter(m_device.machine().root_device());
- for (device_sound_interface &sound : iter)
+ for (device_sound_interface const &sound : iter)
{
// scan each route on the device
- for (auto &route : sound.routes())
+ for (sound_route const &route : sound.routes())
{
// see if we are the target of this route; if we are, make sure the source device is started
- device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
- if (target_device == &m_device && !sound.device().started())
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ if ((target_device == &m_device) && !sound.device().started())
throw device_missing_dependencies();
}
}
@@ -243,14 +266,14 @@ void device_sound_interface::interface_pre_start()
for (device_sound_interface &sound : iter)
{
// scan each route on the device
- for (auto &route : sound.routes())
+ for (sound_route &route : sound.routes())
{
// see if we are the target of this route
- device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
- if (target_device == &m_device && route->m_input == AUTO_ALLOC_INPUT)
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ if ((target_device == &m_device) && (route.m_input == AUTO_ALLOC_INPUT))
{
- route->m_input = m_auto_allocated_inputs;
- m_auto_allocated_inputs += (route->m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
+ route.m_input = m_auto_allocated_inputs;
+ m_auto_allocated_inputs += (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
}
}
}
@@ -268,32 +291,32 @@ void device_sound_interface::interface_post_start()
for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device()))
{
// scan each route on the device
- for (auto &route : sound.routes())
+ for (sound_route const &route : sound.routes())
{
// if we are the target of this route, hook it up
- device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
if (target_device == &m_device)
{
// iterate over all outputs, matching any that apply
- int inputnum = route->m_input;
- int numoutputs = sound.outputs();
+ int inputnum = route.m_input;
+ int const numoutputs = sound.outputs();
for (int outputnum = 0; outputnum < numoutputs; outputnum++)
- if (route->m_output == outputnum || route->m_output == ALL_OUTPUTS)
+ if ((route.m_output == outputnum) || (route.m_output == ALL_OUTPUTS))
{
// find the output stream to connect from
int streamoutputnum;
- sound_stream *outputstream = sound.output_to_stream_output(outputnum, streamoutputnum);
- if (outputstream == nullptr)
- fatalerror("Sound device '%s' specifies route for non-existant output #%d\n", route->m_target.c_str(), outputnum);
+ sound_stream *const outputstream = sound.output_to_stream_output(outputnum, streamoutputnum);
+ if (!outputstream)
+ fatalerror("Sound device '%s' specifies route for non-existent output #%d\n", sound.device().tag(), outputnum);
// find the input stream to connect to
int streaminputnum;
- sound_stream *inputstream = input_to_stream_input(inputnum++, streaminputnum);
- if (inputstream == nullptr)
- fatalerror("Sound device '%s' targeted output #%d to non-existant device '%s' input %d\n", route->m_target.c_str(), outputnum, m_device.tag(), inputnum - 1);
+ sound_stream *const inputstream = input_to_stream_input(inputnum++, streaminputnum);
+ if (!inputstream)
+ fatalerror("Sound device '%s' targeted output #%d to non-existant device '%s' input %d\n", sound.device().tag(), outputnum, m_device.tag(), inputnum - 1);
// set the input
- inputstream->set_input(streaminputnum, outputstream, streamoutputnum, route->m_gain);
+ inputstream->set_input(streaminputnum, outputstream, streamoutputnum, route.m_gain);
}
}
}
@@ -317,25 +340,6 @@ void device_sound_interface::interface_pre_reset()
//**************************************************************************
-// SOUND ROUTE
-//**************************************************************************
-
-//-------------------------------------------------
-// sound_route - constructor
-//-------------------------------------------------
-
-device_sound_interface::sound_route::sound_route(int output, int input, float gain, const char *target, u32 mixoutput)
- : m_output(output),
- m_input(input),
- m_mixoutput(mixoutput),
- m_gain(gain),
- m_target(target)
-{
-}
-
-
-
-//**************************************************************************
// SIMPLE DERIVED MIXER INTERFACE
//**************************************************************************
@@ -381,18 +385,20 @@ void device_mixer_interface::interface_pre_start()
m_outputmap.resize(m_auto_allocated_inputs);
// iterate through all routes that point to us and note their mixer output
- for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device()))
- for (auto &route : sound.routes())
+ for (device_sound_interface const &sound : sound_interface_iterator(m_device.machine().root_device()))
+ {
+ for (sound_route const &route : sound.routes())
{
// see if we are the target of this route
- device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
- if (target_device == &device() && route->m_input < m_auto_allocated_inputs)
+ device_t *const target_device = route.m_base.get().subdevice(route.m_target.c_str());
+ if ((target_device == &device()) && (route.m_input < m_auto_allocated_inputs))
{
- int count = (route->m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
+ int const count = (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
for (int output = 0; output < count; output++)
- m_outputmap[route->m_input + output] = route->m_mixoutput;
+ m_outputmap[route.m_input + output] = route.m_mixoutput;
}
}
+ }
// allocate the mixer stream
m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate());