envelope-segments   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/tests/core/xtlang.xtm

Implementation

(bind-func envelope-segments
  (lambda (points:double* num-of-points:i64)
    (let ((lines:[double,double]** (zone-alloc num-of-points))
    (k 0))
      (dotimes (k num-of-points)
  (let* ((idx (* k 2))
         (x1 (pointer-ref points (+ idx 0)))
         (y1 (pointer-ref points (+ idx 1)))
         (x2 (pointer-ref points (+ idx 2)))
         (y2 (pointer-ref points (+ idx 3)))
         (m (if (= 0.0 (- x2 x1)) 0.0 (/ (- y2 y1) (- x2 x1))))
         (c (- y2 (* m x2)))
         (l (lambda (time) (+ (* m time) c))))
    (pointer-set! lines k l)))
      lines)))


Back to Index

Similar Entries