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