/* Copyright (C) 2001-2002 Stefan Westerfeld stefan@space.twc.de This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include "artsmoduleseffects.h" #include #include #include #include using namespace std; using namespace Arts; static inline bool odd(int x) { return ((x & 1) == 1); } /* returns a blackman window: x is supposed to be in the interval [0..1] */ static inline float blackmanWindow(float x) { if(x < 0) return 0; if(x > 1) return 0; return 0.42-0.5*cos(M_PI*x*2)+0.08*cos(4*M_PI*x); } void firapprox(double *filter, int filtersize, vector& points) { assert((filtersize >= 3) && odd(filtersize)); int fft_size = 8; while(fft_size/2 < filtersize) fft_size *= 2; vector::iterator pi = points.begin(); float lfreq=-2, lval=1.0, rfreq=-1, rval=1.0; float *re = (float*) malloc(fft_size * sizeof(float)); for(int i=0;i rfreq && pi != points.end()) { lfreq = rfreq; rfreq = pi->x; lval = rval; rval = pi->y; pi++; } float pos = (freq-lfreq)/(rfreq-lfreq); float val = lval*(1.0-pos) + rval*pos; //printf("%f %f\n",freq,val); re[i] = re[fft_size-1-i] = val; } float *filter_re = (float*) malloc(fft_size * sizeof(float)); float *filter_im = (float*) malloc(fft_size * sizeof(float)); arts_fft_float (fft_size, 1, re, 0, filter_re, filter_im); for(int i=0;i _frequencies; long _taps; unsigned long bpos; double filter[256]; float lbuffer[256]; float rbuffer[256]; public: Synth_STEREO_FIR_EQUALIZER_impl() { _frequencies.push_back(GraphPoint(0.0,1.0)); _frequencies.push_back(GraphPoint(1.0,1.0)); _taps = 3; for(bpos = 0; bpos < 256; bpos++) lbuffer[bpos] = rbuffer[bpos] = 0.0; calcFilter(); } vector *frequencies() { return new vector(_frequencies); } void frequencies(const vector& newFrequencies) { _frequencies = newFrequencies; calcFilter(); } long taps() { return _taps; } void taps(long newTaps) { arts_return_if_fail(newTaps >= 3 && newTaps <= 255); if(!odd(newTaps)) newTaps++; _taps = newTaps; calcFilter(); } void calcFilter() { firapprox(filter, _taps, _frequencies); } void calculateBlock(unsigned long samples) { for(unsigned i=0;iinsertCatalogue( "artsmodules" ); arts_return_val_if_fail(!object.isNull(), Arts::Widget::null()); Synth_STEREO_FIR_EQUALIZER equalizer = DynamicCast(object); arts_return_val_if_fail(!equalizer.isNull(), Arts::Widget::null()); VBox vbox; vbox.show(); Graph g; g.parent(vbox); g.width(400); g.height(230); g.caption(i18n("a graph").utf8().data()); g.minx(0.0); g.maxx(1.0); g.miny(0.0); g.maxy(1.0); g.show(); GraphLine gline; gline.graph(g); vector *points = equalizer.frequencies(); gline.points(*points); delete points; gline.color("red"); gline.editable(true); connect(gline,"points_changed", equalizer, "frequencies"); g._addChild(gline,"gline"); SpinBox spinbox; spinbox.caption(i18n("channels").utf8().data()); spinbox.min(3); spinbox.max(255); spinbox.value(equalizer.taps()); spinbox.parent(vbox); spinbox.show(); connect(spinbox,"value_changed", equalizer, "taps"); vbox._addChild(spinbox,"spinbox"); vbox._addChild(g,"g"); return vbox; }