diff options
author | 2020-09-18 09:05:49 -0700 | |
---|---|---|
committer | 2020-09-18 09:05:49 -0700 | |
commit | 37e3cd01c2650877911cd376449c6d0b9c715a1a (patch) | |
tree | d577bd6926980c61d7457e0c975b9b6bb8478664 | |
parent | ed6900b990e6f7514af0162d5c5b0fb463b28737 (diff) |
i5000/ics2115/iopspu/iremga20: update to new stream callbacks
-rw-r--r-- | src/devices/sound/i5000.cpp | 11 | ||||
-rw-r--r-- | src/devices/sound/i5000.h | 2 | ||||
-rw-r--r-- | src/devices/sound/ics2115.cpp | 30 | ||||
-rw-r--r-- | src/devices/sound/ics2115.h | 6 | ||||
-rw-r--r-- | src/devices/sound/iopspu.cpp | 2 | ||||
-rw-r--r-- | src/devices/sound/iopspu.h | 2 | ||||
-rw-r--r-- | src/devices/sound/iremga20.cpp | 23 | ||||
-rw-r--r-- | src/devices/sound/iremga20.h | 2 |
8 files changed, 36 insertions, 42 deletions
diff --git a/src/devices/sound/i5000.cpp b/src/devices/sound/i5000.cpp index 747d5e96e19..033da94049d 100644 --- a/src/devices/sound/i5000.cpp +++ b/src/devices/sound/i5000.cpp @@ -44,7 +44,7 @@ void i5000snd_device::device_start() m_lut_volume[0xff] = 0; // create the stream - m_stream = stream_alloc_legacy(0, 2, clock() / 0x400); + m_stream = stream_alloc(0, 2, clock() / 0x400); m_rom_base = (uint16_t *)device().machine().root_device().memregion(":i5000snd")->base(); m_rom_mask = device().machine().root_device().memregion(":i5000snd")->bytes() / 2 - 1; @@ -114,9 +114,10 @@ bool i5000snd_device::read_sample(int ch) } -void i5000snd_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void i5000snd_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - for (int i = 0; i < samples; i++) + constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 16.0); + for (int i = 0; i < outputs[0].samples(); i++) { int32_t mix_l = 0; int32_t mix_r = 0; @@ -157,8 +158,8 @@ void i5000snd_device::sound_stream_update_legacy(sound_stream &stream, stream_sa mix_l += m_channels[ch].output_l; } - outputs[0][i] = mix_r / 16; - outputs[1][i] = mix_l / 16; + outputs[0].put(i, stream_buffer::sample_t(mix_r) * sample_scale); + outputs[1].put(i, stream_buffer::sample_t(mix_l) * sample_scale); } } diff --git a/src/devices/sound/i5000.h b/src/devices/sound/i5000.h index 0bb994ebdb6..abd84f5ac43 100644 --- a/src/devices/sound/i5000.h +++ b/src/devices/sound/i5000.h @@ -33,7 +33,7 @@ protected: virtual void device_start() override; virtual void device_reset() override; - 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; sound_stream *m_stream; diff --git a/src/devices/sound/ics2115.cpp b/src/devices/sound/ics2115.cpp index fa570814019..98c5916c253 100644 --- a/src/devices/sound/ics2115.cpp +++ b/src/devices/sound/ics2115.cpp @@ -63,7 +63,7 @@ void ics2115_device::device_start() m_timer[0].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_0),this), this); m_timer[1].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_1),this), this); - m_stream = stream_alloc_legacy(0, 2, clock() / (32 * 32)); + m_stream = stream_alloc(0, 2, clock() / (32 * 32)); m_irq_cb.resolve_safe(); @@ -316,7 +316,7 @@ int ics2115_device::ics2115_voice::update_oscillator() } //TODO: proper interpolation for 8-bit samples (looping) -stream_sample_t ics2115_device::get_sample(ics2115_voice& voice) +s32 ics2115_device::get_sample(ics2115_voice& voice) { const u32 curaddr = voice.osc.acc >> 12; u32 nextaddr; @@ -385,13 +385,14 @@ void ics2115_device::ics2115_voice::update_ramp() } } -int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t * const outputs[2], int samples) +int ics2115_device::fill_output(ics2115_voice& voice, std::vector<write_stream_view> &outputs) { bool irq_invalid = false; const u16 fine = 1 << (3*(voice.vol.incr >> 6)); voice.vol.add = (voice.vol.incr & 0x3f)<< (10 - fine); - for (int i = 0; i < samples; i++) + constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * (1 << (5 + volume_bits))); + for (int i = 0; i < outputs[0].samples(); i++) { const u32 volacc = (voice.vol.acc >> 10) & 0xffff; const u32 volume = (m_volume[volacc >> 4] * voice.state.ramp) >> 6; @@ -403,15 +404,15 @@ int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t * const ou //final output, even if they are not running. This means that whatever data value //that the voice is pointing at is contributing to the summation. //(austere note: this will of course fix some of the glitches due to multiple transition) - stream_sample_t sample = get_sample(voice); + s32 sample = get_sample(voice); //15-bit volume + (5-bit worth of 32 channel sum) + 16-bit samples = 4-bit extra if (!m_vmode || voice.playing()) { /*if (voice.playing()) {*/ - outputs[0][i] += (sample * vleft) >> (5 + volume_bits - 16); - outputs[1][i] += (sample * vright) >> (5 + volume_bits - 16); + outputs[0].add(i, stream_buffer::sample_t(sample * vleft) * sample_scale); + outputs[1].add(i, stream_buffer::sample_t(sample * vright) * sample_scale); } voice.update_ramp(); @@ -426,10 +427,10 @@ int ics2115_device::fill_output(ics2115_voice& voice, stream_sample_t * const ou return irq_invalid; } -void ics2115_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void ics2115_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - memset(outputs[0], 0, samples * sizeof(stream_sample_t)); - memset(outputs[1], 0, samples * sizeof(stream_sample_t)); + outputs[0].fill(0); + outputs[1].fill(0); bool irq_invalid = false; for (int osc = 0; osc <= m_active_osc; osc++) @@ -447,7 +448,7 @@ void ics2115_device::sound_stream_update_legacy(sound_stream &stream, stream_sam logerror("[%06x=%04x]", curaddr, (s16)sample); #endif */ - if (fill_output(voice, outputs, samples)) + if (fill_output(voice, outputs)) irq_invalid = true; #ifdef ICS2115_DEBUG @@ -479,13 +480,6 @@ void ics2115_device::sound_stream_update_legacy(sound_stream &stream, stream_sam logerror("|"); #endif - //rescale - for (int i = 0; i < samples; i++) - { - outputs[0][i] >>= 16; - outputs[1][i] >>= 16; - } - if (irq_invalid) recalc_irq(); diff --git a/src/devices/sound/ics2115.h b/src/devices/sound/ics2115.h index 777ee8eabf4..5dd18fcf4ed 100644 --- a/src/devices/sound/ics2115.h +++ b/src/devices/sound/ics2115.h @@ -39,7 +39,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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; @@ -119,8 +119,8 @@ private: void recalc_irq(); // stream helper functions - int fill_output(ics2115_voice& voice, stream_sample_t * const outputs[2], int samples); - stream_sample_t get_sample(ics2115_voice& voice); + int fill_output(ics2115_voice& voice, std::vector<write_stream_view> &outputs); + s32 get_sample(ics2115_voice& voice); u8 read_sample(ics2115_voice& voice, u32 addr) { return m_cache.read_byte((voice.osc.saddr << 20) | (addr & 0xfffff)); } sound_stream *m_stream; diff --git a/src/devices/sound/iopspu.cpp b/src/devices/sound/iopspu.cpp index 73399b1ef2c..d07002c9bdd 100644 --- a/src/devices/sound/iopspu.cpp +++ b/src/devices/sound/iopspu.cpp @@ -89,7 +89,7 @@ void iop_spu_device::dma_done(int bank) core.m_status &= ~STATUS_DMA_ACTIVE; } -void iop_spu_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void iop_spu_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { // TODO } diff --git a/src/devices/sound/iopspu.h b/src/devices/sound/iopspu.h index 4348e471051..bea55615c04 100644 --- a/src/devices/sound/iopspu.h +++ b/src/devices/sound/iopspu.h @@ -48,7 +48,7 @@ protected: virtual void device_reset() 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; // HACK: This timer is currently used to trigger an interrupt after the auto-DMA-transferred buffer would have been // mixed and played back, as the PS2 BIOS pulls a null return address and crashes if we trigger the auto-DMA-complete diff --git a/src/devices/sound/iremga20.cpp b/src/devices/sound/iremga20.cpp index ba49eaa75c4..3c5ac7dfe0f 100644 --- a/src/devices/sound/iremga20.cpp +++ b/src/devices/sound/iremga20.cpp @@ -73,7 +73,7 @@ iremga20_device::iremga20_device(const machine_config &mconfig, const char *tag, void iremga20_device::device_start() { - m_stream = stream_alloc_legacy(0, 2, clock()/4); + m_stream = stream_alloc(0, 2, clock()/4); save_item(NAME(m_regs)); for (int i = 0; i < 4; i++) @@ -126,19 +126,18 @@ void iremga20_device::rom_bank_updated() } //------------------------------------------------- -// sound_stream_update_legacy - handle a stream update +// sound_stream_update - handle a stream update //------------------------------------------------- -void iremga20_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void iremga20_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - stream_sample_t *outL, *outR; + auto &outL = outputs[0]; + auto &outR = outputs[1]; - outL = outputs[0]; - outR = outputs[1]; - - for (int i = 0; i < samples; i++) + stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 4.0); + for (int i = 0; i < outL.samples(); i++) { - stream_sample_t sampleout = 0; + s32 sampleout = 0; for (auto &ch : m_channel) { @@ -160,9 +159,9 @@ void iremga20_device::sound_stream_update_legacy(sound_stream &stream, stream_sa } } - sampleout >>= 2; - outL[i] = sampleout; - outR[i] = sampleout; + stream_buffer::sample_t final = stream_buffer::sample_t(sampleout) * sample_scale; + outL.put(i, final); + outR.put(i, final); } } diff --git a/src/devices/sound/iremga20.h b/src/devices/sound/iremga20.h index df9942c9ccb..ae60c563d78 100644 --- a/src/devices/sound/iremga20.h +++ b/src/devices/sound/iremga20.h @@ -36,7 +36,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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; // device_rom_interface overrides virtual void rom_bank_updated() override; |