File: velocity.lsp

package info (click to toggle)
nyquist 3.20%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 58,008 kB
  • sloc: ansic: 74,743; lisp: 17,929; java: 10,723; cpp: 6,690; sh: 171; xml: 58; makefile: 40; python: 15
file content (24 lines) | stat: -rw-r--r-- 495 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
;; velocity.lsp -- conversion routines for MIDI velocity
;;
;; Roger B. Dannenberg
;; July, 2012


(defun db-to-vel (x &optional float)
  (linear-to-vel (db-to-linear x) float))


(defun linear-to-vel (x &optional float)
  (setf x (/ (- (sqrt (abs x)) 0.0239372) 0.00768553))
  (cond (float x)
        (t
         (setf x (round x))
         (max 1 (min 127 x)))))


(defun vel-to-db (v)
  (linear-to-db (vel-to-linear v)))


(defun vel-to-linear (v)
  (power (+ (* v 0.00768553) 0.0239372) 2))