Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time offset in key and beat analysis #2152

Merged
merged 14 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/analyzer/plugins/buffering_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#include "analyzer/plugins/buffering_utils.h"

#include "util/math.h"
#include "util/sample.h"

#include <string.h>

namespace mixxx {

bool DownmixAndOverlapHelper::initialize(size_t windowSize, size_t stepSize, WindowReadyCallback callback) {
m_buffer.resize(windowSize);
m_buffer.assign(windowSize, 0.0);
m_callback = callback;
m_windowSize = windowSize;
m_stepSize = stepSize;
m_bufferWritePosition = 0;
// make sure the first frame is centered into the fft window. This makes sure
// that the result is significant starting fom the first step.
m_bufferWritePosition = windowSize / 2;
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
return m_windowSize > 0 && m_stepSize > 0 &&
m_stepSize <= m_windowSize && callback;
}
Expand Down Expand Up @@ -57,4 +62,4 @@ bool DownmixAndOverlapHelper::finalize() {
return true;
}

}
}
2 changes: 1 addition & 1 deletion src/track/keyfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Keys KeyFactory::makePreferredKeys(
pChange->set_key(it->first);
pChange->set_frame_position(frame);
}
key_map.set_global_key(KeyUtils::calculateGlobalKey(key_changes, iTotalSamples));
key_map.set_global_key(KeyUtils::calculateGlobalKey(key_changes, iTotalSamples, iSampleRate));
key_map.set_source(mixxx::track::io::key::ANALYZER);
Keys keys(key_map);
keys.setSubVersion(subVersion);
Expand Down
4 changes: 2 additions & 2 deletions src/track/keyutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ ChromaticKey KeyUtils::scaleKeySteps(ChromaticKey key, int key_changes) {

// static
mixxx::track::io::key::ChromaticKey KeyUtils::calculateGlobalKey(
const KeyChangeList& key_changes, const int iTotalSamples) {
const KeyChangeList& key_changes, const int iTotalSamples, int iSampleRate) {
const int iTotalFrames = iTotalSamples / 2;
QMap<mixxx::track::io::key::ChromaticKey, double> key_histogram;

Expand All @@ -413,7 +413,7 @@ mixxx::track::io::key::ChromaticKey KeyUtils::calculateGlobalKey(
qDebug() << "Key Histogram";
for (auto it = key_histogram.constBegin();
it != key_histogram.constEnd(); ++it) {
qDebug() << it.key() << ":" << keyDebugName(it.key()) << it.value();
qDebug() << it.key() << ":" << keyDebugName(it.key()) << it.value() / iSampleRate;
if (it.value() > max_delta) {
max_key = it.key();
max_delta = it.value();
Expand Down
2 changes: 1 addition & 1 deletion src/track/keyutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class KeyUtils {
static mixxx::track::io::key::ChromaticKey guessKeyFromText(const QString& text);

static mixxx::track::io::key::ChromaticKey calculateGlobalKey(
const KeyChangeList& key_changes, int iTotalSamples);
const KeyChangeList& key_changes, int iTotalSamples, int iSampleRate);

static void setNotation(
const QMap<mixxx::track::io::key::ChromaticKey, QString>& notation);
Expand Down