Work-in-progress repo for ambisonics extensions for OM-SoX
Alexander Nguyen
22.01.25 92c40d00f8ffe4fc6491c0abb70210b31202bd70
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 (in-package :om)
28
29
30 ;;; Sox-denoise ===============================
31
32 (defmethod! sox-denoise ((amount number) (noiseprofile pathname) &key sox-append)                        
33             :icon 60
34             :initvals '(nil nil nil)
35             :indoc (list "Amount of noise-reduction (1=max. 0=no red.)" "Supply noiseprofile file (generated with sox-noiseprofile)" *sox-append-doc*)
36             :doc  "Reduce the noisefloor in an audio file. 
37
38 How much noise should be removed is specified by 'amount'. 
39 Higher numbers will remove more noise but present a greater likelihood of removing wanted components of the audio signal."
40
41             (let ((thestring (format nil "noisered ~s ~d" (namestring noiseprofile) amount)))
42               (sox-concat sox-append thestring))
43             )
44
45 (defmethod! sox-denoise ((amount number) (noiseprofile t) &key sox-append)
46     (om-beep-msg (format nil "!!! Wrong noiseprofile for sox-denoise: ~A" noiseprofile)))
47
48 (defmethod! sox-denoise ((amount number) (noiseprofile sound) &key sox-append)
49     (sox-denoise amount (sound-path noiseprofile) :sox-append sox-append))
50
51 (defmethod! sox-denoise ((amount number) (noiseprofile string) &key sox-append)
52     (sox-denoise amount (pathname noiseprofile) :sox-append sox-append))
53
54 ;;; Sox-DCRemove ===============================
55 ; DC-removal via highpass-filter
56
57 (defmethod! sox-dcremove (&key (cutoff-freq 10) sox-append)                        
58             :icon 60
59             :initvals '(10 nil)
60             :indoc (list "cutoff-frequency of high-pass-filter" *sox-append-doc*)
61             :doc "remove dc-offset in an audio file"
62
63             (let ((thestring (format nil " highpass ~d" cutoff-freq)))
64               (sox-concat sox-append thestring)))
65
66
67 (defmethod! sox-dcshift ((dc number) &key limitergain sox-append)                        
68             :icon 60
69             :initvals '(nil 0.05)
70             :indoc (list "amount to shift signal" *sox-append-doc*)
71             :doc "Shift the dc in an audio file"
72
73             (let ((thestring (format nil " dcshift ~d " dc)))
74               (when limitergain (setf thestring (string+ thestring (number-to-string limitergain))))
75               (sox-concat sox-append thestring))
76             )
77
78
79 ; Sox-Riaa ===============================
80 ; (Vinyl playback equalisation)
81
82 (defmethod! sox-riaa ( &key sox-append )                        
83             :icon 60
84             :indoc (list *sox-append-doc*)
85             :doc "Apply RIAA vinyl playback equalisation. NB: The sampling rate must be one of: 44.1, 48, 88.2, 96 kHz."
86
87             (let ((thestring (format nil " riaa")))
88               (sox-concat sox-append thestring))
89             )
90               
91
92 ; Sox-deemph ================================
93 ; CD deemphasis filter
94
95 (defmethod! sox-deemph ( &key sox-append )                        
96             :icon 60
97             :indoc (list *sox-append-doc*)
98             :doc "Apply Compact Disc (IEC 60908) de-emphasis (a treble attenuation shelving filter)."
99
100             (let ((thestring (format nil " deemph")))
101               (sox-concat sox-append thestring))
102             )
103
104
105 ;;; Sox-Dither =================================================
106 ; this should always be at the end of the processing chain, thus no "sox-append" here
107
108 (defmethod! sox-dither ((noiseshape string) &key auto-mode)
109                 :icon 90
110                 :initvals '("triangular" t)
111                 :indoc '("Select a noise-shaping filter from the menu." "Enables a mode where dithering (and noise-shaping if applicable) are automatically enabled only when needed.")
112                 :menuins '((0 (("triangular" "triangular") ("sloped-triangular" "sloped-triangular") ("lipshitz" "lipshitz") ("f-weighted" "f-weighted") ("modified-e-weighted" "modified-e-weighted") ("improved-e-weighted" "improved-e-weighted") ("gesemann" "gesemann") ("shibata" "shibata") ("low-shibata" "low-shibata") ("high-shibata" "high-shibata"))))
113                 :doc "Introduce dithering noise to mask quantization artefacts when reducing bit depth.
114
115 Adds a small amount of noise to the signal in order to mask audible quantization effects that can occur if the output bit depth is less than 24 bits. 
116 Note, that most noiseshape types are available only with 44100Hz sample rate.
117 The most likely use for <auto-mode> is when applying fade in or out to an already dithered file, so that the redithering applies only to the faded portions. 
118 However, auto dithering is not fool-proof, so the fades should be carefully checked for any noise modulation.
119 This effect cannot be followed by any other sox-effect."
120
121                 (let ((thestring (format nil "dither ")))
122                   (when auto-mode (setf thestring (concatenate 'string thestring (format nil " -a"))))
123                   (when (equal noiseshape "sloped-triangular")
124                     (setf thestring (concatenate 'string thestring (format nil " -S"))))
125                   (unless (or (equal noiseshape "triangular") (equal noiseshape "sloped-triangular"))
126                          (setf thestring (concatenate 'string thestring (format nil " -f ~a" noiseshape))))
127                   thestring))
128
129
130 ;;; Sox-resample ==========================
131
132 (defmethod! sox-resample ((samplerate number) &key quality sox-append)
133                 :icon 60
134                 :initvals '(48000 "high" nil)
135                 :menuins '((0 (("4kHz" 4000) ("8kHz" 8000) ("16kHz" 16000) ("20kHz" 20000) ("30kHz" 30000) ("44.1kHz" 44100) ("48kHz" 48000) ("88.2kHz" 88200) ("96kHz" 96000) ("192kHz" 192000))) 
136                            (1 (("quick" "quick") ("low" "low") ("medium" "medium") ("high" "high") ("very high" "very high") ("very high linear phase" "very high linear phase") 
137                                ("very high intermediate phase" "very high intermediate phase") ("very high minimum phase" "very high minimum phase"))))
138                 :indoc (list "samplerate (Hz)" "choose algorithm for samplerate-conversion" *sox-append-doc*)
139                 :doc "Changes the sampling rate of audio to <samplerate> with choice of algorithm <quality>."
140
141                 (let ((thestring (format nil "rate ")))     ; this could be done more elegantly with assoc
142                   (cond ((equal quality "quick")
143                          (setf thestring (concatenate 'string thestring (format nil " -q"))))
144                         ((equal quality "low")
145                          (setf thestring (concatenate 'string thestring (format nil " -l"))))
146                         ((equal quality "medium")
147                          (setf thestring (concatenate 'string thestring (format nil " -m"))))
148                         ((equal quality "high")
149                          (setf thestring (concatenate 'string thestring (format nil " -h"))))
150                         ((equal quality "very high")
151                          (setf thestring (concatenate 'string thestring (format nil " -v"))))
152                         ((equal quality "very high linear phase")
153                          (setf thestring (concatenate 'string thestring (format nil " -v -s"))))
154                         ((equal quality "very high intermediate phase")
155                          (setf thestring (concatenate 'string thestring (format nil " -v -s -I"))))
156                         ((equal quality "very high minimum phase")
157                          (setf thestring (concatenate 'string thestring (format nil " -v -s -M")))))
158                   (setf thestring (concatenate 'string thestring (format nil " ~d" samplerate)))
159                   (sox-concat sox-append thestring))
160                 )
161
162 ;;; SoX-upsample and SoX-downsample are almost mathematical DSP functions (similar to sox-multiply etc.)
163 ;;; SoX-upsample ===============================
164
165 (defmethod! sox-upsample ((factor integer) &key sox-append)
166   :icon 21
167   :initvals '(2 nil)
168   :indoc (list "Upsamle factor (integer)"  *sox-append-doc*)
169   :doc "Upsample the signal by an integer factor. 
170
171 factor-1 zero-value samples are inserted between each pair of input samples. As a result, the original spectrum is replicated into the new frequency space (aliasing) and attenuated.
172 This attenuation can be compensated for by amplifying the input signal by <factor> after any further processing. The upsample effect is typically used in combination with filtering effects.
173
174 See also sox-downsample. For a general resampling effect with anti-aliasing, see sox-resample."
175
176
177   (let* ((thestring (format nil " upsample ~d" factor)))
178     (sox-concat sox-append thestring))
179   )
180
181 ;;; SoX-downsample ===============================
182
183 (defmethod! sox-downsample ((factor integer) &key sox-append)
184   :icon 21
185   :initvals '(2 nil)
186   :indoc (list "Downsample factor (integer)"  *sox-append-doc*)
187   :doc "Downsample the signal by an integer factor. 
188
189 Downsample the signal by an integer factor: Only the first out of each factor samples is retained, the others are discarded.
190 No decimation filter is applied. If the input is not a properly bandlimited baseband signal, aliasing will occur. This may be desirable, e.g., for frequency translation.
191
192 See also sox-upsample. For a general resampling effect with anti-aliasing, see sox-resample."
193
194   (let* ((thestring (format nil " downsample ~d" factor)))
195     (sox-concat sox-append thestring))
196   )
197
198 ; Sox-oops ===============================
199 ; (Out of Phase Stereo (Karaoke) Effect)
200
201 (defmethod! sox-oops (&key sox-append)
202   :icon 60
203   :initvals '()
204   :indoc (list *sox-append-doc*)
205   :doc "Out-Of-Phase-Stereo effect. Mixes stereo to twin-mono where each mono channel contains the difference between the left and right stereo channels. 
206
207 This is sometimes known as the 'karaoke' effect as it often has the effect of removing most or all of the vocals from a recording."
208
209   (let ((thestring (format nil " oops")))
210     (setf thestring (sox-concat sox-append thestring))
211     thestring)
212   )
213
214
215 ;;; +++++++++++ HELPER FUNCTIONS ++++++++++++
216
217 ; sox-monofy ===============================
218
219 (defmethod! sox-monofy ( &key sox-append )                        
220             :icon 60
221             :initvals '(nil)
222             :indoc (list *sox-append-doc*)
223             :doc "Mixes all channels in multichannel audio down to a single channel."
224
225             (let* (
226                    (thestring (format nil " channels 1")))
227               (sox-concat sox-append thestring))
228             )
229
230
231 ; Sox-downmix ===============================
232
233 (defmethod! sox-downmix ( &key (channels 1) sox-append )                        
234             :icon 60
235             :initvals '(1 nil)
236             :indoc (list "number of channels" *sox-append-doc*)
237             :doc "Mixes all channels in multichannel audio down to a number of channels specified in <channels>"
238             (let ((thestring (format nil " channels ~d" channels)))
239               (sox-concat sox-append thestring)
240               ))
241
242 ;;; Sox-Invert ==============================
243
244 (defmethod! sox-invert ( &key sox-append)
245             :icon 60
246             :initvals '(nil)
247             :indoc (list *sox-append-doc*)
248             :doc "Inverts the phase of the audio signal"
249
250             (let ((thestring (format nil "vol -1")))
251               (sox-concat sox-append thestring))
252             )
253
254
255 ;;; Sox-Clipguard ==========================
256
257 (defmethod! sox-clipguard (&key sox-append)                        
258             :icon 60
259             :initvals ' (nil)
260             :indoc (list *sox-append-doc*)
261             :doc "Prevents the processing chain from clipping."
262
263             (let ((thestring (format nil " gain -nh ")))
264               (sox-concat sox-append thestring))
265               )