-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Few nits and using QThreadPool/QRunnable
- Loading branch information
1 parent
05df96d
commit 406fc3a
Showing
10 changed files
with
126 additions
and
176 deletions.
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,48 @@ | ||
#include "engine/bufferscalers/rubberbandtask.h" | ||
|
||
#include "engine/engine.h" | ||
#include "util/assert.h" | ||
#include "util/compatibility/qmutex.h" | ||
|
||
RubberBandTask::RubberBandTask( | ||
size_t sampleRate, size_t channels, Options options) | ||
: RubberBand::RubberBandStretcher(sampleRate, channels, options), | ||
QRunnable(), | ||
m_completed(false), | ||
m_input(nullptr), | ||
m_samples(0), | ||
m_isFinal(false) { | ||
setAutoDelete(false); | ||
} | ||
|
||
void RubberBandTask::set(const float* const* input, | ||
size_t samples, | ||
bool isFinal) { | ||
auto locker = lockMutex(&m_waitLock); | ||
m_completed = false; | ||
m_input = input; | ||
m_samples = samples; | ||
m_isFinal = isFinal; | ||
} | ||
|
||
void RubberBandTask::waitReady() { | ||
auto locker = lockMutex(&m_waitLock); | ||
VERIFY_OR_DEBUG_ASSERT(m_input && m_samples) { | ||
return; | ||
}; | ||
while (!m_completed) { | ||
m_waitCondition.wait(&m_waitLock); | ||
} | ||
} | ||
|
||
void RubberBandTask::run() { | ||
auto locker = lockMutex(&m_waitLock); | ||
VERIFY_OR_DEBUG_ASSERT(!m_completed && m_input && m_samples) { | ||
return; | ||
}; | ||
process(m_input, | ||
m_samples, | ||
m_isFinal); | ||
m_completed = true; | ||
m_waitCondition.wakeOne(); | ||
} |
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,45 @@ | ||
#pragma once | ||
|
||
#include <rubberband/RubberBandStretcher.h> | ||
|
||
#include <QMutex> | ||
#include <QRunnable> | ||
#include <QWaitCondition> | ||
#include <atomic> | ||
|
||
#include "audio/types.h" | ||
|
||
using RubberBand::RubberBandStretcher; | ||
|
||
class RubberBandTask : public RubberBandStretcher, public QRunnable { | ||
public: | ||
RubberBandTask(size_t sampleRate, | ||
size_t channels, | ||
Options options = DefaultOptions); | ||
|
||
/// @brief Submit a new stretching task | ||
/// @param stretcher the RubberBand::RubberBandStretcher instance to use. | ||
/// Must remain valid till waitReady() as returned | ||
/// @param input The samples buffer | ||
/// @param samples the samples count | ||
/// @param final whether or not this is the final buffer | ||
void set(const float* const* input, | ||
size_t samples, | ||
bool isFinal); | ||
|
||
// Wait for the current task to complete. | ||
void waitReady(); | ||
|
||
void run(); | ||
|
||
private: | ||
// Used to schedule the thread | ||
QMutex m_waitLock; | ||
QWaitCondition m_waitCondition; | ||
// Whether or not the scheduled job as completed | ||
bool m_completed; | ||
|
||
const float* const* m_input; | ||
size_t m_samples; | ||
bool m_isFinal; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.