summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authormarwik15 <marwik15@gmail.com>2022-05-02 13:19:13 +0200
committermarwik15 <marwik15@gmail.com>2022-05-02 13:19:13 +0200
commit2ef406196751a469323ed622312df2e7e7b1834b (patch)
tree1c75c8715c7c4e5e61a9f78099c543369e36d01b /daemon
parentd417394ae791e9972fede0665587aa612f93bca0 (diff)
downloadhwd-2ef406196751a469323ed622312df2e7e7b1834b.zip
hwd-2ef406196751a469323ed622312df2e7e7b1834b.tar.gz
hwd-2ef406196751a469323ed622312df2e7e7b1834b.tar.bz2
Sine wave changes after CR
Diffstat (limited to 'daemon')
-rw-r--r--daemon/src/Sinewave.cpp15
-rw-r--r--daemon/src/Sinewave.h14
2 files changed, 13 insertions, 16 deletions
diff --git a/daemon/src/Sinewave.cpp b/daemon/src/Sinewave.cpp
index de63553..d1ca5ef 100644
--- a/daemon/src/Sinewave.cpp
+++ b/daemon/src/Sinewave.cpp
@@ -1,9 +1,7 @@
#include "Sinewave.h"
-Sinewave::Sinewave()
+Sinewave::Sinewave() : m_start_time{clock::now()}
{
- m_start_time = std::chrono::high_resolution_clock::now();
-
m_amplitude = 11;
m_frequency = 10;
m_phase = 30;
@@ -13,10 +11,10 @@ void Sinewave::apply(AssemblyContext ctx)
{
ctx.bind("/set_amplitude", [&](double amplitude) { set_amplitude(amplitude); });
ctx.bind("/set_frequency", [&](double frequency) { set_frequency(frequency); });
- ctx.bind("/set_phase", [&](double phase) { set_phase(phase); });
+ ctx.bind("/set_phase", [&](double phase) { set_phase(phase); });
ctx.bind("/get_amplitude", [&]() -> double { return get_amplitude(); });
ctx.bind("/get_frequency", [&]() -> double { return get_frequency(); });
- ctx.bind("/get_phase", [&]() -> double { return get_phase(); });
+ ctx.bind("/get_phase", [&]() -> double { return get_phase(); });
ctx.bind("/get_point", [&]() -> double { return get_point(); });
}
@@ -50,10 +48,9 @@ double Sinewave::get_phase() const
return m_phase;
}
-double Sinewave::get_point()
+double Sinewave::get_point() const
{
- m_current_time = std::chrono::high_resolution_clock::now();
- m_duration_time = m_current_time - m_start_time;
+ const auto time = clock::now() - m_start_time;
- return m_amplitude * sin(2 * 3.14 * m_frequency * m_duration_time.count() + m_phase);
+ return m_amplitude * sin(2 * M_PI * m_frequency * time.count() + m_phase);
}
diff --git a/daemon/src/Sinewave.h b/daemon/src/Sinewave.h
index d8988ad..d5be732 100644
--- a/daemon/src/Sinewave.h
+++ b/daemon/src/Sinewave.h
@@ -1,12 +1,13 @@
#pragma once
-#include <string>
-#include <math.h>
+#include <cmath>
#include <chrono>
#include "Assembly.h"
-class Sinewave {
+class Sinewave
+{
+ using clock = std::chrono::high_resolution_clock;
public:
Sinewave();
@@ -21,13 +22,12 @@ public:
double get_frequency() const;
double get_phase() const;
+ double get_point() const;
+
private:
- std::chrono::time_point<std::chrono::high_resolution_clock> m_start_time, m_current_time;
- std::chrono::duration<double> m_duration_time;
+ const std::chrono::high_resolution_clock::time_point m_start_time;
double m_amplitude;
double m_frequency;
double m_phase;
-
- double get_point();
};