mirror of
https://github.com/holub/mame
synced 2025-04-22 08:22:15 +03:00
disound.cpp, sound.cpp, speaker.cpp: Use fill_n and resize to zero memory instead of memset (nw)
This commit is contained in:
parent
8dd5e3d200
commit
e2fcccbd10
@ -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];
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user