;*********************************************************************
|
; 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
|
)
|