/*************************************************************************** * 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 TQMemArray(); //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 TQMemArray 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); /*TQMemArray 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 TQString &key) const { TQStringList sl; for(int x=0;xwriteEntry(key,sl); } void VoiceSignature::read(KConfigBase *cfg, const TQString &key) { TQStringList sl=cfg->readListEntry(key); for(int x=0;x