PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/liblastfm2/src/fingerprint/fplib/Filter.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 128 lines | 92 code | 17 blank | 19 comment | 22 complexity | 2fdb1948870510b2d5a6e9bdfa26f253 MD5 | raw file
  1/*
  2   Copyright 2005-2009 Last.fm Ltd. <mir@last.fm>
  3
  4   This file is part of liblastfm.
  5
  6   liblastfm is free software: you can redistribute it and/or modify
  7   it under the terms of the GNU General Public License as published by
  8   the Free Software Foundation, either version 3 of the License, or
  9   (at your option) any later version.
 10
 11   liblastfm is distributed in the hope that it will be useful,
 12   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14   GNU General Public License for more details.
 15
 16   You should have received a copy of the GNU General Public License
 17   along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
 18*/
 19#include <iostream>
 20#include <algorithm> // for max
 21#include <vector>
 22
 23#include "Filter.h"
 24#include "fp_helper_fun.h"
 25
 26using namespace std;
 27
 28namespace fingerprint
 29{
 30
 31Filter::Filter(unsigned int id, float threshold, float weight) 
 32: id(id), threshold(threshold), weight(weight)
 33{
 34    float time_rate = 1.5;
 35        
 36    unsigned int t = 1;
 37    vector<unsigned int> time_lengths;
 38
 39    while (t < KEYWIDTH) 
 40   {
 41        time_lengths.push_back(t);
 42      t = max( static_cast<unsigned int>( round__(time_rate*t) ) +
 43               static_cast<unsigned int>( round__(time_rate*t) % 2),
 44               t+1 );
 45    }
 46
 47    unsigned int filter_count = 0;
 48
 49    for (wt = 1; wt <= time_lengths.size(); wt++) 
 50   {
 51        for (wb = 1; wb <= NBANDS; wb++) 
 52      {
 53            for (first_band = 1; first_band <= NBANDS - wb + 1;
 54                 first_band++) 
 55         {
 56                unsigned int time = time_lengths[wt-1];
 57                filter_count++;
 58
 59                if (filter_count == id) 
 60            {
 61                    wt = time_lengths[wt-1];
 62                    filter_type = 1;
 63                    return;
 64                }
 65
 66                if (time > 1) 
 67            {
 68                    filter_count++;
 69                    if (filter_count == id) 
 70               {
 71                        wt = time_lengths[wt-1];
 72                        filter_type = 2;
 73                        return;
 74                    }
 75                }
 76                    
 77                if (wb > 1) 
 78            {
 79                    filter_count++;
 80                    if (filter_count == id) 
 81               {
 82                        wt = time_lengths[wt-1];
 83                        filter_type = 3;
 84                        return;
 85                    }
 86                }
 87
 88                if (time > 1 && wb > 1) 
 89            {
 90                    filter_count++;
 91                    if (filter_count == id) 
 92               {
 93                        wt = time_lengths[wt-1];
 94                        filter_type = 4;
 95                        return;
 96                    }
 97                }
 98                
 99                if (time > 3) 
100            {
101                    filter_count++;
102                    if (filter_count == id) 
103               {
104                        wt = time_lengths[wt-1];
105                        filter_type = 5;
106                        return;
107                    }
108                }
109                
110                if (wb > 3) 
111            {
112                    filter_count++;
113                    if (filter_count == id) 
114               {
115                        wt = time_lengths[wt-1];
116                        filter_type = 6;
117                        return;
118                    }
119                }
120
121            } // for first_band
122        } // for wb
123    } // for wt
124}
125
126} // end of namespace fingerprint
127
128// -----------------------------------------------------------------------------