Skip to content

Commit 993e474

Browse files
committed
Add code to debug chomaprint fingeprint generation usable with DEBUG_PRINT_FINGERPRINT
1 parent 086f48e commit 993e474

2 files changed

Lines changed: 48 additions & 9 deletions

File tree

src/musicbrainz/chromaprinter.cpp

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "util/performancetimer.h"
1313
#include "util/sample.h"
1414

15+
#ifdef DEBUG_PRINT_FINGERPRINT
16+
#include <QCryptographicHash>
17+
#endif
18+
1519
namespace
1620
{
1721

@@ -53,6 +57,14 @@ QString calcFingerprint(
5357
std::vector<SAMPLE> fingerprintSamples(
5458
audioSourceProxy.getSignalInfo().frames2samples(
5559
readableSampleFrames.frameLength()));
60+
61+
#ifdef DEBUG_PRINT_FINGERPRINT
62+
SampleUtil::applyGain(
63+
sampleBuffer.data(),
64+
1,
65+
sampleBuffer.size());
66+
#endif
67+
5668
// Convert floating-point to integer
5769
SampleUtil::convertFloat32ToS16(
5870
&fingerprintSamples[0],
@@ -83,14 +95,40 @@ QString calcFingerprint(
8395
uint32_p fprint = nullptr;
8496
int size = 0;
8597
int ret = chromaprint_get_raw_fingerprint(ctx, &fprint, &size);
98+
99+
#ifdef DEBUG_PRINT_FINGERPRINT
100+
uint32_t simHash;
101+
chromaprint_hash_fingerprint(fprint, size, &simHash);
102+
103+
QByteArray hash =
104+
QCryptographicHash::hash(QByteArray(reinterpret_cast<char*>(fprint),
105+
size * sizeof(fprint[0])),
106+
QCryptographicHash::Md5)
107+
.toHex();
108+
109+
qDebug() << "Hash:" << hash;
110+
qDebug() << "SimHash:" << simHash;
111+
112+
for (int i = 0; i < size; ++i) {
113+
QString item = QString::number(fprint[i], 2).replace('0', ' ');
114+
while (item.length() < 32) {
115+
item.prepend(' ');
116+
}
117+
qDebug() << item << i;
118+
}
119+
#endif
120+
86121
QByteArray fingerprint;
87122
if (ret == 1) {
88123
char_p encoded = nullptr;
89124
int encoded_size = 0;
90-
chromaprint_encode_fingerprint(fprint, size,
91-
CHROMAPRINT_ALGORITHM_DEFAULT,
92-
&encoded,
93-
&encoded_size, 1);
125+
int base64 = 1;
126+
chromaprint_encode_fingerprint(fprint,
127+
size,
128+
CHROMAPRINT_ALGORITHM_DEFAULT,
129+
&encoded,
130+
&encoded_size,
131+
base64);
94132

95133
fingerprint.append(reinterpret_cast<char*>(encoded), encoded_size);
96134

@@ -123,10 +161,11 @@ QString ChromaPrinter::getFingerprint(TrackPointer pTrack) {
123161
return QString();
124162
}
125163

164+
const SINT startFrame = 2;
126165
const auto fingerprintRange = intersect(
127166
pAudioSource->frameIndexRange(),
128167
mixxx::IndexRange::forward(
129-
pAudioSource->frameIndexMin(),
168+
pAudioSource->frameIndexMin() + startFrame,
130169
kFingerprintDuration * pAudioSource->getSignalInfo().getSampleRate()));
131170
mixxx::AudioSourceStereoProxy audioSourceProxy(
132171
pAudioSource,

src/musicbrainz/chromaprinter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "track/track_decl.h"
66

77
class ChromaPrinter: public QObject {
8-
Q_OBJECT
8+
Q_OBJECT
99

10-
public:
11-
explicit ChromaPrinter(QObject* parent = NULL);
12-
QString getFingerprint(TrackPointer pTrack);
10+
public:
11+
explicit ChromaPrinter(QObject* parent = nullptr);
12+
QString getFingerprint(TrackPointer pTrack);
1313
};

0 commit comments

Comments
 (0)