namco_163/nes_apu/nile: Update to new stream callbacks

This commit is contained in:
Aaron Giles 2020-09-20 03:09:57 -07:00
parent 0c07945fe9
commit cf2f443128
6 changed files with 32 additions and 29 deletions

View File

@ -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) 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_t(mconfig, NAMCO_163, tag, owner, clock)
, device_sound_interface(mconfig, *this) , device_sound_interface(mconfig, *this)
, m_ram(nullptr) , m_ram(0x80)
, m_reg_addr(0x78) , m_reg_addr(0x78)
, m_addr(0) , m_addr(0)
, m_inc(false) , 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() void namco_163_sound_device::device_start()
{ {
m_ram = make_unique_clear<u8[]>(0x80); m_stream = stream_alloc(0, 1, clock() / 15);
m_stream = stream_alloc_legacy(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_reg_addr));
save_item(NAME(m_addr)); save_item(NAME(m_addr));
save_item(NAME(m_inc)); 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
std::fill_n(&outputs[0][0], samples, 0);
if (m_disable) if (m_disable)
{
outputs[0].fill(0);
return; return;
}
// Slightly noisy but closer to real hardware behavior // 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]; 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]; 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); 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);
} }
} }

View File

@ -24,7 +24,7 @@ protected:
virtual void device_clock_changed() override; virtual void device_clock_changed() override;
// global sound parameters // global sound parameters
std::unique_ptr<u8[]> m_ram; std::vector<u8> m_ram;
u8 m_reg_addr; u8 m_reg_addr;
u8 m_addr; u8 m_addr;
bool m_inc; bool m_inc;
@ -34,7 +34,7 @@ protected:
// internals // internals
inline s8 get_sample(u16 addr); 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
}; };
DECLARE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device) DECLARE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device)

View File

@ -134,7 +134,7 @@ void nesapu_device::calculate_rates()
if (m_stream != nullptr) if (m_stream != nullptr)
m_stream->set_sample_rate(rate); m_stream->set_sample_rate(rate);
else 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
int accum; int accum;
stream_sample_t *output = outputs[0]; auto &output = outputs[0];
memset( output, 0, samples*sizeof(*output) );
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[0]);
accum += apu_square(&m_APU.squ[1]); 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) else if (accum < -128)
accum = -128; accum = -128;
*output++=accum<<8; output.put(sampindex, stream_buffer::sample_t(accum) * sample_scale);
} }
} }

View File

@ -60,7 +60,7 @@ protected:
virtual void device_start() override; virtual void device_start() override;
// sound stream update overrides // 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;
private: private:
/* GLOBAL CONSTANTS */ /* GLOBAL CONSTANTS */

View File

@ -68,7 +68,7 @@ nile_device::nile_device(const machine_config &mconfig, const char *tag, device_
void nile_device::device_start() 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_sound_regs));
save_item(NAME(m_vpos)); save_item(NAME(m_vpos));
save_item(NAME(m_frac)); 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 // 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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{ {
uint8_t *sound_ram = &m_sound_ram[0]; uint8_t *sound_ram = &m_sound_ram[0];
int v, i, snum; int v, i, snum;
uint16_t *slot; uint16_t *slot;
int32_t mix[48000*2]; int32_t mix[4800*2];
int32_t *mixp; int32_t *mixp;
int16_t sample; int16_t sample;
int sptr, eptr, freq, lsptr, leptr; int sptr, eptr, freq, lsptr, leptr;
lsptr=leptr=0; 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++) 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]; lsptr = slot[NILE_REG_LSPTR_HI]<<16 | slot[NILE_REG_LSPTR_LO];
leptr = slot[NILE_REG_LEPTR_HI]<<16 | slot[NILE_REG_LEPTR_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; 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]; 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[0].put(i, stream_buffer::sample_t(*mixp++) * sample_scale);
outputs[1][i] = (*mixp++)>>4; outputs[1].put(i, stream_buffer::sample_t(*mixp++) * sample_scale);
} }
} }

View File

@ -23,7 +23,7 @@ protected:
virtual void device_start() override; virtual void device_start() override;
// sound stream update overrides // 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;
public: public:
void nile_snd_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); void nile_snd_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);