```
d1
$ note
((scaleP scalePattern
$ off 4 ((+ 2 ).slow 2)
$ off 1 (inversion.slow 2)
$ off 3 (inversion.slow 3)
$ off 1.5 ((+ 2).rev.slow 2)
$ generateMelodicSeed
))#s "[pe-gtr:10,midi]" #gain 1 #orbit 0 #midichan 1
```

```
generateMelodicSeed = slow 4
$ linger 0.5
$ repeatCycles 3
-- $ palindrome \n
$ (+ (slow (irand (4)+1) (sometimes (inversion) (run (irand (4)+1)))))
$ slow ((irand 3) + 1)
$ e ("x"<~>(irand 8)) 8
$ "x*16"<~>(irand 5)
```

```
do
d9 $ midicmd "stop" # s "midi"
hush
```

```
do
cps (86/60/2)
d9 $ midicmd "midiClock*48" # s "midi"
```

# DSF (Discrete Summation Formula)

:cc0:

A DSF is an approximation of an ideal waveform (such as SAW or SQUARE) that uses trig identities to approximate the wave up to a given number of harmonics.

All periodic sound can be represented a Fourier series of individual sine and cosine waves. This infinite series can be truncated to produce a wave with a given number of harmonics. (see: Bandlimited Oscillator) This truncated sum may have a "closed form" solution when trig identities can be used to reduce the sum to a single term. This makes it more efficient to implement than Additive Synthesis.

Like the basic BLIT algorithm, DSF has limitations when it comes to smoothly changing/glissing frequencies the number of harmonics in a DSF formula is an integer value. When trying to render a glissando with a DSF the harmonics entering and leaving the sound can be heard as abrupt steps.

# example

The following is a summary of an example presented in *Computer
Music* by Dodge and Jerse:

A band-limited pulse wave with `N`

harmonics can be
constructed with the formula:

$ y(t) = \frac {A} {N} \sum_{k=1}^{N} cos(2 \pi kf_ot) $

This sum can be reduced to the following "closed form" DSF:

$ y(t) = \frac {A} {2N} [\frac {sin((2N+1) \pi f_ot)} {sin(\pi f_o t)} -1]$

An implementation using the bottom form will need to account for the case where the denominator goes to zero. For this case the formula above can be re-written with cosines:

$ y(t) = \frac {A} {2N} [\frac {(2N+1) cos((2N+1) \pi f_ot)} {cos(\pi f_o t)} - 1] $