From: Alexander Schmidt Date: Sat, 28 Oct 2023 14:30:15 +0000 (+0200) Subject: Play note on velocity sign change X-Git-Url: http://git.treefish.org/~alex/seamulator.git/commitdiff_plain/776129fef279847eb021c4657a6c0bece71c5d13?hp=3185fa3e31555b1b80edb81dc4e76a1d9856f6fb Play note on velocity sign change --- diff --git a/include/dot.h b/include/dot.h index 4e086bd..622c2f7 100644 --- a/include/dot.h +++ b/include/dot.h @@ -31,5 +31,6 @@ private: double m_pos = 0.0; double m_vel = 0.0; double m_maxAbsVel = 0.0; + double m_maxAbsIntVel = 0.0; }; diff --git a/src/dot.cpp b/src/dot.cpp index aa4a563..6ff5bf1 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -15,21 +15,28 @@ void Dot::advance(double deltaT) //deltaT *= 10; auto posBefore = m_pos; + auto velBefore = m_vel; m_vel += -std::pow(m_frequency/440.0, 2.0) * 10.0 * ( m_pos - m_point.getHeight() ) * deltaT; m_vel -= m_vel * 0.01 * deltaT; m_pos += m_vel * deltaT; const auto absVel = std::fabs(m_vel); + m_maxAbsIntVel = std::max(m_maxAbsIntVel, absVel); m_maxAbsVel = std::max(absVel, m_maxAbsVel); //std::cout << m_pos << std::endl; - - if (posBefore * m_pos < 0.0) { -// // std::cout << m_vel / m_maxVel << std::endl; - m_noise.noteOn(m_pos >= 0 ? m_frequency : m_frequency, absVel / m_maxAbsVel); -// //m_noise.pluck(absVel / m_maxAbsVel); -// m_noise.controlChange(4, 1.0 * absVel / m_maxAbsVel); + +// if (posBefore * m_pos < 0.0) { +// // // std::cout << m_vel / m_maxVel << std::endl; +// m_noise.noteOn(m_pos >= 0 ? m_frequency : m_frequency, absVel / m_maxAbsVel); +// // m_noise.pluck(absVel / m_maxAbsVel); +// // m_noise.controlChange(4, 1.0 * absVel / m_maxAbsVel); +// } + + if (m_vel * velBefore < 0.0) { + m_noise.noteOn(m_frequency, m_maxAbsIntVel/m_maxAbsVel); + m_maxAbsIntVel = 0.0; } // m_noise.controlChange(128, 128.0 * absVel / m_maxAbsVel); diff --git a/src/synthesizer.cpp b/src/synthesizer.cpp index 8352e7a..fb920ae 100644 --- a/src/synthesizer.cpp +++ b/src/synthesizer.cpp @@ -42,7 +42,7 @@ Synthesizer::Synthesizer(ConstWaterSurfacePtr surface) : m_startTime{std::chrono::system_clock::now()}, m_lastRuntime{getRuntime()} { - stk::Stk::setSampleRate( 44100.0 ); + stk::Stk::setSampleRate( 48000.0 ); stk::Stk::showWarnings( true ); m_dac = std::make_unique(2);