Use GCD for TapStep.
parent
35ca8c06bb
commit
e1522a7ab3
|
|
@ -129,7 +129,7 @@ short* ResampleStep::execute(short* inputSamples, int numInputSamples, int* numO
|
|||
|
||||
*numOutputSamples = 0;
|
||||
|
||||
auto inputPtr = inputSamples;
|
||||
//auto inputPtr = inputSamples;
|
||||
auto outputPtr = outputSamples_.get();
|
||||
#if 0
|
||||
while (numInputSamples > 0)
|
||||
|
|
|
|||
|
|
@ -36,11 +36,13 @@ TapStep::TapStep(int sampleRate, IPipelineStep* tapStep)
|
|||
: tapStep_(tapStep)
|
||||
, sampleRate_(sampleRate)
|
||||
#if defined(TAP_STEP_USE_THREADING)
|
||||
, endingTapThread_(false)
|
||||
, tapThreadInput_(sampleRate)
|
||||
#if !defined(__APPLE__)
|
||||
, endingTapThread_(false)
|
||||
#endif // !defined(__APPLE__)
|
||||
#endif // defined(TAP_STEP_USE_THREADING)
|
||||
{
|
||||
#if defined(TAP_STEP_USE_THREADING)
|
||||
#if defined(TAP_STEP_USE_THREADING) && !defined(__APPLE__)
|
||||
tapThread_ = std::thread([&]() {
|
||||
const int SAMPLE_RATE_AT_10MS = sampleRate_ / 100;
|
||||
short* fifoInput = new short[SAMPLE_RATE_AT_10MS];
|
||||
|
|
@ -64,16 +66,16 @@ TapStep::TapStep(int sampleRate, IPipelineStep* tapStep)
|
|||
|
||||
delete[] fifoInput;
|
||||
});
|
||||
#endif // defined(TAP_STEP_USE_THREADING)
|
||||
#endif // defined(TAP_STEP_USE_THREADING) && !defined(__APPLE__)
|
||||
}
|
||||
|
||||
TapStep::~TapStep()
|
||||
{
|
||||
#if defined(TAP_STEP_USE_THREADING)
|
||||
#if defined(TAP_STEP_USE_THREADING) && !defined(__APPLE__)
|
||||
endingTapThread_ = true;
|
||||
sem_.signal();
|
||||
tapThread_.join();
|
||||
#endif // defined(TAP_STEP_USE_THREADING)
|
||||
#endif // defined(TAP_STEP_USE_THREADING) && !defined(__APPLE__)
|
||||
}
|
||||
|
||||
int TapStep::getInputSampleRate() const
|
||||
|
|
@ -94,8 +96,25 @@ short* TapStep::execute(short* inputSamples, int numInputSamples, int* numOutput
|
|||
tapThreadInput_.write(inputSamples, numInputSamples);
|
||||
if (tapThreadInput_.numUsed() > (100 * sampleRate_ / 1000))
|
||||
{
|
||||
#if !defined(__APPLE__)
|
||||
sem_.signal();
|
||||
#else
|
||||
enqueue_([&]() {
|
||||
const int SAMPLE_RATE_AT_10MS = sampleRate_ / 100;
|
||||
short* fifoInput = new short[SAMPLE_RATE_AT_10MS];
|
||||
assert(fifoInput != nullptr);
|
||||
|
||||
while (tapThreadInput_.numUsed() >= SAMPLE_RATE_AT_10MS)
|
||||
{
|
||||
int temp = 0;
|
||||
tapThreadInput_.read(fifoInput, SAMPLE_RATE_AT_10MS);
|
||||
tapStep_->execute(fifoInput, SAMPLE_RATE_AT_10MS, &temp);
|
||||
}
|
||||
|
||||
delete[] fifoInput;
|
||||
});
|
||||
}
|
||||
#endif // !defined(__APPLE__)
|
||||
#else
|
||||
int temp = 0;
|
||||
tapStep_->execute(inputSamples, numInputSamples, &temp);
|
||||
|
|
|
|||
|
|
@ -26,14 +26,17 @@
|
|||
#include <memory>
|
||||
#include <thread>
|
||||
#include "../util/GenericFIFO.h"
|
||||
#include "../util/Semaphore.h"
|
||||
#include "../util/ThreadedObject.h"
|
||||
|
||||
#include "IPipelineStep.h"
|
||||
|
||||
// Creates a separate thread for each TapStep instance if uncommented.
|
||||
//#define TAP_STEP_USE_THREADING
|
||||
#define TAP_STEP_USE_THREADING
|
||||
|
||||
class TapStep : public IPipelineStep
|
||||
#if defined(TAP_STEP_USE_THREADING) && defined(__APPLE__)
|
||||
, public ThreadedObject
|
||||
#endif // defined(TAP_STEP_USE_THREADING) && defined(__APPLE__)
|
||||
{
|
||||
public:
|
||||
TapStep(int inputSampleRate, IPipelineStep* tapStep);
|
||||
|
|
@ -48,10 +51,12 @@ private:
|
|||
int sampleRate_;
|
||||
|
||||
#if defined(TAP_STEP_USE_THREADING)
|
||||
GenericFIFO<short> tapThreadInput_;
|
||||
#if !defined(__APPLE__)
|
||||
std::thread tapThread_;
|
||||
bool endingTapThread_;
|
||||
GenericFIFO<short> tapThreadInput_;
|
||||
Semaphore sem_;
|
||||
#endif // !defined(__APPLE__)
|
||||
#endif // defined(TAP_STEP_USE_THREADING)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue