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
8ebb67d3
Commit
8ebb67d3
authored
Mar 24, 2013
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some copyright notices, and removed some dead code
parent
cc3b9521
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
98 deletions
+67
-98
analyzer/analyzer.cc
analyzer/analyzer.cc
+1
-78
analyzer/analyzer.h
analyzer/analyzer.h
+2
-15
analyzer/imms-features.h
analyzer/imms-features.h
+17
-0
analyzer/main.cc
analyzer/main.cc
+13
-4
imms-c.cc
imms-c.cc
+17
-1
imms-c.h
imms-c.h
+17
-0
No files found.
analyzer/analyzer.cc
View file @
8ebb67d3
/*
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
());
}
analyzer/analyzer.h
View file @
8ebb67d3
...
...
@@ -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:
...
...
analyzer/imms-features.h
View file @
8ebb67d3
/*
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
...
...
analyzer/main.cc
View file @
8ebb67d3
/* 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
...
...
imms-c.cc
View file @
8ebb67d3
/*
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
();
}
...
...
imms-c.h
View file @
8ebb67d3
/*
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
...
...
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