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 1 commit
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
3 changes: 1 addition & 2 deletions src/analyzer/plugins/analyzerqueenmarybeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ bool AnalyzerQueenMaryBeats::processSamples(const CSAMPLE* pIn, const int iLen)
}

bool AnalyzerQueenMaryBeats::finalize() {
// TODO(rryan) if iLen is less than frame size, pad with zeros. Do we need
// flush support?
m_helper.finalize();

int nonZeroCount = m_detectionResults.size();
while (nonZeroCount > 0 && m_detectionResults.at(nonZeroCount - 1) <= 0.0) {
Expand Down
1 change: 0 additions & 1 deletion src/analyzer/plugins/analyzerqueenmarykey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ bool AnalyzerQueenMaryKey::processSamples(const CSAMPLE* pIn, const int iLen) {
}

bool AnalyzerQueenMaryKey::finalize() {
// TODO(rryan) do we need a flush?
QMutexLocker locked(&s_mutex);
m_helper.finalize();
m_pKeyMode.reset();
Expand Down
44 changes: 32 additions & 12 deletions src/analyzer/plugins/buffering_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,44 @@ bool DownmixAndOverlapHelper::initialize(size_t windowSize, size_t stepSize, Win

bool DownmixAndOverlapHelper::processStereoSamples(const CSAMPLE* pInput, size_t inputStereoSamples) {
const size_t numInputFrames = inputStereoSamples / 2;
return processInner(pInput, numInputFrames);
}

bool DownmixAndOverlapHelper::finalize() {
// We need to append at least m_windowSize / 2 - m_stepSize silence
// to have a valid analysis results for the last track samples.
size_t framesToFillWindow = m_windowSize - m_bufferWritePosition;
size_t numInputFrames = framesToFillWindow;
if (numInputFrames < m_windowSize / 2 - 1) {
// -1 ensures that silence < m_stepSize ramains unprocessed
Copy link
Contributor

@uklotzde uklotzde Jul 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • typo (and I don't understand this remark)
  • use math_max()

numInputFrames = m_windowSize / 2 - 1;
}
return processInner(nullptr, numInputFrames);
}

bool DownmixAndOverlapHelper::processInner(
const CSAMPLE* pInput, size_t numInputFrames) {
size_t inRead = 0;
double* pDownmix = m_buffer.data();

while (inRead < numInputFrames) {
size_t writeAvailable = math_min(numInputFrames,
m_windowSize - m_bufferWritePosition);

for (size_t i = 0; i < writeAvailable; ++i) {
// We analyze a mono downmix of the signal since we don't think
// stereo does us any good.
pDownmix[m_bufferWritePosition + i] = (pInput[(inRead + i) * 2] +
pInput[(inRead + i) * 2 + 1]) *
0.5;
if (pInput) {
for (size_t i = 0; i < writeAvailable; ++i) {
// We analyze a mono downmix of the signal since we don't think
// stereo does us any good.
pDownmix[m_bufferWritePosition + i] = (pInput[(inRead + i) * 2] +
pInput[(inRead + i) * 2 + 1]) *
0.5;
}
} else {
// we are in the finalize call. Add silence to
// complete samples left in th buffer.
for (size_t i = 0; i < writeAvailable; ++i) {
pDownmix[m_bufferWritePosition + i] = 0;
}
}
m_bufferWritePosition += writeAvailable;
inRead += writeAvailable;
Expand All @@ -57,9 +82,4 @@ bool DownmixAndOverlapHelper::processStereoSamples(const CSAMPLE* pInput, size_t
return true;
}

bool DownmixAndOverlapHelper::finalize() {
// TODO(rryan) flush support?
return true;
}

}
} // namespace mixxx
2 changes: 2 additions & 0 deletions src/analyzer/plugins/buffering_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DownmixAndOverlapHelper {
bool finalize();

private:
bool processInner(const CSAMPLE* pInput, size_t numInputFrames);

std::vector<double> m_buffer;
// The window size in frames.
size_t m_windowSize = 0;
Expand Down