eDSP
0.0.1
A cross-platform DSP library written in C++.
|
The class sin_oscillator generates a sinusoidal signal. More...
#include <sinusoidal.hpp>
Public Types | |
using | value_type = T |
![]() | |
using | value_type = T |
Public Member Functions | |
constexpr | sin_oscillator (value_type amplitude, value_type samplerate, value_type frequency, value_type phase) noexcept |
Creates a sinusoidal oscillator that generates a waveform with the configuration. More... | |
constexpr value_type | operator() () |
Generates one step. 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 sin_oscillator generates a sinusoidal signal.
The sine wave can be considered the most fundamental building block of sound. A cycle of a sine wave is \( \displaystyle 2 \pi \) radians long and has a peak amplitude of \( \displaystyle +/-1 \).
With a sample rate of 44100 cycles per second, and a required cycle length of 1 second, it will take 44100 samples to get from 0 to \( \displaystyle 2\pi \) . In other words, we can determine the steps per cycle \( \displaystyle S \) from cycle length \( \displaystyle T \):
\[ {\displaystyle S=T\cdot F_{s}\,} \]
Where \( {\displaystyle F_{s}} \) is the sample rate. Each step will therefore take the following amount in radians:
\[ {\displaystyle \delta \phi ={\frac {2\pi }{T\cdot F_{s}}}} or {\displaystyle {\frac {2\pi f}{F_{s}}}} \]
Where \( {\displaystyle f} \), in the second result, is the same result in terms of frequency.
using edsp::oscillators::sin_oscillator< T >::value_type = T |
|
noexcept |
Creates a sinusoidal 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). |
phase | Phase shift in radians. |
constexpr sin_oscillator< T >::value_type edsp::oscillators::sin_oscillator< T >::operator() | ( | ) |
Generates one step.