Commit 455c062d authored by henryjandrew's avatar henryjandrew

Merge branch 'develop' of https://git.rwth-aachen.de/ita/ITABase into develop

parents 4219ed77 0dd601ac
......@@ -57,14 +57,16 @@ public:
* and right-side samples can be retrieved via the function GetOverlapSamples().
*
* \param pInput In buffer pointer
* \param iInputLength Length of input samples
* \param iInputLength Length of input samples to run interpolation on (not including overlapping samples required for algorithm, this is given by iInputStartOffset)
* \param iInputStartOffset Offset on input buffer (usually = left-side overlap samples)
* \param pOutput Out buffer pointer
* \param iOutputLength Length of requested output sample
* \param iOutputOffset Offset in output buffer
* \param iOutputOffset Offset where to write into output buffer
*
* \return True, if interpolation algorithm could be executed
*
* @note Raises an exception on bad input
*
*/
virtual bool Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset = 0 ) const = 0;
};
......
#include <ITAInterpolation.h>
#include <ITAConstants.h>
#include <ITAException.h>
#include <ITASampleBuffer.h>
#include <ITANumericUtils.h>
......@@ -15,9 +16,13 @@ float spline_cubic_val_equidistant( const float fX, const float* y, const std::v
bool CITASampleLinearInterpolation::Interpolate( const ITASampleBuffer* pInput, const int iInputLength, const int iInputStartOffset, ITASampleBuffer* pOutput, const int iOutputLength, const int iOutputOffset /*=0*/ ) const
{
assert(pOutput->GetLength() >= iOutputLength + iOutputOffset);
assert(pInput->GetLength() >= iInputLength + iInputStartOffset);
assert( pOutput->GetLength() >= iOutputLength + iOutputOffset );
assert( pInput->GetLength() >= iInputLength + iInputStartOffset );
if( iOutputLength < 1 )
ITA_EXCEPT_INVALID_PARAMETER( "Requested output length for interpolation must be at least 1" );
if( iInputLength < 1 )
ITA_EXCEPT_INVALID_PARAMETER( "Provided input length for interpolation must be at least 1" );
// Interpolation ist nur mglich, wenn der Eingabe-Offset auf dem Eingabepuffer
// grer oder gleich 1 ist, da sonst keine Sttzwerte vorhanden sind.
......@@ -131,12 +136,9 @@ bool CITASampleCubicSplineInterpolation::Interpolate( const ITASampleBuffer* pIn
assert( iOutputLength > 0 );
assert( pOutput->length() >= iOutputLength + iOutputOffset );
// Samples, die aufgeholt (>0) bzw. abgebremst (<0) werden mssen
int iDeltaDelay = ( iInputLength - iInputStartOffset ) - iOutputLength;
// Resamplingfaktor
float r = 1 + iDeltaDelay / ( float ) iOutputLength;
float r = iInputLength / ( float ) iOutputLength;
// --= Resampling =--
......@@ -145,19 +147,18 @@ bool CITASampleCubicSplineInterpolation::Interpolate( const ITASampleBuffer* pIn
float* pOutputData = pOutput->data();
// Return value
std::vector< float > vfInputSecondDerivatives( iInputLength );
spline_cubic_set_equidistant( iInputLength, pInputData, vfInputSecondDerivatives ); // Natural spline interpolation
std::vector< float > vfInputSecondDerivatives( iInputLength + iInputStartOffset );
spline_cubic_set_equidistant( iInputLength + iInputStartOffset, pInputData, vfInputSecondDerivatives ); // Natural spline interpolation
for( int i = 0; i < iOutputLength; i++ )
{
// Position in der Eingabe berechnen (relativ zum Anfang mit Offset)
float fXInput = ( i + 1 )*r - 1;
if( i == iOutputLength - 1 )
assert( iOutputLength + iDeltaDelay == iInputLength - iInputStartOffset );
// Position in the input buffer
float fXInput = ( i + 1 )*r + iInputStartOffset - 1;
// First item (index): fXInput = r - 1
// Last item (index): fXInput = iInputLength + iInputStartOffset - 1
// Spline-Segment auswerten
float fYOutput = spline_cubic_val_equidistant( fXInput + iInputStartOffset, pInputData, vfInputSecondDerivatives );
// Spline segment evaluation at given position
float fYOutput = spline_cubic_val_equidistant( fXInput, pInputData, vfInputSecondDerivatives );
pOutputData[ i + iOutputOffset ] = fYOutput;
......@@ -172,12 +173,9 @@ bool CITASampleWindowedSincInterpolation::Interpolate( const ITASampleBuffer* pI
assert( iInputStartOffset >= m_iWindowSize / 2 );
assert( iOutputLength > 0 );
assert( pOutput->length() >= iOutputLength + iOutputOffset );
// Samples, die aufgeholt (>0) bzw. abgebremst (<0) werden mssen
int iDeltaDelay = ( iInputLength - iInputStartOffset ) - iOutputLength;
// Resamplingfaktor
float r = 1 + iDeltaDelay / ( float ) iOutputLength;
float r = iInputLength / ( float ) iOutputLength;
// --= Resampling =--
......@@ -188,22 +186,19 @@ bool CITASampleWindowedSincInterpolation::Interpolate( const ITASampleBuffer* pI
for( int i = 0; i < iOutputLength; i++ )
{
// Position in der Eingabe berechnen (relativ zum Anfang mit Offset)
float fXInput = ( i + 1 )*r - 1;
if( i == iOutputLength - 1 )
assert( iOutputLength + iDeltaDelay == iInputLength - iInputStartOffset );
float fXInput = ( i + 1 )*r + iInputStartOffset - 1;
// Fenster anwenden & Si-Rekonstruktion
pOutputData[ i + iOutputOffset ] = 0.0f;
for( int j = ( int ) ceil( fXInput - m_iWindowSize / 2 ); j < ( int ) floor( fXInput + m_iWindowSize / 2 ); j++ )
{
int iCenterIndex = j + iInputStartOffset;
int iCenterIndex = j;
assert( iCenterIndex >= 0 && iCenterIndex < iInputLength + m_iWindowSize / 2 ); // berlauf verhindern
float fAmplitude = pInputData[ iCenterIndex ];
// Relativer Abstand zum aktuellen Lesecursor in der Eingabe
float fSincArg = fXInput - iCenterIndex + iInputStartOffset;
float fSincArg = fXInput - iCenterIndex;
assert( std::fabs( fSincArg ) <= ( float ) m_iWindowSize / 2 ); // Fensterberlauf verhindern
float fSincValue = ( fSincArg != 0.0f ) ? ( sin( ITAConstants::PI_F * fSincArg ) / ( ITAConstants::PI_F * fSincArg ) ) : 1.0f;
......
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