diff options
Diffstat (limited to 'src/devices')
-rw-r--r-- | src/devices/machine/netlist.cpp | 35 | ||||
-rw-r--r-- | src/devices/machine/netlist.h | 12 | ||||
-rw-r--r-- | src/devices/sound/spkrdev.cpp | 2 |
3 files changed, 34 insertions, 15 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 8d4d6cedf4d..a3d6ae3e656 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -322,6 +322,7 @@ class NETLIB_NAME(sound_in) : public sound_in_type public: using base_type = sound_in_type; using base_type::base_type; + sound_stream *m_stream = nullptr; }; netlist::setup_t &netlist_mame_device::setup() @@ -1387,6 +1388,11 @@ void netlist_mame_sound_device::device_start() std::vector<nld_sound_in *> indevs = netlist().get_device_list<nld_sound_in>(); for (auto &e : indevs) { + // We cannot use the resampler because the stream is not + // always audio. In particular the ay8910 may send a stream + // of resistor values, which would be destroyed by resampling. + + e->m_stream = stream_alloc(1, 0, SAMPLE_RATE_INPUT_ADAPTIVE); m_in.emplace(e->id(), e); const auto sample_time = netlist::netlist_time::from_raw(static_cast<netlist::netlist_time::internal_type>(nltime_from_attotime(m_attotime_per_clock).as_raw())); e->resolve_params(sample_time); @@ -1399,7 +1405,7 @@ void netlist_mame_sound_device::device_start() m_inbuffer.resize(m_in.size()); /* initialize the stream(s) */ - m_stream = stream_alloc(m_in.size(), m_out.size(), m_sound_clock); + m_stream = stream_alloc(0, m_out.size(), m_sound_clock); LOGDEVCALLS("sound device_start exit\n"); } @@ -1444,21 +1450,30 @@ void netlist_mame_sound_device::update_to_current_time() void netlist_mame_sound_device::sound_stream_update(sound_stream &stream) { - for (auto &e : m_in) + if (stream.input_count() == 1) { - auto clock_period = stream.sample_period(); - auto sample_time = netlist::netlist_time::from_raw(static_cast<netlist::netlist_time::internal_type>(nltime_from_attotime(clock_period).as_raw())); - m_inbuffer[e.first] = netlist_mame_sound_input_buffer(stream, e.first); - e.second->buffer_reset(sample_time, stream.samples(), &m_inbuffer[e.first]); + for (auto &e : m_in) + if (e.second->m_stream == &stream) + { + auto clock_period = stream.sample_period(); + auto sample_time = netlist::netlist_time::from_raw(static_cast<netlist::netlist_time::internal_type>(nltime_from_attotime(clock_period).as_raw())); + m_inbuffer[e.first] = netlist_mame_sound_input_buffer(stream); + e.second->buffer_reset(sample_time, stream.samples(), &m_inbuffer[e.first]); + return; + } + fatalerror("netlist: Got input from an unknown stream\n"); } int samples = stream.samples(); LOGDEBUG("samples %d\n", samples); - // end_time() is the time at the END of the last sample we're generating - // however, the sample value is the value at the START of that last sample, - // so subtract one sample period so that we only process up to the minimum - auto nl_target_time = nltime_from_attotime(stream.end_time() - stream.sample_period()); + // Ensure all input streams are up-to-date + for (auto &e : m_in) + if (e.second->m_stream) + e.second->m_stream->update(); + + // Get the start time of the last sample to generate + auto nl_target_time = nltime_from_attotime(stream.sample_to_time(stream.end_index() - 1)); auto nltime(netlist().exec().time()); if (nltime < nl_target_time) diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 67b6b7d143c..57fc6b05c3a 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -255,14 +255,18 @@ private: class netlist_mame_sound_input_buffer { public: - sound_stream *m_stream = nullptr; - int m_stream_input = 0; + std::vector<sound_stream::sample_t> m_buffer; netlist_mame_sound_input_buffer() {} - netlist_mame_sound_input_buffer(sound_stream &stream, int input) : m_stream(&stream), m_stream_input(input) { } + netlist_mame_sound_input_buffer(sound_stream &stream) { + int samples = stream.samples(); + m_buffer.resize(samples); + for (int i=0; i != samples; i++) + m_buffer[i] = stream.get(0, i); + } - sound_stream::sample_t operator[](std::size_t index) { return m_stream->get(m_stream_input, index); } + sound_stream::sample_t operator[](std::size_t index) { return m_buffer[index]; } }; // ---------------------------------------------------------------------------------------- diff --git a/src/devices/sound/spkrdev.cpp b/src/devices/sound/spkrdev.cpp index 841656ab4ac..16dc6199c2f 100644 --- a/src/devices/sound/spkrdev.cpp +++ b/src/devices/sound/spkrdev.cpp @@ -268,7 +268,7 @@ void speaker_sound_device::level_w(int new_level) /* This is redundant because time update has to be done within sound_stream_update() anyway, * however this ensures synchronization between the speaker and stream timing: */ - m_channel_last_sample_time = m_channel->sample_time(); + m_channel_last_sample_time = m_channel->end_time(); /* sample_time() may be ahead of us */ if (m_channel_last_sample_time > time) |