-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Spectrum analyzer update #5160
Merged
Merged
Spectrum analyzer update #5160
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
9be31e0
tweak amplitude ranges, update and fix readme.md
he29-net 4e2f168
Add and implement advanced settings
he29-net f5eda87
Display waterfall at native resolution
he29-net 7d630e1
Add waterfall cursor, fix time labels and make density change with wi…
he29-net 249d161
Fix normalization so that full scale sinewave is 0 dBFS; tweak perf. …
he29-net 25aa537
Move FFT analysis to a separate thread for better performance and rea…
he29-net 3707eeb
Performance optimizations and some final touches here and there
he29-net cb3e701
Improve cursor coordinates display
he29-net 8d639e5
Fix missed transient in the first block despite having overlapping en…
he29-net 36feb65
workaround for QMouseEvent::localPos() bug
he29-net b650838
Update plugins/SpectrumAnalyzer/SaSpectrumView.cpp
he29-net 42d74db
Make SaProcessor unfriendly to view classes
he29-net 9dd9ef0
Update and improve readme file; use consistent "analyzer" spelling
he29-net 6a5089d
Use QString directly where possible
he29-net 6939702
Fix bug introduced in previous commit
he29-net 11013cc
SaProcessor: make some variables accessed by other classes atomic; ma…
he29-net edefc93
test a change required to make analyzer work after make install
he29-net e3c89d5
Build the ringbuffer libary as part of LMMS core
he29-net 5b1f28c
Attempted fix of missing ringbuffer.cpp symbols on Win platforms
he29-net 7cf189c
Move most ringbuffer cmake setup to 3rdparty/, hijack RINGBUFFER_EXPO…
he29-net 11bb2c7
Add LMMS_EXPORT to LocklessRingBuffer methods
he29-net 2963fb6
Revert "Add LMMS_EXPORT to LocklessRingBuffer methods"
PhysSong 6dd2619
Try to fix an export error
PhysSong 6856b3d
Rework LocklessRingBuffer and force export of <sampleFrame> template …
he29-net 0d56ae8
Move <sampleFrame> instances to the bottom of file
he29-net 228dd2f
Revert "Move <sampleFrame> instances to the bottom of file"
he29-net 22e9163
Move specialized write() above the non-specialized one
he29-net dc2bd91
Move sampleFrame instantiation to the header file
he29-net 8739abb
Try to remove LMMS_EXPORT from LocklessRingBuffer template
he29-net 7a0fc5a
Go back to 'everything in the header' to fix Mac and hope it does not…
he29-net bf793da
Try removing all LMMS_EXPORTs from LocklessRingBuffer
he29-net ad49d36
Merge remote-tracking branch 'upstream/master' into analyzer-update
he29-net a0acc8a
Implement LocklessRingBuffer changes requested in review
he29-net 8ca05a3
Fix code conventions, make some includes harder to read
he29-net c694277
Forgotten rename
he29-net 0caa748
Fix missing part of waterfall when its width limit is reached
he29-net a7388b1
Fix drawing bounds of "overload fill-in"; improve comment on waterfal…
he29-net File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* LocklessRingBuffer.h - LMMS wrapper for a lockless ringbuffer library | ||
* | ||
* Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com> | ||
* | ||
* This file is part of LMMS - https://lmms.io | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program (see COPYING); if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
#ifndef LOCKLESSRINGBUFFER_H | ||
#define LOCKLESSRINGBUFFER_H | ||
|
||
#include <QMutex> | ||
#include <QWaitCondition> | ||
|
||
#include "lmms_basics.h" | ||
#include "lmms_export.h" | ||
#include "../src/3rdparty/ringbuffer/include/ringbuffer/ringbuffer.h" | ||
|
||
|
||
//! A convenience layer for a realtime-safe and thread-safe multi-reader ring buffer library. | ||
template <class T> | ||
class LocklessRingBufferBase | ||
{ | ||
template<class _T> | ||
friend class LocklessRingBufferReader; | ||
public: | ||
LocklessRingBufferBase(std::size_t sz) : m_buffer(sz) | ||
{ | ||
m_buffer.touch(); // reserve storage space before realtime operation starts | ||
} | ||
~LocklessRingBufferBase() {}; | ||
|
||
std::size_t capacity() const {return m_buffer.maximum_eventual_write_space();} | ||
std::size_t free() const {return m_buffer.write_space();} | ||
void wakeAll() {m_notifier.wakeAll();} | ||
|
||
protected: | ||
ringbuffer_t<T> m_buffer; | ||
QWaitCondition m_notifier; | ||
}; | ||
|
||
|
||
// The SampleFrameCopier is required because sampleFrame is just a two-element | ||
// array and therefore does not have a copy constructor needed by std::copy. | ||
class SampleFrameCopier | ||
{ | ||
const sampleFrame* m_src; | ||
public: | ||
SampleFrameCopier(const sampleFrame* src) : m_src(src) {} | ||
void operator()(std::size_t src_offset, std::size_t count, sampleFrame* dest) | ||
{ | ||
for (std::size_t i = src_offset; i < src_offset + count; i++, dest++) | ||
{ | ||
(*dest)[0] = m_src[i][0]; | ||
(*dest)[1] = m_src[i][1]; | ||
} | ||
} | ||
}; | ||
|
||
|
||
//! Standard ring buffer template for data types with copy constructor. | ||
template <class T> | ||
class LocklessRingBuffer : public LocklessRingBufferBase<T> | ||
{ | ||
public: | ||
LocklessRingBuffer(std::size_t sz) : LocklessRingBufferBase<T>(sz) {}; | ||
|
||
std::size_t write(const sampleFrame *src, std::size_t cnt, bool notify = false) | ||
{ | ||
std::size_t written = LocklessRingBufferBase<T>::m_buffer.write(src, cnt); | ||
// Let all waiting readers know new data are available. | ||
if (notify) {LocklessRingBufferBase<T>::m_notifier.wakeAll();} | ||
return written; | ||
} | ||
}; | ||
|
||
|
||
//! Specialized ring buffer template with write function modified to support sampleFrame. | ||
template <> | ||
class LocklessRingBuffer<sampleFrame> : public LocklessRingBufferBase<sampleFrame> | ||
{ | ||
public: | ||
LocklessRingBuffer(std::size_t sz) : LocklessRingBufferBase<sampleFrame>(sz) {}; | ||
|
||
std::size_t write(const sampleFrame *src, std::size_t cnt, bool notify = false) | ||
{ | ||
SampleFrameCopier copier(src); | ||
std::size_t written = LocklessRingBufferBase<sampleFrame>::m_buffer.write_func<SampleFrameCopier>(copier, cnt); | ||
// Let all waiting readers know new data are available. | ||
if (notify) {LocklessRingBufferBase<sampleFrame>::m_notifier.wakeAll();} | ||
return written; | ||
} | ||
}; | ||
|
||
|
||
//! Wrapper for lockless ringbuffer reader | ||
template <class T> | ||
class LocklessRingBufferReader : public ringbuffer_reader_t<T> | ||
{ | ||
public: | ||
LocklessRingBufferReader(LocklessRingBuffer<T> &rb) : | ||
ringbuffer_reader_t<T>(rb.m_buffer), | ||
m_notifier(&rb.m_notifier) {}; | ||
|
||
bool empty() const {return !this->read_space();} | ||
void waitForData() | ||
{ | ||
QMutex useless_lock; | ||
m_notifier->wait(&useless_lock); | ||
useless_lock.unlock(); | ||
} | ||
private: | ||
QWaitCondition *m_notifier; | ||
}; | ||
|
||
#endif //LOCKLESSRINGBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
INCLUDE(BuildPlugin) | ||
INCLUDE_DIRECTORIES(${FFTW3F_INCLUDE_DIRS}) | ||
|
||
LINK_LIBRARIES(${FFTW3F_LIBRARIES}) | ||
|
||
BUILD_PLUGIN(analyzer Analyzer.cpp SaProcessor.cpp SaControls.cpp SaControlsDialog.cpp SaSpectrumView.cpp SaWaterfallView.cpp | ||
MOCFILES SaProcessor.h SaControls.h SaControlsDialog.h SaSpectrumView.h SaWaterfallView.h EMBEDDED_RESOURCES *.svg logo.png) | ||
MOCFILES SaProcessor.h SaControls.h SaControlsDialog.h SaSpectrumView.h SaWaterfallView.h DataprocLauncher.h EMBEDDED_RESOURCES *.svg logo.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* DataprocLauncher.h - QThread::create workaround for older Qt version | ||
* | ||
* Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com> | ||
* | ||
* This file is part of LMMS - https://lmms.io | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program (see COPYING); if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
#ifndef DATAPROCLAUNCHER_H | ||
#define DATAPROCLAUNCHER_H | ||
|
||
#include <QThread> | ||
|
||
#include "SaProcessor.h" | ||
#include "LocklessRingBuffer.h" | ||
|
||
class DataprocLauncher : public QThread | ||
{ | ||
public: | ||
explicit DataprocLauncher(SaProcessor &proc, LocklessRingBuffer<sampleFrame> &buffer) | ||
: m_processor(&proc), | ||
m_inputBuffer(&buffer) | ||
{ | ||
} | ||
|
||
private: | ||
void run() override | ||
{ | ||
m_processor->analyze(*m_inputBuffer); | ||
} | ||
|
||
SaProcessor *m_processor; | ||
LocklessRingBuffer<sampleFrame> *m_inputBuffer; | ||
}; | ||
|
||
#endif // DATAPROCLAUNCHER_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
srcOffset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there really a camel case thing in the conventions before? I often used underscore in local variable names before in all the other classes.
I feel like the conventions are a moving target... There could at least be an announcement when they change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They changed a lot recently. It earlier said: "Variable and method names begin with a lower case letter". @Veratil changed it to "SHOULD be camelCase". So it's indeed optional.
But clang-format will eradicate any style freedom anyways