diff options
Diffstat (limited to 'src/emu/disound.cpp')
-rw-r--r-- | src/emu/disound.cpp | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp index 4d7d60265b6..29d8b4e13b5 100644 --- a/src/emu/disound.cpp +++ b/src/emu/disound.cpp @@ -66,13 +66,23 @@ device_sound_interface &device_sound_interface::add_route(u32 output, device_t & //------------------------------------------------- -// stream_alloc - allocate a stream implicitly +// stream_alloc_legacy - allocate a stream implicitly // associated with this device //------------------------------------------------- +sound_stream *device_sound_interface::stream_alloc_legacy(int inputs, int outputs, int sample_rate) +{ + return device().machine().sound().stream_alloc_legacy(*this, inputs, outputs, sample_rate, stream_update_legacy_delegate(&device_sound_interface::sound_stream_update_legacy, this)); +} + sound_stream *device_sound_interface::stream_alloc(int inputs, int outputs, int sample_rate) { - return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate); + return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate, stream_update_delegate(&device_sound_interface::sound_stream_update, this), STREAM_DEFAULT_FLAGS); +} + +sound_stream *device_sound_interface::stream_alloc(int inputs, int outputs, int sample_rate, sound_stream_flags flags) +{ + return device().machine().sound().stream_alloc(*this, inputs, outputs, sample_rate, stream_update_delegate(&device_sound_interface::sound_stream_update, this), flags); } @@ -171,7 +181,7 @@ float device_sound_interface::input_gain(int inputnum) const { int stream_inputnum; sound_stream *stream = input_to_stream_input(inputnum, stream_inputnum); - return (stream != nullptr) ? stream->input_gain(stream_inputnum) : 0.0f; + return (stream != nullptr) ? stream->input(stream_inputnum).gain() : 0.0f; } @@ -184,7 +194,7 @@ float device_sound_interface::output_gain(int outputnum) const { int stream_outputnum; sound_stream *stream = output_to_stream_output(outputnum, stream_outputnum); - return (stream != nullptr) ? stream->output_gain(stream_outputnum) : 0.0f; + return (stream != nullptr) ? stream->output(stream_outputnum).gain() : 0.0f; } @@ -198,7 +208,7 @@ void device_sound_interface::set_input_gain(int inputnum, float gain) int stream_inputnum; sound_stream *stream = input_to_stream_input(inputnum, stream_inputnum); if (stream != nullptr) - stream->set_input_gain(stream_inputnum, gain); + stream->input(stream_inputnum).set_gain(gain); } @@ -215,7 +225,7 @@ void device_sound_interface::set_output_gain(int outputnum, float gain) for (auto &stream : device().machine().sound().streams()) if (&stream->device() == &device()) for (int num = 0; num < stream->output_count(); num++) - stream->set_output_gain(num, gain); + stream->output(num).set_gain(gain); } // look up the stream and stream output index @@ -224,7 +234,7 @@ void device_sound_interface::set_output_gain(int outputnum, float gain) int stream_outputnum; sound_stream *stream = output_to_stream_output(outputnum, stream_outputnum); if (stream != nullptr) - stream->set_output_gain(stream_outputnum, gain); + stream->output(stream_outputnum).set_gain(gain); } } @@ -240,8 +250,11 @@ int device_sound_interface::inputnum_from_device(device_t &source_device, int ou for (auto &stream : device().machine().sound().streams()) if (&stream->device() == &device()) for (int inputnum = 0; inputnum < stream->input_count(); inputnum++, overall++) - if (stream->input_source_device(inputnum) == &source_device && stream->input_source_outputnum(inputnum) == outputnum) + { + auto &input = stream->input(inputnum); + if (input.valid() && &input.source().stream().device() == &source_device && input.source().index() == outputnum) return overall; + } return -1; } @@ -368,6 +381,28 @@ void device_sound_interface::interface_pre_reset() } +//------------------------------------------------- +// sound_stream_update_legacy - implementation +// that should be overridden by legacy devices +//------------------------------------------------- + +void device_sound_interface::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +{ + throw emu_fatalerror("sound_stream_update_legacy called but not overridden by owning class"); +} + + +//------------------------------------------------- +// sound_stream_update - default implementation +// that should be overridden +//------------------------------------------------- + +void device_sound_interface::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) +{ + throw emu_fatalerror("sound_stream_update called but not overridden by owning class"); +} + + //************************************************************************** // SIMPLE DERIVED MIXER INTERFACE @@ -430,8 +465,11 @@ void device_mixer_interface::interface_pre_start() } } + // keep a small buffer handy for tracking cleared buffers + m_output_clear.resize(m_outputs); + // allocate the mixer stream - m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate()); + m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate(), STREAM_DEFAULT_FLAGS); } @@ -443,9 +481,8 @@ void device_mixer_interface::interface_pre_start() void device_mixer_interface::interface_post_load() { - // Beware that there's not going to be a mixer stream if there was - // no inputs - if (m_mixer_stream) + // mixer stream could be null if no inputs were specified + if (m_mixer_stream != nullptr) m_mixer_stream->set_sample_rate(device().machine().sample_rate()); // call our parent @@ -454,21 +491,36 @@ void device_mixer_interface::interface_post_load() //------------------------------------------------- -// mixer_update - mix all inputs to one output +// sound_stream_update - mix all inputs to one +// output //------------------------------------------------- -void device_mixer_interface::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - // clear output buffers - for (int output = 0; output < m_outputs; output++) - std::fill_n(outputs[output], samples, 0); + // reset the clear flags + std::fill(std::begin(m_output_clear), std::end(m_output_clear), false); - // loop over samples - const u8 *outmap = &m_outputmap[0]; - for (int pos = 0; pos < samples; pos++) + // loop over inputs + for (int inputnum = 0; inputnum < m_auto_allocated_inputs; inputnum++) { - // for each input, add it to the appropriate output - for (int inp = 0; inp < m_auto_allocated_inputs; inp++) - outputs[outmap[inp]][pos] += inputs[inp][pos]; + // skip if the gain is 0 + auto &input = inputs[inputnum]; + if (input.gain() == 0) + continue; + + // either store or accumulate + int outputnum = m_outputmap[inputnum]; + auto &output = outputs[outputnum]; + if (!m_output_clear[outputnum]) + output.copy(input); + else + output.add(input); + + m_output_clear[outputnum] = true; } + + // clear anything unused + for (int outputnum = 0; outputnum < m_outputs; outputnum++) + if (!m_output_clear[outputnum]) + outputs[outputnum].fill(0); } |