# Lecture Slides

## Ring Modulation

```(definstrument rm (start-time duration carrier-freq modulator-freq amplitude
&key
(amp-env '(0 0 0.5 1 1 0)))
(let* ((beg (floor (* start-time *srate*)))
(end (+ beg (floor (* duration *srate*))))
(carrier (make-oscil :frequency carrier-freq))
(modulator (make-oscil :frequency modulator-freq))
(envelope (make-env :envelope amp-env
:scaler amplitude
:duration duration)))
(run
(loop for i from beg to end do
(outa i (* (env envelope)
(* (oscil carrier)(oscil modulator))))))))
```

```(definstrument rmw (start-time duration carrier-freq modulator-freq amplitude
&key
(carrier-spectr '(1 0.5 2 0.2 5 0.1))
(modulator-spectr '(1 0.5 3 0.2 4 0.1))
(amp-env '(0 0 0.5 1 1 0)))
(let* ((beg (floor (* start-time *srate*)))
(end (+ beg (floor (* duration *srate*))))
(wave-c (partials->wave carrier-spectr))
(carrier (make-table-lookup :frequency carrier-freq :wave wave-c))
(wave-m (partials->wave modulator-spectr))
(modulator (make-table-lookup :frequency modulator-freq :wave wave-m))
(envelope (make-env :envelope amp-env
:scaler amplitude
:duration duration)))
(run
(loop for i from beg to end do
(outa i (* (env envelope)
(* (table-lookup carrier)(table-lookup modulator))))))))
```

## Amplitude Modulation

```
(definstrument am (start-time duration carrier-freq modulator-freq amplitude
&key
(amp-env '(0 0 0.5 1 1 0)))
(let* ((beg (floor (* start-time *srate*)))
(end (+ beg (floor (* duration *srate*))))
(carrier (make-oscil :frequency carrier-freq))
(modulator (make-oscil :frequency modulator-freq))
(envelope (make-env :envelope amp-env
:scaler amplitude
:duration duration)))
(run
(loop for i from beg to end do
(outa i (* (env envelope)
(* (oscil carrier)(+ 1.0 (oscil modulator)))))))))
```

## Frequency Modulation

```(definstrument fm (start-time duration carrier-freq modulator-freq index amplitude
&key
(amp-env '(0 0 0.5 1 1 0)))
(let* ((beg (floor (* start-time *srate*)))
(end (+ beg (floor (* duration *srate*))))
(carrier (make-oscil :frequency carrier-freq))
(modulator (make-oscil :frequency modulator-freq))
(envelope (make-env :envelope amp-env
:scaler amplitude
:duration duration)))
(run
(loop for i from beg to end do
(outa i (* (env envelope)
(oscil carrier (* index (oscil modulator))))))))))
```