Commit decb9fd2 authored by ale's avatar ale

add svm similarity blob; cleaned up configure; imss_analyze() takes a file descriptor

parent 274da1a1
......@@ -2,10 +2,11 @@ include $(top_srcdir)/vars.mk
SUBDIRS = ext immscore analyzer model .
include_HEADERS = imms-c.h
lib_LTLIBRARIES = libimms-c.la
libimms_c_la_SOURCES = \
imms-c.cc \
imms-c.h
libimms_c_la_LIBADD = $(ANALYZER_LIB) $(IMMSCORE_LIB) $(TORCH_LIB)
libimms_c_la_LIBADD = $(MODEL_LIB) $(ANALYZER_LIB) $(IMMSCORE_LIB) $(TORCH_LIB)
......@@ -38,7 +38,7 @@ using std::endl;
typedef uint16_t sample_t;
// Calculate acoustic stats for a song and write them to the database.
Features *Analyzer::analyze(FILE *p)
Features *Analyzer::analyze(int infd)
{
static const bool test_mode = 0;
......@@ -52,13 +52,14 @@ Features *Analyzer::analyze(FILE *p)
MFCCKeeper mfcckeeper;
BeatManager beatkeeper;
int r = fread(indata, sizeof(sample_t), OVERLAP, p);
int r = read(infd, indata, sizeof(sample_t) * OVERLAP);
if (r != OVERLAP)
if (r != sizeof(sample_t) * OVERLAP)
return NULL;
while (fread(indata + OVERLAP, sizeof(sample_t), READSIZE, p) ==
READSIZE && ++frames < MAXFRAMES)
int readsz = sizeof(sample_t) * READSIZE;
while (read(infd, indata + OVERLAP, readsz) == readsz
&& ++frames < MAXFRAMES)
{
// calculate MFCCs:
for (int i = 0; i < WINDOWSIZE; ++i)
......
......@@ -48,7 +48,7 @@ class Analyzer
{
public:
Analyzer() : hanwin(WINDOWSIZE) { }
Features *analyze(FILE*);
Features *analyze(int);
protected:
FFTWisdom wisdom;
FFTProvider<WINDOWSIZE> pcmfft;
......
......@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
nice(15);
Analyzer analyzer;
Features *f = analyzer.analyze(stdin);
Features *f = analyzer.analyze(0); // stdin
if (!f)
LOG(ERROR) << "Could not process input data." << endl;
else
......
......@@ -25,44 +25,18 @@ LT_INIT([disable-shared])
AC_CONFIG_SRCDIR([immscore/immsutil.h])
AC_PREFIX_DEFAULT("/usr")
AC_ARG_WITH(taglib,
AC_HELP_STRING([--with-taglib],
[Tag support using TagLib]))
AC_ARG_WITH(id3lib,
AC_HELP_STRING([--with-id3lib],
[Native MP3 tag support]))
AC_ARG_WITH(vorbis,
AC_HELP_STRING([--with-vorbis],
[Native OGG/Vorbis tag support]))
AC_ARG_WITH(screensaver,
AC_HELP_STRING([--with-screensaver],
[Use MIT ScreenSaver extension]))
dnl AC_PREFIX_DEFAULT("/usr")
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug],
[Extra debug output]),
[enable_debug=$enableval])
AC_ARG_ENABLE(queuecontrol,
AC_HELP_STRING([--disable-queuecontrol],
[Don't use XMMS queue control functions]),
[enable_queuecontrol=$enableval])
AC_ARG_ENABLE(analyzer,
AC_HELP_STRING([--disable-analyzer],
[Disable acoustic song similarity analyzer]),
[enable_analyzer=$enableval])
AC_ARG_ENABLE(immsremote,
AC_HELP_STRING([--disable-immsremote],
[Disable building of immsremote]),
[enable_immsremote=$enableval])
AC_PROG_CXX
AC_PROG_CC
AC_PROG_RANLIB
......@@ -104,114 +78,30 @@ else
CPPFLAGS="$CPPFLAGS $pcre_CFLAGS"
fi
AC_CHECK_LIB(z, compress,, [with_zlib=no])
AC_CHECK_HEADERS(zlib.h,, [with_zlib=no])
if test "$with_zlib" = "no"; then
AC_MSG_ERROR([zlib required and missing.])
PKG_CHECK_MODULES([FFTW], [fftw3 >= 3.0],
[], [have_fftw=no])
if test "$have_fftw" = "no"; then
AC_MSG_WARN("fftw3 >= 3.0 required for analyzer and missing");
fi
if test "$enable_analyzer" != "no"; then
PKG_CHECK_MODULES([FFTW], [fftw3 >= 3.0],
[], [have_fftw=no])
if test "$have_fftw" = "no"; then
AC_MSG_WARN([******************************************************]);
AC_MSG_WARN("fftw3 >= 3.0 required for analyzer and missing");
AC_MSG_WARN("Acoustic analyzer will not be built");
AC_MSG_WARN([******************************************************]);
enable_analyzer=no
fi
LIBS="$LIBS $FFTW_LIBS"
CFLAGS="$CFLAGS $FFTW_CFLAGS"
fi
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.0],
[], [AC_MSG_ERROR([Required packages missing.])])
LIBS="$LIBS $FFTW_LIBS"
CFLAGS="$CFLAGS $FFTW_CFLAGS"
saved_cppflags="$CPPFLAGS"
saved_libs="$LIBS"
if test "$enable_analyzer" != "no"; then
CPPFLAGS="`pkg-config fftw3 --cflags`"
LIBS="`pkg-config fftw3 --libs`"
AC_CHECK_HEADERS(fftw3.h,, [with_fftw=no])
AC_CHECK_LIB(fftw3, fftw_plan_dft_r2c_1d,, [with_fftw=no])
if test "$with_fftw" = "no"; then
AC_MSG_WARN([******************************************************]);
AC_MSG_WARN("fftw3 >= 3.0 required for analyzer and missing");
AC_MSG_WARN("Acoustic analyzer will not be built");
AC_MSG_WARN([******************************************************]);
enable_analyzer=no
fi
fi
CPPFLAGS="`pkg-config glib-2.0 --cflags`"
LIBS="`pkg-config glib-2.0 --libs`"
AC_CHECK_HEADERS(glib.h,, [with_glib=no])
AC_CHECK_LIB(glib-2.0, g_timeout_source_new,, [with_glib=no])
if test "$with_glib" = "no"; then
AC_MSG_ERROR([glib 2.0 required and missing.])
CPPFLAGS="`pkg-config fftw3 --cflags`"
LIBS="`pkg-config fftw3 --libs`"
AC_CHECK_HEADERS(fftw3.h,, [with_fftw=no])
AC_CHECK_LIB(fftw3, fftw_plan_dft_r2c_1d,, [with_fftw=no])
if test "$with_fftw" = "no"; then
AC_MSG_ERROR([fftw >= 3.0 required and missing.])
fi
LIBS=$saved_libs
CPPFLAGS=$saved_cppflags
if test "$with_taglib" != "no"; then
AC_CHECK_PROG(with_taglib, taglib-config, "yes", "no")
fi
if test "$with_taglib" != "no"; then
AC_MSG_CHECKING([taglib usability])
saved_libs="$LIBS"
LIBS="$LIBS -ltag"
CPPFLAGS=`taglib-config --cflags`
AC_TRY_LINK([#include <tag.h>
#include <fileref.h>],
[TagLib::FileRef f((TagLib::File*)0); f.tag()->title()],
[TAGCPPFLAGS="$TAGCPPFLAGS `taglib-config --cflags`"
AC_MSG_RESULT(yes)],
[LIBS=$saved_libs; AC_MSG_RESULT(no)])
fi
CPPFLAGS=$saved_cppflags
if test "$with_taglib" = "yes"; then
AC_DEFINE(WITH_TAGLIB,, [Tag support using TagLib])
else
if test "$with_id3lib" != "no"; then
AC_CHECK_LIB(id3, ID3Tag_New,, [with_id3lib=no])
AC_CHECK_HEADERS(id3/tag.h,, [with_id3lib=no])
fi
if test "$with_id3lib" = "no"; then
AC_MSG_WARN([id3lib is missing.])
else
AC_DEFINE(WITH_ID3LIB,, [Native mp3 tag support])
fi
if test "$with_vorbis" != "no"; then
AC_CHECK_LIB(vorbis, vorbis_comment_query,, [with_vorbis=no])
AC_CHECK_LIB(vorbisfile, ov_comment,, [with_vorbis=no])
AC_CHECK_HEADERS(vorbis/codec.h vorbis/vorbisfile.h,,
[with_vorbis=no])
fi
if test "$with_vorbis" = "no"; then
AC_MSG_WARN([Vorbis is missing.])
else
AC_DEFINE(WITH_VORBIS,, [Native Vorbis tag support])
fi
fi
AC_DEFINE(ANALYZER_ENABLED,, [Analyzer enabled])
PLUGINS=""
OPTIONAL="analyzer"
AC_MSG_CHECKING([which plugins to build])
AC_MSG_RESULT($PLUGINS)
AC_MSG_CHECKING([which optional packages to build])
AC_MSG_RESULT($OPTIONAL)
AC_SUBST(CXX)
AC_SUBST(CC)
AC_SUBST(INSTALL)
......
#include <appname.h>
#include "analyzer.h"
#include "model.h"
#include "imms-c.h"
// Define it for all users of the library.
const string AppName = "imms";
imms_features_t imms_analyze(FILE *in) {
imms_features_t imms_analyze(int in_fd) {
Analyzer analyzer;
return analyzer.analyze(in);
return analyzer.analyze(in_fd);
}
imms_features_t imms_features_from_data(char *buf, int n) {
......
#ifndef __imms_cint_H
#define __imms_cint_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
// Opaque types.
typedef void *imms_similarity_model_t;
......@@ -11,8 +11,9 @@ typedef void *imms_features_t;
// C wrappers for the analysis/model API.
// Analyze the input stream and return feature data.
imms_features_t imms_analyze(FILE *);
// Analyze the input stream (given with a file descriptor) and return
// feature data.
imms_features_t imms_analyze(int);
// Deserialize feature data.
imms_features_t imms_features_from_data(char *, int);
......@@ -35,6 +36,8 @@ float imms_similarity_model_evaluate(imms_similarity_model_t, imms_features_t, i
// Free resources associated with the similarity model.
void imms_similarity_model_free(imms_similarity_model_t);
#ifdef __cplusplus
}
#endif
#endif
......@@ -3,36 +3,18 @@
/* Analyzer enabled */
#undef ANALYZER_ENABLED
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <fftw3.h> header file. */
#undef HAVE_FFTW3_H
/* Define to 1 if you have the <glib.h> header file. */
#undef HAVE_GLIB_H
/* Define to 1 if you have the <id3/tag.h> header file. */
#undef HAVE_ID3_TAG_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `fftw3' library (-lfftw3). */
#undef HAVE_LIBFFTW3
/* Define to 1 if you have the `glib-2.0' library (-lglib-2.0). */
#undef HAVE_LIBGLIB_2_0
/* Define to 1 if you have the `id3' library (-lid3). */
#undef HAVE_LIBID3
/* Define to 1 if you have the `vorbis' library (-lvorbis). */
#undef HAVE_LIBVORBIS
/* Define to 1 if you have the `vorbisfile' library (-lvorbisfile). */
#undef HAVE_LIBVORBISFILE
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
......@@ -57,18 +39,13 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <vorbis/codec.h> header file. */
#undef HAVE_VORBIS_CODEC_H
/* Define to 1 if you have the <vorbis/vorbisfile.h> header file. */
#undef HAVE_VORBIS_VORBISFILE_H
/* Define to 1 if you have the <zlib.h> header file. */
#undef HAVE_ZLIB_H
/* initstate_r is usable */
#undef INITSTATE_USABLE
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Name of package */
#undef PACKAGE
......@@ -95,12 +72,3 @@
/* Version number of package */
#undef VERSION
/* Native mp3 tag support */
#undef WITH_ID3LIB
/* Tag support using TagLib */
#undef WITH_TAGLIB
/* Native Vorbis tag support */
#undef WITH_VORBIS
......@@ -2,7 +2,7 @@ include $(top_srcdir)/vars.mk
AM_CPPFLAGS += -DWITH_TORCH
lib_LTLIBRARIES = libimmsmodel.la
noinst_LTLIBRARIES = libimmsmodel.la
libimmsmodel_la_SOURCES = \
distance.cc \
......@@ -10,7 +10,18 @@ libimmsmodel_la_SOURCES = \
emd.c \
emd.h \
model.cc \
model.h
model.h \
svm-similarity-data.c
libimmsmodel_la_LIBADD = $(ANALYZER_LIB) $(IMMSCORE_LIB) $(TORCH_LIB)
BUILT_SOURCES = \
svm-similarity-data.c
libimmsmodel_la_LIBADD = \
$(ANALYZER_LIB) $(IMMSCORE_LIB) $(TORCH_LIB)
OBJCOPY = @OBJCOPY@
OBJCOPYTARGET = @OBJCOPYTARGET@
OBJCOPYARCH = @OBJCOPYARCH@
svm-similarity-data.c: data/svm-similarity
xxd -i $^ > $@
......@@ -56,8 +56,8 @@ static const int num_hidden = 25;
static const int num_outputs = 2;
static const int stdv = 12;
extern char _binary____data_svm_similarity_start;
extern char _binary____data_svm_similarity_end;
extern unsigned char *data_svm_similarity;
extern unsigned int data_svm_similarity_len;
class XFileModeSetter {
public:
......@@ -103,10 +103,8 @@ public:
}
else
{
static const size_t data_size = &_binary____data_svm_similarity_end
- &_binary____data_svm_similarity_start;
model.reset(new MemoryXFile(
&_binary____data_svm_similarity_start, data_size));
data_svm_similarity, data_svm_similarity_len));
}
normalizer.load(model.get());
svm.loadXFile(model.get());
......
......@@ -2,6 +2,7 @@
TORCH_LIB = $(top_builddir)/ext/torch3/libtorch.la
IMMSCORE_LIB = $(top_builddir)/immscore/libimmscore.la
ANALYZER_LIB = $(top_builddir)/analyzer/libimmsanalyzer.la
MODEL_LIB = $(top_builddir)/model/libimmsmodel.la
INCS = \
-I$(top_srcdir)/ext/torch3/core \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment