Browse Source

Updated bindings to match new Bliss version

Polochon-street 4 years ago
parent
commit
e19fe82d9f
4 changed files with 22 additions and 41 deletions
  1. 2
    2
      CMakeLists.txt
  2. 8
    15
      mpd/client.py
  3. 5
    13
      scripts/build_cache.py
  4. 7
    11
      src/analysis.c

+ 2
- 2
CMakeLists.txt View File

@@ -7,7 +7,7 @@ add_subdirectory (bliss)
7 7
 file (GLOB COMMON_SRC "src/*.c")
8 8
 
9 9
 find_package(PkgConfig REQUIRED)
10
-pkg_check_modules(MULTIMEDIA REQUIRED libavformat libavutil libavcodec)
10
+pkg_check_modules(MULTIMEDIA REQUIRED libavformat libavutil libavcodec fftw3)
11 11
 include_directories(${MULTIMEDIA_INCLUDE_DIRS} include/ bliss/include)
12 12
 link_directories(${MULTIMEDIA_LIBRARY_DIRS})
13 13
 add_definitions(${MULTIMEDIA_CFLAGS_OTHER})
@@ -19,6 +19,6 @@ add_executable (blissify
19 19
 target_link_libraries (blissify
20 20
     m
21 21
     sqlite3
22
-    bliss)
22
+    bliss fftw3)
23 23
 
24 24
 install (TARGETS blissify DESTINATION /usr/bin)

+ 8
- 15
mpd/client.py View File

@@ -19,6 +19,7 @@ import sys
19 19
 
20 20
 import mpd
21 21
 
22
+# logging.basicConfig(level='DEBUG')
22 23
 
23 24
 class PersistentMPDClient(mpd.MPDClient):
24 25
     """
@@ -149,7 +150,7 @@ def main(queue_length):
149 150
     logging.info("Currently played song is %s." % (current_song,))
150 151
 
151 152
     # Get current song coordinates
152
-    cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
153
+    cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
153 154
     current_song_coords = cur.fetchone()
154 155
     if current_song_coords is None:
155 156
         logging.error("Current song %s is not in db. You should update the db." %
@@ -161,7 +162,7 @@ def main(queue_length):
161 162
     for i in range(queue_length):
162 163
         # Get cached distances from db
163 164
         cur.execute(
164
-            "SELECT id, filename, distance, similarity, tempo1, tempo2, tempo3, amplitude, frequency, attack FROM (SELECT s2.id AS id, s2.filename AS filename, s2.tempo1 AS tempo1, s2.tempo2 AS tempo2, s2.tempo3 AS tempo3, s2.amplitude AS amplitude, s2.frequency AS frequency, s2.attack AS attack, distances.distance AS distance, distances.similarity AS similarity FROM distances INNER JOIN songs AS s1 ON s1.id=distances.song1 INNER JOIN songs AS s2 on s2.id=distances.song2 WHERE s1.filename=? UNION SELECT s1.id as id, s1.filename AS filename, s1.tempo1 AS tempo1, s1.tempo2 AS tempo2, s1.tempo3 AS tempo3, s1.amplitude AS amplitude, s1.frequency AS frequency, s1.attack AS attack, distances.distance as distance, distances.similarity AS similarity FROM distances INNER JOIN songs AS s1 ON s1.id=distances.song1 INNER JOIN songs AS s2 on s2.id=distances.song2 WHERE s2.filename=?) ORDER BY distance ASC",
165
+            "SELECT id, filename, distance, similarity, tempo, amplitude, frequency, attack FROM (SELECT s2.id AS id, s2.filename AS filename, s2.tempo AS tempo, s2.amplitude AS amplitude, s2.frequency AS frequency, s2.attack AS attack, distances.distance AS distance, distances.similarity AS similarity FROM distances INNER JOIN songs AS s1 ON s1.id=distances.song1 INNER JOIN songs AS s2 on s2.id=distances.song2 WHERE s1.filename=? UNION SELECT s1.id as id, s1.filename AS filename, s1.tempo AS tempo, s1.amplitude AS amplitude, s1.frequency AS frequency, s1.attack AS attack, distances.distance as distance, distances.similarity AS similarity FROM distances INNER JOIN songs AS s1 ON s1.id=distances.song1 INNER JOIN songs AS s2 on s2.id=distances.song2 WHERE s2.filename=?) ORDER BY distance ASC",
165 166
             (current_song_coords["filename"], current_song_coords["filename"]))
166 167
         cached_distances = [row
167 168
                             for row in cur.fetchall()
@@ -193,7 +194,7 @@ def main(queue_length):
193 194
             continue
194 195
 
195 196
         # Get all other songs coordinates and iterate randomly on them
196
-        cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs ORDER BY RANDOM()")
197
+        cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs ORDER BY RANDOM()")
197 198
         for tmp_song_data in cur.fetchall():
198 199
             if(tmp_song_data["filename"] == current_song_coords["filename"] or
199 200
                tmp_song_data["filename"] in cached_distances_songs or
@@ -203,32 +204,24 @@ def main(queue_length):
203 204
                 continue
204 205
             # Compute distance
205 206
             distance = math.sqrt(
206
-                (current_song_coords["tempo1"] - tmp_song_data["tempo1"])**2 +
207
-                (current_song_coords["tempo2"] - tmp_song_data["tempo2"])**2 +
208
-                (current_song_coords["tempo3"] - tmp_song_data["tempo3"])**2 +
207
+                (current_song_coords["tempo"] - tmp_song_data["tempo"])**2 +
209 208
                 (current_song_coords["amplitude"] - tmp_song_data["amplitude"])**2 +
210 209
                 (current_song_coords["frequency"] - tmp_song_data["frequency"])**2 +
211 210
                 (current_song_coords["attack"] - tmp_song_data["attack"])**2
212 211
             )
213 212
             similarity = (
214
-                (current_song_coords["tempo1"] * tmp_song_data["tempo1"] +
215
-                 current_song_coords["tempo2"] * tmp_song_data["tempo2"] +
216
-                 current_song_coords["tempo3"] * tmp_song_data["tempo3"] +
213
+                (current_song_coords["tempo"] * tmp_song_data["tempo"] +
217 214
                  current_song_coords["amplitude"] * tmp_song_data["amplitude"] +
218 215
                  current_song_coords["frequency"] * tmp_song_data["frequency"] +
219 216
                  current_song_coords["attack"] * tmp_song_data["attack"]) /
220 217
                 (
221 218
                     math.sqrt(
222
-                        current_song_coords["tempo1"]**2 +
223
-                        current_song_coords["tempo2"]**2 +
224
-                        current_song_coords["tempo3"]**2 +
219
+                        current_song_coords["tempo"]**2 +
225 220
                         current_song_coords["amplitude"]**2 +
226 221
                         current_song_coords["frequency"]**2 +
227 222
                         current_song_coords["attack"]**2) *
228 223
                     math.sqrt(
229
-                        tmp_song_data["tempo1"]**2 +
230
-                        tmp_song_data["tempo2"]**2 +
231
-                        tmp_song_data["tempo3"]**2 +
224
+                        tmp_song_data["tempo"]**2 +
232 225
                         tmp_song_data["amplitude"]**2 +
233 226
                         tmp_song_data["frequency"]**2 +
234 227
                         tmp_song_data["attack"]**2)

+ 5
- 13
scripts/build_cache.py View File

@@ -25,7 +25,7 @@ def main():
25 25
     cached_distances = cur.fetchall()
26 26
 
27 27
     # Get all songs
28
-    cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs")
28
+    cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs")
29 29
     all_songs = cur.fetchall()
30 30
 
31 31
     for i in range(len(all_songs)):
@@ -42,32 +42,24 @@ def main():
42 42
                 continue
43 43
             # Compute distance
44 44
             distance = math.sqrt(
45
-                (song1["tempo1"] - song2["tempo1"])**2 +
46
-                (song1["tempo2"] - song2["tempo2"])**2 +
47
-                (song1["tempo3"] - song2["tempo3"])**2 +
45
+                (song1["tempo"] - song2["tempo"])**2 +
48 46
                 (song1["amplitude"] - song2["amplitude"])**2 +
49 47
                 (song1["frequency"] - song2["frequency"])**2 +
50 48
                 (song1["attack"] - song2["attack"])**2
51 49
             )
52 50
             similarity = (
53
-                (song1["tempo1"] * song2["tempo1"] +
54
-                 song1["tempo2"] * song2["tempo2"] +
55
-                 song1["tempo3"] * song2["tempo3"] +
51
+                (song1["tempo"] * song2["tempo"] +
56 52
                  song1["amplitude"] * song2["amplitude"] +
57 53
                  song1["frequency"] * song2["frequency"] +
58 54
                  song1["attack"] * song2["attack"]) /
59 55
                 (
60 56
                     math.sqrt(
61
-                        song1["tempo1"]**2 +
62
-                        song1["tempo2"]**2 +
63
-                        song1["tempo3"]**2 +
57
+                        song1["tempo"]**2 +
64 58
                         song1["amplitude"]**2 +
65 59
                         song1["frequency"]**2 +
66 60
                         song1["attack"]**2) *
67 61
                     math.sqrt(
68
-                        song2["tempo1"]**2 +
69
-                        song2["tempo2"]**2 +
70
-                        song2["tempo3"]**2 +
62
+                        song2["tempo"]**2 +
71 63
                         song2["amplitude"]**2 +
72 64
                         song2["frequency"]**2 +
73 65
                         song2["attack"]**2)

+ 7
- 11
src/analysis.c View File

@@ -47,9 +47,7 @@ int _init_db(char *data_folder, char* db_path)
47 47
     }
48 48
     dberr = sqlite3_exec(dbh, "CREATE TABLE IF NOT EXISTS songs( \
49 49
         id INTEGER PRIMARY KEY, \
50
-        tempo1 REAL, \
51
-        tempo2 REAL, \
52
-        tempo3 REAL, \
50
+        tempo REAL, \
53 51
         amplitude REAL, \
54 52
         frequency REAL, \
55 53
         attack REAL, \
@@ -153,7 +151,7 @@ int _parse_music_helper(
153 151
     }
154 152
     // Insert song analysis in database
155 153
     dberr = sqlite3_prepare_v2(dbh,
156
-            "INSERT INTO songs(tempo1, tempo2, tempo3, amplitude, frequency, attack, filename) VALUES(?, ?, ?, ?, ?, ?, ?)",
154
+            "INSERT INTO songs(tempo, amplitude, frequency, attack, filename) VALUES(?, ?, ?, ?, ?)",
157 155
             -1, &res, 0);
158 156
     if (SQLITE_OK != dberr) {
159 157
         fprintf(stderr, "Error while inserting data in db: %s\n\n", sqlite3_errmsg(dbh));
@@ -170,13 +168,11 @@ int _parse_music_helper(
170 168
         // Pass file
171 169
         return 1;
172 170
     }
173
-    sqlite3_bind_double(res, 1, song_analysis.force_vector.tempo1);
174
-    sqlite3_bind_double(res, 2, song_analysis.force_vector.tempo2);
175
-    sqlite3_bind_double(res, 3, song_analysis.force_vector.tempo3);
176
-    sqlite3_bind_double(res, 4, song_analysis.force_vector.amplitude);
177
-    sqlite3_bind_double(res, 5, song_analysis.force_vector.frequency);
178
-    sqlite3_bind_double(res, 6, song_analysis.force_vector.attack);
179
-    sqlite3_bind_text(res, 7, song_uri, strlen(song_uri), SQLITE_STATIC);
171
+    sqlite3_bind_double(res, 1, song_analysis.force_vector.tempo);
172
+    sqlite3_bind_double(res, 2, song_analysis.force_vector.amplitude);
173
+    sqlite3_bind_double(res, 3, song_analysis.force_vector.frequency);
174
+    sqlite3_bind_double(res, 4, song_analysis.force_vector.attack);
175
+    sqlite3_bind_text(res, 5, song_uri, strlen(song_uri), SQLITE_STATIC);
180 176
     dberr = sqlite3_step(res);
181 177
     if (SQLITE_DONE != dberr) {
182 178
         // Free song analysis