From 7704e21dc682475818180b1211630bc09dd2a9f2 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sun, 20 Sep 2020 21:12:33 -0700 Subject: okim6258/okim6376/okim9810/pcd3311/qs1000/qsound: update to new stream callbacks --- src/devices/sound/okim6258.cpp | 17 ++++++----------- src/devices/sound/okim6258.h | 2 +- src/devices/sound/okim6376.cpp | 25 +++++++++++-------------- src/devices/sound/okim6376.h | 2 +- src/devices/sound/okim9810.cpp | 27 +++++++++++++-------------- src/devices/sound/okim9810.h | 5 ++--- src/devices/sound/pcd3311.cpp | 2 +- src/devices/sound/pcd3311.h | 2 +- src/devices/sound/qs1000.cpp | 20 ++++++++++---------- src/devices/sound/qs1000.h | 2 +- src/devices/sound/qsound.cpp | 10 +++++----- src/devices/sound/qsound.h | 2 +- 12 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/devices/sound/okim6258.cpp b/src/devices/sound/okim6258.cpp index 5f063f4cd87..0cf7d2e327e 100644 --- a/src/devices/sound/okim6258.cpp +++ b/src/devices/sound/okim6258.cpp @@ -114,7 +114,7 @@ void okim6258_device::device_start() m_divider = dividers[m_start_divider]; - m_stream = stream_alloc_legacy(0, 1, clock()/m_divider); + m_stream = stream_alloc(0, 1, clock()/m_divider); m_signal = -2; m_step = 0; @@ -141,17 +141,15 @@ void okim6258_device::device_reset() // sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void okim6258_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - stream_sample_t *buffer = outputs[0]; - - memset(outputs[0], 0, samples * sizeof(*outputs[0])); + auto &buffer = outputs[0]; if (m_status & STATUS_PLAYING) { int nibble_shift = m_nibble_shift; - while (samples) + for (int sampindex = 0; sampindex < buffer.samples(); sampindex++) { /* Compute the new amplitude and update the current step */ int nibble = (m_data_in >> nibble_shift) & 0xf; @@ -161,8 +159,7 @@ void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sa nibble_shift ^= 4; - *buffer++ = sample; - samples--; + buffer.put_int(sampindex, sample, 32768); } /* Update the parameters */ @@ -170,9 +167,7 @@ void okim6258_device::sound_stream_update_legacy(sound_stream &stream, stream_sa } else { - /* Fill with 0 */ - while (samples--) - *buffer++ = 0; + buffer.fill(0); } } diff --git a/src/devices/sound/okim6258.h b/src/devices/sound/okim6258.h index c8397b998bf..95189f0ef3c 100644 --- a/src/devices/sound/okim6258.h +++ b/src/devices/sound/okim6258.h @@ -47,7 +47,7 @@ protected: virtual void device_clock_changed() override; // sound stream update overrides - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: void state_save_register(); diff --git a/src/devices/sound/okim6376.cpp b/src/devices/sound/okim6376.cpp index 3cb3e6fc17b..d7cd143e003 100644 --- a/src/devices/sound/okim6376.cpp +++ b/src/devices/sound/okim6376.cpp @@ -169,7 +169,7 @@ void okim6376_device::device_start() m_ch2_update = 0; m_st_pulses = 0; /* generate the name and create the stream */ - m_stream = stream_alloc_legacy(0, 1, get_sample_rate()); + m_stream = stream_alloc(0, 1, get_sample_rate()); /* initialize the voices */ for (voice = 0; voice < OKIM6376_VOICES; voice++) @@ -578,21 +578,18 @@ void okim6376_device::write(uint8_t data) } //------------------------------------------------- -// sound_stream_update_legacy - handle a stream update +// sound_stream_update - handle a stream update //------------------------------------------------- -void okim6376_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void okim6376_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - int i; - - memset(outputs[0], 0, samples * sizeof(*outputs[0])); + outputs[0].fill(0); - for (i = 0; i < OKIM6376_VOICES; i++) + for (int i = 0; i < OKIM6376_VOICES; i++) { struct ADPCMVoice *voice = &m_voice[i]; - stream_sample_t *buffer = outputs[0]; + auto &buffer = outputs[0]; int16_t sample_data[MAX_SAMPLE_CHUNK]; - int remaining = samples; if (i == 0) //channel 1 is the only channel to affect NAR { if (m_nartimer > 0) @@ -606,16 +603,16 @@ void okim6376_device::sound_stream_update_legacy(sound_stream &stream, stream_sa } /* loop while we have samples remaining */ - while (remaining) + for (int sampindex = 0; sampindex < buffer.samples(); ) { + int remaining = buffer.samples() - sampindex; int samples = (remaining > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : remaining; - int samp; generate_adpcm(voice, sample_data, samples,i); - for (samp = 0; samp < samples; samp++) - *buffer++ += sample_data[samp]; + for (int samp = 0; samp < samples; samp++) + buffer.add_int(sampindex + samp, sample_data[samp], 32768); - remaining -= samples; + sampindex += samples; } } } diff --git a/src/devices/sound/okim6376.h b/src/devices/sound/okim6376.h index 83be973fadf..34a23764e3a 100644 --- a/src/devices/sound/okim6376.h +++ b/src/devices/sound/okim6376.h @@ -32,7 +32,7 @@ protected: virtual void device_post_load() override; // sound stream update overrides - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/okim9810.cpp b/src/devices/sound/okim9810.cpp index a28cfb1af79..21e2624cd80 100644 --- a/src/devices/sound/okim9810.cpp +++ b/src/devices/sound/okim9810.cpp @@ -112,7 +112,7 @@ okim9810_device::okim9810_device(const machine_config &mconfig, const char *tag, void okim9810_device::device_start() { // create the stream - m_stream = stream_alloc_legacy(0, 2, clock()); + m_stream = stream_alloc(0, 2, clock()); // save state stuff save_item(NAME(m_TMP_register)); @@ -214,15 +214,15 @@ void okim9810_device::rom_bank_updated() // our sound stream //------------------------------------------------- -void okim9810_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void okim9810_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // reset the output streams - memset(outputs[0], 0, samples * sizeof(*outputs[0])); - memset(outputs[1], 0, samples * sizeof(*outputs[1])); + outputs[0].fill(0); + outputs[1].fill(0); // iterate over voices and accumulate sample data for (auto & elem : m_voice) - elem.generate_audio(*this, outputs, samples, m_global_volume, m_filter_type); + elem.generate_audio(*this, outputs, m_global_volume, m_filter_type); } @@ -613,8 +613,7 @@ okim9810_device::okim_voice::okim_voice() //------------------------------------------------- void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, - stream_sample_t * const *buffers, - int samples, + std::vector &outputs, const uint8_t global_volume, const uint8_t filter_type) { @@ -623,8 +622,8 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, return; // separate out left and right channels - stream_sample_t *outL = buffers[0]; - stream_sample_t *outR = buffers[1]; + auto &outL = outputs[0]; + auto &outR = outputs[1]; // get left and right volumes uint8_t volume_scale_left = volume_scale(global_volume, m_channel_volume, m_pan_volume_left); @@ -636,7 +635,7 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, return; // loop while we still have samples to generate - while (samples-- != 0) + for (int sampindex = 0; sampindex < outL.samples(); sampindex++) { // If interpSampleNum == 0, we are at the beginning of a new interp chunk, gather data if (m_interpSampleNum == 0) @@ -747,11 +746,11 @@ void okim9810_device::okim_voice::generate_audio(device_rom_interface &rom, // output to the stereo buffers, scaling by the volume // signal in range -2048..2047, volume in range 2..128 => signal * volume / 8 in range -32768..32767 - int32_t interpValueL = (interpValue * (int32_t)volume_scale_left) / 8; - *outL++ += interpValueL; + int32_t interpValueL = (interpValue * (int32_t)volume_scale_left); + outL.add_int(sampindex, interpValueL, 32768 * 8); - int32_t interpValueR = (interpValue * (int32_t)volume_scale_right) / 8; - *outR++ += interpValueR; + int32_t interpValueR = (interpValue * (int32_t)volume_scale_right); + outR.add_int(sampindex, interpValueR, 32768 * 8); // if the interpsample has reached its end, move on to the next sample m_interpSampleNum++; diff --git a/src/devices/sound/okim9810.h b/src/devices/sound/okim9810.h index dfb4cd047aa..32dda76fb6b 100644 --- a/src/devices/sound/okim9810.h +++ b/src/devices/sound/okim9810.h @@ -87,7 +87,7 @@ protected: virtual void device_clock_changed() override; // device_sound_interface overrides - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; @@ -98,8 +98,7 @@ protected: public: okim_voice(); void generate_audio(device_rom_interface &rom, - stream_sample_t * const *buffers, - int samples, + std::vector &buffers, const uint8_t global_volume, const uint8_t filter_type); diff --git a/src/devices/sound/pcd3311.cpp b/src/devices/sound/pcd3311.cpp index deae4f61062..67c597fb397 100644 --- a/src/devices/sound/pcd3311.cpp +++ b/src/devices/sound/pcd3311.cpp @@ -52,6 +52,6 @@ void pcd3311_device::device_start() // our sound stream //------------------------------------------------- -void pcd3311_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void pcd3311_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { } diff --git a/src/devices/sound/pcd3311.h b/src/devices/sound/pcd3311.h index f56d63633ba..5d5b8870008 100644 --- a/src/devices/sound/pcd3311.h +++ b/src/devices/sound/pcd3311.h @@ -48,7 +48,7 @@ protected: virtual void device_start() override; // internal callbacks - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; private: int m_a0; diff --git a/src/devices/sound/qs1000.cpp b/src/devices/sound/qs1000.cpp index 5674ab6db18..faf7d22a524 100644 --- a/src/devices/sound/qs1000.cpp +++ b/src/devices/sound/qs1000.cpp @@ -229,7 +229,7 @@ void qs1000_device::device_start() // The QS1000 operates at 24MHz. Creating a stream at that rate // would be overkill so we opt for a fraction of that rate which // gives reasonable results - m_stream = stream_alloc_legacy(0, 2, clock() / 32); + m_stream = stream_alloc(0, 2, clock() / 32); // Resolve CPU port callbacks m_in_p1_cb.resolve_safe(0); @@ -468,11 +468,11 @@ void qs1000_device::wave_w(offs_t offset, uint8_t data) //------------------------------------------------- // sound_stream_update_legacy - //------------------------------------------------- -void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void qs1000_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // Rset the output stream - memset(outputs[0], 0x0, samples * sizeof(*outputs[0])); - memset(outputs[1], 0x0, samples * sizeof(*outputs[1])); + outputs[0].fill(0); + outputs[1].fill(0); // Iterate over voices and accumulate sample data for (auto & chan : m_channels) @@ -485,7 +485,7 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp { if (chan.m_flags & QS1000_ADPCM) { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { if (chan.m_addr >= chan.m_loop_end) { @@ -529,13 +529,13 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK; chan.m_acc &= ((1 << 18) - 1); - outputs[0][samp] += (result * 4 * lvol * vol) >> 12; - outputs[1][samp] += (result * 4 * rvol * vol) >> 12; + outputs[0].add_int(samp, result * 4 * lvol * vol, 32768 << 12); + outputs[1].add_int(samp, result * 4 * rvol * vol, 32768 << 12); } } else { - for (int samp = 0; samp < samples; samp++) + for (int samp = 0; samp < outputs[0].samples(); samp++) { if (chan.m_addr >= chan.m_loop_end) { @@ -558,8 +558,8 @@ void qs1000_device::sound_stream_update_legacy(sound_stream &stream, stream_samp chan.m_addr = (chan.m_addr + (chan.m_acc >> 18)) & QS1000_ADDRESS_MASK; chan.m_acc &= ((1 << 18) - 1); - outputs[0][samp] += (result * lvol * vol) >> 12; - outputs[1][samp] += (result * rvol * vol) >> 12; + outputs[0].add_int(samp, result * lvol * vol, 32768 << 12); + outputs[1].add_int(samp, result * rvol * vol, 32768 << 12); } } } diff --git a/src/devices/sound/qs1000.h b/src/devices/sound/qs1000.h index 0c16e69b193..aad353962a5 100644 --- a/src/devices/sound/qs1000.h +++ b/src/devices/sound/qs1000.h @@ -73,7 +73,7 @@ protected: virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_sound_interface overrides - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; diff --git a/src/devices/sound/qsound.cpp b/src/devices/sound/qsound.cpp index 232e367f1d2..29b2661add5 100644 --- a/src/devices/sound/qsound.cpp +++ b/src/devices/sound/qsound.cpp @@ -207,7 +207,7 @@ void qsound_device::device_add_mconfig(machine_config &config) void qsound_device::device_start() { // hope we get good synchronisation between the DSP and the sound system - m_stream = stream_alloc_legacy(0, 2, clock() / 2 / 1248); + m_stream = stream_alloc(0, 2, clock() / 2 / 1248); // save DSP communication state save_item(NAME(m_rom_bank)); @@ -251,13 +251,13 @@ void qsound_device::device_reset() //------------------------------------------------- -// sound_stream_update_legacy - handle a stream update +// sound_stream_update - handle a stream update //------------------------------------------------- -void qsound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void qsound_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - std::fill_n(outputs[0], samples, m_samples[0]); - std::fill_n(outputs[1], samples, m_samples[1]); + outputs[0].fill(stream_buffer::sample_t(m_samples[0]) * (1.0 / 32768.0)); + outputs[1].fill(stream_buffer::sample_t(m_samples[1]) * (1.0 / 32768.0)); } diff --git a/src/devices/sound/qsound.h b/src/devices/sound/qsound.h index ac0a1053ffe..6a9be5dfbc2 100644 --- a/src/devices/sound/qsound.h +++ b/src/devices/sound/qsound.h @@ -32,7 +32,7 @@ protected: virtual void device_reset() override; // device_sound_interface implementation - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) override; // device_rom_interface implementation virtual void rom_bank_updated() override; -- cgit v1.2.3