Permalink
Browse files

Experimental tool to test edge detection code

  • Loading branch information...
mlang committed Jul 25, 2017
1 parent 918f3ec commit 3d6f4b65be5da1db8172599393c21e9d94e82a02
Showing with 54 additions and 1 deletion.
  1. +3 −0 CMakeLists.txt
  2. +50 −0 edge.cpp
  3. +1 −1 lib/brlapi.hpp
View
@@ -12,3 +12,6 @@ add_executable(stats stats.cpp)
target_link_libraries(stats IO Boost::boost)
add_executable(brltest brltest.cpp)
target_link_libraries(brltest IO)
add_executable(edge edge.cpp)
target_link_libraries(edge IO)
View
@@ -0,0 +1,50 @@
#include <chrono>
#include <thread>
#include <jack.hpp>
template<typename T> T exponentialAverage(T Value, T Average, T Weight) {
return Weight * Value + (T(1) - Weight) * Average;
}
class EdgeDetect : public JACK::Client {
JACK::AudioIn In;
float SlowAverage, FastAverage, PreviousDifference;
std::size_t PulseWidth;
float const Threshold;
public:
EdgeDetect(float Threshold = 0.2)
: JACK::Client("EdgeDetect")
, In(createAudioIn("In"))
, SlowAverage(0), FastAverage(0), PreviousDifference(0), PulseWidth(0)
, Threshold(Threshold) {}
int process(std::uint32_t FrameCount) override {
std::size_t Frame = 0;
for (auto Sample : In.buffer(FrameCount)) {
FastAverage = exponentialAverage(Sample, FastAverage, 0.25f);
SlowAverage = exponentialAverage(Sample, SlowAverage, 0.0625f);
auto Difference = FastAverage - SlowAverage;
if (PreviousDifference < Threshold && Difference > Threshold) {
std::cout << "Positive Edge (" << Frame << ", " << PulseWidth << ")" << "\n";
PulseWidth = 0;
}
PreviousDifference = Difference;
Frame += 1; PulseWidth += 1;
}
return 0;
}
};
using namespace std::literals::chrono_literals;
int main() {
EdgeDetect App;
App.activate();
while (true) {
std::this_thread::sleep_for(1s);
}
return EXIT_SUCCESS;
}
View
@@ -18,7 +18,7 @@ bool operator>(DisplaySize const &, DisplaySize const &);
bool operator>=(DisplaySize const &, DisplaySize const &);
bool operator<=(DisplaySize const &, DisplaySize const &);
bool operator<(DisplaySize const &, DisplaySize const &);
std::ostream &operator<<(std::ostream &Out, DisplaySize const &);
std::ostream &operator<<(std::ostream &, DisplaySize const &);
class Connection;

0 comments on commit 3d6f4b6

Please sign in to comment.