66#include " neuron/core/parameter.h"
77#include " neuron/dsp/generators/generator.h"
88#include " neuron/utils/waveform.h"
9+ #include " neuron/utils/wavetable.h"
910
1011namespace neuron {
1112
12- const size_t WAVETABLE_SIZE = 256 ;
13-
1413 enum OscillatorParameter {
1514 OSC_FREQUENCY,
1615 };
@@ -22,13 +21,9 @@ namespace neuron {
2221 class Oscillator : public Generator <Oscillator>, public Neuron<Oscillator, OscillatorParameter> {
2322 public:
2423 /* *
25- * Creates an oscillator generator.
26- *
27- * @param context The DSP context to be used by the oscillator.
28- * @param frequency The initial frequency of the oscillator.
29- * @return Oscillator
24+ * Creates an oscillator generator that produces the given waveform at the given frequency.
3025 */
31- explicit Oscillator (Context& context = DEFAULT_CONTEXT, float frequency = 440 .0f , Waveform waveform = Waveform::SINE);
26+ explicit Oscillator (float frequency = 440 .0f , Waveform waveform = Waveform::SINE);
3227
3328 /* *
3429 * Frees any memory allocated by the oscillator.
@@ -38,29 +33,21 @@ namespace neuron {
3833 /* *
3934 * Resets the phase of the oscillator, starting it at the beginning
4035 * waveform position.
41- *
42- * @param
4336 */
4437 void Reset (float phase = 0 .0f );
4538
4639 /* *
4740 * Sets the frequency of the oscillator.
48- *
49- * @param frequency The new oscillator output frequency.
5041 */
5142 void SetFrequency (float frequency);
5243
5344 /* *
5445 * Sets the waveform of the oscillator.
55- *
56- * @param waveform The new oscillator output waveform.
5746 */
5847 void SetWaveform (Waveform waveform);
5948
6049 /* *
6150 * Attaches a follower oscillator to be synced to this one.
62- *
63- * @param oscillator The oscillator that will be synced to this one.
6451 */
6552 void AttachFollower (Oscillator* oscillator);
6653
@@ -74,32 +61,33 @@ namespace neuron {
7461 void GenerateImpl (Buffer<Sample>& output);
7562
7663 friend class Neuron <Oscillator, OscillatorParameter>;
77- void SetContextImpl (const Context& context);
64+ void SetContextImpl (Context context);
65+
7866 template <class M >
79- void AttachModulatorImpl (OscillatorParameter parameter, Modulator<M>* modulator);
67+ void AttachModulatorImpl (OscillatorParameter parameter, Modulator<M>* modulator)
68+ {
69+ switch (parameter) {
70+ case OscillatorParameter::OSC_FREQUENCY:
71+ m_frequencyModulator = ModulationSource (modulator);
72+ break ;
73+ default :
74+ break ;
75+ }
76+ }
77+
8078 void DetachModulatorImpl (OscillatorParameter parameter);
8179 void SetModulationDepthImpl (OscillatorParameter parameter, float depth);
82- #ifdef NEO_PLUGIN_SUPPORT
80+ #if NEO_PLUGIN_SUPPORT
8381 void AttachParameterToSourceImpl (OscillatorParameter parameter, std::atomic<float >* source);
8482#endif
8583
8684 private:
87- void PopulateWavetable ();
88- void IncrementPhase ();
89- Sample Lerp ();
90-
91- Context& m_context;
92-
93- Sample m_wavetable[WAVETABLE_SIZE];
94- Waveform m_waveform;
85+ Wavetable m_wavetable;
9586
9687 Parameter<float > p_frequency;
9788 Parameter<float > p_frequencyModulationDepth;
9889 ModulationSource m_frequencyModulator;
9990
100- float m_phase = 0 .0f ;
101- float m_phaseIncrement = 0 .0f ;
102-
10391 Oscillator* m_follower = nullptr ;
10492 };
10593
0 commit comments