Skip to content

Commit

Permalink
Move fast analysis samples calculation to init() and use analyzer/con…
Browse files Browse the repository at this point in the history
…stants.h.
  • Loading branch information
rryan committed Dec 30, 2018
1 parent ce067ea commit 2eb5dd5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
16 changes: 10 additions & 6 deletions src/analyzer/analyzerbeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QHash>
#include <QString>

#include "analyzer/constants.h"
#include "analyzer/plugins/analyzersoundtouchbeats.h"
#include "analyzer/plugins/analyzerqueenmarybeats.h"
#include "track/beatfactory.h"
Expand All @@ -14,8 +15,6 @@

// Only analyze the first minute in fast-analysis mode.
static const int kFastAnalysisSecondsToAnalyze = 60;
// All audio files are converted to stereo first before analysis.
static const int kAnalyzerNumChannels = 2;

// static
QList<mixxx::AnalyzerPluginInfo> AnalyzerBeats::availablePlugins() {
Expand All @@ -34,6 +33,7 @@ AnalyzerBeats::AnalyzerBeats(UserSettingsPointer pConfig, bool enforceBpmDetecti
m_bPreferencesFastAnalysis(false),
m_iSampleRate(0),
m_iTotalSamples(0),
m_iMaxSamplesToProcess(0),
m_iCurrentSample(0),
m_iMinBpm(0),
m_iMaxBpm(9999) {
Expand Down Expand Up @@ -81,6 +81,13 @@ bool AnalyzerBeats::initialize(TrackPointer tio, int sampleRate, int totalSample

m_iSampleRate = sampleRate;
m_iTotalSamples = totalSamples;
// In fast analysis mode, skip processing after
// kFastAnalysisSecondsToAnalyze seconds are analyzed.
if (m_bPreferencesFastAnalysis) {
m_iMaxSamplesToProcess = mixxx::kFastAnalysisSecondsToAnalyze * m_iSampleRate * mixxx::kAnalysisChannels;
} else {
m_iMaxSamplesToProcess = m_iTotalSamples;
}
m_iCurrentSample = 0;

// if we can load a stored track don't reanalyze it
Expand Down Expand Up @@ -171,10 +178,7 @@ void AnalyzerBeats::process(const CSAMPLE *pIn, const int iLen) {
}

m_iCurrentSample += iLen;
// In fast analysis mode, skip processing after
// kFastAnalysisSecondsToAnalyze seconds are analyzed.
const int maxSamples = kFastAnalysisSecondsToAnalyze * m_iSampleRate * kAnalyzerNumChannels;
if (m_bPreferencesFastAnalysis && m_iCurrentSample > maxSamples) {
if (m_iCurrentSample > m_iMaxSamplesToProcess) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/analyzer/analyzerbeats.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AnalyzerBeats: public Analyzer {

int m_iSampleRate;
int m_iTotalSamples;
int m_iMaxSamplesToProcess;
int m_iCurrentSample;
int m_iMinBpm, m_iMaxBpm;
};
Expand Down
21 changes: 12 additions & 9 deletions src/analyzer/analyzerkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
#include <QtDebug>
#include <QVector>

#include "analyzer/constants.h"
#include "analyzer/plugins/analyzerqueenmarykey.h"
#include "proto/keys.pb.h"
#include "track/keyfactory.h"

// Only analyze the first minute in fast-analysis mode.
static const int kFastAnalysisSecondsToAnalyze = 60;
// All audio files are converted to stereo first before analysis.
static const int kAnalyzerNumChannels = 2;

// static
QList<mixxx::AnalyzerPluginInfo> AnalyzerKey::availablePlugins() {
QList<mixxx::AnalyzerPluginInfo> analyzers;
Expand All @@ -23,6 +19,7 @@ AnalyzerKey::AnalyzerKey(KeyDetectionSettings keySettings)
: m_keySettings(keySettings),
m_iSampleRate(0),
m_iTotalSamples(0),
m_iMaxSamplesToProcess(0),
m_iCurrentSample(0),
m_bPreferencesKeyDetectionEnabled(true),
m_bPreferencesFastAnalysisEnabled(false),
Expand Down Expand Up @@ -51,6 +48,13 @@ bool AnalyzerKey::initialize(TrackPointer tio, int sampleRate, int totalSamples)

m_iSampleRate = sampleRate;
m_iTotalSamples = totalSamples;
// In fast analysis mode, skip processing after
// kFastAnalysisSecondsToAnalyze seconds are analyzed.
if (m_bPreferencesFastAnalysisEnabled) {
m_iMaxSamplesToProcess = mixxx::kFastAnalysisSecondsToAnalyze * m_iSampleRate * mixxx::kAnalysisChannels;
} else {
m_iMaxSamplesToProcess = m_iTotalSamples;
}
m_iCurrentSample = 0;

// if we can't load a stored track reanalyze it
Expand Down Expand Up @@ -113,13 +117,12 @@ void AnalyzerKey::process(const CSAMPLE *pIn, const int iLen) {
if (!m_pPlugin) {
return;
}

m_iCurrentSample += iLen;
// In fast analysis mode, skip processing after
// kFastAnalysisSecondsToAnalyze seconds are analyzed.
const int maxSamples = kFastAnalysisSecondsToAnalyze * m_iSampleRate * kAnalyzerNumChannels;
if (m_bPreferencesFastAnalysisEnabled && m_iCurrentSample > maxSamples) {
if (m_iCurrentSample > m_iMaxSamplesToProcess) {
return;
}

bool success = m_pPlugin->process(pIn, iLen);
if (!success) {
m_pPlugin.reset();
Expand Down
1 change: 1 addition & 0 deletions src/analyzer/analyzerkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AnalyzerKey : public Analyzer {
QString m_pluginId;
int m_iSampleRate;
int m_iTotalSamples;
int m_iMaxSamplesToProcess;
int m_iCurrentSample;

bool m_bPreferencesKeyDetectionEnabled;
Expand Down

0 comments on commit 2eb5dd5

Please sign in to comment.