From cf2f4431282271a26aff34243b8e1b237506801f Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sun, 20 Sep 2020 03:09:57 -0700 Subject: namco_163/nes_apu/nile: Update to new stream callbacks --- src/devices/sound/namco_163.cpp | 19 ++++++++++--------- src/devices/sound/namco_163.h | 4 ++-- src/devices/sound/nes_apu.cpp | 14 +++++++------- src/devices/sound/nes_apu.h | 2 +- src/devices/sound/nile.cpp | 20 +++++++++++--------- src/devices/sound/nile.h | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/devices/sound/namco_163.cpp b/src/devices/sound/namco_163.cpp index 153b0bfe042..d23c6e14693 100644 --- a/src/devices/sound/namco_163.cpp +++ b/src/devices/sound/namco_163.cpp @@ -17,7 +17,7 @@ DEFINE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device, "namco_163_sound", "Namco namco_163_sound_device::namco_163_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, NAMCO_163, tag, owner, clock) , device_sound_interface(mconfig, *this) - , m_ram(nullptr) + , m_ram(0x80) , m_reg_addr(0x78) , m_addr(0) , m_inc(false) @@ -33,10 +33,9 @@ namco_163_sound_device::namco_163_sound_device(const machine_config &mconfig, co void namco_163_sound_device::device_start() { - m_ram = make_unique_clear(0x80); - m_stream = stream_alloc_legacy(0, 1, clock() / 15); + m_stream = stream_alloc(0, 1, clock() / 15); - save_pointer(NAME(m_ram), 0x80); + save_item(NAME(m_ram)); save_item(NAME(m_reg_addr)); save_item(NAME(m_addr)); save_item(NAME(m_inc)); @@ -143,15 +142,17 @@ u8 namco_163_sound_device::data_r() } -void namco_163_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void namco_163_sound_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { - std::fill_n(&outputs[0][0], samples, 0); - if (m_disable) + { + outputs[0].fill(0); return; + } // Slightly noisy but closer to real hardware behavior - for (int s = 0; s < samples; s++) + constexpr stream_buffer::sample_t sample_scale = 1.0 / 128.0; + for (int s = 0; s < outputs[0].samples(); s++) { u32 phase = (m_ram[m_reg_addr + 5] << 16) | (m_ram[m_reg_addr + 3] << 8) | m_ram[m_reg_addr + 1]; const u32 freq = ((m_ram[m_reg_addr + 4] & 0x3) << 16) | (m_ram[m_reg_addr + 2] << 8) | m_ram[m_reg_addr + 0]; @@ -171,6 +172,6 @@ void namco_163_sound_device::sound_stream_update_legacy(sound_stream &stream, st { m_reg_addr = 0x78 - ((m_ram[0x7f] & 0x70) >> 1); } - outputs[0][s] = (output << 8); + outputs[0].put(s, stream_buffer::sample_t(output) * sample_scale); } } diff --git a/src/devices/sound/namco_163.h b/src/devices/sound/namco_163.h index 74d2ceacb68..a4e205b6177 100644 --- a/src/devices/sound/namco_163.h +++ b/src/devices/sound/namco_163.h @@ -24,7 +24,7 @@ protected: virtual void device_clock_changed() override; // global sound parameters - std::unique_ptr m_ram; + std::vector m_ram; u8 m_reg_addr; u8 m_addr; bool m_inc; @@ -34,7 +34,7 @@ protected: // internals inline s8 get_sample(u16 addr); - 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; }; DECLARE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device) diff --git a/src/devices/sound/nes_apu.cpp b/src/devices/sound/nes_apu.cpp index 1e79304fb3a..f5f7352bc56 100644 --- a/src/devices/sound/nes_apu.cpp +++ b/src/devices/sound/nes_apu.cpp @@ -134,7 +134,7 @@ void nesapu_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = stream_alloc_legacy(0, 1, rate); + m_stream = stream_alloc(0, 1, rate); } //------------------------------------------------- @@ -725,16 +725,16 @@ void nesapu_device::write(offs_t address, u8 value) //------------------------------------------------- -// sound_stream_update_legacy - handle a stream update +// sound_stream_update - handle a stream update //------------------------------------------------- -void nesapu_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void nesapu_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { int accum; - stream_sample_t *output = outputs[0]; - memset( output, 0, samples*sizeof(*output) ); + auto &output = outputs[0]; - while (samples--) + constexpr stream_buffer::sample_t sample_scale = 1.0 / 128.0; + for (int sampindex = 0; sampindex < output.samples(); sampindex++) { accum = apu_square(&m_APU.squ[0]); accum += apu_square(&m_APU.squ[1]); @@ -748,6 +748,6 @@ void nesapu_device::sound_stream_update_legacy(sound_stream &stream, stream_samp else if (accum < -128) accum = -128; - *output++=accum<<8; + output.put(sampindex, stream_buffer::sample_t(accum) * sample_scale); } } diff --git a/src/devices/sound/nes_apu.h b/src/devices/sound/nes_apu.h index c0e2e02244b..1539f44beab 100644 --- a/src/devices/sound/nes_apu.h +++ b/src/devices/sound/nes_apu.h @@ -60,7 +60,7 @@ protected: virtual void device_start() 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: /* GLOBAL CONSTANTS */ diff --git a/src/devices/sound/nile.cpp b/src/devices/sound/nile.cpp index aeaeeaca59c..83e6b4316a7 100644 --- a/src/devices/sound/nile.cpp +++ b/src/devices/sound/nile.cpp @@ -68,7 +68,7 @@ nile_device::nile_device(const machine_config &mconfig, const char *tag, device_ void nile_device::device_start() { - m_stream = stream_alloc_legacy(0, 2, 44100); + m_stream = stream_alloc(0, 2, 44100); save_item(NAME(m_sound_regs)); save_item(NAME(m_vpos)); save_item(NAME(m_frac)); @@ -78,23 +78,24 @@ void nile_device::device_start() //------------------------------------------------- -// sound_stream_update_legacy - handle update requests +// sound_stream_update - handle update requests // for our sound stream //------------------------------------------------- -void nile_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void nile_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { uint8_t *sound_ram = &m_sound_ram[0]; int v, i, snum; uint16_t *slot; - int32_t mix[48000*2]; + int32_t mix[4800*2]; int32_t *mixp; int16_t sample; int sptr, eptr, freq, lsptr, leptr; lsptr=leptr=0; - memset(mix, 0, sizeof(mix[0])*samples*2); + sound_assert(outputs[0].samples() * 2 < ARRAY_LENGTH(mix)); + std::fill_n(&mix[0], outputs[0].samples()*2, 0); for (v = 0; v < NILE_VOICES; v++) { @@ -111,7 +112,7 @@ void nile_device::sound_stream_update_legacy(sound_stream &stream, stream_sample lsptr = slot[NILE_REG_LSPTR_HI]<<16 | slot[NILE_REG_LSPTR_LO]; leptr = slot[NILE_REG_LEPTR_HI]<<16 | slot[NILE_REG_LEPTR_LO]; - for (snum = 0; snum < samples; snum++) + for (snum = 0; snum < outputs[0].samples(); snum++) { sample = sound_ram[sptr + m_vpos[v]]<<8; @@ -159,10 +160,11 @@ void nile_device::sound_stream_update_legacy(sound_stream &stream, stream_sample } } mixp = &mix[0]; - for (i = 0; i < samples; i++) + constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 16.0); + for (i = 0; i < outputs[0].samples(); i++) { - outputs[0][i] = (*mixp++)>>4; - outputs[1][i] = (*mixp++)>>4; + outputs[0].put(i, stream_buffer::sample_t(*mixp++) * sample_scale); + outputs[1].put(i, stream_buffer::sample_t(*mixp++) * sample_scale); } } diff --git a/src/devices/sound/nile.h b/src/devices/sound/nile.h index a87fb875c11..61add38d44e 100644 --- a/src/devices/sound/nile.h +++ b/src/devices/sound/nile.h @@ -23,7 +23,7 @@ protected: virtual void device_start() 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; public: void nile_snd_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); -- cgit v1.2.3