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