/* Copyright (C) 2001 Charles Samuels 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "noatunarts.h" #include "artsflow.h" #include "fft.h" #include #include #include using namespace std; using namespace Arts; /** * This class is _VERY_ picky * which is why Noatun has it's own Equalizer class, * that does all the error checking and sends it to here **/ namespace Noatun { void resize(vector &vec, unsigned int newsize) { while (newsize < vec.size()) vec.pop_back(); while (newsize > vec.size()) vec.push_back(0.0); } class Equalizer_impl : public Equalizer_skel, public StdSynthModule { vector mLevels; vector mBandLeft, mBandRight; vector mLevelWidths; vector mLevelCenters; bool mEnabled; float mPreamp; float *mBuffer; unsigned int mBufferLength; void reinit() { mBandLeft.clear(); mBandRight.clear(); for (unsigned int i=0; i< mLevelWidths.size(); ++i) { BandPassInfo nfo; BandPassInit(&nfo, mLevelCenters[i], mLevelWidths[i]); mBandLeft.push_back(nfo); mBandRight.push_back(nfo); } } public: void set(const std::vector& levels, const std::vector& centers, const std::vector& widths) { mLevelCenters=centers; mLevelWidths=widths; mLevels=levels; reinit(); } vector* levelCenters() { return new vector(mLevelCenters); } void levelCenters(const vector &l) { mLevelCenters=l; reinit(); } vector* levelWidths() { return new vector(mLevelWidths); } void levelWidths(const vector &l) { mLevelWidths=l; reinit(); } vector* levels() { return new vector(mLevels); } void levels(const vector &l) { mLevels=l; reinit(); } long bands() { return mLevels.size(); } void bands(long b) { resize(mLevels, (int)b); resize(mLevelWidths, (int)b); resize(mLevelCenters, (int)b); reinit(); } long enabled() { return (long)mEnabled; } void enabled(long enabled) { mEnabled=(bool)enabled; } float preamp() { return mPreamp; } void preamp(float a) { mPreamp=a; } void streamInit() { } void streamStart() { } /* BandPassInit(&nfoLeft, 15000.0, 5000.0); * BandPassInit(&nfoLeft, 15000.0, 5000.0); */ void calculateBlock(unsigned long samples) { // works by separating the bands // multiplying, then adding if (mEnabled && samples && &mLevels.front()) { { // preamp; float *left=inleft; float *right=inright; float *end=left+samples; float *oleft=outleft; float *oright=outright; while (left mLevels; vector mBandLeft, mBandRight; vector mLevelWidths; vector mLevelCenters; bool mEnabled; float mPreamp; void reinit() { mBandLeft.clear(); mBandRight.clear(); for (unsigned int i=0; i< mLevelWidths.size(); ++i) { BandPassInfo nfo; BandPassInit(&nfo, mLevelCenters[i], mLevelWidths[i]); mBandLeft.push_back(nfo); mBandRight.push_back(nfo); } } public: void set(const std::vector& levels, const std::vector& centers, const std::vector& widths) { mLevelCenters=centers; mLevelWidths=widths; mLevels=levels; reinit(); } vector* levelCenters() { return new vector(mLevelCenters); } void levelCenters(const vector &l) { mLevelCenters=l; reinit(); } vector* levelWidths() { return new vector(mLevelWidths); } void levelWidths(const vector &l) { mLevelWidths=l; reinit(); } vector* levels() { return new vector(mLevels); } void levels(const vector &l) { mLevels=l; reinit(); } long bands() { return mLevels.size(); } void bands(long b) { resize(mLevels, (int)b); resize(mLevelWidths, (int)b); resize(mLevelCenters, (int)b); reinit(); } long enabled() { return (long)mEnabled; } void enabled(long enabled) { mEnabled=(bool)enabled; } float preamp() { return mPreamp; } void preamp(float a) { mPreamp=a; } void streamInit() { } void streamStart() { } /* BandPassInit(&nfoLeft, 15000.0, 5000.0); * BandPassInit(&nfoLeft, 15000.0, 5000.0); */ void calculateBlock(unsigned long samples) { #ifdef __i386__ // works by separating the bands // multiplying, then adding if (mEnabled && samples) { if (*inleft + *inright == 0.0) goto copy; // just shut up :) { // preamp; float *left=inleft; float *right=inright; float *end=left+samples; float *oleft=outleft; float *oright=outright; while (left