Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
imms
Commits
08a20b7c
Commit
08a20b7c
authored
Oct 12, 2013
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tool to build a comparison matrix for a set of songs
parent
a18b8b1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
Makefile.am
Makefile.am
+7
-0
comparemany.cc
comparemany.cc
+84
-0
No files found.
Makefile.am
View file @
08a20b7c
...
...
@@ -2,6 +2,8 @@ include $(top_srcdir)/vars.mk
SUBDIRS
=
ext immscore analyzer model .
noinst_PROGRAMS
=
comparemany
include_HEADERS
=
imms-c.h
lib_LTLIBRARIES
=
libimms-c.la
...
...
@@ -10,3 +12,8 @@ libimms_c_la_SOURCES = \
imms-c.h
libimms_c_la_LIBADD
=
$(MODEL_LIB)
$(ANALYZER_LIB)
$(IMMSCORE_LIB)
$(TORCH_LIB)
comparemany_SOURCES
=
\
comparemany.cc
comparemany_LDADD
=
libimms-c.la
comparemany.cc
0 → 100644
View file @
08a20b7c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "imms-c.h"
#define min(a, b) (((a) < (b)) ? (a) : (b))
FILE
*
convert_to_22050khz
(
char
*
path
)
{
char
buf
[
1024
];
//sprintf(buf, "avconv -i \"%s\" -f s16le -ar 22050 -ac 1 -ss 60 -t 60 -", path);
sprintf
(
buf
,
"avconv -i
\"
%s
\"
-f u16le -ar 22050 -ac 1 -"
,
path
);
return
popen
(
buf
,
"r"
);
}
imms_features_t
analyze_file
(
char
*
path
)
{
FILE
*
fd
=
convert_to_22050khz
(
path
);
if
(
!
fd
)
{
return
NULL
;
}
imms_analyzer_t
analyzer
=
imms_stream_analyzer_new
();
int
bufsz
=
4096
;
char
*
buf
=
(
char
*
)
malloc
(
bufsz
);
int
n
=
0
;
while
(
!
feof
(
fd
))
{
int
l
=
fread
(
buf
,
1
,
bufsz
,
fd
);
if
(
l
<=
0
)
{
break
;
}
n
+=
l
;
imms_stream_analyzer_process
(
analyzer
,
buf
,
l
);
}
fclose
(
fd
);
printf
(
"read %d bytes
\n
"
,
n
);
// Analyze the resulting data.
imms_features_t
f
=
imms_stream_analyzer_get_result
(
analyzer
);
imms_stream_analyzer_free
(
analyzer
);
free
(
buf
);
return
f
;
}
void
compare_many
(
char
**
paths
,
int
n
)
{
int
i
,
j
,
k
;
imms_features_t
*
feats
=
(
imms_features_t
*
)
malloc
(
sizeof
(
imms_features_t
)
*
n
);
for
(
i
=
0
,
k
=
0
;
i
<
n
;
i
++
)
{
printf
(
"extracting features from %s
\n
"
,
paths
[
i
]);
imms_features_t
f
=
analyze_file
(
paths
[
i
]);
if
(
f
==
NULL
)
{
printf
(
"NULL features for %s
\n
"
,
paths
[
i
]);
}
else
{
feats
[
k
++
]
=
f
;
}
}
n
=
k
;
imms_similarity_model_t
model
=
imms_similarity_model_new
();
int
*
results
=
(
int
*
)
calloc
(
sizeof
(
int
),
n
*
n
);
printf
(
"comparing...
\n
"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
0
;
j
<=
i
;
j
++
)
{
float
value
=
imms_similarity_model_evaluate
(
model
,
feats
[
i
],
feats
[
j
]);
results
[
i
*
n
+
j
]
=
(
int
)(
100
*
value
);
}
}
imms_similarity_model_free
(
model
);
printf
(
"
\n
results:
\n
"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
0
;
j
<
n
;
j
++
)
{
printf
(
" %6d"
,
results
[
i
*
n
+
j
]);
}
printf
(
"
\n
"
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
compare_many
(
argv
+
1
,
argc
-
1
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment