From 84da08d7b7fcda12c85caeb5a10b4903770a6f69 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/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- noatun-plugins/nexscope/input.cpp | 238 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 noatun-plugins/nexscope/input.cpp (limited to 'noatun-plugins/nexscope/input.cpp') diff --git a/noatun-plugins/nexscope/input.cpp b/noatun-plugins/nexscope/input.cpp new file mode 100644 index 0000000..4c787e7 --- /dev/null +++ b/noatun-plugins/nexscope/input.cpp @@ -0,0 +1,238 @@ + +#include "nex.h" +#include "convolve.h" + +#include +#include +#include +#include + +Input::Input() +{ + memset(haystack, 0, sizeof(float)*512); + state=new convolve_state; + + float d, *costab, *sintab; + long ul, ndiv2 = 512 / 2; + + for (costab = fhtTab, sintab = fhtTab + 512 / 2 + 1, ul = 0; ul < 512; ul++) + { + d = PI * ul / ndiv2; + *costab = *sintab = ::cos(d); + + costab += 2, sintab += 2; + if (sintab > fhtTab + 512 * 2) + sintab = fhtTab + 1; + } + + notifier=0; + mScope=0; + + connect(); +} + +Input::~Input() +{ + delete mScope; + std::cerr<< "Scope gone"<< std::endl; + delete notifier; +// delete [] audio[2]; +// delete [] audio[3]; +// delete [] audio[4]; +// delete [] audio[5]; +} + +void Input::setConvolve(bool on) +{ + mConvolve=on; +} + +void Input::connect() +{ + do + { + delete notifier; + delete mScope; + ok=true; + mScope=new StereoScope(10, Visualization::noatunPid()); + mScope->setSamples(samples>(512+256) ? samples : samples+256); + + notifier=new QObject; + new BoolNotifier(&ok, new ExitNotifier(Visualization::noatunPid(), notifier), notifier); + } while (!mScope->connected()); +} + +// [0] pcm left +// [1] pcm right +// [2] pcm center +// [3] FFT (FHT) left +// [4] FFT right +// [5] FFT center + +void Input::getAudio(float **audio) +{ + static bool first=true; + if (first) + { + audio[2]=new float[samples]; + audio[3]=new float[fhtsamples]; + audio[4]=new float[fhtsamples]; + audio[5]=new float[fhtsamples]; + first=false; + } + + if (!ok || !mScope->connected()) + { + std::cerr << "reconnect" <setSamples(samples); + } + std::vector *left, *right; + mScope->scopeData(left, right); + + register float *inleft=&*left->begin(); + register float *inright=&*right->begin(); + + + int offset=0; + if (mConvolve) + { // find the offset + for (register int i=0; i<512+256; ++i) + temp[i]=inleft[i]+inright[i]; + offset=::convolve_match(haystack, temp, state); + if (offset==-1) offset=0; + inleft+=offset; + inright+=offset; + + for (register int i=0; i<512; ++i) + { + haystack[i]*=.5; + haystack[i]+=temp[i+offset]; + } + } + + memcpy(outleft, inleft, samples*sizeof(float)); + memcpy(outright, inright, samples*sizeof(float)); + + audio[0]=outleft; + audio[1]=outright; + + // center channel + for (int i=0; i