summaryrefslogtreecommitdiff
path: root/daemon/src/Sinewave.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/src/Sinewave.cpp')
-rw-r--r--daemon/src/Sinewave.cpp15
1 files changed, 6 insertions, 9 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);
}