SineWave

A source unit that can generate a sinusoid or sine wave. The signal is remapped to oscillate between 0 and 1 (rather than -1 and 1 as the traditional sine wave).

_images/Plaquette-SineWave.png

Example

Pulses an LED.

#include <Plaquette.h>

AnalogOut led(9);

SineWave osc;

void begin() {
  osc.frequency(5.0); // frequency of 5 Hz
}

void step() {
  osc >> led;
}
class SineWave : public AbstractWave

Sine oscillator. Phase is expressed as % of period.

Public Functions

virtual void period(float period)

Sets the period (in seconds).

Parameters:

period – the period of oscillation (in seconds)

virtual void frequency(float frequency)

Sets the frequency (in Hz).

Parameters:

frequency – the frequency of oscillation (in Hz)

inline virtual float frequency() const

Returns the frequency (in Hz).

virtual void bpm(float bpm)

Sets the frequency in beats-per-minute.

Parameters:

bpm – the frequency of oscillation (in BPM)

inline virtual float bpm() const

Returns the frequency (in BPM).

virtual void width(float width)

Sets the width of the signal as a % of period.

Parameters:

width – the width as a value in [0, 1]

inline virtual float width() const

Returns the width of the signal.

virtual void amplitude(float amplitude)

Sets the amplitude of the wave.

Parameters:

amplitude – a value in [0, 1] that determines the amplitude of the wave (centered at 0.5).

inline virtual float amplitude() const

Returns the amplitude of the wave.

virtual void phase(float phase)

Sets the phase (ie.

the offset, in % of period).

Parameters:

phase – the phase (in % of period)

inline virtual float phase() const

Returns the phase (in % of period).

virtual float shiftBy(float phaseShift)

Returns oscillator’s value with given phase shift (in %).

Supports negative phase shifts. Eg. shiftBy(0.2) returns future value of oscillator after 20% of its period would have passed.

Parameters:

phase – the phase shift (in % of period)

Returns:

the value of oscillator with given phase shift

inline virtual float get()

Returns value in [0, 1].

inline virtual float mapTo(float toLow, float toHigh)

Maps value to new range.

See Also