aboutsummaryrefslogtreecommitdiff
path: root/oscillator.bqn
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-06 21:56:30 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-06 21:56:30 -0500
commit44a0fe64a165fd49fd1699d7e227a5705ecc09cb (patch)
treea437fb9b376e6e2ac3626962a409caba8d33f2e6 /oscillator.bqn
parent4d39c3ead7603626ce2feaac011ae59829328e91 (diff)
Oscillators
Diffstat (limited to 'oscillator.bqn')
-rw-r--r--oscillator.bqn32
1 files changed, 32 insertions, 0 deletions
diff --git a/oscillator.bqn b/oscillator.bqn
new file mode 100644
index 0000000..8df742d
--- /dev/null
+++ b/oscillator.bqn
@@ -0,0 +1,32 @@
+# Standard oscillators for (usually subtractive) synthesis
+# In each case, the right argument argument is a list giving the
+# frequency for each sample.
+# If not otherwise specified, the left argument is optional and gives
+# the phase offset.
+
+"oscillator.bqn takes a single option namespace, or no arguments" ! 1≥≠•args
+o ← ≠◶⟨•Import∘"options.bqn", ⊑⟩ •args
+
+# Utilities
+Ce ← 1-˜2⊸× # Center: transform [0,1] to [¯1,1]
+SP ← (4⊸×÷5⊸-) 4׬⊸× # Sine π×𝕩 by Bhaskara I
+Rand ← Ce {o.RandFloats 𝕩}
+
+# Basic waveforms
+Id ← {𝕨++`𝕩÷o.freq} # Identity
+P ← 1|Id # Phase
+
+# Deterministic waveforms for synthesis
+Saw ⇐ Ce∘P # Sawtooth wave //////
+Triangle ⇐ Ce∘| {𝕨+0.25}Saw⊢ # Triangle wave ´\/\/\
+Square⇐ Ce 0.5<P # Square wave ⊔¯⊔¯⊔¯
+Pulse ⇐ Ce <⟜P # Pulse wave with duty cycle 𝕨
+#Sine ⇐ •Math.Sine (2×π) × Id # Sine wave
+Sine ⇐ (××SP∘|) {𝕨+0.5}Saw⊢ # Sine wave, more or less
+
+# Random waveforms
+White ⇐ Rand ≢ # White noise
+Brown ⇐ +` White # Brown noise
+# Pink noise
+#Pink ⇐ ÷⟜(⌈´|) (2⊸/⊸+˜´∘⌽ · Rand¨ 2⋆↕)⊸÷∘(1+·⌈2⋆⁼⊢)⊸(↑˜)∘≠
+Pink ⇐ ÷⟜(⌈´|) (+` ·⥊∘⍉∘≍´ ·-⟜«∘Rand¨ 2⋆1⌈⌽∘↕)∘(1+·⌈2⋆⁼⊢)⊸(↑˜)∘≠