Sine wave oscillator
Nucli

Sine wave oscillator

This DSP code generates a sine wave oscillator with an adjustable frequency and output level, using a phase accumulator to create a continuous waveform. It outputs the same signal to both the left and right audio channels, so the sound is centered in stereo
LanguageNucli
Added16 Oct 2026
Views26

Free to use for anything. No credit needed.

No ratings yet

Log in to rate this code.

Code 21 lines

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

function choice(phase) {
  if (phase >= 1) { phase = phase - 1 }
  return phase
}

history hist1 = 0

let div1 = freq / samplerate
let lowpass1 = lowpass(level, 20)
let add1 = hist1 + div1
let choice1 = choice(add1)
let mul1 = choice1 * twopi
let sin1 = sin(mul1)
let mul2 = sin1 * lowpass1
out1 = mul2
out2 = mul2

hist1 = choice1

Comments

No comments yet.

← Back to code