Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/engine/enginefilterblock.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           enginefilterblock.cpp  -  description
00003                              -------------------
00004     begin                : Thu Apr 4 2002
00005     copyright            : (C) 2002 by Tue and Ken Haste Andersen
00006     email                :
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 ***************************************************************************/
00017 
00018 #include <QtDebug>
00019 #include "controlpushbutton.h"
00020 #include "controllogpotmeter.h"
00021 #include "engine/enginefilterblock.h"
00022 #include "engine/enginefilteriir.h"
00023 #include "engine/enginefilter.h"
00024 #include "engine/enginefilterbutterworth8.h"
00025 #include "sampleutil.h"
00026 
00027 ControlPotmeter* EngineFilterBlock::s_loEqFreq = NULL;
00028 ControlPotmeter* EngineFilterBlock::s_hiEqFreq = NULL;
00029 ControlPushButton* EngineFilterBlock::s_lofiEq = NULL;
00030 
00031 EngineFilterBlock::EngineFilterBlock(const char * group)
00032 {
00033     ilowFreq = 0;
00034     ihighFreq = 0;
00035     blofi = false;
00036 
00037 #ifdef __LOFI__
00038     low = new EngineFilterIIR(bessel_lowpass4_DJM800,4);
00039     band = new EngineFilterIIR(bessel_bandpass8_DJM800,8);
00040     high = new EngineFilterIIR(bessel_highpass4_DJM800,4);
00041     qDebug() << "Using LoFi EQs";
00042 #else
00043 
00044     //Setup Filter Controls
00045 
00046     if (s_loEqFreq == NULL) {
00047         s_loEqFreq = new ControlPotmeter(ConfigKey("[Mixer Profile]", "LoEQFrequency"), 0., 22040);
00048         s_hiEqFreq = new ControlPotmeter(ConfigKey("[Mixer Profile]", "HiEQFrequency"), 0., 22040);
00049         s_lofiEq = new ControlPushButton(ConfigKey("[Mixer Profile]", "LoFiEQs"));
00050     }
00051 
00052     high = band = low = NULL;
00053 
00054     //Load Defaults
00055     setFilters(true);
00056 
00057 #endif
00058     /*
00059        lowrbj = new EngineFilterRBJ();
00060        lowrbj->calc_filter_coeffs(6, 100., 44100., 0.3, 0., true);
00061        midrbj = new EngineFilterRBJ();
00062        midrbj->calc_filter_coeffs(6, 1000., 44100., 0.3, 0., true);
00063        highrbj = new EngineFilterRBJ();
00064        highrbj->calc_filter_coeffs(8, 10000., 48000., 0.3, 0., true);
00065 
00066        lowrbj = new EngineFilterRBJ();
00067        lowrbj->calc_filter_coeffs(0, 100., 48000., 0.3., 0., false);
00068        highrbj = new EngineFilterRBJ();
00069        highrbj->calc_filter_coeffs(1, 10000., 48000., 0.3., 0., false);
00070      */
00071 
00072     filterpotLow = new ControlLogpotmeter(ConfigKey(group, "filterLow"), 4.);
00073     filterKillLow = new ControlPushButton(ConfigKey(group, "filterLowKill"));
00074     filterKillLow->setToggleButton(true);
00075 
00076     filterpotMid = new ControlLogpotmeter(ConfigKey(group, "filterMid"), 4.);
00077     filterKillMid = new ControlPushButton(ConfigKey(group, "filterMidKill"));
00078     filterKillMid->setToggleButton(true);
00079 
00080     filterpotHigh = new ControlLogpotmeter(ConfigKey(group, "filterHigh"), 4.);
00081     filterKillHigh = new ControlPushButton(ConfigKey(group, "filterHighKill"));
00082     filterKillHigh->setToggleButton(true);
00083 
00084     m_pTemp1 = new CSAMPLE[MAX_BUFFER_LEN];
00085     m_pTemp2 = new CSAMPLE[MAX_BUFFER_LEN];
00086     m_pTemp3 = new CSAMPLE[MAX_BUFFER_LEN];
00087 
00088     memset(m_pTemp1, 0, sizeof(CSAMPLE) * MAX_BUFFER_LEN);
00089     memset(m_pTemp2, 0, sizeof(CSAMPLE) * MAX_BUFFER_LEN);
00090     memset(m_pTemp3, 0, sizeof(CSAMPLE) * MAX_BUFFER_LEN);
00091 }
00092 
00093 EngineFilterBlock::~EngineFilterBlock()
00094 {
00095     delete high;
00096     delete band;
00097     delete low;
00098     delete [] m_pTemp3;
00099     delete [] m_pTemp2;
00100     delete [] m_pTemp1;
00101     delete filterpotLow;
00102     delete filterKillLow;
00103     delete filterpotMid;
00104     delete filterKillMid;
00105     delete filterpotHigh;
00106     delete filterKillHigh;
00107 
00108     // Delete and clear these static controls. We need to clear them so that
00109     // other instances of EngineFilterBlock won't delete them as well.
00110     delete s_loEqFreq;
00111     s_loEqFreq = NULL;
00112     delete s_hiEqFreq;
00113     s_hiEqFreq = NULL;
00114     delete s_lofiEq;
00115     s_lofiEq = NULL;
00116 }
00117 
00118 void EngineFilterBlock::setFilters(bool forceSetting)
00119 {
00120     if((ilowFreq != (int)s_loEqFreq->get()) ||
00121        (ihighFreq != (int)s_hiEqFreq->get()) ||
00122        (blofi != (int)s_lofiEq->get()) || forceSetting)
00123     {
00124         delete low;
00125         delete band;
00126         delete high;
00127         ilowFreq = (int)s_loEqFreq->get();
00128         ihighFreq = (int)s_hiEqFreq->get();
00129         blofi = (int)s_lofiEq->get();
00130         if(blofi)
00131         {
00132             // why is this DJM800 at line ~34 (LOFI ifdef) and just
00133             // bessel_lowpass# here? bkgood
00134             low = new EngineFilterIIR(bessel_lowpass4,4);
00135             band = new EngineFilterIIR(bessel_bandpass,8);
00136             high = new EngineFilterIIR(bessel_highpass4,4);
00137         }
00138         else
00139         {
00140             low = new EngineFilterButterworth8(FILTER_LOWPASS, 44100, (int)s_loEqFreq->get());
00141             band = new EngineFilterButterworth8(FILTER_BANDPASS, 44100, (int)s_loEqFreq->get(), (int)s_hiEqFreq->get());
00142             high = new EngineFilterButterworth8(FILTER_HIGHPASS, 44100, (int)s_hiEqFreq->get());
00143         }
00144 
00145     }
00146 }
00147 
00148 void EngineFilterBlock::process(const CSAMPLE * pIn, const CSAMPLE * pOut, const int iBufferSize)
00149 {
00150     CSAMPLE * pOutput = (CSAMPLE *)pOut;
00151     float fLow=0.f, fMid=0.f, fHigh=0.f;
00152 
00153 
00154     if (filterKillLow->get()==0.)
00155         fLow = filterpotLow->get(); //*0.7;
00156     if (filterKillMid->get()==0.)
00157         fMid = filterpotMid->get(); //*1.1;
00158     if (filterKillHigh->get()==0.)
00159         fHigh = filterpotHigh->get(); //*1.2;
00160 
00161 #ifndef __LOFI__
00162     setFilters();
00163 #endif
00164 
00165     low->process(pIn, m_pTemp1, iBufferSize);
00166     band->process(pIn, m_pTemp2, iBufferSize);
00167     high->process(pIn, m_pTemp3, iBufferSize);
00168 
00169     SampleUtil::copy3WithGain(pOutput,
00170                               m_pTemp1, fLow,
00171                               m_pTemp2, fMid,
00172                               m_pTemp3, fHigh, iBufferSize);
00173 }
00174 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines