From e578deb112949093b28b2b67d660f2ec10e722ff Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 14 Aug 2013 17:54:38 -0700 Subject: [PATCH] Timeline: Avoid unaligned access. --- nonlib/dsp.C | 8 ++++++++ nonlib/dsp.h | 1 + timeline/src/Engine/Audio_Region.C | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nonlib/dsp.C b/nonlib/dsp.C index 5548425..e9301d6 100644 --- a/nonlib/dsp.C +++ b/nonlib/dsp.C @@ -45,6 +45,14 @@ buffer_apply_gain ( sample_t * __restrict__ buf, nframes_t nframes, float g ) *(buf_++) *= g; } +void +buffer_apply_gain_unaligned ( sample_t * __restrict__ buf, nframes_t nframes, float g ) +{ + if ( g != 1.0f ) + while ( nframes-- ) + *(buf++) *= g; +} + void buffer_apply_gain_buffer ( sample_t * __restrict__ buf, const sample_t * __restrict__ gainbuf, nframes_t nframes ) { diff --git a/nonlib/dsp.h b/nonlib/dsp.h index bdb28c8..705636c 100644 --- a/nonlib/dsp.h +++ b/nonlib/dsp.h @@ -25,6 +25,7 @@ sample_t *buffer_alloc ( nframes_t size ); void buffer_apply_gain ( sample_t *buf, nframes_t nframes, float g ); +void buffer_apply_gain_unaligned ( sample_t *buf, nframes_t nframes, float g ); void buffer_apply_gain_buffer ( sample_t *buf, const sample_t *gainbuf, nframes_t nframes ); void buffer_copy_and_apply_gain_buffer ( sample_t *dst, const sample_t *src, const sample_t *gainbuf, nframes_t nframes ); void buffer_mix ( sample_t *dst, const sample_t *src, nframes_t nframes ); diff --git a/timeline/src/Engine/Audio_Region.C b/timeline/src/Engine/Audio_Region.C index 3d186b9..c21d90b 100644 --- a/timeline/src/Engine/Audio_Region.C +++ b/timeline/src/Engine/Audio_Region.C @@ -192,7 +192,7 @@ Audio_Region::read ( sample_t *buf, nframes_t pos, nframes_t nframes, int channe /* apply gain */ - buffer_apply_gain( buf + ofs, cnt, _scale ); + buffer_apply_gain_unaligned( buf + ofs, cnt, _scale ); /* perform declicking if necessary */