diff options
Diffstat (limited to 'src/devices/sound/k051649.cpp')
-rw-r--r-- | src/devices/sound/k051649.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/devices/sound/k051649.cpp b/src/devices/sound/k051649.cpp index 1114fa47c6c..a675c4f2c11 100644 --- a/src/devices/sound/k051649.cpp +++ b/src/devices/sound/k051649.cpp @@ -26,6 +26,7 @@ #include "emu.h" #include "k051649.h" +#include <algorithm> #define FREQ_BITS 16 #define DEF_GAIN 8 @@ -51,7 +52,6 @@ k051649_device::k051649_device(const machine_config &mconfig, const char *tag, d m_rate(0), m_mixer_table(nullptr), m_mixer_lookup(nullptr), - m_mixer_buffer(nullptr), m_test(0) { } @@ -69,7 +69,7 @@ void k051649_device::device_start() m_mclock = clock(); // allocate a buffer to mix into - 1 second's worth should be more than enough - m_mixer_buffer = std::make_unique<short[]>(2 * m_rate); + m_mixer_buffer.resize(2 * m_rate); // build the mixer table make_mixer_table(5); @@ -97,13 +97,42 @@ void k051649_device::device_reset() //------------------------------------------------- +// device_post_load - device-specific post-load +//------------------------------------------------- + +void k051649_device::device_post_load() +{ + device_clock_changed(); +} + + +//------------------------------------------------- +// device_clock_changed - called if the clock +// changes +//------------------------------------------------- + +void k051649_device::device_clock_changed() +{ + uint32_t old_rate = m_rate; + m_rate = clock()/16; + m_mclock = clock(); + + if (old_rate < m_rate) + { + m_mixer_buffer.resize(2 * m_rate, 0); + } + m_stream->set_sample_rate(m_rate); +} + + +//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) { // zap the contents of the mixer buffer - memset(m_mixer_buffer.get(), 0, samples * sizeof(short)); + std::fill(m_mixer_buffer.begin(), m_mixer_buffer.end(), 0); for (sound_channel &voice : m_channel_list) { @@ -115,8 +144,6 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t * int c=voice.counter; int step = ((int64_t(m_mclock) << FREQ_BITS) / float((voice.frequency + 1) * 16 * (m_rate / 32))) + 0.5f; - short *mix = m_mixer_buffer.get(); - // add our contribution for (int i = 0; i < samples; i++) { @@ -124,7 +151,7 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t * c += step; offs = (c >> FREQ_BITS) & 0x1f; - *mix++ += (w[offs] * v)>>3; + m_mixer_buffer[i] += (w[offs] * v)>>3; } // update the counter for this voice @@ -134,9 +161,8 @@ void k051649_device::sound_stream_update(sound_stream &stream, stream_sample_t * // mix it down stream_sample_t *buffer = outputs[0]; - short *mix = m_mixer_buffer.get(); for (int i = 0; i < samples; i++) - *buffer++ = m_mixer_lookup[*mix++]; + *buffer++ = m_mixer_lookup[m_mixer_buffer[i]]; } |