-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_tracks.m
60 lines (49 loc) · 1.91 KB
/
add_tracks.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function s = add_tracks(filename,d)
%% add_tracks - Analyzes songs and stores its hashes in a database.
%
% s = add_tracks(filename, d)
%
% This function reads the file called filename that contains info about the songs
% we want to store in the database d, and processes and stores them.
%
% The read file must have the following format: it must have a row for each song.
% In each row, it will give us the path of the mp3 we have to read, the group that
% plays it, the album it appeared in, the year it was released, the path of its
% album cover image and the path of a text file containing its lyrics. Each one of
% this piece of information must be separed of the others with a '---'.
%
% EXAMPLE: Canciones/Target/Wonderwall.mp3---Oasis---Live_at_Earls_Court---1995---Imagenes/Wonderwall.jpg---Letra/Wonderwall.txt
%
% add_tracks will output a [#songs, 6] cell containing all the info of each one of
% the songs stored. Besides, it will fill the db with them.
%
% @author: Alex Gascon y Mireia Segovia
%% CHANGELOG
% 1.0 (2015/02/07): Initial version
%% FUNCTION
% Preparing the variables
detalles = textread(filename,'%s');
l = length(detalles);
dilate_size = [30, 30];
s = cell(l, 6);
% Reading the file and obtaining the song information
for i = 1:l
sROW = strsplit(detalles{i}, '---');
s(i,:) = sROW;
end
% Processing the songs
for i = 1:l
% We read the song and convert it to its 8 KHz mono version
[c, fs] = audioread(s{i,1});
cMono = 0.5*(c(:,1) + c(:,2));
c8000 = resample (cMono, 8000, fs);
% Finding the landmarks and storing its hashes in the database
[L, ~, ~] = find_landmarks(c8000, dilate_size);
H = landmark2hash(L, i);
record_hashes(H,d);
% Control output, used so we can check that everything is going well
display('Leido')
disp(sprintf('Número de hashes de la canción %d: %d',i, length(H)))
% Freeing up memory
clear c cMono c8000 L S maxes H
end