Work-in-progress repo for ambisonics extensions for OM-SoX
Marlon Schumacher
4 days ago 4020656850c3f64875a927ae9687127c163d9099
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
791513 189     (if (probe-file *sox-path*)
402065 190         (progn          
MS 191           (let* ((sound (list! (sound sox-input))))
b36c86 192
MS 193             (when (and (find-if 'stringp sound) (equal output "pipe")) 
194               (om-message-abort "Pipe output not possible with this type of input."))
195             
402065 196             (let* ((filenames (loop for soundfile in sound collect (namestring soundfile))) ; not needed - soundfile should be an atom
b36c86 197                    (outfile (create-path nil output filetype)))
MS 198               
199               (setf str (format nil " ~s ~a" (namestring *sox-path*) *sox-options*))
200               (if (= (length filenames) 1)
791513 201                         ; case: one file 
402065 202                   (let* ((filename (first filenames)))
MS 203                        ;  (position positions-ae))
b36c86 204                     (if (= (order sox-input) 0) 
MS 205                      ; case: order = 0
206                         (setf str (string+ str (format nil " ~s" filename)))
207                      ; case: order > 0
e43e60 208                       (progn ; here it would be more redundant to call sox-merge with the given params
b36c86 209                         (setf str (string+ str " -M"))
402065 210                         (loop for gain in (sox-hoaencode-gains-up-to-order (order sox-input) (azimuth sox-input) (elevation sox-input)) 
b36c86 211                               do (setf str (string+ str (format nil " -v~d ~s" gain filename))))
791513 212                         )
b36c86 213                       )
402065 214                     ))
MS 215             
b36c86 216               (setf str 
MS 217                     (cond 
218                      ((equal output "realtime") 
219                       (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
220                      ((equal output "pipe") 
221                       (sox-samplebits str bitdepth samplerate "-p"))
222                      (t 
223                       (sox-samplebits str bitdepth samplerate outfile))
224                      )
791513 225                     )
b36c86 226               (setf str (string+ str sox-effect))
MS 227               (print str)
228               (sox-out str sox-input output outfile recursive)
197ce0 229
MS 230                        ;optional removal of temp file
231                   ;    (add-tmp-file outfile_tmp)
232                   ;    (when *delete-inter-file* (clean-tmp-files))
233
b36c86 234               )
791513 235             )
b36c86 236           )
MS 237       (sox-not-found)
238       )
791513 239     )
AN 240
92c40d 241 ; === sox-mix =============
AN 242
243 (defmethod! sox-process ((sox-input sox-mix) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
244             (if (probe-file *sox-path*)
245
246                  (progn
247                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe"))
248                     (om-message-abort "Pipe output not possible with this type of input."))
249
250                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
251
252                     (let* ((filenames 
253                             (loop for soundfile in (sound sox-input) collect ;I guess this throws the error when using pipes as inputs
254                                   (namestring soundfile))))
255
256                       (setf str (format nil "~s ~a -m " (namestring *sox-path*) *sox-options*))
257                                                           
258                       ;potentially not needed...
259                    ;(if (1/n sox-input) 
260                         
261                    ;     (loop for filename in filenames do
262                    ;           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?
263                    ;           (setf str (string+ str (format nil " -v~d ~s " gain filename )))) ; is it not scaling when volumes are given? try out!
264
265                       (loop for filename in filenames do
266                               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?
267                               (setf str (string+ str (format nil " -v~d ~s " gain filename ))))
268                       ;)
269
270                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
271                                     ((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...
272                                     (t (sox-samplebits str bitdepth samplerate outfile))))
273
274                     (setf str (string+ str sox-effect))
275
276                     (sox-out str sox-input output outfile recursive))))
277
278               (sox-not-found))
279             )
280
281 ; === sox-multiply =============
282
283 (defmethod! sox-process ((sox-input sox-multiply) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
284             (if (probe-file *sox-path*)
285
286                  (progn
287                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe"))
288                     (om-message-abort "Pipe output not possible with this type of input."))
289
290                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
291
292                     (let* ((filenames 
293                             (loop for soundfile in (sound sox-input) collect ;I guess this throws the error when using pipes as inputs
294                                   (namestring soundfile))))
295
296                       (setf str (format nil "~s ~a -T " (namestring *sox-path*) *sox-options*))
297                                                           
298                       (loop for filename in filenames do
299                               for gain in (db->lin (gains sox-input)) do 
300                               (setf str (string+ str (format nil " -v~d ~s " gain filename )))) ; note that "-v" suppresses sox's in-built clipping protection
301                       ;)
302
303                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
304                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
305                                     (t (sox-samplebits str bitdepth samplerate outfile))))
306
307                     (setf str (string+ str sox-effect))
308
309                     (sox-out str sox-input output outfile recursive))))
310
311               (sox-not-found))
312             )
313
314
315 ; === sox-concatenate =============
316
317 (defmethod! sox-process ((sox-input sox-concatenate) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
318             (if (probe-file *sox-path*)
319
320                 (progn
321                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
322
323                   (let ((outfile (create-path nil output filetype))) ;(create-path (first (soundfiles sox-input)) output filetype)
324
325                     (let* ((filenames (loop for soundfile in (sound sox-input) collect
326                                             (namestring soundfile))))    
327                                
328                       (setf str (format nil "~s ~a " (namestring *sox-path*) *sox-options*))
329                                   
330                       (if (gains sox-input)
331                           (loop for filename in filenames do
332                                 for gain in (db->lin (list! (gains sox-input))) do
333                                 (setf str (string+ str (format nil " -v~d ~s  " gain filename ))))
334                         ;I think this case never happens
335                         (loop for filename in filenames do 
336                               (setf str (string+ str (format nil " ~s" filename)))))
337                       
338                       (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
339                                       ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
340                                       (t (sox-samplebits str bitdepth samplerate outfile))))
341
342                       (setf str (string+ str sox-effect))
343                       (sox-out str sox-input output outfile recursive))))
344
345               (sox-not-found))
346             )
347
348 ; === sox-splice ============
349
350 (defmethod! sox-process ((sox-input sox-splice) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
351             (if (probe-file *sox-path*)
352              
353               (progn
354                   (when (and (find-if 'stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
355
356                   (let ((outfile (create-path nil output filetype)))
357
358                     (let* ((mysoundfiles (sound sox-input))
359                            (filenames (loop for soundfile in mysoundfiles collect (namestring soundfile)))
360                            (first-dur (sox-sound-duration (car (sound sox-input))))
361                            (begins (list! (splice-begin sox-input)))
362                            (ends (list! (splice-end sox-input)))
363                            (tols (list! (tolerance sox-input))))
364
365                       (sox-print (format nil "begins: ~a" begins))
366                       (sox-print (format nil "ends: ~a" ends))
367                       (sox-print (format nil "tols: ~a" tols))
368
369                       (setf str (format nil "~s ~a " (namestring *sox-path*) *sox-options*))
370                       
371                       (loop for filename in filenames do
372                             for gain in (db->lin (list! (gains sox-input))) do
373                             (setf str (string+ str (format nil " -v~d ~s " gain filename ))))
374
375                     (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
376                                     ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
377                                     (t (sox-samplebits str bitdepth samplerate outfile))))
378
379                     (setf str 
380                           (cond ((eql (fade-type sox-input) 'linear)  (string+ str (format nil " splice -t " )))
381                                 ((eql (fade-type sox-input) 'half-cosine)  (string+ str (format nil " splice -h " )))
382                                 ((eql (fade-type sox-input) 'quarter-cosine)  (string+ str  (format nil " splice -q " )))
383                                 (t  (string+ str  (format nil " splice " )))))
384
385                     ;dbl-check the sum-calculation. Something's fishy!
386
387                     (loop for mysound in (sound sox-input) 
388                           for end in ends 
389                           counting end into ordinal
390                           summing (or (sox-sound-duration mysound) 0) into dur-sum
391                           do
392                           (progn (sox-print ordinal)
393                           (let ((i (- ordinal 1))
394                                 (current-sum (- dur-sum (or first-dur 0))))
395                             
396                             (sox-print (format nil "begins: ~d" (nth i begins)))
397                             (sox-print (format nil "ends: ~d" (nth i ends)))
398                             (sox-print (format nil "current-sum: ~d" current-sum))
399                             
400                           (cond ((and (nth i begins) (nth i tols))
401                                  (progn 
402                                    (sox-print "begin+tol") 
403                                    (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))))))
404                                 ((nth i begins)
405                                  (progn 
406                                    (print "begin") 
407                                    (setf str (string+ str (format nil "~d,~d " (+ current-sum (nth i ends)) (* 0.5 (- (nth i ends) (nth i begins))))))))
408                                 (t (progn 
409                                      (print "end")
410                                      (setf str (string+ str (format nil "~d " (+ current-sum (nth i ends))))))))
411                           )))
412
413                     (setf str (sox-commands sox-effect str))
414                     (sox-out str sox-input output outfile recursive)
415                     )))
416             (sox-not-found))
417             )
418
419
420 ; === sox-remix =============
421
422 (defmethod! sox-process ((sox-input sox-remix) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
423            ;(print (first (channels sox-input)))
424             (if (probe-file *sox-path*)
425
426                 (progn
427                   (when (and (stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
428
429                   (let* ((inpath (sound sox-input))
430                          (outfile (create-path inpath output filetype)) ;(create-path nil output filetype)
431                          (channel-matrix (list! (channel-matrix sox-input)))) ; is this still needed?
432                     
433                     (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* (namestring inpath)))
434                    ; (print (channels sox-input))
435                    ; (print (gains sox-input))
436
437                     (when bitdepth (setf str (string+ str (format nil " -b ~d" bitdepth)))) ;could I not use sox-samplebits here?
438                     (setf str (string+ str (format nil " ~s remix ~a" 
439                                                    (cond ((equal output "realtime")  *sox-audio-device*) ;should add a quiet mode here...
440                                                          ((equal output "pipe") "-p")
441                                                          (t (namestring outfile)))
442                                                    (sox-remixconc-no-norm (gain-matrix sox-input) (channel-matrix sox-input))
443                                                    )))
444
445                     (when samplerate (setf str (string+ str (format nil " rate ~d " samplerate))))
446                     (setf str (string+ str sox-effect))
447                     (sox-out str inpath output outfile recursive)))
448             (sox-not-found))
449             )
450
451 ; === sox-pan ====================
452
453 (defmethod! sox-process ((sox-input sox-pan) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
454            ;(print (first (channels sox-input)))
455             (sox-process (sox-pan->sox-remix (sound sox-input) (car (list! (gains sox-input))) (car (list! (panning sox-input))) (numchannels sox-input))
456                          sox-effect
457                          :output output
458                          :filetype filetype
459                          :samplerate samplerate
460                          :bitdepth bitdepth
461                          :recursive recursive
462                          :batch-mode batch-mode))
463
464
465 ; === sox-mix-console =============
466
467
197ce0 468 ; Notes on polymorphism
92c40d 469 ; 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 470 ;   OR: keep this as an extra function for the player
471 ; 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?
472
473
474 (defmethod! sox-process ((sox-input sox-mix-console) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
475             (if (probe-file *sox-path*)
476
477                 (progn
478                   ;(print "sox-process: sox-mix-console")
479                   (when (and (stringp (sound sox-input)) (equal output "pipe")) (om-message-abort "Pipe output not possible with this type of input."))
480
481                   (let* ((inpath (sound sox-input))
482                          (outfile (create-path inpath output filetype)) ;(create-path nil output filetype)  ; Filetype MUST NOT be pipe (it can be only a sound)
483
484                          (list-of-pans (loop for path in (list! inpath)
485                                for gain in (gains sox-input)
486                                for pan in (panning sox-input) collect
487                                (make-instance 'sox-pan 
488                                               :sound path
489                                               :gains gain
490                                               :panning pan)))
491                          
492                          (list-of-pipes (loop for sox-pan in list-of-pans 
493                                               for i from 0 to (length list-of-pans) collect 
494                                               (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
495                                                            :output "pipe"
496                                                            :filetype filetype 
497                                                            :samplerate samplerate 
498                                                            :bitdepth bitdepth
499                                                            :recursive recursive 
500                                                            :batch-mode batch-mode)))
501                          )
502                     (if (> (length list-of-pipes) 1)
503                         (sox-process (make-instance 'sox-mix :sound list-of-pipes) ""
504                                      :output output
505                                      :filetype filetype 
506                                      :samplerate samplerate 
507                                      :bitdepth bitdepth
508                                      :recursive recursive 
509                                      :batch-mode batch-mode
510                                      )
511                       (sox-process list-of-pipes ""
512                                      :output output
513                                      :filetype filetype 
514                                      :samplerate samplerate 
515                                      :bitdepth bitdepth
516                                      :recursive recursive 
517                                      :batch-mode batch-mode
518                                      ))
519                       ))
520               (sox-not-found)
521               ))
522
523
524
525
526 ; === sox-split =============
527 ; special method with (sox-effect t) only for sox-split (returns a sequence of sox-remixes)
528
529 (defmethod! sox-process ((sox-input sox-split) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
530             (if (probe-file *sox-path*)
531
532                 (progn
533                   (cond ((equal output "replace file") (om-message-abort "Replace output not possible with sox-split."))
534                         ((and (equal output "pipe") (stringp (sound sox-input))) (om-message-abort "Pipe output not possible with this type of input")))
535                   
536                   (let*
537                       ((thesoundfile (sound sox-input))
538                        (list-of-remixes (loop for channel in (channels sox-input)
539                                               for gain in (gains sox-input) collect
540                                               (make-instance 'sox-remix
541                                                              :sound thesoundfile
542                                                              :gain-matrix (list gain)
543                                                              :channel-matrix (list (list channel)))))
544                      ;here the 'realtime' and 'pipe' ??
545                        (list-of-outpaths  (loop for channel in (channels sox-input) collect
546                                                 (format nil "~a_omsox-ch~d" (pathname-name thesoundfile) channel))
547                                           ))
548                     
549                     (sox-process list-of-remixes sox-effect 
550                                  :output (or output list-of-outpaths)
551                                  :filetype filetype 
552                                  :samplerate samplerate 
553                                  :bitdepth bitdepth 
554                                  :recursive recursive 
555                                  :batch-mode batch-mode)))
556
557               (sox-not-found))
558             )
559
560
561
562
563
564 ; === sox-record =============
565
566 (defmethod! sox-process ((sox-input sox-record) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
567             (if (probe-file *sox-path*)
568
569                 (let ((outfile (create-path nil output filetype)))                         
570                   
571                   (setf str (format nil "~s ~a ~s" (namestring *sox-path*) *sox-options* *sox-audio-device*)) ;perhaps sox-recording vs playback-device?
572                   
573                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
574                                   ((equal output "pipe") (sox-samplebits (string+ str " -q ") bitdepth samplerate "-p"))
575                                   (t (sox-samplebits (string+ str " -q ") bitdepth samplerate outfile))))
576                   
577                   (setf str (string+ str (format nil " trim 0 ~d " (duration sox-input))))
578                   
579                   (cond ((and (channels sox-input) (gains sox-input))
580                          (let ((newstr (format nil " remix" )))
581                            (loop for channel in (channels sox-input)
582                                  for gain in (gains sox-input) do
583                                  (setf newstr (string+ newstr (format nil " ~av~d " channel (db->lin gain)))))                                                   
584                            (setf str (string+ str newstr))))
585                         
586                         ((gains sox-input)
587                          (let ((newstr (format nil " remix" )))
588                            (loop for item from 1 to (length (gains sox-input))
589                                  for gain in (gains sox-input) do
590                                  (setf newstr (string+ newstr (format nil " ~av~d " item (db->lin gain)))))
591                            (setf str (string+ str newstr))))
592                         
593                         ((channels sox-input)
594                          (let ((newstr (format nil " remix" )))
595                            (loop for channel in (channels sox-input) do
596                                  (setf newstr (string+ newstr (format nil " ~a" channel))))                                                   
597                            (setf str (string+ str newstr))))
598                         )
599
600                   (setf str (string+ str sox-effect))       
601
602                   (sox-out str sox-input output outfile recursive))
603                     
604               (sox-not-found))
605             )
606
607
608 ; === sox synth =========
609 #|
610 (defmethod! sox-process ((sox-input sox-synth) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
611             (if (probe-file *sox-path*)
612
613                 (let ((outfile (create-path nil output filetype)))
614                   (setf str (format nil "~s ~a -n" (namestring *sox-path*) *sox-options*))
615                   (setf str (cond ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
616                                   ((equal output "pipe") (sox-samplebits str bitdepth samplerate '-p))
617                                   (t (sox-samplebits str bitdepth samplerate outfile))))
618                   (setf str (string+ str " synth" (sox-synth-format sox-input)))
619                   (setf str (string+ str sox-effect))
620                   (sox-out str sox-input output outfile recursive))
621               
622               (sox-not-found))
623             )          
624 |#
625 ; %%%%%%%%%%%% LIST METHODS %%%%%%%%%%%%%%%%%%%%%%
626
627 ; for string + list + list/string
628 (defmethod! sox-process ((sox-input t) (sox-effect list) &key output filetype samplerate bitdepth recursive batch-mode)
629             (if (and (listp output) (first output))
630                 (mapcar (lambda (thesox-effect thepath)
631                           (sox-process sox-input thesox-effect :output thepath :filetype filetype :samplerate samplerate 
632                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-effect output)
633               (mapcar (lambda (thesox-effect)
634                         (sox-process sox-input thesox-effect :output output :filetype filetype :samplerate samplerate 
635                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-effect)))
636
637 ; these functions below can be grouped together into multiple if/when statements for the different types of 'output'
638 ;--------------------------------------------------------------------------------------------------------------------
639 ; for list + string + string
640 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
641             (mapcar (lambda (file) 
642                       (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
643                                    :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input))
644
645 ; #### 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)
646 ; for list + string + function
647 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
648             (if (functionp output)
649                 ; these 2 cases seem to be identical 
650                 (mapcar (lambda (file) 
651                           (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
652                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)
653               (mapcar (lambda (file) 
654                         (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
655                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)))
656
657 ; for list + string + list 
658 (defmethod! sox-process ((sox-input list) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
659             (if (and (listp output) (first output))
660                 (mapcar (lambda (file thepath) 
661                           (sox-process file sox-effect :output thepath :filetype filetype :samplerate samplerate 
662                                        :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input output)
663               (mapcar (lambda (file) 
664                         (sox-process file sox-effect :output output :filetype filetype :samplerate samplerate 
665                                      :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input)))
666
667 ; ---------------------------------------------------------------------------------------------------------------------
668
669 ; for list + list + string/list
670 (defmethod! sox-process ((sox-input list) (sox-effect list) &key output filetype samplerate bitdepth recursive batch-mode)
671             (let (
672                   (numsounds (length sox-input))
673                   (numsox-effect (length sox-effect)))
674              
675               (when (> numsounds numsox-effect)
676                 (progn
677                   (when (equal batch-mode 'cycle)
678                     (setf sox-effect
679                           (flat (group-list sox-effect (list numsounds) 'circular))))
680                  (when (equal batch-mode 'repeat)
681                     (setf sox-effect
682                           (flat (x-append sox-effect (repeat-n (last sox-effect) (- numsounds numsox-effect))))))))
683
684               (if (consp output)
685                   (mapcar (lambda (file thesox-effect thepaths)
686                             (sox-process file thesox-effect :output thepaths :filetype filetype :samplerate samplerate 
687                                          :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input sox-effect output)
688                 (mapcar (lambda (file thesox-effect)
689                             (sox-process file thesox-effect :output output :filetype filetype :samplerate samplerate 
690                                          :bitdepth bitdepth :recursive recursive :batch-mode batch-mode)) sox-input sox-effect))))
691
692
693 ; for anything else beep ------------------
694 (defmethod! sox-process ((sox-input t) (sox-effect t) &key output filetype samplerate bitdepth recursive batch-mode)
695     (om-beep-msg (format nil "!!! Wrong input type or command for sox-process: ~A with ~A" sox-input sox-effect)))
696
697