# Sonification

Sometimes we want to convert data to sound just to perceive the data in a different way or maybe for an aesthetic reason. Sonification is a broad subject that deals with the transformation of data to sound.

The main thing we must know about sonification is that sometimes we need to rescale data to fit another range. We can accomplish this using the normalize function.

``````(normalize '(100 200 300 400 500) 1 5)
;; => (1 2 3 4 5)
(normalize '(100 200 300 400 500) 1 10)
;; => (1 3 6 8 10)
(normalize '(100 200 300 400 500) 1 100)
;; => (1 26 51 75 100)
(normalize '(100 200 300 400 500) 50 100)
;; => (50 63 75 88 100)
(normalize '(100 200 300 400 500) 50 1000)
;; => (50 288 525 763 1000)
``````

## Sonification Example

In this example we will normalize a small set of data and convert it into a musical representation. First we set the tempo, for this case, we'll use 220 BPM.

``````(set-tempo '((0 0 220)))
``````

Now we will use arbitrary data that will be rescaled to a new range.

``````(define data '(200 300 44 122 155 231 278))
``````

After defining our data, we can now use the normalize function to rescale the data into a new range. We will use different values for pitches, durations and velocities.

``````(define pitches (normalize data 70 100))
(define lengths (normalize data 100 1000))
(define vels (normalize data 40 127))
``````

Finally, we will create our events and save as MIDI.

``````(save-midi (create-events 0 pitches lengths vels 1))
``````

The complete code should look something like this:

``````;; sonification

(set-tempo '((0 0 220)))

(define data '(200 300 44 122 155 231 278))

(define pitches (normalize data 70 100))
(define lengths (normalize data 100 1000))
(define vels (normalize data 40 127))

(save-midi (create-events 0 pitches lengths vels 1))
``````