Commit 8ebb67d3 authored by ale's avatar ale

added some copyright notices, and removed some dead code

parent cc3b9521
/*
IMMS: Intelligent Multimedia Management System
Copyright (C) 2001-2009 Michael Grigoriev
Copyright (C) 2013 <ale@incal.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -125,81 +126,3 @@ Features *StreamAnalyzer::get_result() {
return new Features(mfcckeeper.get_result(), beatkeeper.get_result());
}
// Calculate acoustic stats for a song and write them to the database.
Features *Analyzer::analyze(int infd)
{
static const bool test_mode = 0;
StackTimer t;
size_t frames = 0;
sample_t indata[WINDOWSIZE];
vector<double> outdata(NUMFREQS);
MFCCKeeper mfcckeeper;
BeatManager beatkeeper;
int r = read(infd, indata, sizeof(sample_t) * OVERLAP);
if (r != sizeof(sample_t) * OVERLAP)
return NULL;
int readsz = sizeof(sample_t) * READSIZE;
while (read(infd, indata + OVERLAP, readsz) == readsz
&& ++frames < MAXFRAMES)
{
// calculate MFCCs:
for (int i = 0; i < WINDOWSIZE; ++i)
pcmfft.input()[i] = (double)indata[i];
// window the data
hanwin.apply(pcmfft.input(), WINDOWSIZE);
// fft to get the spectrum
pcmfft.execute();
// calculate the power spectrum
for (int i = 0; i < NUMFREQS; ++i)
outdata[i] = pow(pcmfft.output()[i][0], 2) +
pow(pcmfft.output()[i][1], 2);
// apply mel filter bank
vector<double> melfreqs;
mfbank.apply(outdata, melfreqs);
beatkeeper.process(melfreqs);
// compute log energy
for (int i = 0; i < NUMMEL; ++i)
melfreqs[i] = log(melfreqs[i]);
// another fft to get the MFCCs
specfft.apply(melfreqs);
// discard the first mfcc
float cepstrum[NUMCEPSTR];
for (int i = 1; i <= NUMCEPSTR; ++i)
cepstrum[i - 1] = specfft.output()[i][0];
mfcckeeper.process(cepstrum);
// finally shift the already read data
memmove(indata, indata + READSIZE, OVERLAP * sizeof(sample_t));
}
#ifdef DEBUG
cerr << "obtained " << frames << " frames" << endl;
#endif
// did we read enough data?
if (test_mode || frames < 100)
return NULL;
mfcckeeper.finalize();
beatkeeper.finalize();
return new Features(mfcckeeper.get_result(), beatkeeper.get_result());
}
......@@ -28,6 +28,8 @@
#include "fftprovider.h"
#include "hanning.h"
typedef uint16_t sample_t;
// Calculate acoustic stats for a song.
//
// Analyzer calculates the Beats Per Minute (BPM) and
......@@ -44,21 +46,6 @@
// As of IMMS 1.2 Analyzer is a separate application, and called as needed.
// Analyzer is an optional component; if not used IMMS will simply use its
// other sources to determine the next song.
class Analyzer
{
public:
Analyzer() : hanwin(WINDOWSIZE) { }
Features *analyze(int);
protected:
FFTWisdom wisdom;
FFTProvider<WINDOWSIZE> pcmfft;
FFTProvider<NUMMEL> specfft;
MelFilterBank mfbank;
HanningWindow hanwin;
};
typedef uint16_t sample_t;
class StreamAnalyzer
{
public:
......
/*
Copyright (C) 2013 <ale@incal.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __imms_features_H
#define __imms_features_H
......
/* Test program for StreamAnalyzer. */
#include <iostream>
#include <sstream>
......@@ -38,6 +39,17 @@ void dump_features_json(Features *f) {
<< "}" << endl;
}
Features *analyze(FILE *stream) {
int n;
char buf[1024];
StreamAnalyzer analyzer;
while ((n = fread(buf, 1, sizeof(buf), stream)) > 0) {
analyzer.process(buf, n);
}
return analyzer.get_result();
}
int main(int argc, char *argv[])
{
if (argc > 1)
......@@ -49,10 +61,7 @@ int main(int argc, char *argv[])
return -1;
}
nice(15);
Analyzer analyzer;
Features *f = analyzer.analyze(0); // stdin
Features *f = analyze(stdin);
if (!f)
LOG(ERROR) << "Could not process input data." << endl;
else
......
/*
Copyright (C) 2013 <ale@incal.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <appname.h>
#include "analyzer.h"
......@@ -7,7 +24,6 @@
// Define it for all users of the library.
const string AppName = "imms";
imms_analyzer_t imms_stream_analyzer_new() {
return (imms_analyzer_t)new StreamAnalyzer();
}
......
/*
Copyright (C) 2013 <ale@incal.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __imms_cint_H
#define __imms_cint_H
......
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