Skip to content
Snippets Groups Projects
Select Git revision
  • v1.1-rc0
  • master default
  • sp/trace-zero-ranges
  • stable-2.5
  • stable-2.4
  • stable-2.3
  • stable-2.2
  • stable-2.1
  • stable-2.0
  • stable-1.7
  • stable-1.6
  • stable-1.5
  • stable-1.4
  • stable-1.3
  • stable-1.2
  • stable-1.1
  • stable-1.0
  • stable-0.15
  • stable-0.14
  • stable-0.13
  • stable-0.12
  • v2.7.0-rc1
  • v2.7.0-rc0
  • v2.6.0
  • v2.5.1.1
  • v2.6.0-rc5
  • v2.6.0-rc4
  • v2.6.0-rc3
  • v2.6.0-rc2
  • v2.6.0-rc1
  • v2.6.0-rc0
  • v2.5.1
  • v2.5.0
  • v2.5.0-rc4
  • v2.5.0-rc3
  • v2.5.0-rc2
  • v2.5.0-rc1
  • v2.5.0-rc0
  • v2.4.1
  • v2.4.0.1
  • v2.3.1
41 results

COPYING.LIB

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    This project is licensed under the GNU Lesser General Public License v2.1 only. Learn more
    ITABiquad.cpp 3.41 KiB
    #include <ITABiquad.h>
    #include <ITAException.h>
    #include <ITABaseDefinitions.h>
    
    CITABiquad::CITABiquad()
    {
    	ClearAccumulators();
    }
    
    void CITABiquad::ClearAccumulators()
    {
    	m_vfAccumulators.push_back( 0.0f );
    	m_vfAccumulators.push_back( 0.0f );
    }
    
    void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const int iNumSamples )
    {
    	// Local accumulators
    	float z0, z1, z2;
    
    	// Restore accumulators from last process call
    	z1 = m_vfAccumulators[ 0 ];
    	z2 = m_vfAccumulators[ 1 ];
    
    	for( int i = 0; i < iNumSamples; i++ )
    	{
    		// w[n] = x[n] - a_1*w[n-1] - a_2*w[n-2]
    		z0 = oParams.g * pfInputData[ i ] - oParams.a1 * z1 - oParams.a2 * z2;
    
    		// y[n] = b_0*w[n] + b_1*w[n-1] + b_2*w[n-2]
    		pfOutputData[ i ] = oParams.b0 * z0 + oParams.b1 * z1 + oParams.b2 * z2;
    
    		// Shift accumulators
    		z2 = z1;
    		z1 = z0;
    	}
    
    	// Store accumulators for next process call
    	m_vfAccumulators[ 0 ] = z1;
    	m_vfAccumulators[ 1 ] = z2;
    
    	return;
    }
    
    void CITABiquad::Process( const float* pfInputData, float* pfOutputData, const int iNumSamples, const float fOutputGain, const int iOutputMode )
    {
    	// Local accumulators
    	float z0, z1, z2;
    
    	z1 = m_vfAccumulators[ 0 ];
    	z2 = m_vfAccumulators[ 1 ];
    
    	if( iOutputMode == ITABase::MixingMethod::ADD )
    	{
    		for( int i = 0; i < iNumSamples; i++ )
    		{
    			z0 = oParams.g * pfInputData[ i ] - oParams.a1*z1 - oParams.a2*z2;
    			pfOutputData[ i ] += ( oParams.b0*z0 + oParams.b1*z1 + oParams.b2*z2 ) * fOutputGain;
    
    			// Shift accumulators
    			z2 = z1;
    			z1 = z0;
    		}
    	}
    	else if( iOutputMode == ITABase::MixingMethod::OVERWRITE )
    	{
    		for( int i = 0; i < iNumSamples; i++ )
    		{
    			z0 = oParams.g*pfInputData[ i ] - oParams.a1*z1 - oParams.a2*z2;
    			pfOutputData[ i ] = ( oParams.b0 * z0 + oParams.b1 * z1 + oParams.b2*z2 ) * fOutputGain;
    
    			// Shift accumulators
    			z2 = z1;
    			z1 = z0;
    		}
    	}
    	else
    	{
    		ITA_EXCEPT1( INVALID_PARAMETER, "Unrecognized output write mode in CITABiquad" );
    	}
    
    	// Store accumulators
    	m_vfAccumulators[ 0 ] = z1;
    	m_vfAccumulators[ 1 ] = z2;
    
    	return;
    }
    
    void CITABiquad::Process( const float* pfInputData, float* out, const int iNumSamples, const float fOutputGain1, const float fOutputGain2, const int iOutputWriteMode )
    {
    	if( iNumSamples == 0 )
    		return;
    
    	// Local accumulators
    	float z0, z1, z2;
    	z1 = m_vfAccumulators[ 0 ];
    	z2 = m_vfAccumulators[ 1 ];
    
    	// Factor for linear gain
    	const float fLinearGainFactor = ( fOutputGain2 - fOutputGain1 ) / float( iNumSamples );
    
    	if( iOutputWriteMode == ITABase::MixingMethod::ADD )
    	{
    		for( int i = 0; i < iNumSamples; i++ )
    		{
    			const float fSampleGain = fOutputGain1 + i * fLinearGainFactor;
    
    			z0 = oParams.g*pfInputData[ i ] - oParams.a1*z1 - oParams.a2*z2;
    			out[ i ] += ( oParams.b0*z0 + oParams.b1*z1 + oParams.b2*z2 ) * fSampleGain;
    
    			// Shift accumulators
    			z2 = z1;
    			z1 = z0;
    		}
    
    	}
    	else if( iOutputWriteMode == ITABase::MixingMethod::OVERWRITE )
    	{
    		for( int i = 0; i < iNumSamples; i++ )
    		{
    			const float fSampleGain = fOutputGain1 + i * fLinearGainFactor;
    
    			z0 = oParams.g*pfInputData[ i ] - oParams.a1*z1 - oParams.a2*z2;
    			out[ i ] = ( oParams.b0*z0 + oParams.b1*z1 + oParams.b2*z2 ) * fSampleGain;
    
    			// Shift accumulators
    			z2 = z1;
    			z1 = z0;
    		}
    	}
    	else
    	{
    		ITA_EXCEPT1( INVALID_PARAMETER, "Unrecognized output write mode in CITABiquad" );
    	}
    
    	// Store accumulators
    	m_vfAccumulators[ 0 ] = z1;
    	m_vfAccumulators[ 1 ] = z2;
    }
    
    CITABiquad::CParams::CParams()
    	: g( 1 )
    	, a1( 0 )
    	, a2( 0 )
    	, b0( 1 )
    	, b1( 0 )
    	, b2( 0 )
    {
    }