summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2020-09-19 12:01:52 -0700
committer Aaron Giles <aaron@aarongiles.com>2020-09-19 12:01:52 -0700
commit8fd87a7257668ebad32b72541cbd4360c15faac8 (patch)
treef1762c2926c9a75510b596bd387199eaf67f61ed
parentdf9d66ec85d8f71279b581e9f4046aa3dd8f75e0 (diff)
k005289/k007232/k051649/k053260/k054539/ks0164: update to new stream callbacks
-rw-r--r--src/devices/sound/k005289.cpp40
-rw-r--r--src/devices/sound/k005289.h8
-rw-r--r--src/devices/sound/k007232.cpp19
-rw-r--r--src/devices/sound/k007232.h2
-rw-r--r--src/devices/sound/k051649.cpp24
-rw-r--r--src/devices/sound/k051649.h6
-rw-r--r--src/devices/sound/k053260.cpp17
-rw-r--r--src/devices/sound/k053260.h2
-rw-r--r--src/devices/sound/k054539.cpp11
-rw-r--r--src/devices/sound/k054539.h2
-rw-r--r--src/devices/sound/ks0164.cpp11
-rw-r--r--src/devices/sound/ks0164.h2
12 files changed, 72 insertions, 72 deletions
diff --git a/src/devices/sound/k005289.cpp b/src/devices/sound/k005289.cpp
index bf07743f7d3..b80f77839d7 100644
--- a/src/devices/sound/k005289.cpp
+++ b/src/devices/sound/k005289.cpp
@@ -59,9 +59,7 @@ k005289_device::k005289_device(const machine_config &mconfig, const char *tag, d
, m_sound_prom(*this, DEVICE_SELF)
, m_stream(nullptr)
, m_rate(0)
- , m_mixer_table(nullptr)
, m_mixer_lookup(nullptr)
- , m_mixer_buffer(nullptr)
{
}
@@ -74,10 +72,7 @@ void k005289_device::device_start()
{
/* get stream channels */
m_rate = clock() / CLOCK_DIVIDER;
- m_stream = stream_alloc_legacy(0, 1, m_rate);
-
- /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
- m_mixer_buffer = std::make_unique<short[]>(2 * m_rate);
+ m_stream = stream_alloc(0, 1, m_rate);
/* build the mixer table */
make_mixer_table(2);
@@ -101,17 +96,19 @@ void k005289_device::device_start()
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update
+// sound_stream_update - handle a stream update
//-------------------------------------------------
-void k005289_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void k005289_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- stream_sample_t *buffer = outputs[0];
+ auto &buffer = outputs[0];
short *mix;
int i,v,f;
/* zap the contents of the mixer buffer */
- memset(m_mixer_buffer.get(), 0, samples * sizeof(int16_t));
+ if (m_mixer_buffer.size() < buffer.samples())
+ m_mixer_buffer.resize(buffer.samples());
+ std::fill_n(&m_mixer_buffer[0], buffer.samples(), 0);
v=m_volume[0];
f=m_frequency[0];
@@ -120,10 +117,10 @@ void k005289_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
const unsigned char *w = &m_sound_prom[m_waveform[0]];
int c = m_counter[0];
- mix = m_mixer_buffer.get();
+ mix = &m_mixer_buffer[0];
/* add our contribution */
- for (i = 0; i < samples; i++)
+ for (i = 0; i < buffer.samples(); i++)
{
int offs;
@@ -143,10 +140,10 @@ void k005289_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
const unsigned char *w = &m_sound_prom[m_waveform[1]];
int c = m_counter[1];
- mix = m_mixer_buffer.get();
+ mix = &m_mixer_buffer[0];
/* add our contribution */
- for (i = 0; i < samples; i++)
+ for (i = 0; i < buffer.samples(); i++)
{
int offs;
@@ -160,9 +157,9 @@ void k005289_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
}
/* mix it down */
- mix = m_mixer_buffer.get();
- for (i = 0; i < samples; i++)
- *buffer++ = m_mixer_lookup[*mix++];
+ mix = &m_mixer_buffer[0];
+ for (i = 0; i < buffer.samples(); i++)
+ buffer.put(i, m_mixer_lookup[*mix++]);
}
@@ -178,18 +175,19 @@ void k005289_device::make_mixer_table(int voices)
int gain = 16;
/* allocate memory */
- m_mixer_table = std::make_unique<int16_t[]>(256 * voices);
+ m_mixer_table.resize(256 * voices);
/* find the middle of the table */
- m_mixer_lookup = m_mixer_table.get() + (128 * voices);
+ m_mixer_lookup = &m_mixer_table[128 * voices];
/* fill in the table - 16 bit case */
for (i = 0; i < count; i++)
{
int val = i * gain * 16 / voices;
if (val > 32767) val = 32767;
- m_mixer_lookup[ i] = val;
- m_mixer_lookup[-i] = -val;
+ stream_buffer::sample_t fval = stream_buffer::sample_t(val) / 32768.0;
+ m_mixer_lookup[ i] = fval;
+ m_mixer_lookup[-i] = -fval;
}
}
diff --git a/src/devices/sound/k005289.h b/src/devices/sound/k005289.h
index a8dc7b1d0b0..656dccbcb7f 100644
--- a/src/devices/sound/k005289.h
+++ b/src/devices/sound/k005289.h
@@ -26,7 +26,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<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
private:
void make_mixer_table(int voices);
@@ -36,9 +36,9 @@ private:
int m_rate;
/* mixer tables and internal buffers */
- std::unique_ptr<int16_t[]> m_mixer_table;
- int16_t *m_mixer_lookup;
- std::unique_ptr<short[]> m_mixer_buffer;
+ std::vector<stream_buffer::sample_t> m_mixer_table;
+ stream_buffer::sample_t *m_mixer_lookup;
+ std::vector<short> m_mixer_buffer;
uint32_t m_counter[2];
uint16_t m_frequency[2];
diff --git a/src/devices/sound/k007232.cpp b/src/devices/sound/k007232.cpp
index 3b35eeb9d5c..5d7d20dc6d8 100644
--- a/src/devices/sound/k007232.cpp
+++ b/src/devices/sound/k007232.cpp
@@ -86,7 +86,7 @@ void k007232_device::device_start()
for (auto & elem : m_wreg)
elem = 0;
- m_stream = stream_alloc_legacy(0, 2, clock()/128);
+ m_stream = stream_alloc(0, 2, clock()/128);
save_item(STRUCT_MEMBER(m_channel, vol));
save_item(STRUCT_MEMBER(m_channel, addr));
@@ -206,14 +206,11 @@ void k007232_device::set_bank(int chan_a_bank, int chan_b_bank)
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update
+// sound_stream_update - handle a stream update
//-------------------------------------------------
-void k007232_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void k007232_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));
-
if (K007232_LOG_PCM)
{
for (int i = 0; i < KDAC_A_PCM_MAX; i++)
@@ -239,8 +236,10 @@ void k007232_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
}
}
- for (int j = 0; j < samples; j++)
+ constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0;
+ for (int j = 0; j < outputs[0].samples(); j++)
{
+ s32 lsum = 0, rsum = 0;
for (int i = 0; i < KDAC_A_PCM_MAX; i++)
{
channel_t *channel = &m_channel[i];
@@ -279,9 +278,11 @@ void k007232_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
int out = (read_sample(i, addr) & 0x7f) - 0x40;
- outputs[0][j] += out * vol_a;
- outputs[1][j] += out * vol_b;
+ lsum += out * vol_a;
+ rsum += out * vol_b;
}
}
+ outputs[0].put(j, stream_buffer::sample_t(lsum) * sample_scale);
+ outputs[1].put(j, stream_buffer::sample_t(rsum) * sample_scale);
}
}
diff --git a/src/devices/sound/k007232.h b/src/devices/sound/k007232.h
index e9a4ba255da..57cb72fcf7b 100644
--- a/src/devices/sound/k007232.h
+++ b/src/devices/sound/k007232.h
@@ -37,7 +37,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_memory_interface configuration
virtual space_config_vector memory_space_config() const override;
diff --git a/src/devices/sound/k051649.cpp b/src/devices/sound/k051649.cpp
index 0e39a94230a..9a1f748580e 100644
--- a/src/devices/sound/k051649.cpp
+++ b/src/devices/sound/k051649.cpp
@@ -56,7 +56,6 @@ k051649_device::k051649_device(const machine_config &mconfig, const char *tag, d
, device_sound_interface(mconfig, *this)
, m_stream(nullptr)
, m_rate(0)
- , m_mixer_table(nullptr)
, m_mixer_lookup(nullptr)
, m_test(0)
{
@@ -71,7 +70,7 @@ void k051649_device::device_start()
{
// get stream channels
m_rate = clock()/16;
- m_stream = stream_alloc_legacy(0, 1, m_rate);
+ m_stream = stream_alloc(0, 1, m_rate);
// allocate a buffer to mix into - 1 second's worth should be more than enough
m_mixer_buffer.resize(2 * m_rate);
@@ -140,10 +139,10 @@ void k051649_device::device_clock_changed()
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update
+// sound_stream_update - handle a stream update
//-------------------------------------------------
-void k051649_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void k051649_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
// zap the contents of the mixer buffer
std::fill(m_mixer_buffer.begin(), m_mixer_buffer.end(), 0);
@@ -159,7 +158,7 @@ void k051649_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
const int step = voice.frequency;
// add our contribution
- for (int i = 0; i < samples; i++)
+ for (int i = 0; i < outputs[0].samples(); i++)
{
c += 32;
while (c > step)
@@ -177,9 +176,9 @@ void k051649_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
}
// mix it down
- stream_sample_t *buffer = outputs[0];
- for (int i = 0; i < samples; i++)
- *buffer++ = m_mixer_lookup[m_mixer_buffer[i]];
+ auto &buffer = outputs[0];
+ for (int i = 0; i < buffer.samples(); i++)
+ buffer.put(i, m_mixer_lookup[m_mixer_buffer[i]]);
}
@@ -309,16 +308,17 @@ u8 k051649_device::k051649_test_r()
void k051649_device::make_mixer_table(int voices)
{
// allocate memory
- m_mixer_table = std::make_unique<s16[]>(512 * voices);
+ m_mixer_table.resize(512 * voices);
// find the middle of the table
- m_mixer_lookup = m_mixer_table.get() + (256 * voices);
+ m_mixer_lookup = &m_mixer_table[256 * voices];
// fill in the table - 16 bit case
for (int i = 0; i < (voices * 256); i++)
{
const int val = std::min(32767, i * DEF_GAIN * 16 / voices);
- m_mixer_lookup[ i] = val;
- m_mixer_lookup[-i] = -val;
+ stream_buffer::sample_t fval = stream_buffer::sample_t(val) / 32768.0;
+ m_mixer_lookup[ i] = fval;
+ m_mixer_lookup[-i] = -fval;
}
}
diff --git a/src/devices/sound/k051649.h b/src/devices/sound/k051649.h
index 2fda5936685..368ef6c58a9 100644
--- a/src/devices/sound/k051649.h
+++ b/src/devices/sound/k051649.h
@@ -38,7 +38,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;
private:
// Parameters for a channel
@@ -71,8 +71,8 @@ private:
int m_rate;
/* mixer tables and internal buffers */
- std::unique_ptr<s16[]> m_mixer_table;
- s16 *m_mixer_lookup;
+ std::vector<stream_buffer::sample_t> m_mixer_table;
+ stream_buffer::sample_t *m_mixer_lookup;
std::vector<s16> m_mixer_buffer;
/* chip registers */
diff --git a/src/devices/sound/k053260.cpp b/src/devices/sound/k053260.cpp
index ff2356ac600..4158e5a11e7 100644
--- a/src/devices/sound/k053260.cpp
+++ b/src/devices/sound/k053260.cpp
@@ -115,7 +115,7 @@ void k053260_device::device_start()
m_sh1_cb.resolve_safe();
m_sh2_cb.resolve_safe();
- m_stream = stream_alloc_legacy( 0, 2, clock() / CLOCKS_PER_SAMPLE );
+ m_stream = stream_alloc( 0, 2, clock() / CLOCKS_PER_SAMPLE );
/* register with the save state system */
save_item(NAME(m_portdata));
@@ -310,14 +310,15 @@ static constexpr s32 MAXOUT = 0x7fff;
static constexpr s32 MINOUT = -0x8000;
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update
+// sound_stream_update - handle a stream update
//-------------------------------------------------
-void k053260_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void k053260_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
if (m_mode & 2)
{
- for ( int j = 0; j < samples; j++ )
+ constexpr stream_buffer::sample_t sample_scale = 1.0f / stream_buffer::sample_t(MAXOUT);
+ for ( int j = 0; j < outputs[0].samples(); j++ )
{
stream_sample_t buffer[2] = {0, 0};
@@ -327,14 +328,14 @@ void k053260_device::sound_stream_update_legacy(sound_stream &stream, stream_sam
voice.play(buffer);
}
- outputs[0][j] = limit( buffer[0], MAXOUT, MINOUT );
- outputs[1][j] = limit( buffer[1], MAXOUT, MINOUT );
+ outputs[0].put(j, stream_buffer::sample_t(limit( buffer[0], MAXOUT, MINOUT )) * sample_scale);
+ outputs[1].put(j, stream_buffer::sample_t(limit( buffer[1], MAXOUT, MINOUT )) * sample_scale);
}
}
else
{
- std::fill_n(&outputs[0][0], samples, 0);
- std::fill_n(&outputs[1][0], samples, 0);
+ outputs[0].fill(0);
+ outputs[1].fill(0);
}
}
diff --git a/src/devices/sound/k053260.h b/src/devices/sound/k053260.h
index 4288b603d5a..a50b8b9196e 100644
--- a/src/devices/sound/k053260.h
+++ b/src/devices/sound/k053260.h
@@ -42,7 +42,7 @@ protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) 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;
diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp
index 2ed7dc134a2..b1aa643d994 100644
--- a/src/devices/sound/k054539.cpp
+++ b/src/devices/sound/k054539.cpp
@@ -23,7 +23,7 @@ k054539_device::k054539_device(const machine_config &mconfig, const char *tag, d
, device_sound_interface(mconfig, *this)
, device_rom_interface(mconfig, *this)
, flags(0)
- , ram(nullptr)
+ , ram(0x4000)
, reverb_pos(0)
, cur_ptr(0)
, cur_limit(0)
@@ -115,7 +115,7 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vector<read_
};
- int16_t *rbase = (int16_t *)ram.get();
+ int16_t *rbase = (int16_t *)&ram[0];
if(!(regs[0x22f] & 1))
{
@@ -321,10 +321,9 @@ void k054539_device::init_chip()
memset(posreg_latch, 0, sizeof(posreg_latch)); //*
flags |= UPDATE_AT_KEYON; //* make it default until proven otherwise
- ram = std::make_unique<uint8_t[]>(0x4000);
reverb_pos = 0;
cur_ptr = 0;
- memset(ram.get(), 0, 0x4000);
+ memset(&ram[0], 0, 0x4000);
stream = stream_alloc(0, 2, clock() / 384);
@@ -335,7 +334,7 @@ void k054539_device::init_chip()
save_item(NAME(flags));
save_item(NAME(regs));
- save_pointer(NAME(ram), 0x4000);
+ save_item(NAME(ram));
save_item(NAME(reverb_pos));
save_item(NAME(cur_ptr));
save_item(NAME(cur_limit));
@@ -553,7 +552,7 @@ void k054539_device::device_reset()
{
regs[0x22c] = 0;
regs[0x22f] = 0;
- memset(ram.get(), 0, 0x4000);
+ memset(&ram[0], 0, 0x4000);
m_timer->enable(false);
}
diff --git a/src/devices/sound/k054539.h b/src/devices/sound/k054539.h
index 6e4b6c10c8c..ec019ba990e 100644
--- a/src/devices/sound/k054539.h
+++ b/src/devices/sound/k054539.h
@@ -88,7 +88,7 @@ private:
int flags;
unsigned char regs[0x230];
- std::unique_ptr<uint8_t[]> ram;
+ std::vector<uint8_t> ram;
int reverb_pos;
int32_t cur_ptr;
diff --git a/src/devices/sound/ks0164.cpp b/src/devices/sound/ks0164.cpp
index 5280af611f6..ac1579280b0 100644
--- a/src/devices/sound/ks0164.cpp
+++ b/src/devices/sound/ks0164.cpp
@@ -50,7 +50,7 @@ void ks0164_device::device_start()
space().install_rom(0, rend, ((1 << 23) - 1) ^ rmask, m_mem_region->base());
}
- m_stream = stream_alloc_legacy(0, 2, clock()/3/2/2/32);
+ m_stream = stream_alloc(0, 2, clock()/3/2/2/32);
space().cache(m_mem_cache);
m_timer = timer_alloc(0);
@@ -368,9 +368,10 @@ u16 ks0164_device::uncomp_8_16(u8 value)
return o;
}
-void ks0164_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void ks0164_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
- for(int sample = 0; sample != samples; sample++) {
+ constexpr stream_buffer::sample_t sample_scale = 1.0 / (32768.0 * 32.0);
+ for(int sample = 0; sample != outputs[0].samples(); sample++) {
s32 suml = 0, sumr = 0;
for(int voice = 0; voice < 0x20; voice++) {
u16 *regs = m_sregs[voice];
@@ -415,7 +416,7 @@ void ks0164_device::sound_stream_update_legacy(sound_stream &stream, stream_samp
sumr += samp;
}
}
- outputs[0][sample] = suml >> 5;
- outputs[1][sample] = sumr >> 5;
+ outputs[0].put(sample, stream_buffer::sample_t(suml) * sample_scale);
+ outputs[1].put(sample, stream_buffer::sample_t(sumr) * sample_scale);
}
}
diff --git a/src/devices/sound/ks0164.h b/src/devices/sound/ks0164.h
index a668753f250..cc707699f2e 100644
--- a/src/devices/sound/ks0164.h
+++ b/src/devices/sound/ks0164.h
@@ -23,7 +23,7 @@ public:
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;
virtual void device_add_mconfig(machine_config &config) override;
virtual space_config_vector memory_space_config() const override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;