view sv/filter/EqualizerFilter.cpp @ 229:7d5d51145b81

support stereo in MultiRealTimeFilter and integrate Equalizer filter
author lbajardsilogic
date Wed, 05 Mar 2008 14:08:57 +0000
parents 3200ed3fc957
children 70b88fbbfb5c
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*	Sound Access	
		EASAIER client application.	
		Silogic 2007. Laure Bajard. 
	
	Integration of the filter provided by:
	Dublin Institute of Technology - Audio Research Group 2007
	www.audioresearchgroup.com
	Author: Dan Barry

	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.  See the file    
	COPYING included with this distribution for more information.
*/

#include <math.h>
#include <iostream>

#include "EqualizerFilter.h"

#include  "FFTReal.h"
#include  "DSP.h"

#include "system/System.h"
#include "main/MainWindow.h"


EqualizerFilter::EqualizerFilter() : PropertyContainer()
{
	setObjectName("Equalizer");

	for(int i = 0 ; i < 400 ; i++){
		m_eqcurve.push_back(0);
	}

	m_curve = (float *) calloc(400, sizeof(float));

	setFilterEnabled(false);		
}

EqualizerFilter::~EqualizerFilter()
{
	m_eqcurve.clear();
}

EqualizerFilter::PropertyList EqualizerFilter::getProperties() const
{
	PropertyList list;
    list.push_back("Equalizer");
    list.push_back("Enable");
	return list;
}

QString EqualizerFilter::getPropertyLabel(const PropertyName &name) const
{
    if (name == "Equalizer") return tr("Equalizer");
    return "";
}

EqualizerFilter::PropertyType EqualizerFilter::getPropertyType(const PropertyName &name) const
{
	if (name == "Equalizer") return PlotProperty;
    if (name == "Enable") return InvalidProperty;
	return InvalidProperty;
}

int EqualizerFilter::getPropertyRangeAndValue(const PropertyName &name,
                                    int *min, int *max, int *deflt) const
{
    //!!! factor this colour handling stuff out into a colour manager class
	int val = 0;

	if (name == "Equalizer") {
        /*if (deflt) *deflt = 0;
		val = (m_peakcheck ? 1 : 0);*/
    }

	if (name == "Enable") {
        if (deflt) *deflt = 0;
		val = (m_enabled ? 1 : 0);
    }

#ifdef DEBUG_FILTERS
	std::cerr << "EqualizerFilter::getPropertyRangeAndValue = " << val << std::endl;
#endif
    return val;
}

QString EqualizerFilter::getPropertyValueLabel(const PropertyName &name,
				    int value) const
{
    return tr("<unknown>");
}

void EqualizerFilter::setProperty(const PropertyName &name, int value)
{
    if (name == "Equalizer"){
		
	} else if (name == "Enable"){
		if (value > 0)
		{
			m_enabled = true;
		} else 
		{
			m_enabled = false;
		}
		emit propertyChanged("Enable");
	} 
#ifdef DEBUG_FILTERS
	std::cerr << "EqualizerFilter::hopfactor = " << hopfactor << std::endl;
	std::cerr << "EqualizerFilter::m_interpfactor = " << m_interpfactor << std::endl;
	std::cerr << "EqualizerFilter::m_hop = " << m_hop << std::endl;
	std::cerr << "EqualizerFilter::skip = " << getRequiredSkipSamples() << std::endl;
#endif

}

void EqualizerFilter::setProperty(const PropertyName &name , QVector<int> value)
{
	if (name == "Equalizer"){
		m_eqcurve.clear();
		for (int i = 0; i < value.size(); i++)
		{
			//if (i < m_eqcurve.size())
			m_eqcurve.push_back(value.at(i));
		}
	}
}

void EqualizerFilter::setFilterEnabled(bool b){
	m_enabled=b;
	emit filterEnabled(m_enabled);
}

void EqualizerFilter::setFilterEnabled(int b){
	m_enabled=b;
	emit filterEnabled(m_enabled);
}

void EqualizerFilter::emitPlotFFTArray(float *signal, int framesize)
{
	log10plot(signal, m_curve, framesize, m_eqcurve.size());	

	emit signalChanged(m_curve);	
}