From 4162285358cb4611e9faa7de576d57b47dbf2ec4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 23 Jul 2019 22:45:04 +0100 Subject: [PATCH] Use memset for zeroing float buffers; it's faster, and I think we get away with it on all the platforms we care about. --- src/lib/audio_buffers.cc | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc index 825c6c2f3..8d3a897c4 100644 --- a/src/lib/audio_buffers.cc +++ b/src/lib/audio_buffers.cc @@ -125,12 +125,7 @@ AudioBuffers::set_frames (int32_t f) { DCPOMATIC_ASSERT (f <= _allocated_frames); - for (int c = 0; c < _channels; ++c) { - for (int i = f; i < _frames; ++i) { - _data[c][i] = 0; - } - } - + make_silent (f, _frames - f); _frames = f; } @@ -151,9 +146,10 @@ AudioBuffers::make_silent (int c) { DCPOMATIC_ASSERT (c >= 0 && c < _channels); - for (int i = 0; i < _frames; ++i) { - _data[c][i] = 0; - } + /* This isn't really allowed, as all-bits-0 is not guaranteed to mean a 0 float, + but it seems that we can get away with it. + */ + memset (_data[c], 0, _frames * sizeof(float)); } /** Make some frames. @@ -166,9 +162,10 @@ AudioBuffers::make_silent (int32_t from, int32_t frames) DCPOMATIC_ASSERT ((from + frames) <= _allocated_frames); for (int c = 0; c < _channels; ++c) { - for (int i = from; i < (from + frames); ++i) { - _data[c][i] = 0; - } + /* This isn't really allowed, as all-bits-0 is not guaranteed to mean a 0 float, + but it seems that we can get away with it. + */ + memset (_data[c] + from, 0, frames * sizeof(float)); } } @@ -270,11 +267,9 @@ AudioBuffers::ensure_size (int32_t frames) if (!_data[i]) { throw bad_alloc (); } - for (int j = _allocated_frames; j < frames; ++j) { - _data[i][j] = 0; - } } + make_silent (_allocated_frames, frames - _allocated_frames); _allocated_frames = frames; } -- 2.30.2