- reverted to PM and added FM as a new modulation method\n- improved performance, specially PM/FM\n- moved fraction() to global scope\n- removed absolute value from userWaveSample, it's handled by fraction()

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@150 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Javier Serrano Polo
2006-06-09 21:15:20 +00:00
parent 0e09bdf3d3
commit 1e77ddff85
4 changed files with 73 additions and 24 deletions

38
include/lmms_math.h Normal file
View File

@@ -0,0 +1,38 @@
/*
* lmms_math.h - defines math functions
*
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef _LMMS_MATH_H
#define _LMMS_MATH_H
// Equivalent to _x - floorf( _x )
static inline float fraction( const float _x )
{
return( _x - ( _x >= 0.0f ? static_cast<int>( _x ) :
static_cast<int>( _x ) - 1 ) );
}
#endif

View File

@@ -37,6 +37,7 @@
#include "mixer.h"
#include "sample_buffer.h"
#include "lmms_constants.h"
#include "lmms_math.h"
class oscillator
@@ -56,7 +57,7 @@ public:
enum modulationAlgos
{
FREQ_MODULATION, AMP_MODULATION, MIX, SYNC
PHASE_MODULATION, AMP_MODULATION, MIX, SYNC, FREQ_MODULATION
} ;
oscillator( const waveShapes * _wave_shape,
@@ -86,11 +87,6 @@ public:
"fistpl %0\n" \
"shrl $1,%0" : "=m" (out) : "t" (in),"m"(round_const) : "st") ;*/
static inline float fraction( const float _sample )
{
return( _sample - static_cast<int>( _sample ) );
}
// now follow the wave-shape-routines...
static inline sample_t sinSample( const float _sample )
@@ -176,7 +172,7 @@ private:
void updateNoSub( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
void updateFM( sampleFrame * _ab, const fpab_t _frames,
void updatePM( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
void updateAM( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
@@ -184,6 +180,8 @@ private:
const ch_cnt_t _chnl );
void updateSync( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
void updateFM( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
float syncInit( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );

View File

@@ -53,6 +53,7 @@
#include "mixer.h"
#include "interpolation.h"
#include "types.h"
#include "lmms_math.h"
class QPainter;
@@ -150,15 +151,10 @@ public:
_dst_sr, _buf->eng() ) );
}
static inline float fraction( const float _sample )
{
return( _sample - static_cast<int>( _sample ) );
}
inline sample_t userWaveSample( const float _sample )
{
m_dataMutex.lock();
const float frame = fraction( fabs( _sample ) ) * m_frames;
const float frame = fraction( _sample ) * m_frames;
const f_cnt_t f1 = static_cast<f_cnt_t>( frame );
const f_cnt_t f2 = ( f1 + 1 ) % m_frames;
sample_t waveSample = linearInterpolate( m_data[f1][0],