#include "Sine.hpp" namespace muz { /*explicit*/ Sine::Sine(AudioConf const& conf, std::unique_ptr freq) : m_conf { conf } , m_out_freq {std::vector (m_conf.channels(), 0.0f)} , m_freq { std::move(freq) } { for (size_t i=0; i(m_conf.channels()); i++) { m_phases.push_back(0.0f); } } /*virtual*/ Sine::~Sine() { } void Sine::next(std::vector& out) /*override*/ { assert(m_freq); m_freq->next(m_out_freq); if (m_out_freq.size() != m_phases.size()) { throw signal_error {"cannot generate sine: channel number mismatch"}; } for (size_t i=0; i(m_conf.channels()); i++) { float const value = std::sin(m_phases[i]); m_phases[i] += 2 * M_PI * m_out_freq[i] / static_cast(m_conf.samplerate()); m_phases[i] = std::fmod(m_phases[i], 2.0f * M_PI); out[i] = value; } } }