sfFDN
Loading...
Searching...
No Matches
oscillator.h
1// Copyright (C) 2025 Alexandre St-Onge
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "audio_buffer.h"
6
7namespace sfFDN
8{
11{
12 public:
13 Generator() = default;
14 virtual ~Generator() = default;
15
17 virtual void Generate(std::span<float> output) = 0;
18};
19
23class SineWave : public Generator
24{
25 public:
32 SineWave(float frequency = 0.0f, float initial_phase = 0.0f);
33
35 void ResetPhase();
36
40 void SetFrequency(float frequency);
41
45 void SetAmplitude(float amplitude);
46
50 float GetAmplitude() const;
51
57 void SetOffset(float offset);
58
62 float GetOffset() const;
63
67 void SetPhaseOffset(float phase_offset);
68
70 float NextOut() const;
71
73 float Tick();
74
76 void Generate(std::span<float> output) override;
77
83 void Multiply(std::span<const float> input, std::span<float> output);
84
90 void MultiplyAccumulate(std::span<const float> input, std::span<float> output);
91
92 private:
93 float phase_;
94 float phase_increment_;
95
96 float amplitude_;
97 float offset_;
98 float phase_offset_;
99};
100
101} // namespace sfFDN
Base class for oscillators and signal generators.
Definition oscillator.h:11
virtual void Generate(std::span< float > output)=0
Fills the output span with generated samples.
A sine wave oscillator.
Definition oscillator.h:24
void SetOffset(float offset)
Sets the DC offset of the sine wave oscillator.
float GetAmplitude() const
Returns the amplitude of the sine wave oscillator.
float GetOffset() const
Returns the DC offset of the sine wave oscillator.
SineWave(float frequency=0.0f, float initial_phase=0.0f)
Constructs a sine wave oscillator.
void Multiply(std::span< const float > input, std::span< float > output)
Multiply input by the sine wave and store the result in output.
void ResetPhase()
Resets the phase of the sine wave oscillator.
void SetPhaseOffset(float phase_offset)
Sets the phase offset of the sine wave oscillator.
float Tick()
Advances the phase and returns the next output sample.
void Generate(std::span< float > output) override
Fills the output span with generated samples.
void SetAmplitude(float amplitude)
Sets the amplitude of the sine wave oscillator.
void SetFrequency(float frequency)
Sets the frequency of the sine wave oscillator.
void MultiplyAccumulate(std::span< const float > input, std::span< float > output)
Multiply input by the sine wave and accumulate the result in output.
float NextOut() const
Returns the next output sample without advancing the phase.