diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-06 21:56:30 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-12-06 21:56:30 -0500 |
| commit | 44a0fe64a165fd49fd1699d7e227a5705ecc09cb (patch) | |
| tree | a437fb9b376e6e2ac3626962a409caba8d33f2e6 | |
| parent | 4d39c3ead7603626ce2feaac011ae59829328e91 (diff) | |
Oscillators
| -rw-r--r-- | options.bqn | 6 | ||||
| -rw-r--r-- | oscillator.bqn | 32 |
2 files changed, 37 insertions, 1 deletions
diff --git a/options.bqn b/options.bqn index 7e2aa25..2cc055a 100644 --- a/options.bqn +++ b/options.bqn @@ -3,8 +3,12 @@ fmt ⇐ 1‿16 # Format: 16-bit integer freq ⇐ 44100 # Frequency: 44.1kHz Set ⇐ {fmt‿freq↩𝕩} +# For generating random waveforms; result is a shape 𝕩 array of uniform +# random numbers between 0 and 1 +RandFloats ⇐ •RAND∘⥊⟜0 + # For reading/writing wave files warn_dither ⇐ 0 # Whether to warn on non-integer signal warn_clip ⇐ 1 # Whether to warn on out-of-bounds signal -Dither ⇐ ⌊ (-˝ 0 •RAND∘⥊˜ 2∾≢)⊸+ +Dither ⇐ ⌊ (-˝ ·RandFloats 2∾≢)⊸+ Resample ⇐ "No resampling function specified"!0˙ 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⋆⁼⊢)⊸(↑˜)∘≠ |
