diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 30b36940c6a..147c8c48f81 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -267,28 +267,29 @@ public: , m_mult(*this, "MULT", 1000.0) , m_offset(*this, "OFFSET", 0.0) , m_buffer(nullptr) - , m_sample(netlist::netlist_time::from_hz(1)) //sufficiently big enough + , m_bufsize(0) + , m_sample_time(netlist::netlist_time::from_hz(1)) //sufficiently big enough , m_in(*this, "IN") , m_cur(0.0) , m_last_pos(0) - , m_last_buffer(*this, "m_last_buffer", netlist::netlist_time::zero()) + , m_last_buffer_time(*this, "m_last_buffer", netlist::netlist_time::zero()) { } - static const int BUFSIZE = 2048; + //static const int BUFSIZE = 2048; ATTR_COLD void reset() override { m_cur = 0.0; m_last_pos = 0; - m_last_buffer = netlist::netlist_time::zero(); + m_last_buffer_time = netlist::netlist_time::zero(); } ATTR_HOT void sound_update(const netlist::netlist_time &upto) { - int pos = (upto - m_last_buffer) / m_sample; - if (pos >= BUFSIZE) - netlist().log().fatal("sound {1}: exceeded BUFSIZE\n", name().c_str()); + int pos = (upto - m_last_buffer_time) / m_sample_time; + if (pos > m_bufsize) + netlist().log().fatal("sound {1}: pos {2} exceeded bufsize {3}\n", name().c_str(), pos, m_bufsize); while (m_last_pos < pos ) { m_buffer[m_last_pos++] = (stream_sample_t) m_cur; @@ -313,7 +314,7 @@ public: ATTR_HOT void buffer_reset(const netlist::netlist_time &upto) { m_last_pos = 0; - m_last_buffer = upto; + m_last_buffer_time = upto; m_cur = 0.0; } @@ -321,13 +322,15 @@ public: netlist::param_double_t m_mult; netlist::param_double_t m_offset; stream_sample_t *m_buffer; - netlist::netlist_time m_sample; + int m_bufsize; + + netlist::netlist_time m_sample_time; private: netlist::analog_input_t m_in; double m_cur; int m_last_pos; - netlist::state_var m_last_buffer; + netlist::state_var m_last_buffer_time; }; // ---------------------------------------------------------------------------------------- @@ -337,58 +340,57 @@ private: class NETLIB_NAME(sound_in) : public netlist::device_t { public: + + static const int MAX_INPUT_CHANNELS = 16; + NETLIB_NAME(sound_in)(netlist::netlist_t &anetlist, const pstring &name) : netlist::device_t(anetlist, name) + , m_inc(netlist::netlist_time::from_nsec(1)) , m_feedback(*this, "FB") // clock part , m_Q(*this, "Q") , m_pos(0) - , m_num_channel(0) + , m_num_channels(0) { connect(m_feedback, m_Q); - m_inc = netlist::netlist_time::from_nsec(1); - for (int i = 0; i < MAX_INPUT_CHANNELS; i++) { - m_param_name[i] = std::make_unique(*this, plib::pfmt("CHAN{1}")(i), ""); - m_param_mult[i] = std::make_unique(*this, plib::pfmt("MULT{1}")(i), 1.0); - m_param_offset[i] = std::make_unique(*this, plib::pfmt("OFFSET{1}")(i), 0.0); + m_channels[i].m_param_name = std::make_unique(*this, plib::pfmt("CHAN{1}")(i), ""); + m_channels[i].m_param_mult = std::make_unique(*this, plib::pfmt("MULT{1}")(i), 1.0); + m_channels[i].m_param_offset = std::make_unique(*this, plib::pfmt("OFFSET{1}")(i), 0.0); } } - static const int MAX_INPUT_CHANNELS = 10; - ATTR_COLD void reset() override { m_pos = 0; - for (auto & elem : m_buffer) - elem = nullptr; + for (auto & elem : m_channels) + elem.m_buffer = nullptr; } - ATTR_COLD int resolve() + ATTR_COLD void resolve() { m_pos = 0; for (int i = 0; i < MAX_INPUT_CHANNELS; i++) { - if ((*m_param_name[i])() != pstring("")) + if ((*m_channels[i].m_param_name)() != pstring("")) { - if (i != m_num_channel) + if (i != m_num_channels) netlist().log().fatal("sound input numbering has to be sequential!"); - m_num_channel++; - m_param[i] = dynamic_cast(setup().find_param((*m_param_name[i])(), true)); + m_num_channels++; + m_channels[i].m_param = dynamic_cast(setup().find_param((*m_channels[i].m_param_name)(), true)); } } - return m_num_channel; } NETLIB_UPDATEI() { - for (int i=0; isetTo(v * (*m_param_mult[i])() + (*m_param_offset[i])()); + const nl_double v = m_channels[i].m_buffer[m_pos]; + m_channels[i].m_param->setTo(v * (*m_channels[i].m_param_mult)() + (*m_channels[i].m_param_offset)()); } m_pos++; m_Q.net().toggle_and_push_to_queue(m_inc); @@ -400,19 +402,25 @@ public: m_pos = 0; } - std::unique_ptr m_param_name[MAX_INPUT_CHANNELS]; - netlist::param_double_t *m_param[MAX_INPUT_CHANNELS]; - stream_sample_t *m_buffer[MAX_INPUT_CHANNELS]; - std::unique_ptr m_param_mult[MAX_INPUT_CHANNELS]; - std::unique_ptr m_param_offset[MAX_INPUT_CHANNELS]; + struct channel + { + std::unique_ptr m_param_name; + netlist::param_double_t *m_param; + stream_sample_t *m_buffer; + std::unique_ptr m_param_mult; + std::unique_ptr m_param_offset; + }; + channel m_channels[MAX_INPUT_CHANNELS]; netlist::netlist_time m_inc; + int num_channels() { return m_num_channels; } + private: netlist::logic_input_t m_feedback; netlist::logic_output_t m_Q; int m_pos; - int m_num_channel; + int m_num_channels; }; @@ -1088,7 +1096,6 @@ netlist_mame_sound_device::netlist_mame_sound_device(const machine_config &mconf , device_sound_interface(mconfig, *this) , m_in(nullptr) , m_stream(nullptr) - , m_num_inputs(0) { } @@ -1116,13 +1123,15 @@ void netlist_mame_sound_device::device_start() //if (chan < 0 || chan >= MAX_OUT || chan >= outdevs.size()) // fatalerror("illegal channel number"); m_out[chan] = outdevs[i]; - m_out[chan]->m_sample = netlist::netlist_time::from_hz(clock()); + m_out[chan]->m_sample_time = netlist::netlist_time::from_hz(clock()); m_out[chan]->m_buffer = nullptr; + m_out[chan]->m_bufsize = 0; } // Configure inputs + // FIXME: The limitation to one input device seems artificial. + // We should allow multiple devices with one channel each. - m_num_inputs = 0; m_in = nullptr; std::vector indevs = netlist().get_device_list(); @@ -1131,12 +1140,12 @@ void netlist_mame_sound_device::device_start() if (indevs.size() == 1) { m_in = indevs[0]; - m_num_inputs = m_in->resolve(); + m_in->resolve(); m_in->m_inc = netlist::netlist_time::from_hz(clock()); } /* initialize the stream(s) */ - m_stream = machine().sound().stream_alloc(*this, m_num_inputs, m_out.size(), clock()); + m_stream = machine().sound().stream_alloc(*this, m_in ? m_in->num_channels() : 0, m_out.size(), clock()); } @@ -1153,15 +1162,17 @@ void netlist_mame_sound_device::sound_stream_update(sound_stream &stream, stream for (auto &e : m_out) { e.second->m_buffer = outputs[e.first]; + e.second->m_bufsize = samples; } - if (m_num_inputs) - m_in->buffer_reset(); - - for (int i=0; i < m_num_inputs; i++) + if (m_in) { - m_in->m_buffer[i] = inputs[i]; + m_in->buffer_reset(); + for (int i=0; i < m_in->num_channels(); i++) + { + m_in->m_channels[i].m_buffer = inputs[i]; + } } netlist::netlist_time cur(netlist().time()); diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index f207f54cbd7..b400acdf32a 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -234,7 +234,6 @@ private: std::map m_out; nld_sound_in *m_in; sound_stream *m_stream; - int m_num_inputs; }; // ----------------------------------------------------------------------------------------