Refactoring fading definitions, now all in ITABaseDefinition and with...

Refactoring fading definitions, now all in ITABaseDefinition and with appropriate namespacing and enum declaration
parent 15e41411
......@@ -20,13 +20,55 @@
#define INCLUDE_WATCHER_ITA_BASE_DEFINITIONS
#if ( defined WIN32 ) && !( defined ITA_BASE_STATIC )
#ifdef ITA_BASE_EXPORT
#define ITA_BASE_API __declspec( dllexport )
#else
#define ITA_BASE_API __declspec( dllimport )
#endif
#ifdef ITA_BASE_EXPORT
#define ITA_BASE_API __declspec( dllexport )
#else
#define ITA_BASE_API
#define ITA_BASE_API __declspec( dllimport )
#endif
#else
#define ITA_BASE_API
#endif
namespace ITABase
{
enum MixingMethod
{
OVERWRITE = 0, //!< Overwrites the target buffer with new samples
ADD = 1, //!< Adds (mixes) the new samples to the target buffer
};
enum SwitchingMethod
{
};
//! berblendfunktionen
enum FadingFunction
{
LINEAR = 0, //!< Lineare berblendung aka. Rampe
COSINE_SQUARE = 1, //!< Cosinus-Quadrat berblendung (aka Hanning-Fenster)
};
//! Fading sign
/**
* Direction how to fade, i.e. in or out
*/
enum FadingSign
{
IN = 0, //!< Fade in
OUT = 1, //!< Fade out
};
//! Crossfade direction
/**
* Fading direction from source or to source
*/
enum CrossfadeDirection
{
TO_SOURCE = 0, //!< Crossfade to the source signal
OFF_SOURCE = 1, //!< Crossfade off source signal
};
}
#endif // INCLUDE_WATCHER_ITA_BASE_DEFINITIONS
......@@ -22,14 +22,6 @@
// ITABase
#include <ITABaseDefinitions.h>
//! Blend-Modi (Ein-/Ausblenden)
const int ITA_FADE_IN = 0;
const int ITA_FADE_OUT = 1;
//! Blend-Funktionen
const int ITA_FADE_LINEAR = 0 << 1; //!< Lineare Überblendung aka. Rampe
const int ITA_FADE_COSINE_SQUARE = 1 << 1; //!< Cosinus-Quadrat Überblendung
//! Signal blenden
/**
* Multipliziert alle Werte im Array pfData mit den entsprechenden Blendkoeffizienten.
......@@ -37,9 +29,10 @@ const int ITA_FADE_COSINE_SQUARE = 1 << 1; //!< Cosinus-Quadrat
*
* \param pfData Array mit den zu blendenden Werten
* \param iFadeLength Länge der Blendung (darf Länge von pfData nicht überschreiten)
* \param iFadeFlags Blend-Parameter
* @param iFadingSign Fade in or out
* @param iFadingFunction Fading function
*/
void ITA_BASE_API Fade(float* pfData, int iFadeLength, int iFadeFlags);
void ITA_BASE_API Fade(float* pfData, int iFadeLength, int iFadingSign, int iFadingFunction );
//! Signal blenden (erweitert)
/**
......@@ -48,12 +41,13 @@ void ITA_BASE_API Fade(float* pfData, int iFadeLength, int iFadeFlags);
*
* \param pfData Array mit den zu blendenden Werten
* \param iFadeLength Länge der Blendung (darf hier die Länge die pfData nicht überschreiten)
* \param iFadeFlags Blend-Parameter
* @param iFadingSign Fade in or out
* @param iFadingFunction Fading function
* \param iOffset Start-Position in der gesamten Blendung
* (benötigt für Blenden in mehreren Schritten)
* \param iLength Anzahl Samples die ab Beginn von pfData modifiziert werden.
*/
void ITA_BASE_API Fade(float* pfData, int iFadeLength, int iFadeFlags, int iOffset, int iLength);
void ITA_BASE_API Fade( float* pfData, int iFadeLength, int iFadingSign, int iFadingFunction, int iOffset, int iLength );
//! Signale kreuzblenden
/**
......@@ -64,8 +58,8 @@ void ITA_BASE_API Fade(float* pfData, int iFadeLength, int iFadeFlags, int iOffs
* \param pfSrc2 Quellpuffer (nach)
* \param pfDest Zielpuffer (von)
* \param iFadeLength Länge der Kreuzblende (darf Längen der drei Puffer nicht überschreiten)
* \param iFadeFlags Blend-Parameter
* @param iFadingFunction Fading function
*/
void ITA_BASE_API Crossfade(const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFadeLength, int iFadeFlags);
void ITA_BASE_API Crossfade( const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFadeLength, int iFadingFunction );
#endif // INCLUDE_WATCHER_ITA_FADE
#include <ITAFade.h>
#include <ITAConstants.h>
#include <ITAException.h>
#include <cmath>
void Fade( float* pfData, int iFadeLength, int iFadeFlags )
void Fade( float* pfData, int iFadeLength, int iFadingSign, int iFadeFunction )
{
Fade( pfData, iFadeLength, iFadeFlags, 0, iFadeLength );
Fade( pfData, iFadeLength, iFadingSign, iFadeFunction, 0, iFadeLength );
}
void Fade( float* pfData, int iFadeLength, int iFadeFlags, int iOffset, int iLength )
void Fade( float* pfData, int iFadeLength, int iFadingSign, int iFadeFunction, int iOffset, int iLength )
{
if( iFadeLength == 0 ) return;
if( iFadeLength == 0 )
return;
int iFadeFunction = iFadeFlags & 6;
int iFadeDirection = iFadeFlags & 1;
const float halfPi = 1.5707963267948966192f;
float alpha;
switch( iFadeFunction ) {
case ITA_FADE_LINEAR:
case ITABase::FadingFunction::LINEAR:
{
alpha = 1 / ( float ) iFadeLength;
if( iFadeDirection == ITA_FADE_IN ) {
if( iFadingSign == ITABase::FadingSign::IN )
{
// Einblenden
for( int i = 0; i < iLength; i++ ) {
for( int i = 0; i < iLength; i++ )
{
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) < 0 )
pfData[ i ] = 0;
......@@ -33,9 +34,11 @@ void Fade( float* pfData, int iFadeLength, int iFadeFlags, int iOffset, int iLen
pfData[ i ] *= alpha * ( float ) ( i + iOffset );
}
}
else {
else // fade out
{
// Ausblenden
for( int i = 0; i < iLength; i++ ) {
for( int i = 0; i < iLength; i++ )
{
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) >= iFadeLength )
pfData[ i ] = 0;
......@@ -46,53 +49,60 @@ void Fade( float* pfData, int iFadeLength, int iFadeFlags, int iOffset, int iLen
}
break;
}
case ITABase::FadingFunction::COSINE_SQUARE:
{
alpha = ITAConstants::HALF_PI_F / ( float ) iFadeLength;
case ITA_FADE_COSINE_SQUARE:
alpha = halfPi / ( float ) iFadeLength;
if( iFadeDirection == ITA_FADE_IN )
for( int i = 0; i < iLength; i++ ) {
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) < 0 )
pfData[ i ] = 0;
else
if( ( i + iOffset ) < iFadeLength ) {
float c = cos( alpha * ( float ) ( i + iOffset ) );
float csq = ( float ) ( c*c );
pfData[ i ] *= ( 1 - csq );
}
if( iFadingSign == ITABase::FadingSign::IN )
for( int i = 0; i < iLength; i++ )
{
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) < 0 )
pfData[ i ] = 0;
else
if( ( i + iOffset ) < iFadeLength )
{
float c = cos( alpha * ( float ) ( i + iOffset ) );
float csq = ( float ) ( c*c );
pfData[ i ] *= ( 1 - csq );
}
}
else
for( int i = 0; i < iLength; i++ ) {
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) >= iFadeLength )
pfData[ i ] = 0;
else
if( ( i + iOffset ) >= 0 ) {
float c = cos( alpha * ( float ) ( i + iOffset ) );
float csq = ( float ) ( c*c );
pfData[ i ] *= csq;
}
else // fade out
for( int i = 0; i < iLength; i++ )
{
// Saubere Werte vor bzw. hinter der Blendphase
if( ( i + iOffset ) >= iFadeLength )
pfData[ i ] = 0;
else
if( ( i + iOffset ) >= 0 )
{
float c = cos( alpha * ( float ) ( i + iOffset ) );
float csq = ( float ) ( c*c );
pfData[ i ] *= csq;
}
}
break;
}
default:
{
ITA_EXCEPT1( INVALID_PARAMETER, "Invalid flags" );
}
}
}
void Crossfade( const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFadeLength, int iFadeFlags ) {
if( iFadeLength == 0 ) return;
int iFadeFunction = iFadeFlags & 6;
int iFadeDirection = iFadeFlags & 1;
void Crossfade( const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFadeLength, int iFadeFunction )
{
if( iFadeLength == 0 )
return;
const float halfPi = 1.5707963267948966192f;
float alpha;
switch( iFadeFunction ) {
case ITA_FADE_LINEAR:
switch( iFadeFunction )
{
case ITABase::FadingFunction::LINEAR:
{
alpha = 1 / ( float ) iFadeLength;
for( int i = 0; i < iFadeLength; i++ ) {
......@@ -101,9 +111,10 @@ void Crossfade( const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFa
}
break;
case ITA_FADE_COSINE_SQUARE:
alpha = halfPi / ( float ) iFadeLength;
}
case ITABase::FadingFunction::COSINE_SQUARE:
{
alpha = ITAConstants::HALF_PI_F / ( float ) iFadeLength;
for( int i = 0; i < iFadeLength; i++ ) {
float c = cos( alpha * ( float ) i );
......@@ -112,9 +123,10 @@ void Crossfade( const float* pfSrc1, const float* pfSrc2, float* pfDest, int iFa
}
break;
}
default:
{
ITA_EXCEPT1( INVALID_PARAMETER, "Invalid flags" );
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment