Bandlimit changes/algorithm tweaking, add sinc function to lmms_math

This commit is contained in:
Vesa
2014-04-08 12:06:39 +03:00
parent 13237f9c8e
commit 5397bbeaf4
2 changed files with 19 additions and 6 deletions

View File

@@ -120,5 +120,12 @@ static inline double fastPow( double a, double b )
return u.d;
}
// sinc function
static inline double sinc( double _x )
{
return sin( F_PI * _x ) / ( F_PI * _x );
}
#endif

View File

@@ -44,13 +44,15 @@ void BandLimitedWave::generateWaves()
{
int harm = 1;
double s = 0.0f;
double hlen;
do
{
const double amp = -1.0 / static_cast<double>( harm );
hlen = static_cast<double>( len ) / static_cast<double>( harm );
const double amp = -1.0 / static_cast<double>( harm ) * ( hlen <= 4 ? 0.5 : 1.0 ) * ( hlen < 8 ? 0.75 : 1.0 );
const double a2 = cos( om * harm * F_2PI );
s += amp * a2 * sin( static_cast<double>( ph * harm ) / static_cast<double>( len ) * F_2PI );
harm++;
} while( len/harm > 2 );
} while( hlen >= 2.0 );
s_waveforms[ BandLimitedWave::BLSaw ].setSampleAt( i, ph, s );
max = qMax( max, qAbs( s ) );
}
@@ -73,13 +75,15 @@ void BandLimitedWave::generateWaves()
{
int harm = 1;
double s = 0.0f;
double hlen;
do
{
const double amp = 1.0 / static_cast<double>( harm );
hlen = static_cast<double>( len ) / static_cast<double>( harm );
const double amp = 1.0 / static_cast<double>( harm ) * ( hlen <= 4 ? 0.5 : 1.0 ) * ( hlen < 8 ? 0.75 : 1.0 );
const double a2 = cos( om * harm * F_2PI );
s += amp * a2 * sin( static_cast<double>( ph * harm ) / static_cast<double>( len ) * F_2PI );
harm += 2;
} while( len/harm > 2 );
} while( hlen >= 2.0 );
s_waveforms[ BandLimitedWave::BLSquare ].setSampleAt( i, ph, s );
max = qMax( max, qAbs( s ) );
}
@@ -103,14 +107,16 @@ void BandLimitedWave::generateWaves()
{
int harm = 1;
double s = 0.0f;
double hlen;
do
{
const double amp = 1.0 / static_cast<double>( harm * harm );
hlen = static_cast<double>( len ) / static_cast<double>( harm );
const double amp = 1.0 / static_cast<double>( harm * harm ) * ( hlen <= 4 ? 0.5 : 1.0 ) * ( hlen < 8 ? 0.75 : 1.0 );
//const double a2 = cos( om * harm * F_2PI );
s += amp * /*a2 **/ sin( ( static_cast<double>( ph * harm ) / static_cast<double>( len ) +
( ( harm + 1 ) % 4 == 0 ? 0.5 : 0.0 ) ) * F_2PI );
harm += 2;
} while( len/harm > 2 );
} while( hlen >= 2.0 );
s_waveforms[ BandLimitedWave::BLTriangle ].setSampleAt( i, ph, s );
max = qMax( max, qAbs( s ) );
}