Work-in-progress repo for ambisonics extensions for OM-SoX
Marlon Schumacher
4 days ago 3c36efb7ea5dd8cccd9bcc47f4f6e71ee4cfcbb2
commit | author | age
92c40d 1 ;*********************************************************************
AN 2 ; OM-SoX, (c) 2011-2014 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
31 ; %%%%%%%%%%%%%%% SOX-PROCESS %%%%%%%%%%%%%%%%%%%%
32 ;           Main Processing Function 
33
34 ;== method for pathname + string =======
35 (defmethod! sox-process ((sox-input pathname) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
36             :icon 08
37             :initvals '(nil "" "realtime" nil nil nil Off "break")
38             :menuins (list (list 2 *sox-output-options*)
39                            (list 3 *sox-file-formats*)
40                            (list 4 *sox-samplerates*)
41                            (list 5 *sox-bitdephts*)
42                            (list 6 '(("On" On) ("Off" Off)))
43                            (list 7 '(("break" break) ("repeat" repeat) ("cycle" cycle))))                       
44             :indoc '("Audio input to be processed [sound, path, string/pipe, sox-input]" 
45                      "Sox-effect to be applied to audio input [string]" "Output type (new file, replace file, pipe, or realtime) [string]. Also accepts directory, filename, filepath [path]"
46                      "Filetype of produced audio [string]" "Samplerate of produced audio [string]" "Bitdepth of produced audio [number]"
47                      "recursive (when 'on' applies processing recursively to audio) [symbol]" "Mode for batch-processing (break, repeat, cycle) [symbol]") 
48             :doc "Main audio processing function for OM-SoX. Takes audio provided in <sox-input> and processes it with sox-effects provided in <sox-effect>. 
49
50 <output> determines whether output is to be rendered into 
51 a) new file, 
52 b) replace the input file, 
53 c) create a sox-command as a pipe (for further processing), 
54 d) play back in realtime through audio device.
55
56 Alternatively, a filename, directory, or path can be provided which will write an audio file to the given destination. 
57 It is also posisble to connect a function/patch in lambda mode, which (if available) will receive the path of <sox-input> as first argument. 
58 This can be used to algorithmically name output files (e.g. in batch processes).
59
60 Optionally, the audio output <filetype> can be specified, as well as the <samplerate> and <bitdepth> (default: same as input). 
61 <recursive> is an experimental option allowing to apply a sox-effect recursively to audio input (e.g. trimming).
62 <batch-mode> determines the behaviour when processing lists of sox-inputs and sox-effects that differ in length.
63 "
64
65             (if (probe-file *sox-path*)
66
67                 (let ((outfile (create-path sox-input output filetype)))
68
69                   (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* (namestring sox-input)))
70
71                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*)) 
72                                   ((equal output "pipe") (sox-samplebits str bitdepth samplerate '-p))
73                                   (t (sox-samplebits str bitdepth samplerate outfile))))
74
75                   (setf str (string+ str sox-effect))
76                  
77                   ; optional removal of temp-files
78                   (if *delete-inter-file* 
79                       (let ((outstring (sox-out str sox-input output outfile recursive))) 
80                         (if (>= *om-version* 6.07)
81                             (om-run-process "cleantempfiles" #'sleep&clean 5)
82                           (om-run-process "cleantempfiles" sleep&clean 5))
83                         outstring)                   
84                     (sox-out str sox-input output outfile recursive)
85                     ))
86               (sox-not-found))
87             )
88
89
90 ;== method for sound + string =======
91 (defmethod! sox-process ((sox-input sound) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
92             (let ((gainval (sox-vol-convert (vol sox-input)))
93                   (panval (+ (tracknum sox-input) (* 0.01 (pan sox-input)))))
94               (if (equal (tracknum sox-input) 0)
95                   (sox-process (sound-path sox-input) (string+ sox-effect " gain " (makestring gainval)) 
96                                :output output :filetype filetype :samplerate samplerate :bitdepth bitdepth 
97                                :recursive recursive :batch-mode batch-mode)            
98                 (sox-process (make-instance 'sox-pan
99                                             :sound sox-input
100                                             :gains gainval
101                                             :panning panval
102                                             :numchannels nil)
103                              sox-effect 
104                              :output output :filetype filetype :samplerate samplerate :bitdepth bitdepth 
105                              :recursive recursive :batch-mode batch-mode)))
106             )
107
108
109 ;== method for string + string =======
110 ;-> allows for arbitrary 'manual' sox-effect or options or pipe inputs...
111 (defmethod! sox-process ((sox-input string) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
112             (if (probe-file *sox-path*)
113
114             ;catch exception ---------
115                 (if (and (pipe-p sox-input) (equal output "pipe") )
116                    (om-message-abort "Pipe output not possible with this type of input.") 
117             ; ------------------------
118
119                 (let ((outfile (create-path nil output filetype)))
120
121                   (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* sox-input))
122                   
123                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*)) 
124                                   ((equal output "pipe") (sox-samplebits str bitdepth samplerate '-p))
125                                   (t (sox-samplebits str bitdepth samplerate outfile))))
126
127                   (setf str (string+ str sox-effect))
128
129                   (if *delete-inter-file* 
130                       (let ((outstring (sox-out str sox-input output outfile recursive))) 
131                         (if (>= *om-version* 6.07)
132                             (om-run-process "cleantempfiles" #'sleep&clean 5)
133                           (om-run-process "cleantempfiles" sleep&clean 5))
134                         outstring)                   
135                     (sox-out str sox-input output outfile recursive)
136                     )))
137
138               (sox-not-found))
139               )
140
141 ; %%%%%%%% METHODS FOR SOX-INPUT CLASSES %%%%%%%%%%%%
142
143 ; === sox-merge =============
144
145 (defmethod! sox-process ((sox-input sox-merge) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
146             (if (probe-file *sox-path*)
147
148                 (progn
149                   ;(print (sound sox-input))
150                   (let* ((sound (if (> (length (gains sox-input)) (length (list! (sound sox-input)))) 
151                                         (repeat-n (first (list! (sound sox-input))) (length (gains sox-input)))
152                                       (sound sox-input))))                                     
153
154                   (when (and (find-if 'stringp sound) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
155
156                 (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
157
158                   (let* ((filenames (loop for soundfile in sound collect                              
159                                           (namestring soundfile))))          
160
161                     (setf str (format nil "~s ~a -M " (namestring *sox-path*) *sox-options* )) 
162                     
163                     (if (gains sox-input)
164                         (loop for filename in filenames do
165                               for gain in (db->lin (list! (gains sox-input))) do
166                               (setf str (string+ str (format nil " -v~d ~s  " gain filename))))
167                       (loop for filename in filenames do
168                             (setf str (string+ str (format nil " ~s" filename)))))
169  
170                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
171                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
172                                     (t (sox-samplebits str bitdepth samplerate outfile))))
173
174                     (setf str (string+ str sox-effect))
175
176                     (sox-out str sox-input output outfile recursive)))))
177
178               (sox-not-found))
179             )
180
791513 181 ; === sox-hoaencode =============
AN 182
183 (defmethod! sox-process ((sox-input sox-hoaencode) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
197ce0 184
MS 185 ; would be more consistent with OO programming to have a function sox-hoaencode->sox-merge 
186 ; (consider how to deal with multiple sounds to be hoaencoded and mixed later on... sox-mix might be better done in an explicit way rather than via the class directly. 
187 ; in that case a 3DC would have to be used by using points (point-pairs) in a loop 
188
3c36ef 189     (if (probe-file *sox-path*)         
03b73c 190           (let ((sound (sound sox-input)))
b36c86 191
03b73c 192             (when (and (stringp sound) (equal output "pipe")) 
b36c86 193               (om-message-abort "Pipe output not possible with this type of input."))
MS 194             
03b73c 195             (let ((filename (namestring sound)) 
MS 196                   (outfile (create-path nil output filetype)))
b36c86 197               
MS 198               (setf str (format nil " ~s ~a" (namestring *sox-path*) *sox-options*))
03b73c 199
MS 200                 (if (= (order sox-input) 0) 
b36c86 201                      ; case: order = 0
03b73c 202                     (setf str (string+ str (format nil " ~s" filename)))
b36c86 203                      ; case: order > 0
3c36ef 204                   (progn ; it is impossible to create a sox-merge instance as gain values are in dB which cannot represent negative amplitudes
MS 205
03b73c 206                     (setf str (string+ str " -M"))
3c36ef 207                     (loop for gain in (print (sox-hoaencode-gains-up-to-order (order sox-input) (azimuth sox-input) (elevation sox-input))) 
03b73c 208                           do (setf str (string+ str (format nil " -v~d ~s" gain filename))))
MS 209                     )
210                   )
3c36ef 211                 )
402065 212             
b36c86 213               (setf str 
MS 214                     (cond 
215                      ((equal output "realtime") 
216                       (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
217                      ((equal output "pipe") 
218                       (sox-samplebits str bitdepth samplerate "-p"))
03b73c 219                      (t (sox-samplebits str bitdepth samplerate outfile))
b36c86 220                      )
791513 221                     )
3c36ef 222               
b36c86 223               (setf str (string+ str sox-effect))
MS 224               (print str)
225               (sox-out str sox-input output outfile recursive)
03b73c 226               
197ce0 227                        ;optional removal of temp file
MS 228                   ;    (add-tmp-file outfile_tmp)
229                   ;    (when *delete-inter-file* (clean-tmp-files))
230
b36c86 231               )
MS 232       (sox-not-found)
233       )
791513 234     )
AN 235
3c36ef 236
92c40d 237 ; === sox-mix =============
AN 238
239 (defmethod! sox-process ((sox-input sox-mix) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
240             (if (probe-file *sox-path*)
241
242                  (progn
243                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe"))
244                     (om-message-abort "Pipe output not possible with this type of input."))
245
246                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
247
248                     (let* ((filenames 
249                             (loop for soundfile in (sound sox-input) collect ;I guess this throws the error when using pipes as inputs
250                                   (namestring soundfile))))
251
252                       (setf str (format nil "~s ~a -m " (namestring *sox-path*) *sox-options*))
253                                                           
254                       ;potentially not needed...
255                    ;(if (1/n sox-input) 
256                         
257                    ;     (loop for filename in filenames do
258                    ;           for gain in (om/ (db->lin (gains sox-input)) (length (gains sox-input))) do ;(db->lin (list! (gains sox-input))) -> but it's always going to be a list, no?
259                    ;           (setf str (string+ str (format nil " -v~d ~s " gain filename )))) ; is it not scaling when volumes are given? try out!
260
261                       (loop for filename in filenames do
262                               for gain in (db->lin (gains sox-input)) do ;(db->lin (list! (gains sox-input))) -> but it's always going to be a list, no?
263                               (setf str (string+ str (format nil " -v~d ~s " gain filename ))))
264                       ;)
265
266                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
267                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p")) ; "-p is an alias for '-t sox -' " and it's better but I can't use as I need to provide the sox path again...
268                                     (t (sox-samplebits str bitdepth samplerate outfile))))
269
270                     (setf str (string+ str sox-effect))
271
272                     (sox-out str sox-input output outfile recursive))))
273
274               (sox-not-found))
275             )
276
277 ; === sox-multiply =============
278
279 (defmethod! sox-process ((sox-input sox-multiply) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
280             (if (probe-file *sox-path*)
281
282                  (progn
283                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe"))
284                     (om-message-abort "Pipe output not possible with this type of input."))
285
286                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
287
288                     (let* ((filenames 
289                             (loop for soundfile in (sound sox-input) collect ;I guess this throws the error when using pipes as inputs
290                                   (namestring soundfile))))
291
292                       (setf str (format nil "~s ~a -T " (namestring *sox-path*) *sox-options*))
293                                                           
294                       (loop for filename in filenames do
295                               for gain in (db->lin (gains sox-input)) do 
296                               (setf str (string+ str (format nil " -v~d ~s " gain filename )))) ; note that "-v" suppresses sox's in-built clipping protection
297                       ;)
298
299                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
300                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
301                                     (t (sox-samplebits str bitdepth samplerate outfile))))
302
303                     (setf str (string+ str sox-effect))
304
305                     (sox-out str sox-input output outfile recursive))))
306
307               (sox-not-found))
308             )
309
310
311 ; === sox-concatenate =============
312
313 (defmethod! sox-process ((sox-input sox-concatenate) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
314             (if (probe-file *sox-path*)
315
316                 (progn
317                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
318
319                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
320
321                     (let* ((filenames (loop for soundfile in (sound sox-input) collect
322                                             (namestring soundfile))))    
323                                
324                       (setf str (format nil "~s ~a " (namestring *sox-path*) *sox-options*))
325                                   
326                       (if (gains sox-input)
327                           (loop for filename in filenames do
328                                 for gain in (db->lin (list! (gains sox-input))) do
329                                 (setf str (string+ str (format nil " -v~d ~s  " gain filename ))))
330                         ;I think this case never happens
331                         (loop for filename in filenames do 
332                               (setf str (string+ str (format nil " ~s" filename)))))
333                       
334                       (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
335                                       ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
336                                       (t (sox-samplebits str bitdepth samplerate outfile))))
337
338                       (setf str (string+ str sox-effect))
339                       (sox-out str sox-input output outfile recursive))))
340
341               (sox-not-found))
342             )
343
344 ; === sox-splice ============
345
346 (defmethod! sox-process ((sox-input sox-splice) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
347             (if (probe-file *sox-path*)
348              
349               (progn
350                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
351
352                   (let ((outfile (create-path nil output filetype)))
353
354                     (let* ((mysoundfiles (sound sox-input))
355                            (filenames (loop for soundfile in mysoundfiles collect (namestring soundfile)))
356                            (first-dur (sox-sound-duration (car (sound sox-input))))
357                            (begins (list! (splice-begin sox-input)))
358                            (ends (list! (splice-end sox-input)))
359                            (tols (list! (tolerance sox-input))))
360
361                       (sox-print (format nil "begins: ~a" begins))
362                       (sox-print (format nil "ends: ~a" ends))
363                       (sox-print (format nil "tols: ~a" tols))
364
365                       (setf str (format nil "~s ~a " (namestring *sox-path*) *sox-options*))
366                       
367                       (loop for filename in filenames do
368                             for gain in (db->lin (list! (gains sox-input))) do
369                             (setf str (string+ str (format nil " -v~d ~s " gain filename ))))
370
371                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
372                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
373                                     (t (sox-samplebits str bitdepth samplerate outfile))))
374
375                     (setf str 
376                           (cond ((eql (fade-type sox-input) 'linear)  (string+ str (format nil " splice -t " )))
377                                 ((eql (fade-type sox-input) 'half-cosine)  (string+ str (format nil " splice -h " )))
378                                 ((eql (fade-type sox-input) 'quarter-cosine)  (string+ str  (format nil " splice -q " )))
379                                 (t  (string+ str  (format nil " splice " )))))
380
381                     ;dbl-check the sum-calculation. Something's fishy!
382
383                     (loop for mysound in (sound sox-input) 
384                           for end in ends 
385                           counting end into ordinal
386                           summing (or (sox-sound-duration mysound) 0) into dur-sum
387                           do
388                           (progn (sox-print ordinal)
389                           (let ((i (- ordinal 1))
390                                 (current-sum (- dur-sum (or first-dur 0))))
391                             
392                             (sox-print (format nil "begins: ~d" (nth i begins)))
393                             (sox-print (format nil "ends: ~d" (nth i ends)))
394                             (sox-print (format nil "current-sum: ~d" current-sum))
395                             
396                           (cond ((and (nth i begins) (nth i tols))
397                                  (progn 
398                                    (sox-print "begin+tol") 
399                                    (setf str (string+ str (format nil "~d,~d,~d " (+ current-sum (nth i ends))  (* 0.5 (- (nth i ends) (nth i begins))) (nth i tols))))))
400                                 ((nth i begins)
401                                  (progn 
402                                    (print "begin") 
403                                    (setf str (string+ str (format nil "~d,~d " (+ current-sum (nth i ends)) (* 0.5 (- (nth i ends) (nth i begins))))))))
404                                 (t (progn 
405                                      (print "end")
406                                      (setf str (string+ str (format nil "~d " (+ current-sum (nth i ends))))))))
407                           )))
408
409                     (setf str (sox-commands sox-effect str))
410                     (sox-out str sox-input output outfile recursive)
411                     )))
412             (sox-not-found))
413             )
414
415
416 ; === sox-remix =============
417
418 (defmethod! sox-process ((sox-input sox-remix) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
419            ;(print (first (channels sox-input)))
420             (if (probe-file *sox-path*)
421
422                 (progn
423                   (when (and (stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
424
425                   (let* ((inpath (sound sox-input))
426                          (outfile (create-path inpath output filetype)) ;(create-path nil output filetype)
427                          (channel-matrix (list! (channel-matrix sox-input)))) ; is this still needed?
428                     
429                     (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* (namestring inpath)))
430                    ; (print (channels sox-input))
431                    ; (print (gains sox-input))
432
433                     (when bitdepth (setf str (string+ str (format nil " -b ~d" bitdepth)))) ;could I not use sox-samplebits here?
434                     (setf str (string+ str (format nil " ~s remix ~a" 
435                                                    (cond ((equal output "realtime")  *sox-audio-device*) ;should add a quiet mode here...
436                                                          ((equal output "pipe") "-p")
437                                                          (t (namestring outfile)))
438                                                    (sox-remixconc-no-norm (gain-matrix sox-input) (channel-matrix sox-input))
439                                                    )))
440
441                     (when samplerate (setf str (string+ str (format nil " rate ~d " samplerate))))
442                     (setf str (string+ str sox-effect))
443                     (sox-out str inpath output outfile recursive)))
444             (sox-not-found))
445             )
446
447 ; === sox-pan ====================
448
449 (defmethod! sox-process ((sox-input sox-pan) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
450            ;(print (first (channels sox-input)))
451             (sox-process (sox-pan->sox-remix (sound sox-input) (car (list! (gains sox-input))) (car (list! (panning sox-input))) (numchannels sox-input))
452                          sox-effect
453                          :output output
454                          :filetype filetype
455                          :samplerate samplerate
456                          :bitdepth bitdepth
457                          :recursive recursive
458                          :batch-mode batch-mode))
459
460
461 ; === sox-mix-console =============
462
463
197ce0 464 ; Notes on polymorphism
92c40d 465 ; I could make this sox-mix-console (non-consistent) a method where a list of effects will be applied to each sound in the mix-console
AN 466 ;   OR: keep this as an extra function for the player
467 ; I can't use pipe-input to the mix-console as it makes sox-remix instances with pipe-outputs ->is a pipe in a pipe not possible?
468
469
470 (defmethod! sox-process ((sox-input sox-mix-console) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
471             (if (probe-file *sox-path*)
472
473                 (progn
474                   ;(print "sox-process: sox-mix-console")
475                   (when (and (stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
476
477                   (let* ((inpath (sound sox-input))
478                          (outfile (create-path inpath output filetype)) ;(create-path nil output filetype)  ; Filetype MUST NOT be pipe (it can be only a sound)
479
480                          (list-of-pans (loop for path in (list! inpath)
481                                for gain in (gains sox-input)
482                                for pan in (panning sox-input) collect
483                                (make-instance 'sox-pan 
484                                               :sound path
485                                               :gains gain
486                                               :panning pan)))
487                          
488                          (list-of-pipes (loop for sox-pan in list-of-pans 
489                                               for i from 0 to (length list-of-pans) collect 
490                                               (sox-process sox-pan (or (nth i (list! sox-effect)) "") ;note that in this special case a list of effects is applied to each in-sound
491                                                            :output "pipe"
492                                                            :filetype filetype 
493                                                            :samplerate samplerate 
494                                                            :bitdepth bitdepth
495                                                            :recursive recursive 
496                                                            :batch-mode batch-mode)))
497                          )
498                     (if (> (length list-of-pipes) 1)
499                         (sox-process (make-instance 'sox-mix :sound list-of-pipes) ""
500                                      :output output
501                                      :filetype filetype 
502                                      :samplerate samplerate 
503                                      :bitdepth bitdepth
504                                      :recursive recursive 
505                                      :batch-mode batch-mode
506                                      )
507                       (sox-process list-of-pipes ""
508                                      :output output
509                                      :filetype filetype 
510                                      :samplerate samplerate 
511                                      :bitdepth bitdepth
512                                      :recursive recursive 
513                                      :batch-mode batch-mode
514                                      ))
515                       ))
516               (sox-not-found)
517               ))
518
519
520
521
522 ; === sox-split =============
523 ; special method with (sox-effect t) only for sox-split (returns a sequence of sox-remixes)
524
525 (defmethod! sox-process ((sox-input sox-split) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
526             (if (probe-file *sox-path*)
527
528                 (progn
529                   (cond ((equal output "replace file") (om-message-abort "Replace output not possible with sox-split."))
530                         ((and (equal output "pipe") (stringp (sound sox-input))) (om-message-abort "Pipe output not possible with this type of input")))
531                   
532                   (let*
533                       ((thesoundfile (sound sox-input))
534                        (list-of-remixes (loop for channel in (channels sox-input)
535                                               for gain in (gains sox-input) collect
536                                               (make-instance 'sox-remix
537                                                              :sound thesoundfile
538                                                              :gain-matrix (list gain)
539                                                              :channel-matrix (list (list channel)))))
540                      ;here the 'realtime' and 'pipe' ??
541                        (list-of-outpaths  (loop for channel in (channels sox-input) collect
542                                                 (format nil "~a_omsox-ch~d" (pathname-name thesoundfile) channel))
543                                           ))
544                     
545                     (sox-process list-of-remixes sox-effect 
546                                  :output (or output list-of-outpaths)
547                                  :filetype filetype 
548                                  :samplerate samplerate 
549                                  :bitdepth bitdepth 
550                                  :recursive recursive 
551                                  :batch-mode batch-mode)))
552
553               (sox-not-found))
554             )
555
556
557
558
559
560 ; === sox-record =============
561
562 (defmethod! sox-process ((sox-input sox-record) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
563             (if (probe-file *sox-path*)
564
565                 (let ((outfile (create-path nil output filetype)))                         
566                   
567                   (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* *sox-audio-device*)) ;perhaps sox-recording vs playback-device?
568                   
569                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
570                                   ((equal output "pipe") (sox-samplebits (string+ str " -q ") bitdepth samplerate "-p"))
571                                   (t (sox-samplebits (string+ str " -q ") bitdepth samplerate outfile))))
572                   
573                   (setf str (string+ str (format nil " trim 0 ~d " (duration sox-input))))
574                   
575                   (cond ((and (channels sox-input) (gains sox-input))
576                          (let ((newstr (format nil " remix" )))
577                            (loop for channel in (channels sox-input)
578                                  for gain in (gains sox-input) do
579                                  (setf newstr (string+ newstr (format nil " ~av~d " channel (db->lin gain)))))                                                   
580                            (setf str (string+ str newstr))))
581                         
582                         ((gains sox-input)
583                          (let ((newstr (format nil " remix" )))
584                            (loop for item from 1 to (length (gains sox-input))
585                                  for gain in (gains sox-input) do
586                                  (setf newstr (string+ newstr (format nil " ~av~d " item (db->lin gain)))))
587                            (setf str (string+ str newstr))))
588                         
589                         ((channels sox-input)
590                          (let ((newstr (format nil " remix" )))
591                            (loop for channel in (channels sox-input) do
592                                  (setf newstr (string+ newstr (format nil " ~a" channel))))                                                   
593                            (setf str (string+ str newstr))))
594                         )
595
596                   (setf str (string+ str sox-effect))       
597
598                   (sox-out str sox-input output outfile recursive))
599                     
600               (sox-not-found))
601             )
602
603
604 ; === sox synth =========
605 #|
606 (defmethod! sox-process ((sox-input sox-synth) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
607             (if (probe-file *sox-path*)
608
609                 (let ((outfile (create-path nil output filetype)))
610                   (setf str (format nil "~s ~a -n" (namestring *sox-path*) *sox-options*))
611                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
612                                   ((equal output "pipe") (sox-samplebits str bitdepth samplerate '-p))
613                                   (t (sox-samplebits str bitdepth samplerate outfile))))
614                   (setf str (string+ str " synth" (sox-synth-format sox-input)))
615                   (setf str (string+ str sox-effect))
616                   (sox-out str sox-input output outfile recursive))
617               
618               (sox-not-found))
619             )          
620 |#
621 ; %%%%%%%%%%%% LIST METHODS %%%%%%%%%%%%%%%%%%%%%%
622
623 ; for string + list + list/string
624 (defmethod! sox-process ((sox-input t) (sox-effect list) &key output filetype samplerate bitdepth recursive batch-mode)
625             (if (and (listp output) (first output))
626                 (mapcar (lambda (thesox-effect thepath)
627                           (sox-process sox-input thesox-effect :output thepath :filetype filetype :samplerate samplerate 
628                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-effect output)
629               (mapcar (lambda (thesox-effect)
630                         (sox-process sox-input thesox-effect :output output :filetype filetype :samplerate samplerate 
631                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-effect)))
632
633 ; these functions below can be grouped together into multiple if/when statements for the different types of 'output'
634 ;--------------------------------------------------------------------------------------------------------------------
635 ; for list + string + string
636 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
637             (mapcar (lambda (file) 
638                       (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
639                                    :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input))
640
641 ; #### NEED TO MAKE AN EXAMPLE FOR THIS CASE // ALSO, THE LIST LIST FUNCTION method seems to be missing.. PROBABLY FOR AUTO_NAMING FILES (batch processing)
642 ; for list + string + function
643 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
644             (if (functionp output)
645                 ; these 2 cases seem to be identical 
646                 (mapcar (lambda (file) 
647                           (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
648                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)
649               (mapcar (lambda (file) 
650                         (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
651                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)))
652
653 ; for list + string + list 
654 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
655             (if (and (listp output) (first output))
656                 (mapcar (lambda (file thepath) 
657                           (sox-process file sox-effect :output thepath :filetype filetype :samplerate samplerate 
658                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input output)
659               (mapcar (lambda (file) 
660                         (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
661                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)))
662
663 ; ---------------------------------------------------------------------------------------------------------------------
664
665 ; for list + list + string/list
666 (defmethod! sox-process ((sox-input list) (sox-effect list) &key output filetype samplerate bitdepth recursive batch-mode)
667             (let (
668                   (numsounds (length sox-input))
669                   (numsox-effect (length sox-effect)))
670              
671               (when (> numsounds numsox-effect)
672                 (progn
673                   (when (equal batch-mode 'cycle)
674                     (setf sox-effect
675                           (flat (group-list sox-effect (list numsounds) 'circular))))
676                  (when (equal batch-mode 'repeat)
677                     (setf sox-effect
678                           (flat (x-append sox-effect (repeat-n (last sox-effect) (- numsounds numsox-effect))))))))
679
680               (if (consp output)
681                   (mapcar (lambda (file thesox-effect thepaths)
682                             (sox-process file thesox-effect :output thepaths :filetype filetype :samplerate samplerate 
683                                          :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input sox-effect output)
684                 (mapcar (lambda (file thesox-effect)
685                             (sox-process file thesox-effect :output output :filetype filetype :samplerate samplerate 
686                                          :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input sox-effect))))
687
688
689 ; for anything else beep ------------------
690 (defmethod! sox-process ((sox-input t) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
691     (om-beep-msg (format nil "!!! Wrong input type or command for sox-process: ~A with ~A" sox-input sox-effect)))
692
693