Andreas Pflug wrote:
Albert Santoni wrote:
Hey Andreas,

Just a quick note - I think this is really cool, but I don't think I
know enough about the existing EQ code yet to comment. I've forwarded
your email to John Sully and Ben Wheeler and asked them for thoughts.
The functions replace _processXXXpass (the c version always, the as version if the calling conventions match; If the loop around _processXXXpass is done in assember too, it's probably be less sensitive)
Um, I just realized this information isn't complete. My functions take a float array as coef param, while libfir will deliver a double array, so the fi_design_coef result needs a deep copy to a float array. Attached the enginefilterbutterworth.cpp I'm using (filterstuff.h has just the prototypes).


Regards,
Andreas
/***************************************************************************
 *      enginefilter.cpp - Wrapper for FidLib Filter Library	           *
 *			----------------------                             *
 *   copyright      : (C) 2007 by John Sully                               *
 *   email          : [email protected]                                *
 *                                                                         *
 **************************************************************************/

/***************************************************************************
*                                                                         *
*   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.                                   *
*                                                                         *
***************************************************************************/



#include "enginefilterbutterworth8.h"
#include "enginefilter.h"
#include "engineobject.h"
#include "../lib/fidlib-0.9.9/fidlib.h"

extern "C"
{
#include "filterstuff.h"
}


inline double zap_denormal2(CSAMPLE x)
{
    // fabs too slow on Windows...
    CSAMPLE absx;
    if (x<0)
        absx = -x;
    else
        absx = x;

    return (absx > 1e-15f && absx < 1e15f) ? x : 0.f;
}


inline void zap_buffer_denormals2(CSAMPLE *buf, int bufSize)
{
	for(int i=0; i < bufSize; i++)
		buf[i] = zap_denormal2(buf[i]);
}


#define FILTERORDER 4
EngineFilterButterworth8::EngineFilterButterworth8(filterType type, int sampleRate, double freqCorner1, double freqCorner2)
{
	m_type = type;


   double m_coef[MAX_COEFS];

   switch(type)
	{
		case FILTER_LOWPASS:
			m_bufSize = FILTERORDER*2;
			Q_ASSERT(freqCorner2 == 0);
			m_coef[0] = 1 * fid_design_coef(m_coef + 1, m_bufSize, "LpBu8", sampleRate, freqCorner1, 0, 0);
			break;

		case FILTER_BANDPASS:
			m_bufSize = FILTERORDER*4;
			m_coef[0]= 1 * fid_design_coef(m_coef + 1, m_bufSize, "BpBu8", sampleRate, freqCorner1, freqCorner2, 0);
			break;

		case FILTER_HIGHPASS:
			m_bufSize = FILTERORDER*2;
			Q_ASSERT(freqCorner2 == 0);
			m_coef[0] = 1 * fid_design_coef(m_coef + 1, m_bufSize, "HpBu8", sampleRate, freqCorner1, 0, 0);
			break;
	}

	memset(buf1, 0, sizeof(CSAMPLE)*m_bufSize);
	memset(buf2, 0, sizeof(CSAMPLE)*m_bufSize);
	
	for (int i=0 ; i <= m_bufSize ; i++)
	    coef[i] = (CSAMPLE)m_coef[i];
}

EngineFilterButterworth8::~EngineFilterButterworth8()
{
}

void EngineFilterButterworth8::process(const CSAMPLE *pIn, const CSAMPLE *ppOut, const int iBufferSize)
{
	CSAMPLE * pOutput = (CSAMPLE *)ppOut;
	switch(m_type)
	{
	case FILTER_LOWPASS:
		for(int i=0; i < iBufferSize; i += 2)
		{
			pOutput[i] =     doLowpass(coef, buf1, pIn[i]);
			pOutput[i+1] = doLowpass(coef, buf2, pIn[i+1]);
		}
		break;

	case FILTER_BANDPASS:
		for(int i=0; i < iBufferSize; i += 2)
		{
			pOutput[i] =     doBandpass(coef, buf1, pIn[i]);
			pOutput[i+1] = doBandpass(coef, buf2, pIn[i+1]);
			if(pOutput[i] != pOutput[i])	//Check for NaN
				pOutput[i] = 0;
			if(pOutput[i+1] != pOutput[i+1])	//Check for NaN
				pOutput[i+1] = 0;
		}
		break;

	case FILTER_HIGHPASS:
		for(int i=0; i < iBufferSize; i += 2)
		{
		        pOutput[i] =     doHighpass(coef, buf1, pIn[i]);
			pOutput[i+1] = doHighpass(coef, buf2, pIn[i+1]);
  	       } 
		break;
	}
	zap_buffer_denormals2(buf1, m_bufSize);
	zap_buffer_denormals2(buf2, m_bufSize);
}

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to