Triangle Wave Oscillator
Nucli

Triangle Wave Oscillator

Generates a triangle wave with adjustable frequency and output level. Its symmetrical shape produces a softer tone with fewer upper harmonics than a sawtooth wave.
LanguageNucli
Added16 Oct 2026
Views27

Free to use for anything. No credit needed.

No ratings yet

Log in to rate this code.

Code 26 lines

param freq = 220 (20 .. 2000)
param level = 0.3 (0 .. 1)

history phase = 0

let increment = freq / samplerate
let nextPhase = phase + increment

if (nextPhase >= 1) {
  nextPhase = nextPhase - 1
}

let triangle = 0

if (nextPhase < 0.5) {
  triangle = (nextPhase * 4) - 1
} else {
  triangle = 3 - (nextPhase * 4)
}

let output = triangle * level

out1 = output
out2 = output

phase = nextPhase

Comments

No comments yet.

← Back to code