lfo_pwm_u

Unipolar LFO with phase, pwm and reset inputs
Author: Are Leistad
License: BSD
Github: drj/lfo/lfo_pwm.axo

IO Variants: 2


Variant: 1

Inlets

frac32.bipolar Pitch input

frac32.bipolar Phase input

frac32.bipolar Pulse width modulation

bool32.rising Reset phase

Outlets

frac32.positive PWM output

Parameters

frac32.s.map.lfopitch Pitch

frac32.u.map.ratio Pulse width

Declaration
uint32_t phase;
int32_t old_reset;
Init
phase = 0;
old_reset = 0;
Control Rate
int32_t pulsewidth;
uint32_t phase2;

if (inlet_reset && !old_reset) {
  phase = 0;
} else {
  int32_t freq;
  MTOFEXTENDED(param_pitch + inlet_pitch, freq);
  phase += freq >> 2;
}
old_reset = inlet_reset;

pulsewidth = param_pw + inlet_pwm;
if (pulsewidth > (1 << 27)) {
  pulsewidth = (1 << 27);
} else if (pulsewidth < 0) {
  pulsewidth = 0;
}

phase2 = phase + (inlet_phase << 4);
if ((phase2 >> 5) > pulsewidth) {
  outlet_pwm = 0;
} else {
  outlet_pwm = (1 << 27) - 1;
}

Variant: 2

Inlets

frac32.bipolar Pitch input

frac32.bipolar Phase input

frac32.bipolar Pulse width modulation

bool32.rising Reset phase

Outlets

frac32.bipolar PWM output

Parameters

frac32.s.map.lfopitch Pitch

frac32.u.map.ratio Pulse width

Declaration
uint32_t phase;
int32_t old_reset;
Init
phase = 0;
old_reset = 0;
Control Rate
int32_t pulsewidth;
uint32_t phase2;

if (inlet_reset && !old_reset) {
  phase = 0;
} else {
  int32_t freq;
  MTOFEXTENDED(param_pitch + inlet_pitch, freq);
  phase += freq >> 2;
}
old_reset = inlet_reset;

pulsewidth = param_pw + inlet_pwm;
if (pulsewidth > (1 << 27)) {
  pulsewidth = (1 << 27);
} else if (pulsewidth < 0) {
  pulsewidth = 0;
}

phase2 = phase + (inlet_phase << 4);
if ((phase2 >> 5) > pulsewidth) {
  outlet_pwm = -(1 << 27);
} else {
  outlet_pwm = (1 << 27) - 1;
}

Privacy

© 2024 Zrna Research