Skip to content

Commit

Permalink
Wait for a few buffer switches before exiting FlexASIOTest.
Browse files Browse the repository at this point in the history
See #7.
  • Loading branch information
dechamps committed Oct 23, 2018
1 parent bda5a28 commit 72f8a9a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions FlexASIOTest/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <condition_variable>
#include <iostream>
#include <functional>
#include <mutex>
#include <optional>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -269,9 +271,21 @@ namespace flexasio_test {

std::cout << std::endl;

std::mutex bufferSwitchCountMutex;
std::condition_variable bufferSwitchCountCondition;
size_t bufferSwitchCount = 0;
const auto incrementBufferSwitchCount = [&] {
{
std::scoped_lock bufferSwitchCountLock(bufferSwitchCountMutex);
++bufferSwitchCount;
}
bufferSwitchCountCondition.notify_all();
};

Callbacks callbacks;
callbacks.bufferSwitch = [&](long doubleBufferIndex, ASIOBool directProcess) {
std::cout << "bufferSwitch(doubleBufferIndex = " << doubleBufferIndex << ", directProcess = " << directProcess << ")" << std::endl;
incrementBufferSwitchCount();
std::cout << "<-" << std::endl;
};
callbacks.sampleRateDidChange = [&](ASIOSampleRate sampleRate) {
Expand All @@ -285,6 +299,7 @@ namespace flexasio_test {
};
callbacks.bufferSwitchTimeInfo = [&](ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess) {
std::cout << "bufferSwitchTimeInfo(params = " << params << ", doubleBufferIndex = " << doubleBufferIndex << ", directProcess = " << directProcess << ")" << std::endl;
incrementBufferSwitchCount();
std::cout << "<- nullptr" << std::endl;
return nullptr;
};
Expand All @@ -307,6 +322,18 @@ namespace flexasio_test {

std::cout << std::endl;

constexpr size_t bufferSwitchCountThreshold = 10;
std::cout << "Now waiting for " << bufferSwitchCountThreshold << " buffer switches..." << std::endl;
std::cout << std::endl;

{
std::unique_lock bufferSwitchCountLock(bufferSwitchCountMutex);
bufferSwitchCountCondition.wait(bufferSwitchCountLock, [&] { return bufferSwitchCount >= bufferSwitchCountThreshold; });
}

std::cout << std::endl;
std::cout << "Reached " << bufferSwitchCountThreshold << " buffer switches, stopping" << std::endl;

if (!Stop()) return false;

// Note: we don't call ASIOExit() because it gets confused by our driver setup trickery (see InitAndRun()).
Expand Down

0 comments on commit 72f8a9a

Please sign in to comment.