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