From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun/library/noatunarts/FFTScopes.cpp | 422 ++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 noatun/library/noatunarts/FFTScopes.cpp (limited to 'noatun/library/noatunarts/FFTScopes.cpp') diff --git a/noatun/library/noatunarts/FFTScopes.cpp b/noatun/library/noatunarts/FFTScopes.cpp new file mode 100644 index 00000000..ab2a3bbb --- /dev/null +++ b/noatun/library/noatunarts/FFTScopes.cpp @@ -0,0 +1,422 @@ +/* +Copyright (C) 2000 Stefan Westerfeld + 2000 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., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + +*/ + +#include "noatunarts.h" +#include "artsflow.h" +#include "fft.h" +#include +#include +#include + +#include + +using namespace std; +using namespace Arts; + +namespace Noatun +{ + +#define SAMPLES 4096 + +static void doFft(float combine, float *inBuffer, vector &scope) +{ + float out_real[SAMPLES],out_img[SAMPLES]; + fft_float(SAMPLES,0,inBuffer,0,out_real,out_img); + + scope.clear(); + + int previous=0; + int index=20; + + while (previous < 2048 && index < 2048) + { + int end = int(std::exp(double(index)*combine)); + float xrange = 0.0; + + while (previous < end) + { + xrange += (std::fabs(out_img[previous]) + std::fabs(out_real[previous])); + previous++; + } + + xrange /= float(SAMPLES); + scope.push_back(xrange); + + index++; + } +} + + +class FFTScopeStereo_impl : public FFTScopeStereo_skel, public StdSynthModule +{ +protected: + vector mScopeLeft; + vector mScopeRight; + + float mCombine; + + float *mWindow; + + float *mInBufferLeft, *mInBufferRight; + unsigned long mInBufferPos; + +public: + void bandResolution(float res) { mCombine=res; } + float bandResolution() { return mCombine; } + void streamInit() + { + unsigned long i; + for(i=0;i *scopeLeft() + { + return new vector(mScopeLeft); + } + vector *scopeRight() + { + return new vector(mScopeRight); + } + /* + in audio stream inleft, inright; + out audio stream outleft, outright; + */ + void calculateBlock(unsigned long samples) + { + unsigned long i; + for(i=0;i mScope; + + float mCombine; + + float *mWindow; + float *mInBuffer; + unsigned long mInBufferPos; + +public: + void bandResolution(float res) { mCombine=res; } + float bandResolution() { return mCombine; } + void streamInit() + { + unsigned long i; + for(i=0;i *scope() + { + return new vector(mScope); + } + + /* + in audio stream inleft, inright; + out audio stream outleft, outright; + */ + void calculateBlock(unsigned long samples) + { + unsigned long i; + + float *inBufferIt=mInBuffer+mInBufferPos; + float *inleftIt=inleft; + float *inrightIt=inright; + float *windowIt=mWindow+mInBufferPos; + + for(i=0;i *scope() + { + vector *buf = new vector; + buf->resize(mScopeLength); + char *front = (char *)(&buf->front()); + memcpy(front, mCurrent, (mScopeEnd - mCurrent) * sizeof(float)); + memcpy(front + (mScopeEnd - mCurrent)*sizeof(float), mScope, + (mCurrent - mScope) * sizeof(float)); + return buf; + } + + void buffer(long len) + { + delete [] mScope; + + mScopeLength=len; + mScope=new float[len]; + mScopeEnd=mScope+mScopeLength; + mCurrent=mScope; + + memset(mScope, 0, mScopeLength); + } + + long buffer() + { + return mScopeLength; + } + + void calculateBlock(unsigned long samples) + { + for (unsigned long i=0; i=mScopeEnd) + mCurrent=mScope; + } + + memcpy(outleft, inleft, sizeof(float)*samples); + memcpy(outright, inright, sizeof(float)*samples); + + } + + RawScope_impl() + { + mScope=0; + buffer(512); + + } + + ~RawScope_impl() + { + delete [] mScope; + } + + AutoSuspendState autoSuspend() { return asSuspend; } +}; + +class RawScopeStereo_impl : public RawScopeStereo_skel, public StdSynthModule +{ +protected: + int mScopeLength; + + float *mScopeLeft; + float *mScopeEndLeft; + float *mCurrentLeft; + + float *mScopeRight; + float *mScopeEndRight; + float *mCurrentRight; + +public: + vector *scopeLeft() + { + vector *buf = new vector; + buf->resize(mScopeLength); + char *front = (char *)(&buf->front()); + memcpy(front, mCurrentLeft, (mScopeEndLeft - mCurrentLeft) * sizeof(float)); + memcpy(front + (mScopeEndLeft - mCurrentLeft)*sizeof(float), mScopeLeft, + (mCurrentLeft - mScopeLeft) * sizeof(float)); + return buf; + } + + vector *scopeRight() + { + vector *buf = new vector; + buf->resize(mScopeLength); + char *front = (char *)(&buf->front()); + memcpy(front, mCurrentRight, (mScopeEndRight - mCurrentRight) * sizeof(float)); + memcpy(front + (mScopeEndRight - mCurrentRight)*sizeof(float), mScopeRight, + (mCurrentRight - mScopeRight) * sizeof(float)); + return buf; + } + + void buffer(long len) + { + delete [] mScopeRight; + delete [] mScopeLeft; + + mScopeLength=len; + mScopeRight=new float[len]; + mScopeLeft=new float[len]; + mScopeEndRight=mScopeRight+mScopeLength; + mScopeEndLeft=mScopeLeft+mScopeLength; + mCurrentRight=mScopeRight; + mCurrentLeft=mScopeLeft; + + memset(mScopeRight, 0, mScopeLength); + memset(mScopeLeft, 0, mScopeLength); + } + + long buffer() + { + return mScopeLength; + } + + void calculateBlock(unsigned long samples) + { + for (unsigned long i=0; i=mScopeEndLeft) + mCurrentLeft=mScopeLeft; + } + + for (unsigned long i=0; i=mScopeEndRight) + mCurrentRight=mScopeRight; + } + + memcpy(outleft, inleft, sizeof(float)*samples); + memcpy(outright, inright, sizeof(float)*samples); + } + + RawScopeStereo_impl() + { + mScopeLeft=mScopeRight=0; + buffer(512); + + } + + ~RawScopeStereo_impl() + { + delete [] mScopeRight; + delete [] mScopeLeft; + } + + AutoSuspendState autoSuspend() { return asSuspend; } +}; + + + +REGISTER_IMPLEMENTATION(FFTScope_impl); +REGISTER_IMPLEMENTATION(FFTScopeStereo_impl); +REGISTER_IMPLEMENTATION(RawScope_impl); +REGISTER_IMPLEMENTATION(RawScopeStereo_impl); + +} + +#undef SAMPLES -- cgit v1.2.1