From 4aed2c8219774f5d797760606b8489a92ddc5163 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/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- khotkeys/shared/voicesignature.cpp | 422 +++++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 khotkeys/shared/voicesignature.cpp (limited to 'khotkeys/shared/voicesignature.cpp') diff --git a/khotkeys/shared/voicesignature.cpp b/khotkeys/shared/voicesignature.cpp new file mode 100644 index 000000000..c77c278b3 --- /dev/null +++ b/khotkeys/shared/voicesignature.cpp @@ -0,0 +1,422 @@ +/*************************************************************************** + * Copyright (C) 2005 by Olivier Goffart * + * ogoffart@kde.org * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "voicesignature.h" +#include "sound.h" +#include + +#include +#ifdef PI +#undef PI +#endif +#define PI (2.0 * asin(1.0)) + + +#include +#include + +#undef Complex + +namespace KHotKeys +{ + + +inline static float ABS(float X) +{ + return (X>0) ? X : -X ; +} +inline static int MAX(int X , int Y) +{ + return (X>Y) ? X : Y ; +} +inline static int MIN(int X , int Y) +{ + return (X fft(const Sound& sound, unsigned int start, unsigned int stop) +{ + if(start>=stop || sound.size() == 0) + return QMemArray(); + + //We need a sample with a size of a power of two + uint size=stop-start; + unsigned short log2size=0; + while( (1< size/4 || 1< sound.size() ) + { + log2size--; + diff=(1<sound.size()) + { + start2-= stop2 - sound.size(); + stop2=sound.size(); + if(start2<0) + { + stop2-=start2; + start2=0; + } + } + + //Generate an array to work in + QMemArray samples(size); + + //Fill it with samples in the "reversed carry" order + int rev_carry = 0; + for (uint f = 0; f < size - 1; f++) + { + samples[f]=sound.at(start2+rev_carry)* hamming(rev_carry, size); +// KDEBUG(rev_carry); + int mask = size>>1; // N / 2 + // add 1 backwards + while (rev_carry >= mask) + { + rev_carry -= mask; // turn off this bit + mask >>= 1; + } + rev_carry += mask; + } + samples[size-1]=sound.at(start2+size-1)*hamming(size-1, size); + + //FFT + for(uint level=0; level < log2size; level++) + { + for( int k=0; k< (size>>1) ; k++) + { + uint indice1 = (k << (level+1) ) % (size-1); // (k*2*2^l)%(N-1) + uint indice2 = indice1 + (1< result(size); + for(uint f=0;f VoiceSignature::fft(const Sound& sound, unsigned int start, unsigned int stop) +{ + return KHotKeys::fft(sound, start, stop); + /*QMemArray result(8000); + for(int f=0; f<8000;f++) + { + Complex c(0); + + for(uint x=start; xWINDOW_MINIMUM*unit) + isNoise=true; + + for(uint x=unit; xWINDOW_MINIMUM*unit && isNoise) + return false; + + stop=MIN(length,stop+WINDOW_MINIMUM_ECART); + start=MAX(0 ,start-WINDOW_MINIMUM_ECART); + + if(_start) + *_start=start; + if(_stop) + *_stop=stop; + return start fourrier=fft(sound, w_start,w_stop); + + temp_fft+=t.restart(); + + //MEL conversion + double mel_start=HZ_TO_MEL(FFT_RANGE_INF); + uint mel_stop=HZ_TO_MEL(FFT_RANGE_SUP); + + for(int four=0; four > VoiceSignature::pond; + + + +void VoiceSignature::write(KConfigBase *cfg, const QString &key) const +{ + QStringList sl; + for(int x=0;xwriteEntry(key,sl); +} + +void VoiceSignature::read(KConfigBase *cfg, const QString &key) +{ + QStringList sl=cfg->readListEntry(key); + for(int x=0;x