From dc0ede3c90717ed25de0695c555b861f06344f18 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Thu, 17 Sep 2020 00:45:29 -0700 Subject: sound: Improved view interfaces to match usage patterns * read/write_stream_views now have an internal index * get/put/add/fill/copy now implicitly use and advance this index * new method reset() can (re)set the internal index * new method done() checks if index is past the end * new method remaining() indicates how many samples remain * get_indexed/put_indexed/etc available for random access * updated all consumers to new interfaces --- 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, 249 insertions(+), 239 deletions(-) diff --git a/src/devices/cpu/tms57002/tms57002.cpp b/src/devices/cpu/tms57002/tms57002.cpp index c2cf28f3f92..dcc6e615cea 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); - for (int s = 0; s < bufl.samples(); ++s) + while (!bufl.done()) { 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(s) * 32767.0); + m_DSP.EXTS[i] = s16(inputs[i].get() * 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(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); + 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); } } diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index e03494040ab..c7e467b617c 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 i, ch; + int 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); + samples_this_time = std::min(256 - master_count, 64 - noise_clock); /* sum the output of the tone generators */ if (m_a_state) @@ -166,7 +165,7 @@ void astrocade_io_device::sound_stream_update(sound_stream &stream, std::vector< cursample += m_reg[7] >> 4; /* scale to max and output */ - dest.fill(stream_buffer::sample_t(cursample) * sample_scale, sampindex, samples_this_time); + samples_this_time = dest.fill(stream_buffer::sample_t(cursample) * sample_scale, 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 19f734cd468..007217db048 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(i, stream_buffer::sample_t(s16(m_dma_space->read_word(offset + m_play_ptr + 2))) * sample_scale); + outL.put(stream_buffer::sample_t(s16(m_dma_space->read_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); m_play_ptr += 4; } diff --git a/src/devices/sound/ay8910.cpp b/src/devices/sound/ay8910.cpp index 26e99cf1bc7..0152d83620a 100644 --- a/src/devices/sound/ay8910.cpp +++ b/src/devices/sound/ay8910.cpp @@ -1086,12 +1086,10 @@ 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(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(m_vol_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(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(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(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(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); + outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume >> (3-tone_envelope(tone)) : 0]); else - outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); + outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? env_volume : 0]); } } else { if (is_expanded_mode()) - outputs[chan].put(sampindex, m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); + outputs[chan].put(m_env_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); else - outputs[chan].put(sampindex, m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); + outputs[chan].put(m_vol_table[chan][m_vol_enabled[chan] ? tone_volume(tone) : 0]); } } } else { - outputs[0].put(sampindex, mix_3D()); + outputs[0].put(mix_3D()); } } } diff --git a/src/devices/sound/beep.cpp b/src/devices/sound/beep.cpp index 58096c4b561..a9cfd6747cc 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(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); + 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); } } diff --git a/src/devices/sound/c6280.cpp b/src/devices/sound/c6280.cpp index d01dd74125a..e8de8151be6 100644 --- a/src/devices/sound/c6280.cpp +++ b/src/devices/sound/c6280.cpp @@ -55,6 +55,10 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorcontrol & 0x80) { @@ -77,7 +81,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectornoise_control & 0x1f) ^ 0x1f; - for (int i = 0; i < outputs[0].samples(); i += 1) + while (!outputs[0].done()) { s16 data = BIT(chan->noise_seed, 0) ? 0x1f : 0; chan->noise_counter--; @@ -88,18 +92,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(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); + 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); } } else if (chan->control & 0x40) { /* DDA mode */ - for (int i = 0; i < outputs[0].samples(); i++) + while (!outputs[0].done()) { - 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); + 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); } } else @@ -112,7 +116,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorfrequency ? lfo_srcchan->frequency : 0x1000; - for (int i = 0; i < outputs[0].samples(); i += 1) + while (!outputs[0].done()) { s32 step = lfo_dstchan->frequency ? lfo_dstchan->frequency : 0x1000; if (m_lfo_control & 0x80) // reset LFO @@ -138,8 +142,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; lfo_dstchan->index = (lfo_dstchan->index + 1) & 0x1f; } - 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); + 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); } } } @@ -147,7 +151,7 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectorfrequency ? chan->frequency : 0x1000; - for (int i = 0; i < outputs[0].samples(); i += 1) + while (!outputs[0].done()) { const s16 data = chan->waveform[chan->index]; chan->tick--; @@ -156,8 +160,8 @@ void c6280_device::sound_stream_update(sound_stream &stream, std::vectortick = step; chan->index = (chan->index + 1) & 0x1f; } - 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); + 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); } } } diff --git a/src/devices/sound/cdda.cpp b/src/devices/sound/cdda.cpp index ca2bd280de8..4cecdc95ee7 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(0); - m_audio_volume[1] = outputs[1].get(0); + m_audio_volume[0] = outputs[0].get_indexed(0); + m_audio_volume[1] = outputs[1].get_indexed(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; - for (int sampindex = 0; sampindex < bufL.samples(); ) + while (!bufL.done()) { /* 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, sampindex); - bufR.fill(0, sampindex); + bufL.fill(0); + bufR.fill(0); return; } - int samples = bufL.samples() - sampindex; + int samples = bufL.remaining(); if (samples > m_audio_samples) { samples = m_audio_samples; @@ -191,11 +191,10 @@ 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(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++; + 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++; } - 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 984a306b28a..fd84ff0cd75 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 { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - 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; + 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; stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } }; @@ -107,20 +107,20 @@ protected: { if (this->m_code & (1 << (bits - 1))) { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ ~(~0U << bits)); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } else { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } } @@ -134,12 +134,12 @@ protected: virtual void sound_stream_update_tag(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - 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; + 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; stream_buffer::sample_t const vout = vref_neg + dac_multiply(vref_pos - vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } }; @@ -154,20 +154,20 @@ protected: { if (this->m_code & (1 << (bits - 1))) { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get(samp) * this->m_gain; + double const vref_neg = inputs[DAC_VREF_NEG_INPUT].get() * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_neg, this->m_code ^ (1 << (bits - 1))); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } else { - for (int samp = 0; samp < outputs[0].samples(); samp++) + while (!outputs[0].done()) { - double const vref_pos = inputs[DAC_VREF_POS_INPUT].get(samp) * this->m_gain; + double const vref_pos = inputs[DAC_VREF_POS_INPUT].get() * this->m_gain; stream_buffer::sample_t const vout = dac_multiply(vref_pos, this->m_code); - outputs[0].put(samp, vout); + outputs[0].put(vout); } } } diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index f26ea891879..1c82ab6691e 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(cpos != sout.samples()) { + while (!sout.done()) { if(m_zero_count == 0 && m_dac_index == 128) digitalker_step(); if(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; + m_zero_count -= sout.fill(0, m_zero_count); } else if(m_dac_index != 128) { - while(cpos != sout.samples() && m_dac_index != 128) { + while(!sout.done() && 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(cpos != sout.samples() && pp != m_pitch) { - sout.put(cpos++, v); + while(!sout.done() && pp != m_pitch) { + sout.put(v); pp++; } if(pp == m_pitch) { @@ -577,7 +571,7 @@ void digitalker_device::sound_stream_update(sound_stream &stream, std::vectorput(m_outview_sample++, val * (1.0 / 32768.0)); + m_outview->put(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_sample = 0; } + virtual void set_output_ptr(write_stream_view &view) override { m_outview = &view; m_outview->reset(); } private: write_stream_view *m_outview; - u32 m_outview_sample; }; DISCRETE_CLASS(dso_csvlog, 0, @@ -232,7 +231,6 @@ 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 1c6c9a6dba5..729227dea24 100644 --- a/src/devices/sound/disc_inp.hxx +++ b/src/devices/sound/disc_inp.hxx @@ -250,10 +250,7 @@ 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(m_inview_sample) * 32768.0 * m_gain + m_offset); - m_inview_sample++; - } + set_output(0, m_inview->get() * 32768.0 * m_gain + m_offset); else set_output(0, 0); } diff --git a/src/devices/sound/discrete.cpp b/src/devices/sound/discrete.cpp index 7d6a84a4fc7..9e3b4f60d0c 100644 --- a/src/devices/sound/discrete.cpp +++ b/src/devices/sound/discrete.cpp @@ -1079,7 +1079,6 @@ 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 2ed7dc134a2..4a271009fa1 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(i, stream_buffer::sample_t(l_noise_data) * sample_scale); - rmix.add(i, stream_buffer::sample_t(r_noise_data) * sample_scale); + lmix.add(stream_buffer::sample_t(l_noise_data) * sample_scale); + rmix.add(stream_buffer::sample_t(r_noise_data) * sample_scale); } else { - lmix.add(i, stream_buffer::sample_t(-l_noise_data) * sample_scale); - rmix.add(i, stream_buffer::sample_t(-r_noise_data) * sample_scale); + lmix.add(stream_buffer::sample_t(-l_noise_data) * sample_scale); + rmix.add(stream_buffer::sample_t(-r_noise_data) * sample_scale); } if (hold) @@ -779,6 +779,7 @@ void namco_audio_device::sound_stream_update(sound_stream &stream, std::vectorvolume[0]; if (voice->noise_sw) { @@ -791,17 +792,16 @@ 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 */ - for (i = 0; i < buffer.samples(); i++) + while (!buffer.done()) { int cnt; if (voice->noise_state) - buffer.add(i, stream_buffer::sample_t(noise_data) * sample_scale); + buffer.add(stream_buffer::sample_t(noise_data) * sample_scale); else - buffer.add(i, stream_buffer::sample_t(-noise_data) * sample_scale); + buffer.add(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 c3aee26e52e..29461f7f37c 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 f749afad2ae..f405cd01255 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::vectorsamples(); sampindex++) + while (!lbuffer->done()) { // 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(sampindex, stream_buffer::sample_t(out) * sample_scale); + lbuffer->put(stream_buffer::sample_t(out) * sample_scale); if (m_stereo) - rbuffer->put(sampindex, stream_buffer::sample_t(out2) * sample_scale); + rbuffer->put(stream_buffer::sample_t(out2) * sample_scale); } } diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index e18143a29b0..da836cde53c 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,14 +291,8 @@ 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 - while (remaining-- != 0) - outputs[0].put(sampindex++, value); + m_pwm_index += outputs[0].fill(value, remaining); } } } diff --git a/src/devices/sound/tms3615.cpp b/src/devices/sound/tms3615.cpp index e59c64eab04..53c1df7d52a 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.samples(); + int length = (output.remaining() > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : output.remaining(); /* generate the samples and copy to the target buffer */ process(sample_data, length); for (int index = 0; index < length; index++) - output.put(sampindex++, sample_data[index] * sample_scale); + output.put(sample_data[index] * sample_scale); } } diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index fc07c0f95ab..1da8fd7c11c 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -738,12 +738,11 @@ void upd775x_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - for(int i=0; i> 7) * 0.5; - for (int i = 0; i < outputs[0].samples(); i++) + while (!outputs[0].done()) { // clock duty cycle m_sh_duty = (m_sh_duty + 1) & 0xf; - outputs[0].put(i, (m_sh_duty < volume) ? sample_on : 0.0); + outputs[0].put((m_sh_duty < volume) ? sample_on : 0.0); } } diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp index 29d8b4e13b5..1e7be43b32f 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(input); + output.copy_indexed(0, input); else - output.add(input); + output.add_indexed(0, 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(0); + outputs[outputnum].fill_indexed(0, 0); } diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index a00546f7af3..d2c968ca370 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(samplebase + sampindex) * 32768.0); + buffer[sampindex] = s16(view.get_indexed(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(NAN); + m_output_view[outindex].fill_indexed(0, 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(sampindex); + m_output_view[outindex].get_indexed(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 && dstindex < numsamples) + while (latency > output_start && !output.done()) { - output.put(dstindex++, 0); + output.put(0); output_start += output.sample_period(); } - if (dstindex >= numsamples) + if (output.done()) return; // create a rebased input buffer around the adjusted start time @@ -1055,15 +1053,14 @@ 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(srcindex++); - for ( ; dstindex < numsamples; dstindex++) + stream_buffer::sample_t cursample = rebased.get(); + while (!output.done()) { // if still within the current sample, just replicate if (srcpos <= 1.0) - output.put(dstindex, cursample); + output.put(cursample); // if crossing a sample boundary, blend with the neighbor else @@ -1071,19 +1068,18 @@ 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(srcindex++); - output.put(dstindex, stepinv * (prevsample * (step - srcpos) + srcpos * cursample)); + cursample = rebased.get(); + output.put(stepinv * (prevsample * (step - srcpos) + srcpos * cursample)); } srcpos += step; } - sound_assert(srcindex <= rebased.samples()); } // input is oversampled: sum the energy else { - float cursample = rebased.get(srcindex++); - for ( ; dstindex < numsamples; dstindex++) + float cursample = rebased.get(); + while (!output.done()) { // compute the partial first sample and advance stream_buffer::sample_t scale = 1.0 - srcpos; @@ -1093,18 +1089,17 @@ 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(srcindex++); + sample += rebased.get(); remaining -= 1.0; } // add in the final partial sample - cursample = rebased.get(srcindex++); + cursample = rebased.get(); sample += cursample * remaining; - output.put(dstindex, sample * stepinv); + output.put(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 5ccc78c015b..d7a833c749d 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -239,6 +239,7 @@ public: m_buffer(buffer), m_end(end), m_start(start), + m_offset(0), m_gain(gain) { normalize_start_end(); @@ -275,6 +276,7 @@ public: m_start = rhs.m_start; m_end = rhs.m_end; m_gain = rhs.m_gain; + m_offset = 0; normalize_start_end(); return *this; } @@ -292,6 +294,18 @@ 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); } @@ -303,7 +317,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(s32 index) const + sample_t get_indexed(s32 index) const { sound_assert(u32(index) < samples()); index += m_start; @@ -314,7 +328,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(s32 index) const + sample_t getraw_indexed(s32 index) const { sound_assert(u32(index) < samples()); index += m_start; @@ -323,6 +337,10 @@ 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() @@ -338,6 +356,7 @@ 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 }; @@ -364,8 +383,11 @@ 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(s32 index, sample_t sample) + void put_indexed(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); index += m_start; @@ -375,7 +397,7 @@ public: } // safely add a gain-applied sample to the buffer - void add(s32 index, sample_t sample) + void add_indexed(s32 index, sample_t sample) { sound_assert(u32(index) < samples()); index += m_start; @@ -385,9 +407,9 @@ public: } // fill part of the view with the given value - void fill(sample_t value, s32 start, s32 count) + s32 fill_indexed(s32 start, sample_t value, s32 count = -1) { - if (start + count > samples()) + if (count < 0 || start + count > samples()) count = samples() - start; u32 index = start + m_start; for (s32 sampindex = 0; sampindex < count; sampindex++) @@ -395,39 +417,51 @@ 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 - void copy(read_stream_view const &src, s32 start, s32 count) + s32 copy_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1) { - if (start + count > samples()) + if (count < 0 || 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(start + sampindex)); + m_buffer->put(index, src.get_indexed(srcstart + 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 - void add(read_stream_view const &src, s32 start, s32 count) + s32 add_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1) { - if (start + count > samples()) + if (count < 0 || 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(start + sampindex)); + m_buffer->put(index, m_buffer->get(index) + src.get_indexed(start + sampindex)); index = m_buffer->next_index(index); } + 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()); } + + // 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; } }; diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp index 3cbb14355a4..b487b5d8aea 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; - for (int sample = 0; sample < expected_samples; sample++) + while (!view.done()) { - m_current_max = std::max(m_current_max, fabsf(view.get(sample))); + m_current_max = std::max(m_current_max, fabsf(view.get())); if (++m_samples_this_bucket >= samples_per_bucket) { m_max_sample.push_back(m_current_max); @@ -84,6 +84,7 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample m_samples_this_bucket = 0; } } + view.reset(); } // mix if sound is enabled @@ -93,7 +94,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(sample); + stream_buffer::sample_t cursample = view.get(); leftmix[sample] += cursample; rightmix[sample] += cursample; } @@ -101,12 +102,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(sample); + leftmix[sample] += view.get(); // 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(sample); + rightmix[sample] += view.get(); } } diff --git a/src/mame/audio/sente6vb.cpp b/src/mame/audio/sente6vb.cpp index 22c9721a18a..311f8929c17 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 { - for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++) + while (!outputs[0].done()) { - outputs[0].put(sampindex, BIT(m_noise_state, 0) ? 1.0 : 0.0); + outputs[0].put(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