Merge pull request #6 from Polochon-street/master

Updated bindings to match new Bliss version
This commit is contained in:
Lucas Verney 2016-10-11 13:24:34 -04:00 committed by GitHub
commit 384f70da5f
4 changed files with 23 additions and 42 deletions

View File

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

View File

@ -19,6 +19,7 @@ import sys
import mpd
# logging.basicConfig(level='DEBUG')
class PersistentMPDClient(mpd.MPDClient):
"""
@ -149,7 +150,7 @@ def main(queue_length):
logging.info("Currently played song is %s." % (current_song,))
# Get current song coordinates
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
current_song_coords = cur.fetchone()
if current_song_coords is None:
logging.error("Current song %s is not in db. You should update the db." %
@ -161,7 +162,7 @@ def main(queue_length):
for i in range(queue_length):
# Get cached distances from db
cur.execute(
"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",
"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",
(current_song_coords["filename"], current_song_coords["filename"]))
cached_distances = [row
for row in cur.fetchall()
@ -171,7 +172,7 @@ def main(queue_length):
if cached_distances:
closest_song = (cached_distances[0],
cached_distances[0]["distance"],
cached_distances[1]["similarity"])
cached_distances[0]["similarity"])
else:
closest_song = None
@ -193,7 +194,7 @@ def main(queue_length):
continue
# Get all other songs coordinates and iterate randomly on them
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs ORDER BY RANDOM()")
cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs ORDER BY RANDOM()")
for tmp_song_data in cur.fetchall():
if(tmp_song_data["filename"] == current_song_coords["filename"] or
tmp_song_data["filename"] in cached_distances_songs or
@ -203,32 +204,24 @@ def main(queue_length):
continue
# Compute distance
distance = math.sqrt(
(current_song_coords["tempo1"] - tmp_song_data["tempo1"])**2 +
(current_song_coords["tempo2"] - tmp_song_data["tempo2"])**2 +
(current_song_coords["tempo3"] - tmp_song_data["tempo3"])**2 +
(current_song_coords["tempo"] - tmp_song_data["tempo"])**2 +
(current_song_coords["amplitude"] - tmp_song_data["amplitude"])**2 +
(current_song_coords["frequency"] - tmp_song_data["frequency"])**2 +
(current_song_coords["attack"] - tmp_song_data["attack"])**2
)
similarity = (
(current_song_coords["tempo1"] * tmp_song_data["tempo1"] +
current_song_coords["tempo2"] * tmp_song_data["tempo2"] +
current_song_coords["tempo3"] * tmp_song_data["tempo3"] +
(current_song_coords["tempo"] * tmp_song_data["tempo"] +
current_song_coords["amplitude"] * tmp_song_data["amplitude"] +
current_song_coords["frequency"] * tmp_song_data["frequency"] +
current_song_coords["attack"] * tmp_song_data["attack"]) /
(
math.sqrt(
current_song_coords["tempo1"]**2 +
current_song_coords["tempo2"]**2 +
current_song_coords["tempo3"]**2 +
current_song_coords["tempo"]**2 +
current_song_coords["amplitude"]**2 +
current_song_coords["frequency"]**2 +
current_song_coords["attack"]**2) *
math.sqrt(
tmp_song_data["tempo1"]**2 +
tmp_song_data["tempo2"]**2 +
tmp_song_data["tempo3"]**2 +
tmp_song_data["tempo"]**2 +
tmp_song_data["amplitude"]**2 +
tmp_song_data["frequency"]**2 +
tmp_song_data["attack"]**2)

View File

@ -25,7 +25,7 @@ def main():
cached_distances = cur.fetchall()
# Get all songs
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs")
cur.execute("SELECT id, tempo, amplitude, frequency, attack, filename FROM songs")
all_songs = cur.fetchall()
for i in range(len(all_songs)):
@ -42,32 +42,24 @@ def main():
continue
# Compute distance
distance = math.sqrt(
(song1["tempo1"] - song2["tempo1"])**2 +
(song1["tempo2"] - song2["tempo2"])**2 +
(song1["tempo3"] - song2["tempo3"])**2 +
(song1["tempo"] - song2["tempo"])**2 +
(song1["amplitude"] - song2["amplitude"])**2 +
(song1["frequency"] - song2["frequency"])**2 +
(song1["attack"] - song2["attack"])**2
)
similarity = (
(song1["tempo1"] * song2["tempo1"] +
song1["tempo2"] * song2["tempo2"] +
song1["tempo3"] * song2["tempo3"] +
(song1["tempo"] * song2["tempo"] +
song1["amplitude"] * song2["amplitude"] +
song1["frequency"] * song2["frequency"] +
song1["attack"] * song2["attack"]) /
(
math.sqrt(
song1["tempo1"]**2 +
song1["tempo2"]**2 +
song1["tempo3"]**2 +
song1["tempo"]**2 +
song1["amplitude"]**2 +
song1["frequency"]**2 +
song1["attack"]**2) *
math.sqrt(
song2["tempo1"]**2 +
song2["tempo2"]**2 +
song2["tempo3"]**2 +
song2["tempo"]**2 +
song2["amplitude"]**2 +
song2["frequency"]**2 +
song2["attack"]**2)

View File

@ -47,9 +47,7 @@ int _init_db(char *data_folder, char* db_path)
}
dberr = sqlite3_exec(dbh, "CREATE TABLE IF NOT EXISTS songs( \
id INTEGER PRIMARY KEY, \
tempo1 REAL, \
tempo2 REAL, \
tempo3 REAL, \
tempo REAL, \
amplitude REAL, \
frequency REAL, \
attack REAL, \
@ -153,7 +151,7 @@ int _parse_music_helper(
}
// Insert song analysis in database
dberr = sqlite3_prepare_v2(dbh,
"INSERT INTO songs(tempo1, tempo2, tempo3, amplitude, frequency, attack, filename) VALUES(?, ?, ?, ?, ?, ?, ?)",
"INSERT INTO songs(tempo, amplitude, frequency, attack, filename) VALUES(?, ?, ?, ?, ?)",
-1, &res, 0);
if (SQLITE_OK != dberr) {
fprintf(stderr, "Error while inserting data in db: %s\n\n", sqlite3_errmsg(dbh));
@ -170,13 +168,11 @@ int _parse_music_helper(
// Pass file
return 1;
}
sqlite3_bind_double(res, 1, song_analysis.force_vector.tempo1);
sqlite3_bind_double(res, 2, song_analysis.force_vector.tempo2);
sqlite3_bind_double(res, 3, song_analysis.force_vector.tempo3);
sqlite3_bind_double(res, 4, song_analysis.force_vector.amplitude);
sqlite3_bind_double(res, 5, song_analysis.force_vector.frequency);
sqlite3_bind_double(res, 6, song_analysis.force_vector.attack);
sqlite3_bind_text(res, 7, song_uri, strlen(song_uri), SQLITE_STATIC);
sqlite3_bind_double(res, 1, song_analysis.force_vector.tempo);
sqlite3_bind_double(res, 2, song_analysis.force_vector.amplitude);
sqlite3_bind_double(res, 3, song_analysis.force_vector.frequency);
sqlite3_bind_double(res, 4, song_analysis.force_vector.attack);
sqlite3_bind_text(res, 5, song_uri, strlen(song_uri), SQLITE_STATIC);
dberr = sqlite3_step(res);
if (SQLITE_DONE != dberr) {
// Free song analysis