summaryrefslogtreecommitdiff
path: root/runtime/upic.sal
blob: 87b433d18d08e434e53fe1c8d60e501632b4169c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;; upic.sal -- play upic data
;;

define function upic(data)
  begin
    if data then
      ;; use reverse to make a copy of data since sort is destructive
      return upic-curve(sort(reverse(data), quote(upic-compare)))
    else
      return s-rest() 
  end


define function upic-compare(a, b)
  return third(a) < third(b)


define function upic-curve(data)
  begin
    with curve = first(data),
         waveform = first(curve),
         envelope = second(curve),
         points = cddr(curve),
         from-time = first(points),
         to-time = nth(length(points) - 2, points),
         dur = to-time - from-time,
         next = rest(data),
         next-start, snd
    ;; shift curve to start at t = 0
    loop
      with relpoints
      while points
      set relpoints @= first(points) - from-time
      set relpoints @= second(points)
      set points = cddr(points)
      finally set points = cdr(reverse(relpoints))
    end
    set snd = hzosc(pwlv-list(points), symbol-value(waveform)) *
              (funcall(envelope) ~ dur)
    if next then
      begin
        set next-start = third(first(next))
        ;; display "curve", from-time, dur
        set snd = seq(set-logical-stop(snd, next-start - from-time),
                      upic-curve(next))
       end
    return snd
  end


define function upic-env()
  return env(0.01, 0.01, 0.01, 1, 1, 1)