Repository Public
1// ORIX Sonata2// File: Examples/sonification.sonata3// Description: Data sonification: a measured series is mapped to pitch, loudness and stereo position.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// expect: notes 209// expect: tracks 210// expect: duration 4.0000s11// expect: deterministic12// Monthly mean temperature anomalies in hundredths of a degree (an illustrative series).13const series = [12, 18, 9, 22, 31, 27, 35, 44, 39, 52, 61, 58, 70, 66, 81, 93]1415fn normalise(x: Number, lo: Number, hi: Number) -> Number {16 return (x - lo) / (hi - lo)17}1819// Maps a value in [0, 1] onto two octaves of a scale.20fn to_pitch(t: Number, notes: List<Pitch>) -> Pitch {21 let index = round(t * (len(notes) - 1))22 return notes[index]23}2425composition "Sonification" {26 tempo 120bpm27 key C lydian2829 let lo = min(series)30 let hi = max(series)31 let notes = scale(C4, lydian) + (scale(C4, lydian) + 12st) + [C6]3233 instrument data: Vibraphone {34 gain -6dB35 for x in series {36 let t = normalise(x, lo, hi)37 play to_pitch(t, notes) duration 1/8 velocity lerp(0.35, 0.95, t)38 }39 effects {40 reverb hall(mix: 0.3)41 }42 }4344 // The trend as a slow line: one note per four data points, their mean.45 instrument trend: ChoirOohs {46 gain -12dB47 for i in 0..4 {48 let mean = sum(take(drop(series, i * 4), 4)) / 449 play to_pitch(normalise(mean, lo, hi), notes) - 12st duration 1/250 }51 }5253 marker "minimum" at 2/854 marker "maximum" at 15/855}56