summaryrefslogtreecommitdiff
path: root/grani.scm
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@iem.at>2017-01-23 13:23:12 +0100
committerIOhannes m zmölnig <zmoelnig@iem.at>2017-01-23 13:23:12 +0100
commite56861860a027030bb6d8386ba25f95a057bccdd (patch)
tree952f78b2c7b2dc0925d69df7236358c0af294065 /grani.scm
parent0b84e302c3cc5e4456ca13b292750f0ae63406bc (diff)
New upstream version 17.1
Diffstat (limited to 'grani.scm')
-rw-r--r--grani.scm60
1 files changed, 30 insertions, 30 deletions
diff --git a/grani.scm b/grani.scm
index 6673f3d..725cb7e 100644
--- a/grani.scm
+++ b/grani.scm
@@ -53,30 +53,30 @@
;; yl,yh = y coordinates of segment ends
;; yle,yhe = exponential values of y coords of segment ends
;; error = linear domain error bound for rendering
- (define (exp-seg xl yle xh yhe yl yh error)
-
- ;; linear interpolation
- (define (interpolate xl yl xh yh xi)
- (+ yl (* (- xi xl) (/ (- yh yl) (- xh xl)))))
-
- (let* ((xint (/ (+ xl xh) 2.0))
- (yint (interpolate xl yl xh yh xint))
- (yexp (expt base yint)))
- (let ((yinte (interpolate xl yle xh yhe xint))
- (yerr (- (expt base (+ yint error)) yexp)))
- ;; is the linear approximation accurate enough?
- ;; are we still over the cutoff limit?
- (if (not (and (> (abs (- yexp yinte)) yerr)
- (or (not (real? ycutoff))
- (> yinte ycutoff))))
- ;; yes --> don't need to add nu'ting to the envelope
- (values () ())
- ;; no --> add a breakpoint and recurse right and left
- ((lambda (xi yi xj yj)
- (values (append xi (cons xint xj))
- (append yi (cons yexp yj))))
- (exp-seg xl yle xint yexp yl yint error)
- (exp-seg xint yexp xh yhe yint yh error))))))
+ (define exp-seg
+ (let ((interpolate (lambda (xl yl xh yh xi)
+ (+ yl (* (- xi xl)
+ (/ (- yh yl)
+ (- xh xl)))))))
+ (lambda (xl yle xh yhe yl yh error)
+ (let* ((xint (/ (+ xl xh) 2.0))
+ (yint (interpolate xl yl xh yh xint))
+ (yexp (expt base yint)))
+ (let ((yinte (interpolate xl yle xh yhe xint))
+ (yerr (- (expt base (+ yint error)) yexp)))
+ ;; is the linear approximation accurate enough?
+ ;; are we still over the cutoff limit?
+ (if (not (and (> (abs (- yexp yinte)) yerr)
+ (or (not (real? ycutoff))
+ (> yinte ycutoff))))
+ ;; yes --> don't need to add nu'ting to the envelope
+ (values () ())
+ ;; no --> add a breakpoint and recurse right and left
+ ((lambda (xi yi xj yj)
+ (values (append xi (cons xint xj))
+ (append yi (cons yexp yj))))
+ (exp-seg xl yle xint yexp yl yint error)
+ (exp-seg xint yexp xh yhe yint yh error))))))))
;; loop for each segment in the envelope
(let segs ((en env1))
@@ -220,7 +220,7 @@
;;; convert a time in seconds to a number of samples
(define-macro (to-samples time srate)
- `(floor (* ,time ,srate)))
+ (list 'floor (list '* time srate)))
;;; create a constant envelope if argument is a number
@@ -232,11 +232,11 @@
;;; create a float-vector from an envelope
(define* (make-gr-env env1 (len 512))
- (let ((env-float-vector (make-float-vector len))
- (length-1 (* 1.0 (- len 1))))
- (do ((i 0 (+ 1 i)))
- ((= i len) env-float-vector)
- (set! (env-float-vector i) (envelope-interp (/ i length-1) env1)))))
+ (do ((env-float-vector (make-float-vector len))
+ (length-1 (* 1.0 (- len 1)))
+ (i 0 (+ i 1)))
+ ((= i len) env-float-vector)
+ (set! (env-float-vector i) (envelope-interp (/ i length-1) env1))))
;;;-----------------------------------------------------------------------------
;;; Grain envelopes