diff options
author | Robin Gareus <robin@gareus.org> | 2019-09-22 04:54:28 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-09-22 04:54:28 +0200 |
commit | 0e68d3f74200413fa62526c62ce9c19d15a1ff72 (patch) | |
tree | 706c49b3f0faa2f872144b781318b1098ed661d7 /libs/ardour/ardour/audio_buffer.h | |
parent | a1c48e0a802fd7423c24db6be17ce39c05e610a9 (diff) |
Optimize Audio-buffer summing
* skip silent buffers
* use vectorized copy
* prefer memset for zero-gain
Diffstat (limited to 'libs/ardour/ardour/audio_buffer.h')
-rw-r--r-- | libs/ardour/ardour/audio_buffer.h | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/libs/ardour/ardour/audio_buffer.h b/libs/ardour/ardour/audio_buffer.h index 24c310f6ea..4ae4631e45 100644 --- a/libs/ardour/ardour/audio_buffer.h +++ b/libs/ardour/ardour/audio_buffer.h @@ -52,7 +52,7 @@ public: assert(src != 0); assert(_capacity > 0); assert(len <= _capacity); - memcpy(_data + dst_offset, src + src_offset, sizeof(Sample) * len); + copy_vector(_data + dst_offset, src + src_offset, len); _silent = false; _written = true; } @@ -69,7 +69,13 @@ public: assert(src.type() == DataType::AUDIO); assert(dst_offset + len <= _capacity); assert( src_offset <= ((samplecnt_t) src.capacity()-len)); - memcpy(_data + dst_offset, ((const AudioBuffer&)src).data() + src_offset, sizeof(Sample) * len); + + if (src.silent()) { + memset (_data + dst_offset, 0, sizeof (Sample) * len); + } else { + copy_vector (_data + dst_offset, ((const AudioBuffer&)src).data() + src_offset, len); + } + if (dst_offset == 0 && src_offset == 0 && len == _capacity) { _silent = src.silent(); } else { @@ -89,7 +95,9 @@ public: void accumulate_from (const AudioBuffer& src, samplecnt_t len, sampleoffset_t dst_offset = 0, sampleoffset_t src_offset = 0) { assert(_capacity > 0); assert(len <= _capacity); - + if (src.silent ()) { + return; + } Sample* const dst_raw = _data + dst_offset; const Sample* const src_raw = src.data() + src_offset; @@ -116,11 +124,10 @@ public: /** Accumulate (add) @a len samples @a src starting at @a src_offset into self starting at @dst_offset * scaling by @a gain_coeff */ void accumulate_with_gain_from (const AudioBuffer& src, samplecnt_t len, gain_t gain_coeff, sampleoffset_t dst_offset = 0, sampleoffset_t src_offset = 0) { - assert(_capacity > 0); assert(len <= _capacity); - if (src.silent()) { + if (src.silent() || gain_coeff == 0) { return; } @@ -155,6 +162,10 @@ public: assert(_capacity > 0); assert(len <= _capacity); + if (initial == 0 && target == 0) { + return; + } + Sample* dst = _data + dst_offset; gain_t gain_delta = (target - initial)/len; @@ -172,6 +183,13 @@ public: * @param len number of samples to amplify */ void apply_gain (gain_t gain, samplecnt_t len) { + if (gain == 0) { + memset (_data, 0, sizeof (Sample) * len); + if (len == _capacity) { + _silent = true; + } + return; + } apply_gain_to_buffer (_data, len, gain); } |