From 9e4e576de92786fb504fd09c7757c20137aa9619 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 25 Oct 2008 10:12:44 +0000 Subject: [PATCH] * fixed out-of-boundary array access when reversing samples * optimized loops for loading samples git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1793 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 6 ++++++ src/core/sample_buffer.cpp | 23 +++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5bb787b1d..1cd31839d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-25 Tobias Doerffel + + * src/core/sample_buffer.cpp: + - fixed out-of-boundary array access when reversing samples + - optimized loops for loading samples + 2008-10-21 Tobias Doerffel * include/plugin.h: diff --git a/src/core/sample_buffer.cpp b/src/core/sample_buffer.cpp index 74ddef4bb..8fe7325e0 100644 --- a/src/core/sample_buffer.cpp +++ b/src/core/sample_buffer.cpp @@ -215,35 +215,30 @@ void sampleBuffer::update( bool _keep_settings ) const float fac = m_amplification / OUTPUT_SAMPLE_MULTIPLIER; m_data = new sampleFrame[m_frames]; + const int ch = ( channels > 1 ) ? 1 : 0; // if reversing is on, we also reverse when // scaling if( m_reversed ) { + int idx = ( m_frames - 1 ) * channels; for( f_cnt_t frame = 0; frame < m_frames; ++frame ) { - for( ch_cnt_t chnl = 0; - chnl < DEFAULT_CHANNELS; - ++chnl ) - { -const f_cnt_t idx = ( m_frames - frame ) * channels + ( chnl % channels ); -m_data[frame][chnl] = buf[idx] * fac; - } + m_data[frame][0] = buf[idx+0] * fac; + m_data[frame][1] = buf[idx+ch] * fac; + idx -= channels; } } else { + int idx = 0; for( f_cnt_t frame = 0; frame < m_frames; ++frame ) { - for( ch_cnt_t chnl = 0; - chnl < DEFAULT_CHANNELS; - ++chnl ) - { - const f_cnt_t idx = frame * channels + ( chnl % channels ); - m_data[frame][chnl] = buf[idx] * fac; - } + m_data[frame][0] = buf[idx+0] * fac; + m_data[frame][1] = buf[idx+ch] * fac; + idx += channels; } }