-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pan_Analizer.ny
33 lines (30 loc) · 1.13 KB
/
Pan_Analizer.ny
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
;nyquist plug-in
;version 4
;type analyze
;name "Pan Analizer"
;copyright "Released under terms of the GNU General Public License version 2 or later"
(defun calculate-median-incremental (sound)
(let ((values '())
(value (snd-fetch sound)))
(while value
(setq values (cons value values))
(setq value (snd-fetch sound)))
(if values
(let* ((sorted (sort values #'<))
(len (length sorted))
(middle (/ len 2)))
(if (evenp len)
(/ (+ (nth middle sorted) (nth (1- middle) sorted)) 2)
(nth middle sorted)))
0)))
(defun find-pan-center (track)
(let* ((left (snd-copy (aref track 0)))
(right (snd-copy (aref track 1)))
(left-median (calculate-median-incremental left))
(right-median (calculate-median-incremental right))
(total-median (+ (abs left-median) (abs right-median)))
(pan-center (if (> total-median 0)
(/ (- right-median left-median) total-median)
0)))
(round (* pan-center 100))))
(find-pan-center *track*)