OpenWareLaboratory
PolyBlepOscillator.cpp
Go to the documentation of this file.
1 #include "PolyBlepOscillator.h"
2 #include "basicmaths.h"
3 
5  mul(1.0f/sr),
6  nfreq(0.0f),
7  shape(0.5f),
8  pw(0.5f) {
9  osc.Init();
10 }
11 
13  mul(1.0f/sr),
14  shape(0.5f),
15  pw(0.5f) {
16  setFrequency(freq);
17  osc.Init();
18 }
19 
21  mul = 1.0f/sr;
22 }
23 
25  return 1.0f/mul;
26 }
27 
29  nfreq = mul*freq;
30 }
31 
33  return nfreq/mul;
34 }
35 
36 void PolyBlepOscillator::setShape(float value){
37  shape = value;
38 }
39 
41  return shape;
42 }
43 
45  pw = value;
46 }
47 
49  return pw;
50 }
51 
53  return osc.getMasterPhase()*2*M_PI;
54 }
55 
56 void PolyBlepOscillator::setPhase(float phase){
57  osc.setMasterPhase(phase/(2*M_PI));
58 }
59 
61  float sample;
62  osc.Render<true>(nfreq, pw, shape, &sample, 1);
63  return sample;
64 }
65 
67  float sample;
68  osc.Render<true>(nfreq*(1+fm), pw, shape, &sample, 1);
69  return sample;
70 }
71 
73  osc.Render<true>(nfreq, pw, shape, output, output.getSize());
74 }
75 
77  output.copyFrom(fm);
78  output.multiply(nfreq); // scale by base frequency
79  output.add(nfreq); // add base frequency : freq = nfreq + nfreq*fm
80  osc.Render<true>(output, pw, shape, output, output.getSize());
81 }
82 
84  freqs.multiply(mul); // normalise frequencies
85  osc.Render<true>(freqs, pw, shape, output, output.getSize());
86 }
87 
89  return new PolyBlepOscillator(sr);
90 }
91 
93  return new PolyBlepOscillator(freq, sr);
94 }
95 
97  delete osc;
98 }
#define M_PI
Definition: basicmaths.h:52
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
void multiply(FloatArray operand2, FloatArray destination)
Element-wise multiplication between arrays.
Definition: FloatArray.cpp:290
void add(FloatArray operand2, FloatArray destination)
Element-wise sum between arrays.
Definition: FloatArray.cpp:231
static PolyBlepOscillator * create(float sr)
void setFrequency(float freq)
Set oscillator frequency in Hertz.
void getSamples(FloatArray output, FloatArray freq)
float generate()
Produce the next consecutive sample.
PolyBlepOscillator(float sr=48000)
float getPhase()
Get current oscillator phase in radians.
static void destroy(PolyBlepOscillator *osc)
void setSampleRate(float sr)
Set oscillator sample rate.
float getFrequency()
Get oscillator frequency in Hertz.
void setPhase(float phase)
Set current oscillator phase in radians.
void setShape(float value)
set waveform shape: 0.0 for saw, 1.0 for square wave
void setPulseWidth(float value)
set square wave pulse width: 0.0 to 1.0 for 0% to 100%
void copyFrom(SimpleArray< T > source)
Copies the content of another array into this array.
Definition: SimpleArray.h:86
size_t getSize() const
Definition: SimpleArray.h:31