forked from acoustid/acoustid-fingerprinter
/
analyzefiletask.cpp
58 lines (49 loc) · 1.46 KB
/
analyzefiletask.cpp
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
#include <QDebug>
#include "decoder.h"
#include "tagreader.h"
#include "utils.h"
#include "analyzefiletask.h"
#include "constants.h"
AnalyzeFileTask::AnalyzeFileTask(const QString &path)
: m_path(path)
{
}
void AnalyzeFileTask::run()
{
qDebug() << "Analyzing file" << m_path;
AnalyzeResult *result = new AnalyzeResult();
result->fileName = m_path;
TagReader tags(m_path);
if (!tags.read()) {
result->error = true;
result->errorMessage = "Couldn't read metadata";
emit finished(result);
return;
}
result->mbid = tags.mbid();
result->length = tags.length();
result->bitrate = tags.bitrate();
if (result->length < 10) {
result->error = true;
result->errorMessage = "Too short audio stream, should be at least 10 seconds";
emit finished(result);
return;
}
Decoder decoder(qPrintable(m_path));
if (!decoder.Open()) {
result->error = true;
result->errorMessage = QString("Couldn't open the file: ") + QString::fromStdString(decoder.LastError());
emit finished(result);
return;
}
FingerprintCalculator fpcalculator;
if (!fpcalculator.start(decoder.SampleRate(), decoder.Channels())) {
result->error = true;
result->errorMessage = "Error while fingerpriting the file";
emit finished(result);
return;
}
decoder.Decode(&fpcalculator, AUDIO_LENGTH);
result->fingerprint = fpcalculator.finish();
emit finished(result);
}