-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Spectrum analyzer update #5160
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
Changes from 31 commits
9be31e0
4e2f168
f5eda87
7d630e1
249d161
25aa537
3707eeb
cb3e701
8d639e5
36feb65
b650838
42d74db
9dd9ef0
6a5089d
6939702
11013cc
edefc93
e3c89d5
5b1f28c
7cf189c
11bb2c7
2963fb6
6dd2619
6856b3d
0d56ae8
228dd2f
22e9163
dc2bd91
8739abb
7a0fc5a
bf793da
ad49d36
a0acc8a
8ca05a3
c694277
0caa748
a7388b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * 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 "lmms_export.h" | ||
| #include "../src/3rdparty/ringbuffer/include/ringbuffer/ringbuffer.h" | ||
| #include "lmms_basics.h" | ||
| #include <QMutex> | ||
| #include <QWaitCondition> | ||
|
|
||
|
|
||
| //! A convenience layer for a realtime-safe and thread-safe multi-reader ring buffer library. | ||
| template <class T> | ||
| class LocklessRingBuffer | ||
| { | ||
| template<class _T> | ||
| friend class LocklessRingBufferReader; | ||
| public: | ||
| LocklessRingBuffer(std::size_t sz) : m_buffer(sz) {}; | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ~LocklessRingBuffer() {}; | ||
|
|
||
| std::size_t write(const T *src, size_t cnt) | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| std::size_t written = m_buffer.write(src, cnt); | ||
| m_notifier.wakeAll(); // Let all waiting readers know new data are available. | ||
| return written; | ||
| } | ||
| std::size_t capacity() {return m_buffer.maximum_eventual_write_space();} | ||
| std::size_t free() {return m_buffer.write_space();} | ||
| void wakeAll() {m_notifier.wakeAll();} | ||
|
|
||
| private: | ||
| ringbuffer_t<T> m_buffer; | ||
| QWaitCondition m_notifier; | ||
| }; | ||
|
|
||
|
|
||
| // The sampleFrame_copier is required because sampleFrame is just a two-element | ||
| // array and therefore does not have a copy constructor needed by std::copy. | ||
| class sampleFrame_copier | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| const sampleFrame* src; | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| sampleFrame_copier(const sampleFrame* src) : src(src) {} | ||
| void operator()(std::size_t src_offset, std::size_t count, sampleFrame* dest) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| { | ||
| for (std::size_t i = src_offset; i < src_offset + count; i++, dest++) | ||
| { | ||
| (*dest)[0] = src[i][0]; | ||
| (*dest)[1] = src[i][1]; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| //! Specialized version with write function modified to support sampleFrame. | ||
| template <> | ||
| class LocklessRingBuffer<sampleFrame> | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| template<class _T> | ||
| friend class LocklessRingBufferReader; | ||
| public: | ||
| LocklessRingBuffer(std::size_t sz) : m_buffer(sz) {}; | ||
| ~LocklessRingBuffer() {}; | ||
|
|
||
| std::size_t write(const sampleFrame *src, size_t cnt) | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| sampleFrame_copier copier(src); | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::size_t written = m_buffer.write_func<sampleFrame_copier>(copier, cnt); | ||
| // Let all waiting readers know new data are available. | ||
| m_notifier.wakeAll(); | ||
| return written; | ||
| } | ||
|
|
||
| std::size_t capacity() {return m_buffer.maximum_eventual_write_space();} | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::size_t free() {return m_buffer.write_space();} | ||
| void wakeAll() {m_notifier.wakeAll();} | ||
|
|
||
| private: | ||
| ringbuffer_t<sampleFrame> m_buffer; | ||
| QWaitCondition m_notifier; | ||
| }; | ||
|
|
||
|
|
||
| //! 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() {return !this->read_space();} | ||
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
he29-net marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void waitForData() | ||
| { | ||
| QMutex useless_lock; | ||
| m_notifier->wait(&useless_lock); | ||
| useless_lock.unlock(); | ||
| } | ||
| private: | ||
| QWaitCondition *m_notifier; | ||
| }; | ||
|
|
||
|
|
||
| // This is required to force MSVC compilers to export symbols for template class methods. | ||
| // Any template instances that are not specified here will not work in plugins. | ||
| //template class LMMS_EXPORT LocklessRingBufferReader<sampleFrame>; | ||
|
|
||
| #endif //LOCKLESSRINGBUFFER_H | ||
| 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) |
| 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 |
Uh oh!
There was an error while loading. Please reload this page.