From 6f05b70b5f68a54657d2e2e52e9e363056b3e574 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 3 Aug 2008 13:19:13 +0000 Subject: [PATCH] made oscillator-phase always being positive which allows further optimizations of fraction()-method git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1431 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 7 ++++++ include/lmms_math.h | 54 ++++++++++++++++++++++++++++++++++++++--- src/core/oscillator.cpp | 3 ++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf9bbb082..532e8b00f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-08-03 Tobias Doerffel + + * include/lmms_math.h: + * src/core/oscillator.cpp: + made oscillator-phase always being positive which allows further + optimizations of fraction()-method + 2008-08-01 Tobias Doerffel * include/visualization_widget.h: diff --git a/include/lmms_math.h b/include/lmms_math.h index 108a8d7eb..9eac3c94f 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -31,21 +31,67 @@ #include -// Equivalent to _x - floorf( _x ) -static inline float fraction( const float _x ) +static inline float absFraction( const float _x ) { return( _x - ( _x >= 0.0f ? floorf( _x ) : floorf( _x ) - 1 ) ); } +static inline float fraction( const float _x ) +{ + return( _x - floorf( _x ) ); +} + #else -// Equivalent to _x - floorf( _x ) -static inline float fraction( const float _x ) +static inline float absFraction( const float _x ) { return( _x - ( _x >= 0.0f ? static_cast( _x ) : static_cast( _x ) - 1 ) ); } +static inline float fraction( const float _x ) +{ + return( _x - static_cast( _x ) ); +} + + +#if 0 +// SSE3-version +static inline float absFraction( float _x ) +{ + unsigned int tmp; + asm( + "fld %%st\n\t" + "fisttp %1\n\t" + "fild %1\n\t" + "ftst\n\t" + "sahf\n\t" + "jae 1f\n\t" + "fld1\n\t" + "fsubrp %%st, %%st(1)\n\t" + "1:\n\t" + "fsubrp %%st, %%st(1)" + : "+t"( _x ), "=m"( tmp ) + : + : "st(1)", "cc" ); + return( _x ); +} + +static inline float absFraction( float _x ) +{ + unsigned int tmp; + asm( + "fld %%st\n\t" + "fisttp %1\n\t" + "fild %1\n\t" + "fsubrp %%st, %%st(1)" + : "+t"( _x ), "=m"( tmp ) + : + : "st(1)" ); + return( _x ); +} +#endif + #endif diff --git a/src/core/oscillator.cpp b/src/core/oscillator.cpp index 779a40991..b0902c869 100644 --- a/src/core/oscillator.cpp +++ b/src/core/oscillator.cpp @@ -317,7 +317,8 @@ inline void oscillator::recalcPhase( void ) m_phaseOffset = m_ext_phaseOffset; m_phase += m_phaseOffset; } - m_phase = fraction( m_phase ); + m_phase = absFraction( m_phase )+2; // make sure we're not running + // negative when doing PM }