summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-11-24 15:24:18 -0500
committer AJR <ajrhacker@users.noreply.github.com>2019-11-24 15:24:18 -0500
commite2fcccbd101b7c92376eb750c6870e941d316b52 (patch)
treec5e1169bb3fb6c2787040bf83a1f46ddac0dcd04 /src/emu
parent8dd5e3d2006f3f28c6bc2a5108c8db324ec3845d (diff)
disound.cpp, sound.cpp, speaker.cpp: Use fill_n and resize to zero memory instead of memset (nw)
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/disound.cpp2
-rw-r--r--src/emu/sound.cpp30
-rw-r--r--src/emu/speaker.cpp4
3 files changed, 15 insertions, 21 deletions
diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp
index a8a0a55ad38..6135b4a2f64 100644
--- a/src/emu/disound.cpp
+++ b/src/emu/disound.cpp
@@ -461,7 +461,7 @@ void device_mixer_interface::sound_stream_update(sound_stream &stream, stream_sa
{
// clear output buffers
for (int output = 0; output < m_outputs; output++)
- memset(outputs[output], 0, samples * sizeof(outputs[0][0]));
+ std::fill_n(outputs[output], samples, 0);
// loop over samples
const u8 *outmap = &m_outputmap[0];
diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp
index 805a6920fed..c876431c41b 100644
--- a/src/emu/sound.cpp
+++ b/src/emu/sound.cpp
@@ -410,7 +410,7 @@ void sound_stream::update_with_accounting(bool second_tick)
{
// if we have samples to move, do so for each output
if (output_bufindex > 0)
- for (auto & output : m_output)
+ for (auto &output : m_output)
{
memmove(&output.m_buffer[0], &output.m_buffer[samples_to_lose], sizeof(output.m_buffer[0]) * (output_bufindex - samples_to_lose));
}
@@ -457,8 +457,8 @@ void sound_stream::apply_sample_rate_changes()
// clear out the buffer
if (m_max_samples_per_update)
- for (auto & elem : m_output)
- memset(&elem.m_buffer[0], 0, m_max_samples_per_update * sizeof(elem.m_buffer[0]));
+ for (auto &elem : m_output)
+ std::fill_n(&elem.m_buffer[0], m_max_samples_per_update, 0);
}
@@ -474,7 +474,7 @@ void sound_stream::recompute_sample_rate_data()
{
m_sample_rate = 0;
// When synchronous, pick the sample rate for the inputs, if any
- for (auto & input : m_input)
+ for (auto &input : m_input)
{
if (input.m_source != nullptr)
{
@@ -506,7 +506,7 @@ void sound_stream::recompute_sample_rate_data()
allocate_output_buffers();
// iterate over each input
- for (auto & input : m_input)
+ for (auto &input : m_input)
{
// if we have a source, see if its sample rate changed
@@ -569,11 +569,8 @@ void sound_stream::allocate_resample_buffers()
m_resample_bufalloc = bufsize;
// iterate over outputs and realloc their buffers
- for (auto & elem : m_input) {
- unsigned int old_size = elem.m_resample.size();
- elem.m_resample.resize(m_resample_bufalloc);
- memset(&elem.m_resample[old_size], 0, (m_resample_bufalloc - old_size)*sizeof(elem.m_resample[0]));
- }
+ for (auto &elem : m_input)
+ elem.m_resample.resize(m_resample_bufalloc, 0);
}
}
@@ -593,11 +590,8 @@ void sound_stream::allocate_output_buffers()
m_output_bufalloc = bufsize;
// iterate over outputs and realloc their buffers
- for (auto & elem : m_output) {
- unsigned int old_size = elem.m_buffer.size();
- elem.m_buffer.resize(m_output_bufalloc);
- memset(&elem.m_buffer[old_size], 0, (m_output_bufalloc - old_size)*sizeof(elem.m_buffer[0]));
- }
+ for (auto &elem : m_output)
+ elem.m_buffer.resize(m_output_bufalloc, 0);
}
}
@@ -612,8 +606,8 @@ void sound_stream::postload()
recompute_sample_rate_data();
// make sure our output buffers are fully cleared
- for (auto & elem : m_output)
- memset(&elem.m_buffer[0], 0, m_output_bufalloc * sizeof(elem.m_buffer[0]));
+ for (auto &elem : m_output)
+ std::fill_n(&elem.m_buffer[0], m_output_bufalloc, 0);
// recompute the sample indexes to make sense
m_output_sampindex = m_attoseconds_per_sample ? m_device.machine().sound().last_update().attoseconds() / m_attoseconds_per_sample : 0;
@@ -684,7 +678,7 @@ stream_sample_t *sound_stream::generate_resampled_data(stream_input &input, u32
stream_sample_t *dest = &input.m_resample[0];
if (input.m_source == nullptr || input.m_source->m_stream->m_attoseconds_per_sample == 0)
{
- memset(dest, 0, numsamples * sizeof(*dest));
+ std::fill_n(dest, numsamples, 0);
return &input.m_resample[0];
}
diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp
index de2ad1127a0..5b3091892de 100644
--- a/src/emu/speaker.cpp
+++ b/src/emu/speaker.cpp
@@ -79,8 +79,8 @@ void speaker_device::mix(s32 *leftmix, s32 *rightmix, int &samples_this_update,
samples_this_update = numsamples;
// reset the mixing streams
- memset(leftmix, 0, samples_this_update * sizeof(*leftmix));
- memset(rightmix, 0, samples_this_update * sizeof(*rightmix));
+ std::fill_n(leftmix, samples_this_update, 0);
+ std::fill_n(rightmix, samples_this_update, 0);
}
assert(samples_this_update == numsamples);