summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/gomoku.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mame/audio/gomoku.cpp')
-rw-r--r--src/mame/audio/gomoku.cpp57
1 files changed, 13 insertions, 44 deletions
diff --git a/src/mame/audio/gomoku.cpp b/src/mame/audio/gomoku.cpp
index 6aeb288f6db..2b0d936bbd7 100644
--- a/src/mame/audio/gomoku.cpp
+++ b/src/mame/audio/gomoku.cpp
@@ -32,10 +32,6 @@ gomoku_sound_device::gomoku_sound_device(const machine_config &mconfig, const ch
, m_sound_rom(*this, DEVICE_SELF)
, m_sound_enable(0)
, m_stream(nullptr)
- , m_mixer_table(nullptr)
- , m_mixer_lookup(nullptr)
- , m_mixer_buffer(nullptr)
- , m_mixer_buffer_2(nullptr)
{
std::fill(std::begin(m_soundregs1), std::end(m_soundregs1), 0);
std::fill(std::begin(m_soundregs2), std::end(m_soundregs2), 0);
@@ -52,14 +48,10 @@ void gomoku_sound_device::device_start()
int ch;
// get stream channels
- m_stream = stream_alloc_legacy(0, 1, clock());
+ m_stream = stream_alloc(0, 1, clock());
- // 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 * clock());
- m_mixer_buffer_2 = m_mixer_buffer.get() + clock(); // this is never used?
-
- // build the mixer table
- make_mixer_table(8, DEFGAIN);
+ // allocate a buffer to mix into - 1 second's worth should be more than enough
+ m_mixer_buffer.resize(clock()/50);
// start with sound enabled, many games don't have a sound enable register
m_sound_enable = 1;
@@ -76,7 +68,6 @@ void gomoku_sound_device::device_start()
save_item(NAME(m_soundregs1));
save_item(NAME(m_soundregs2));
- save_pointer(NAME(m_mixer_buffer), 2 * clock());
// save_item(NAME(m_sound_enable)); // set to 1 at device start and never updated?
save_item(STRUCT_MEMBER(m_channel_list, channel));
save_item(STRUCT_MEMBER(m_channel_list, frequency));
@@ -87,12 +78,12 @@ void gomoku_sound_device::device_start()
//-------------------------------------------------
-// sound_stream_update_legacy - handle a stream update in mono
+// sound_stream_update - handle a stream update in mono
//-------------------------------------------------
-void gomoku_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples)
+void gomoku_sound_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];
sound_channel *voice;
short *mix;
int ch;
@@ -100,12 +91,12 @@ void gomoku_sound_device::sound_stream_update_legacy(sound_stream &stream, strea
// if no sound, we're done
if (m_sound_enable == 0)
{
- memset(buffer, 0, samples * sizeof(*buffer));
+ buffer.fill(0);
return;
}
// zap the contents of the mixer buffer
- memset(m_mixer_buffer.get(), 0, samples * sizeof(short));
+ std::fill_n(&m_mixer_buffer[0], buffer.samples(), 0);
// loop over each voice and add its contribution
for (ch = 0, voice = std::begin(m_channel_list); voice < std::end(m_channel_list); ch++, voice++)
@@ -124,10 +115,10 @@ void gomoku_sound_device::sound_stream_update_legacy(sound_stream &stream, strea
else
w_base = 0x100 * (m_soundregs2[0x1d] & 0x0f);
- mix = m_mixer_buffer.get();
+ mix = &m_mixer_buffer[0];
// add our contribution
- for (int i = 0; i < samples; i++)
+ for (int i = 0; i < buffer.samples(); i++)
{
c += f;
@@ -167,31 +158,9 @@ void gomoku_sound_device::sound_stream_update_legacy(sound_stream &stream, strea
}
// mix it down
- mix = m_mixer_buffer.get();
- for (int i = 0; i < samples; i++)
- *buffer++ = m_mixer_lookup[*mix++];
-}
-
-
-// build a table to divide by the number of voices; gain is specified as gain*16
-void gomoku_sound_device::make_mixer_table(int voices, int gain)
-{
- int count = voices * 128;
-
- // allocate memory
- m_mixer_table = std::make_unique<int16_t[]>(256 * voices);
-
- // find the middle of the table
- m_mixer_lookup = m_mixer_table.get() + (128 * voices);
-
- // fill in the table - 16 bit case
- for (int 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;
- }
+ mix = &m_mixer_buffer[0];
+ for (int i = 0; i < buffer.samples(); i++)
+ buffer.put_int(i, *mix++, 128 * MAX_VOICES);
}