eDSP
0.0.1
A cross-platform DSP library written in C++.
|
The class square_oscillator generates a square signal. More...
#include <square.hpp>
Public Types | |
using | value_type = T |
![]() | |
using | value_type = T |
Public Member Functions | |
constexpr | square_oscillator (value_type amplitude, value_type samplerate, value_type frequency, value_type duty) noexcept |
Creates a square oscillator that generates a waveform with the configuration. More... | |
constexpr value_type | operator() () |
Generates one step. More... | |
constexpr void | set_duty (value_type duty) noexcept |
Set the duty cycle of the oscillator. More... | |
constexpr value_type | duty () const noexcept |
Returns the current duty cycle. More... | |
![]() | |
constexpr | oscillator (value_type amplitude, value_type samplerate, value_type frequency, value_type phase) noexcept |
Creates an oscillator that generates a waveform with the configuration. More... | |
constexpr value_type | frequency () const noexcept |
Returns the fundamental frequency in Hz. More... | |
constexpr void | set_frequency (value_type frequency) noexcept |
Sets the fundamental frequency of the periodic signal. More... | |
constexpr value_type | phase () const noexcept |
Returns the phase shift in radians. More... | |
constexpr void | set_phase (value_type phase) noexcept |
Sets the phase shift of the periodic signal. More... | |
constexpr value_type | timestamp () const noexcept |
Returns the current timestamp of the signal in seconds. More... | |
constexpr void | set_timestamp (value_type timestamp) noexcept |
Sets the current timestamp of the periodic signal. More... | |
constexpr value_type | samplerate () const noexcept |
Returns the sampling frequency in Hz. More... | |
constexpr void | set_samplerate (value_type samplerate) noexcept |
Sets the sampling frequency. More... | |
constexpr value_type | sampling_period () const noexcept |
Returns the sampling period in secs. More... | |
constexpr value_type | amplitude () const noexcept |
Returns the amplitude of the periodic signal. More... | |
constexpr void | set_amplitude (value_type amplitude) noexcept |
Set the amplitude of the periodic signal. More... | |
constexpr void | reset () noexcept |
Reset the oscillator to the original state. More... | |
The class square_oscillator generates a square signal.
The square wave can be constructed from straight line segments. The square waves contain a wide range of harmonics. It can be defined as simply the sign function of a sinusoid:
\[ {\displaystyle {\begin{aligned}x(t)&={sgn} \left(\sin {\frac {t}{T}}\right)={sgn}(\sin ft)\\v(t)&={sgn} \left(\cos {\frac {t}{T}}\right)={sgn}(\cos ft),\end{aligned}}} \]
which will be 1 when the sinusoid is positive, −1 when the sinusoid is negative, and 0 at the discontinuities. Here, T is the period of the square wave, or equivalently, f is its frequency, where f = 1/T.
using edsp::oscillators::square_oscillator< T >::value_type = T |
|
noexcept |
Creates a square oscillator that generates a waveform with the configuration.
amplitude | Amplitude of the waveform. |
samplerate | The sampling frequency in Hz. |
frequency | The fundamental frequency of the signal (also known as pitch). |
duty | Duty factor, numeric value from [0,1] |
|
noexcept |
Returns the current duty cycle.
constexpr square_oscillator< T >::value_type edsp::oscillators::square_oscillator< T >::operator() | ( | ) |
Generates one step.
|
noexcept |
Set the duty cycle of the oscillator.
The duty cycle is the fraction of one period in which a signal or system is active. In this case a signal is active when the output is 1.
duty | Numeric value representing the duty cycle [0, 1] |