commit | author | age
|
92c40d
|
1 |
;********************************************************************* |
AN |
2 |
; OM-SoX, (c) 2011-2013 Marlon Schumacher (CIRMMT/McGill University) * |
|
3 |
; http://sourceforge.net/projects/omsox/ * |
|
4 |
; * |
|
5 |
; Multichannel Audio Manipulation and Functional Batch Processing. * |
|
6 |
; DSP based on SoX - (c) C.Bagwell and Contributors * |
|
7 |
; http://sox.sourceforge.net/ * |
|
8 |
;********************************************************************* |
|
9 |
; |
|
10 |
;This program is free software; you can redistribute it and/or |
|
11 |
;modify it under the terms of the GNU General Public License |
|
12 |
;as published by the Free Software Foundation; either version 2 |
|
13 |
;of the License, or (at your option) any later version. |
|
14 |
; |
|
15 |
;See file LICENSE for further informations on licensing terms. |
|
16 |
; |
|
17 |
;This program is distributed in the hope that it will be useful, |
|
18 |
;but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 |
;GNU General Public License for more details. |
|
21 |
; |
|
22 |
;You should have received a copy of the GNU General Public License |
|
23 |
;along with this program; if not, write to the Free Software |
|
24 |
;Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,10 USA. |
|
25 |
; |
|
26 |
;Authors: M. Schumacher |
|
27 |
|
|
28 |
(in-package :om) |
|
29 |
|
|
30 |
(defmethod! om-sum ((self list)) |
|
31 |
(loop for item in self |
|
32 |
sum item) |
|
33 |
) |
|
34 |
; squared sum |
|
35 |
(defmethod! om-sum2 ((self list)) |
|
36 |
(loop for item in self |
|
37 |
sum (* item item)) |
|
38 |
) |
|
39 |
|
|
40 |
;*** sine/cosine functions for lists |
|
41 |
|
|
42 |
(defmethod! om-sin ((arg1 number)) |
|
43 |
:initvals '(nil) |
|
44 |
:icon '(209) |
|
45 |
:indoc '("list") |
|
46 |
:doc "Sine for every item in list." |
|
47 |
(sin arg1)) |
|
48 |
|
|
49 |
(defmethod! om-sin ((arg1 list)) |
|
50 |
(mapcar #'(lambda (input) |
|
51 |
(sin input)) arg1)) |
|
52 |
|
|
53 |
;*** cosine function for lists |
|
54 |
|
|
55 |
(defmethod! om-cos ((arg1 number)) |
|
56 |
:initvals '(nil) |
|
57 |
:icon '(209) |
|
58 |
:indoc '("list") |
|
59 |
:doc "Cos for every item in list." |
|
60 |
(cos arg1)) |
|
61 |
|
|
62 |
(defmethod! om-cos ((arg1 list)) |
|
63 |
(mapcar #'(lambda (input) |
|
64 |
(cos input)) arg1)) |
|
65 |
|
|
66 |
(defmethod! om-scale-exp ((self t) (minout number) (maxout number) (exponent number) &optional (minin 0) (maxin 0)) |
|
67 |
:initvals '(1 0 1 1) |
|
68 |
:indoc '("number or list" "a number" "a number" "an exponent") |
|
69 |
:icon '(209) |
|
70 |
:doc |
|
71 |
"Scales <self> (a number or list of numbers) considered to be in the interval [<minin> <maxin>] towards the interval [<minout> <maxout>]. |
|
72 |
|
|
73 |
If [<minin> <maxin>] not specified or equal to [0 0], it is bound to the min and the max of the list. |
|
74 |
|
|
75 |
Ex. (om-scale 5 0 100 0 10) => 50 |
|
76 |
Ex. (om-scale '(0 2 5) 0 100 0 10) => (0 20 50) |
|
77 |
Ex. (om-scale '(0 2 5) 0 100) => (0 40 100) |
|
78 |
" |
|
79 |
(om-scale (om^ (om-scale self 0. 1. minin maxin) exponent) minout maxout 0. 1.) |
|
80 |
) |
|
81 |
|
|
82 |
(defmethod! mag->lin ((magnitude number) (windowsize number) (wcoef number)) |
|
83 |
:icon 141 |
|
84 |
:indoc '("a value or list of values" "windowsize" "window coefficient") |
|
85 |
:initvals '(100 4096 1) |
|
86 |
:doc "Converts magnitude values of a power spectrum to linear gain" |
|
87 |
(* 2 (/ (sqrt magnitude) windowsize) wcoef)) |
|
88 |
|
|
89 |
(defmethod! mag->lin ((magnitude list) (windowsize number) (wcoef number)) |
|
90 |
(mapcar (lambda (themagnitude) |
|
91 |
(mag->lin themagnitude windowsize wcoef)) magnitude) |
|
92 |
) |
|
93 |
|
|
94 |
(defun sox-covariance (scalars) |
|
95 |
(sqrt (/ (om-sum2 scalars) (length scalars))) |
|
96 |
) |
|
97 |
|
|
98 |
(defmethod! sox-centroid ((freqs list) (amps list)) |
|
99 |
(/ |
|
100 |
(loop for x in freqs |
|
101 |
for y in amps |
|
102 |
finally |
|
103 |
sum (* x y) |
|
104 |
) |
|
105 |
(+ (om-sum amps) 0.000001) ;avoid division by zero |
|
106 |
)) |
|
107 |
|
|
108 |
(defmethod! sox-energy ((amps list)) |
|
109 |
(om-sum amps) ;avoid division by zero |
|
110 |
) |