From 8d7d01caef380b119fbd8653fa5ad23e0d592564 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Thu, 17 Sep 2020 01:24:17 -0700 Subject: Revert "sound: Improved view interfaces to match usage patterns" This reverts commit dc0ede3c90717ed25de0695c555b861f06344f18. --- src/devices/cpu/tms57002/tms57002.cpp | 16 ++++---- src/devices/machine/netlist.cpp | 8 ++-- src/devices/machine/netlist.h | 2 +- src/devices/sound/aica.cpp | 8 ++-- src/devices/sound/asc.cpp | 14 +++---- src/devices/sound/astrocde.cpp | 7 ++-- src/devices/sound/awacs.cpp | 6 +-- src/devices/sound/ay8910.cpp | 24 ++++++------ src/devices/sound/beep.cpp | 4 +- src/devices/sound/c140.cpp | 12 +++--- src/devices/sound/c352.cpp | 10 ++--- src/devices/sound/c6280.cpp | 28 ++++++-------- src/devices/sound/cdda.cpp | 17 +++++---- src/devices/sound/cdp1863.cpp | 4 +- src/devices/sound/cdp1864.cpp | 4 +- src/devices/sound/cdp1869.cpp | 4 +- src/devices/sound/cem3394.cpp | 6 +-- src/devices/sound/dac.h | 40 ++++++++++---------- src/devices/sound/dave.cpp | 6 +-- src/devices/sound/digitalk.cpp | 18 ++++++--- src/devices/sound/disc_cls.h | 6 ++- src/devices/sound/disc_inp.hxx | 5 ++- src/devices/sound/discrete.cpp | 1 + src/devices/sound/k054539.cpp | 6 +-- src/devices/sound/namco.cpp | 24 ++++++------ src/devices/sound/okim6295.cpp | 4 +- src/devices/sound/pokey.cpp | 8 ++-- src/devices/sound/samples.cpp | 6 +-- src/devices/sound/sn76496.cpp | 6 +-- src/devices/sound/sp0250.cpp | 14 +++++-- src/devices/sound/tms3615.cpp | 6 +-- src/devices/sound/tms5220.cpp | 6 +-- src/devices/sound/upd7759.cpp | 8 ++-- src/devices/sound/vgm_visualizer.cpp | 4 +- src/devices/sound/votrax.cpp | 4 +- src/devices/sound/ym2151.cpp | 6 +-- src/devices/video/i8244.cpp | 4 +- src/emu/disound.cpp | 6 +-- src/emu/sound.cpp | 41 +++++++++++--------- src/emu/sound.h | 70 +++++++++-------------------------- src/emu/speaker.cpp | 11 +++--- src/mame/audio/sente6vb.cpp | 4 +- 42 files changed, 239 insertions(+), 249 deletions(-) diff --git a/src/devices/cpu/tms57002/tms57002.cpp b/src/devices/cpu/tms57002/tms57002.cpp index dcc6e615cea..c2cf28f3f92 100644 --- a/src/devices/cpu/tms57002/tms57002.cpp +++ b/src/devices/cpu/tms57002/tms57002.cpp @@ -924,16 +924,16 @@ void tms57002_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, w int i; constexpr stream_buffer::sample_t sample_scale = 1.0 / stream_buffer::sample_t(32768 << SHIFT); - while (!bufl.done()) + for (int s = 0; s < bufl.samples(); ++s) { s32 smpl = 0, smpr = 0; @@ -1275,7 +1275,7 @@ void aica_device::DoMasterSamples(std::vector const &inputs, w { if (EFSDL(i + 16)) // 16,17 for EXTS { - m_DSP.EXTS[i] = s16(inputs[i].get() * 32767.0); + m_DSP.EXTS[i] = s16(inputs[i].get(s) * 32767.0); u32 Enc = ((EFPAN(i + 16)) << 0x8) | ((EFSDL(i + 16)) << 0xd); smpl += (m_DSP.EXTS[i] * m_LPANTABLE[Enc]) >> SHIFT; smpr += (m_DSP.EXTS[i] * m_RPANTABLE[Enc]) >> SHIFT; @@ -1293,8 +1293,8 @@ void aica_device::DoMasterSamples(std::vector const &inputs, w smpr = clip16(smpr >> 3); } - bufl.put(stream_buffer::sample_t(smpl * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); - bufr.put(stream_buffer::sample_t(smpr * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); + bufl.put(s, stream_buffer::sample_t(smpl * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); + bufr.put(s, stream_buffer::sample_t(smpr * m_LPANTABLE[MVOL() << 0xd]) * sample_scale); } } diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index c7e467b617c..e03494040ab 100644 --- a/src/devices/sound/asc.cpp +++ b/src/devices/sound/asc.cpp @@ -119,7 +119,7 @@ void asc_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void asc_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - int ch; + int i, ch; static uint32_t wtoffs[2] = { 0, 0x200 }; auto &outL = outputs[0]; @@ -149,7 +149,7 @@ void asc_device::sound_stream_update(sound_stream &stream, std::vector(dest.samples() - sampindex, 256 - master_count); + samples_this_time = std::min(samples_this_time, 64 - noise_clock); /* sum the output of the tone generators */ if (m_a_state) @@ -165,7 +166,7 @@ void astrocade_io_device::sound_stream_update(sound_stream &stream, std::vector< cursample += m_reg[7] >> 4; /* scale to max and output */ - samples_this_time = dest.fill(stream_buffer::sample_t(cursample) * sample_scale, samples_this_time); + dest.fill(stream_buffer::sample_t(cursample) * sample_scale, sampindex, samples_this_time); /* clock the noise; a 2-bit counter clocks a 4-bit counter which clocks the LFSR */ noise_clock += samples_this_time; diff --git a/src/devices/sound/awacs.cpp b/src/devices/sound/awacs.cpp index 007217db048..19f734cd468 100644 --- a/src/devices/sound/awacs.cpp +++ b/src/devices/sound/awacs.cpp @@ -96,10 +96,10 @@ void awacs_device::sound_stream_update(sound_stream &stream, std::vectorread_word(offset + m_play_ptr))) * sample_scale); - outR.put(stream_buffer::sample_t(s16(m_dma_space->read_word(offset + m_play_ptr + 2))) * sample_scale); + outL.put(i, stream_buffer::sample_t(s16(m_dma_space->read_word(offset + m_play_ptr))) * sample_scale); + outR.put(i, stream_buffer::sample_t(s16(m_dma_space->read_word(offset + m_play_ptr + 2))) * sample_scale); m_play_ptr += 4; } diff --git a/src/devices/sound/ay8910.cpp b/src/devices/sound/ay8910.cpp index 0152d83620a..26e99cf1bc7 100644 --- a/src/devices/sound/ay8910.cpp +++ b/src/devices/sound/ay8910.cpp @@ -1086,10 +1086,12 @@ void ay8910_device::sound_stream_update(sound_stream &stream, std::vector>= 1; if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - outputs[chan].put(m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } else { if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } } else { if (m_feature & PSG_EXTENDED_ENVELOPE) // AY8914 Has a two bit tone_envelope field - outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } } else { if (is_expanded_mode()) - outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); + outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); else - outputs[chan].put(m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); + outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); } } } else { - outputs[0].put(mix_3D()); + outputs[0].put(sampindex, mix_3D()); } } } diff --git a/src/devices/sound/beep.cpp b/src/devices/sound/beep.cpp index a9cfd6747cc..58096c4b561 100644 --- a/src/devices/sound/beep.cpp +++ b/src/devices/sound/beep.cpp @@ -83,9 +83,9 @@ void beep_device::sound_stream_update(sound_stream &stream, std::vector> 8; } - buffer_fl.put(stream_buffer::sample_t(s16(out[0] >> 3)) * sample_scale); - buffer_fr.put(stream_buffer::sample_t(s16(out[1] >> 3)) * sample_scale); - buffer_rl.put(stream_buffer::sample_t(s16(out[2] >> 3)) * sample_scale); - buffer_rr.put(stream_buffer::sample_t(s16(out[3] >> 3)) * sample_scale); + buffer_fl.put(i, stream_buffer::sample_t(s16(out[0] >> 3)) * sample_scale); + buffer_fr.put(i, stream_buffer::sample_t(s16(out[1] >> 3)) * sample_scale); + buffer_rl.put(i, stream_buffer::sample_t(s16(out[2] >> 3)) * sample_scale); + buffer_rr.put(i, stream_buffer::sample_t(s16(out[3] >> 3)) * sample_scale); } } diff --git a/src/devices/sound/c6280.cpp b/src/devices/sound/c6280.cpp index e8de8151be6..d01dd74125a 100644 --- a/src/devices/sound/c6280.cpp +++ b/src/devices/sound/c6280.cpp @@ -55,10 +55,6 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorcontrol & 0x80) { @@ -81,7 +77,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectornoise_control & 0x1f) ^ 0x1f; - while (!outputs[0].done()) + for (int i = 0; i < outputs[0].samples(); i += 1) { s16 data = BIT(chan->noise_seed, 0) ? 0x1f : 0; chan->noise_counter--; @@ -92,18 +88,18 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectornoise_seed = (seed >> 1) | ((BIT(seed, 0) ^ BIT(seed, 1) ^ BIT(seed, 11) ^ BIT(seed, 12) ^ BIT(seed, 17)) << 17); } - outputs[0].add(stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); + outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); } } else if (chan->control & 0x40) { /* DDA mode */ - while (!outputs[0].done()) + for (int i = 0; i < outputs[0].samples(); i++) { - outputs[0].add(stream_buffer::sample_t(s16(vll * (chan->dda - 16))) * sample_scale); - outputs[1].add(stream_buffer::sample_t(s16(vlr * (chan->dda - 16))) * sample_scale); + outputs[0].add(i, stream_buffer::sample_t(s16(vll * (chan->dda - 16))) * sample_scale); + outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (chan->dda - 16))) * sample_scale); } } else @@ -116,7 +112,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorfrequency ? lfo_srcchan->frequency : 0x1000; - while (!outputs[0].done()) + for (int i = 0; i < outputs[0].samples(); i += 1) { s32 step = lfo_dstchan->frequency ? lfo_dstchan->frequency : 0x1000; if (m_lfo_control & 0x80) // reset LFO @@ -142,8 +138,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; lfo_dstchan->index = (lfo_dstchan->index + 1) & 0x1f; } - outputs[0].add(stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); + outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); } } } @@ -151,7 +147,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorfrequency ? chan->frequency : 0x1000; - while (!outputs[0].done()) + for (int i = 0; i < outputs[0].samples(); i += 1) { const s16 data = chan->waveform[chan->index]; chan->tick--; @@ -160,8 +156,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; chan->index = (chan->index + 1) & 0x1f; } - outputs[0].add(stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); - outputs[1].add(stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); + outputs[0].add(i, stream_buffer::sample_t(s16(vll * (data - 16))) * sample_scale); + outputs[1].add(i, stream_buffer::sample_t(s16(vlr * (data - 16))) * sample_scale); } } } diff --git a/src/devices/sound/cdda.cpp b/src/devices/sound/cdda.cpp index 4cecdc95ee7..ca2bd280de8 100644 --- a/src/devices/sound/cdda.cpp +++ b/src/devices/sound/cdda.cpp @@ -18,8 +18,8 @@ void cdda_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { get_audio_data(outputs[0], outputs[1]); - m_audio_volume[0] = outputs[0].get_indexed(0); - m_audio_volume[1] = outputs[1].get_indexed(0); + m_audio_volume[0] = outputs[0].get(0); + m_audio_volume[1] = outputs[1].get(0); } //------------------------------------------------- @@ -165,7 +165,7 @@ void cdda_device::get_audio_data(write_stream_view &bufL, write_stream_view &buf int16_t *audio_cache = (int16_t *) m_audio_cache.get(); constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; - while (!bufL.done()) + for (int sampindex = 0; sampindex < bufL.samples(); ) { /* if no file, audio not playing, audio paused, or out of disc data, just zero fill */ @@ -177,12 +177,12 @@ void cdda_device::get_audio_data(write_stream_view &bufL, write_stream_view &buf m_audio_ended_normally = true; } - bufL.fill(0); - bufR.fill(0); + bufL.fill(0, sampindex); + bufR.fill(0, sampindex); return; } - int samples = bufL.remaining(); + int samples = bufL.samples() - sampindex; if (samples > m_audio_samples) { samples = m_audio_samples; @@ -191,10 +191,11 @@ void cdda_device::get_audio_data(write_stream_view &bufL, write_stream_view &buf for (i = 0; i < samples; i++) { /* CD-DA data on the disc is big-endian */ - bufL.put(stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; - bufR.put(stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; + bufL.put(sampindex + i, stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; + bufR.put(sampindex + i, stream_buffer::sample_t(s16(big_endianize_int16( audio_cache[ m_audio_bptr ] ))) * sample_scale); m_audio_bptr++; } + sampindex += samples; m_audio_samples -= samples; if (m_audio_samples == 0) diff --git a/src/devices/sound/cdp1863.cpp b/src/devices/sound/cdp1863.cpp index fd84ff0cd75..984a306b28a 100644 --- a/src/devices/sound/cdp1863.cpp +++ b/src/devices/sound/cdp1863.cpp @@ -114,9 +114,9 @@ void cdp1863_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } }; @@ -107,20 +107,20 @@ protected: { if (this->m_code & (1 << (bits - 1))) { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ ~(~0U << bits)); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } else { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } } @@ -134,12 +134,12 @@ protected: virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } }; @@ -154,20 +154,20 @@ protected: { if (this->m_code & (1 << (bits - 1))) { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } else { - while (!outputs[0].done()) + for (int samp = 0; samp < outputs[0].samples(); samp++) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0].put(vout); + outputs[0].put(samp, vout); } } } diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index 1c82ab6691e..f26ea891879 100644 --- a/src/devices/sound/dave.cpp +++ b/src/devices/sound/dave.cpp @@ -206,7 +206,7 @@ void dave_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { auto &sout = outputs[0]; + int cpos = 0; constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; - while (!sout.done()) { + while(cpos != sout.samples()) { if(m_zero_count == 0 && m_dac_index == 128) digitalker_step(); if(m_zero_count) { - m_zero_count -= sout.fill(0, m_zero_count); + int n = sout.samples() - cpos; + if(n > m_zero_count) + n = m_zero_count; + sout.fill(0, cpos, n); + cpos += n; + m_zero_count -= n; } else if(m_dac_index != 128) { - while(!sout.done() && m_dac_index != 128) { + while(cpos != sout.samples() && m_dac_index != 128) { stream_buffer::sample_t v = stream_buffer::sample_t(m_dac[m_dac_index]) * sample_scale; int pp = m_pitch_pos; - while(!sout.done() && pp != m_pitch) { - sout.put(v); + while(cpos != sout.samples() && pp != m_pitch) { + sout.put(cpos++, v); pp++; } if(pp == m_pitch) { @@ -571,7 +577,7 @@ void digitalker_device::sound_stream_update(sound_stream &stream, std::vectorput(val * (1.0 / 32768.0)); + m_outview->put(m_outview_sample++, val * (1.0 / 32768.0)); } virtual int max_output(void) override { return 0; } - virtual void set_output_ptr(write_stream_view &view) override { m_outview = &view; m_outview->reset(); } + virtual void set_output_ptr(write_stream_view &view) override { m_outview = &view; m_outview_sample = 0; } private: write_stream_view *m_outview; + u32 m_outview_sample; }; DISCRETE_CLASS(dso_csvlog, 0, @@ -231,6 +232,7 @@ public: //protected: uint32_t m_stream_in_number; read_stream_view const *m_inview; /* current in ptr for stream */ + uint32_t m_inview_sample; private: void stream_generate(sound_stream &stream, std::vector const &inputs, std::vector &outputs); diff --git a/src/devices/sound/disc_inp.hxx b/src/devices/sound/disc_inp.hxx index 729227dea24..1c6c9a6dba5 100644 --- a/src/devices/sound/disc_inp.hxx +++ b/src/devices/sound/disc_inp.hxx @@ -250,7 +250,10 @@ DISCRETE_STEP(dss_input_stream) { /* the context pointer is set to point to the current input stream data in discrete_stream_update */ if (EXPECTED(m_inview)) - set_output(0, m_inview->get() * 32768.0 * m_gain + m_offset); + { + set_output(0, m_inview->get(m_inview_sample) * 32768.0 * m_gain + m_offset); + m_inview_sample++; + } else set_output(0, 0); } diff --git a/src/devices/sound/discrete.cpp b/src/devices/sound/discrete.cpp index 9e3b4f60d0c..7d6a84a4fc7 100644 --- a/src/devices/sound/discrete.cpp +++ b/src/devices/sound/discrete.cpp @@ -1079,6 +1079,7 @@ void discrete_sound_device::sound_stream_update(sound_stream &stream, std::vecto for_each(discrete_dss_input_stream_node **, node, &m_input_stream_list) { (*node)->m_inview = &inputs[(*node)->m_stream_in_number]; + (*node)->m_inview_sample = 0; } /* just process it */ diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp index 4a271009fa1..2ed7dc134a2 100644 --- a/src/devices/sound/k054539.cpp +++ b/src/devices/sound/k054539.cpp @@ -125,7 +125,7 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vectorvolume[0]; int rv = voice->volume[1]; @@ -699,13 +699,13 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectornoise_state) { - lmix.add(stream_buffer::sample_t(l_noise_data) * sample_scale); - rmix.add(stream_buffer::sample_t(r_noise_data) * sample_scale); + lmix.add(i, stream_buffer::sample_t(l_noise_data) * sample_scale); + rmix.add(i, stream_buffer::sample_t(r_noise_data) * sample_scale); } else { - lmix.add(stream_buffer::sample_t(-l_noise_data) * sample_scale); - rmix.add(stream_buffer::sample_t(-r_noise_data) * sample_scale); + lmix.add(i, stream_buffer::sample_t(-l_noise_data) * sample_scale); + rmix.add(i, stream_buffer::sample_t(-r_noise_data) * sample_scale); } if (hold) @@ -779,7 +779,6 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectorvolume[0]; if (voice->noise_sw) { @@ -792,16 +791,17 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectornoise_counter; int16_t noise_data = OUTPUT_LEVEL(0x07 * (v >> 1)); + int i; /* add our contribution */ - while (!buffer.done()) + for (i = 0; i < buffer.samples(); i++) { int cnt; if (voice->noise_state) - buffer.add(stream_buffer::sample_t(noise_data) * sample_scale); + buffer.add(i, stream_buffer::sample_t(noise_data) * sample_scale); else - buffer.add(stream_buffer::sample_t(-noise_data) * sample_scale); + buffer.add(i, stream_buffer::sample_t(-noise_data) * sample_scale); if (hold) { diff --git a/src/devices/sound/okim6295.cpp b/src/devices/sound/okim6295.cpp index 29461f7f37c..c3aee26e52e 100644 --- a/src/devices/sound/okim6295.cpp +++ b/src/devices/sound/okim6295.cpp @@ -182,7 +182,7 @@ void okim6295_device::sound_stream_update(sound_stream &stream, std::vector= m_count) diff --git a/src/devices/sound/pokey.cpp b/src/devices/sound/pokey.cpp index f405cd01255..f749afad2ae 100644 --- a/src/devices/sound/pokey.cpp +++ b/src/devices/sound/pokey.cpp @@ -702,11 +702,11 @@ void pokey_device::sound_stream_update(sound_stream &stream, std::vectordone()) + for (int sampindex = 0; sampindex < lbuffer->samples(); sampindex++) { // clock chip once if (m_current_clock > 0) // not ready for new divided clock @@ -445,9 +445,9 @@ void sn76496_base_device::sound_stream_update(sound_stream &stream, std::vector< if (m_negate) { out = -out; out2 = -out2; } - lbuffer->put(stream_buffer::sample_t(out) * sample_scale); + lbuffer->put(sampindex, stream_buffer::sample_t(out) * sample_scale); if (m_stereo) - rbuffer->put(stream_buffer::sample_t(out2) * sample_scale); + rbuffer->put(sampindex, stream_buffer::sample_t(out2) * sample_scale); } } diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index da836cde53c..e18143a29b0 100644 --- a/src/devices/sound/sp0250.cpp +++ b/src/devices/sound/sp0250.cpp @@ -259,12 +259,12 @@ void sp0250_device::sound_stream_update(sound_stream &stream, std::vector= PWM_CLOCKS) @@ -291,8 +291,14 @@ void sp0250_device::sound_stream_update(sound_stream &stream, std::vector output.samples() - sampindex) + remaining = output.samples() - sampindex; + m_pwm_index += remaining; + // fill the output - m_pwm_index += outputs[0].fill(value, remaining); + while (remaining-- != 0) + outputs[0].put(sampindex++, value); } } } diff --git a/src/devices/sound/tms3615.cpp b/src/devices/sound/tms3615.cpp index 53c1df7d52a..e59c64eab04 100644 --- a/src/devices/sound/tms3615.cpp +++ b/src/devices/sound/tms3615.cpp @@ -57,7 +57,7 @@ void tms3615_device::sound_stream_update(sound_stream &stream, std::vector MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.remaining(); + int length = (output.samples() > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.samples(); /* generate the samples and copy to the target buffer */ process(sample_data, length); for (int index = 0; index < length; index++) - output.put(sample_data[index] * sample_scale); + output.put(sampindex++, sample_data[index] * sample_scale); } } diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index 1da8fd7c11c..fc07c0f95ab 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -738,11 +738,12 @@ void upd775x_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - while (!outputs[0].done()) { + for(int i=0; i> 7) * 0.5; - while (!outputs[0].done()) + for (int i = 0; i < outputs[0].samples(); i++) { // clock duty cycle m_sh_duty = (m_sh_duty + 1) & 0xf; - outputs[0].put((m_sh_duty < volume) ? sample_on : 0.0); + outputs[0].put(i, (m_sh_duty < volume) ? sample_on : 0.0); } } diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp index 1e7be43b32f..29d8b4e13b5 100644 --- a/src/emu/disound.cpp +++ b/src/emu/disound.cpp @@ -512,9 +512,9 @@ void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vect int outputnum = m_outputmap[inputnum]; auto &output = outputs[outputnum]; if (!m_output_clear[outputnum]) - output.copy_indexed(0, input); + output.copy(input); else - output.add_indexed(0, input); + output.add(input); m_output_clear[outputnum] = true; } @@ -522,5 +522,5 @@ void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vect // clear anything unused for (int outputnum = 0; outputnum < m_outputs; outputnum++) if (!m_output_clear[outputnum]) - outputs[outputnum].fill_indexed(0, 0); + outputs[outputnum].fill(0); } diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index d2c968ca370..a00546f7af3 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -208,7 +208,7 @@ void stream_buffer::flush_wav() // convert and fill for (int sampindex = 0; sampindex < cursamples; sampindex++) - buffer[sampindex] = s16(view.get_indexed(samplebase + sampindex) * 32768.0); + buffer[sampindex] = s16(view.get(samplebase + sampindex) * 32768.0); // write to the WAV wav_add_data_16(m_wav_file, buffer, cursamples); @@ -743,7 +743,7 @@ read_stream_view sound_stream::update_view(attotime start, attotime end, u32 out #if (SOUND_DEBUG) // clear each output view to NANs before we call the callback for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) - m_output_view[outindex].fill_indexed(0, NAN); + m_output_view[outindex].fill(NAN); #endif // if we have an extended callback, that's all we need @@ -753,7 +753,7 @@ read_stream_view sound_stream::update_view(attotime start, attotime end, u32 out // make sure everything was overwritten for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) for (int sampindex = 0; sampindex < m_output_view[outindex].samples(); sampindex++) - m_output_view[outindex].get_indexed(sampindex); + m_output_view[outindex].get(sampindex); for (unsigned int outindex = 0; outindex < m_output.size(); outindex++) m_output[outindex].m_buffer.flush_wav(); @@ -934,7 +934,7 @@ void sound_stream::stream_update_legacy(sound_stream &stream, std::vector output_start && !output.done()) + while (latency > output_start && dstindex < numsamples) { - output.put(0); + output.put(dstindex++, 0); output_start += output.sample_period(); } - if (output.done()) + if (dstindex >= numsamples) return; // create a rebased input buffer around the adjusted start time @@ -1053,14 +1055,15 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std: sound_assert(srcpos <= 1.0f); // input is undersampled: point sample except where our sample period covers a boundary + s32 srcindex = 0; if (step < 1.0) { - stream_buffer::sample_t cursample = rebased.get(); - while (!output.done()) + stream_buffer::sample_t cursample = rebased.get(srcindex++); + for ( ; dstindex < numsamples; dstindex++) { // if still within the current sample, just replicate if (srcpos <= 1.0) - output.put(cursample); + output.put(dstindex, cursample); // if crossing a sample boundary, blend with the neighbor else @@ -1068,18 +1071,19 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std: srcpos -= 1.0; sound_assert(srcpos <= step + 1e-5); stream_buffer::sample_t prevsample = cursample; - cursample = rebased.get(); - output.put(stepinv * (prevsample * (step - srcpos) + srcpos * cursample)); + cursample = rebased.get(srcindex++); + output.put(dstindex, stepinv * (prevsample * (step - srcpos) + srcpos * cursample)); } srcpos += step; } + sound_assert(srcindex <= rebased.samples()); } // input is oversampled: sum the energy else { - float cursample = rebased.get(); - while (!output.done()) + float cursample = rebased.get(srcindex++); + for ( ; dstindex < numsamples; dstindex++) { // compute the partial first sample and advance stream_buffer::sample_t scale = 1.0 - srcpos; @@ -1089,17 +1093,18 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std: stream_buffer::sample_t remaining = step - scale; while (remaining >= 1.0) { - sample += rebased.get(); + sample += rebased.get(srcindex++); remaining -= 1.0; } // add in the final partial sample - cursample = rebased.get(); + cursample = rebased.get(srcindex++); sample += cursample * remaining; - output.put(sample * stepinv); + output.put(dstindex, sample * stepinv); // our position is now the remainder srcpos = remaining; + sound_assert(srcindex <= rebased.samples()); } } } diff --git a/src/emu/sound.h b/src/emu/sound.h index d7a833c749d..5ccc78c015b 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -239,7 +239,6 @@ public: m_buffer(buffer), m_end(end), m_start(start), - m_offset(0), m_gain(gain) { normalize_start_end(); @@ -276,7 +275,6 @@ public: m_start = rhs.m_start; m_end = rhs.m_end; m_gain = rhs.m_gain; - m_offset = 0; normalize_start_end(); return *this; } @@ -294,18 +292,6 @@ public: // return the number of samples represented by the buffer u32 samples() const { return m_end - m_start; } - // return the current offset within the buffer - s32 offset() const { return m_offset; } - - // return the number of samples remaining from the current offset - s32 remaining() const { return samples() - m_offset; } - - // (re)set the current offset within the buffer - read_stream_view const &reset(s32 offset = 0) const { m_offset = offset; return *this; } - - // return true if we've consumed all the samples in the view - bool done() const { return m_offset >= samples(); } - // return the starting or ending time of the buffer attotime start_time() const { return m_buffer->index_time(m_start); } attotime end_time() const { return m_buffer->index_time(m_end); } @@ -317,7 +303,7 @@ public: read_stream_view &apply_gain(float gain) { m_gain *= gain; return *this; } // safely fetch a gain-scaled sample from the buffer - sample_t get_indexed(s32 index) const + sample_t get(s32 index) const { sound_assert(u32(index) < samples()); index += m_start; @@ -328,7 +314,7 @@ public: // safely fetch a raw sample from the buffer; if you use this, you need to // apply the gain yourself for correctness - sample_t getraw_indexed(s32 index) const + sample_t getraw(s32 index) const { sound_assert(u32(index) < samples()); index += m_start; @@ -337,10 +323,6 @@ public: return m_buffer->get(index); } - // non-indexed versions of the above that use the implied offset - sample_t get() const { sound_assert(m_offset < samples()); return get_indexed(m_offset++); } - sample_t getraw() const { sound_assert(m_offset < samples()); return getraw_indexed(m_offset++); } - protected: // normalize start/end void normalize_start_end() @@ -356,7 +338,6 @@ protected: stream_buffer *m_buffer; // pointer to the stream buffer we're viewing s32 m_end; // ending sample index (always >= start) s32 m_start; // starting sample index - mutable s32 m_offset; // current read/write offset sample_t m_gain; // overall gain factor }; @@ -383,11 +364,8 @@ public: { } - // (re)set the current offset within the buffer - write_stream_view &reset(s32 offset = 0) { m_offset = offset; return *this; } - // safely write a gain-applied sample to the buffer - void put_indexed(s32 index, sample_t sample) + void put(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); index += m_start; @@ -397,7 +375,7 @@ public: } // safely add a gain-applied sample to the buffer - void add_indexed(s32 index, sample_t sample) + void add(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); index += m_start; @@ -407,9 +385,9 @@ public: } // fill part of the view with the given value - s32 fill_indexed(s32 start, sample_t value, s32 count = -1) + void fill(sample_t value, s32 start, s32 count) { - if (count < 0 || start + count > samples()) + if (start + count > samples()) count = samples() - start; u32 index = start + m_start; for (s32 sampindex = 0; sampindex < count; sampindex++) @@ -417,51 +395,39 @@ public: m_buffer->put(index, value); index = m_buffer->next_index(index); } - return count; } + void fill(sample_t value, s32 start) { fill(value, start, samples() - start); } + void fill(sample_t value) { fill(value, 0, samples()); } // copy data from another view - s32 copy_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1) + void copy(read_stream_view const &src, s32 start, s32 count) { - if (count < 0 || start + count > samples()) + if (start + count > samples()) count = samples() - start; - if (srcstart < 0) - srcstart = start; - if (srcstart + count > src.samples()) - count = src.samples() - srcstart; u32 index = start + m_start; for (s32 sampindex = 0; sampindex < count; sampindex++) { - m_buffer->put(index, src.get_indexed(srcstart + sampindex)); + m_buffer->put(index, src.get(start + sampindex)); index = m_buffer->next_index(index); } - return count; } + void copy(read_stream_view const &src, s32 start) { copy(src, start, samples() - start); } + void copy(read_stream_view const &src) { copy(src, 0, samples()); } // add data from another view to our current values - s32 add_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1) + void add(read_stream_view const &src, s32 start, s32 count) { - if (count < 0 || start + count > samples()) + if (start + count > samples()) count = samples() - start; - if (srcstart < 0) - srcstart = start; - if (srcstart + count > src.samples()) - count = src.samples() - srcstart; u32 index = start + m_start; for (s32 sampindex = 0; sampindex < count; sampindex++) { - m_buffer->put(index, m_buffer->get(index) + src.get_indexed(start + sampindex)); + m_buffer->put(index, m_buffer->get(index) + src.get(start + sampindex)); index = m_buffer->next_index(index); } - return count; } - - // non-indexed versions of the above that use the implied offset - void put(sample_t sample) { sound_assert(m_offset < samples()); put_indexed(m_offset++, sample); } - void add(sample_t sample) { sound_assert(m_offset < samples()); add_indexed(m_offset++, sample); } - s32 fill(sample_t value, s32 count = -1) { m_offset += count = fill_indexed(m_offset, value, count); return count; } - s32 copy(read_stream_view const &src, s32 count = -1) { count = copy_indexed(m_offset, src, m_offset, count); m_offset += count; src.reset(src.offset() + count); return count; } - s32 add(read_stream_view const &src, s32 count = -1) { count = add_indexed(m_offset, src, m_offset, count); m_offset += count; src.reset(src.offset() + count); return count; } + void add(read_stream_view const &src, s32 start) { add(src, start, samples() - start); } + void add(read_stream_view const &src) { add(src, 0, samples()); } }; diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp index b487b5d8aea..3cbb14355a4 100644 --- a/src/emu/speaker.cpp +++ b/src/emu/speaker.cpp @@ -74,9 +74,9 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample if (machine().options().speaker_report() != 0) { u32 samples_per_bucket = m_mixer_stream->sample_rate() / BUCKETS_PER_SECOND; - while (!view.done()) + for (int sample = 0; sample < expected_samples; sample++) { - m_current_max = std::max(m_current_max, fabsf(view.get())); + m_current_max = std::max(m_current_max, fabsf(view.get(sample))); if (++m_samples_this_bucket >= samples_per_bucket) { m_max_sample.push_back(m_current_max); @@ -84,7 +84,6 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample m_samples_this_bucket = 0; } } - view.reset(); } // mix if sound is enabled @@ -94,7 +93,7 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample if (m_x == 0) for (int sample = 0; sample < expected_samples; sample++) { - stream_buffer::sample_t cursample = view.get(); + stream_buffer::sample_t cursample = view.get(sample); leftmix[sample] += cursample; rightmix[sample] += cursample; } @@ -102,12 +101,12 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample // if the speaker is to the left, send only to the left else if (m_x < 0) for (int sample = 0; sample < expected_samples; sample++) - leftmix[sample] += view.get(); + leftmix[sample] += view.get(sample); // if the speaker is to the right, send only to the right else for (int sample = 0; sample < expected_samples; sample++) - rightmix[sample] += view.get(); + rightmix[sample] += view.get(sample); } } diff --git a/src/mame/audio/sente6vb.cpp b/src/mame/audio/sente6vb.cpp index 311f8929c17..22c9721a18a 100644 --- a/src/mame/audio/sente6vb.cpp +++ b/src/mame/audio/sente6vb.cpp @@ -98,9 +98,9 @@ protected: // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - while (!outputs[0].done()) + for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++) { - outputs[0].put(BIT(m_noise_state, 0) ? 1.0 : 0.0); + outputs[0].put(sampindex, BIT(m_noise_state, 0) ? 1.0 : 0.0); m_noise_state = (m_noise_state >> 1) | ((BIT(m_noise_state, 0) ^ BIT(m_noise_state, 3)) << 16); } } -- cgit v1.2.3