Work-in-progress repo for ambisonics extensions for OM-SoX
Marlon Schumacher
5 days ago 3c36efb7ea5dd8cccd9bcc47f4f6e71ee4cfcbb2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
;*********************************************************************
; OM-SoX, (c) 2011-2013 Marlon Schumacher (CIRMMT/McGill University) *
;             http://sourceforge.net/projects/omsox/                 *
;                                                                    *
;  Multichannel Audio Manipulation and Functional Batch Processing.  *
;        DSP based on SoX - (c) C.Bagwell and Contributors           *
;                  http://sox.sourceforge.net/                       *
;*********************************************************************
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.
;
;See file LICENSE for further informations on licensing terms.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,10 USA.
;
;Authors: M. Schumacher
 
 
; Some possible default options:
; -norm to guard against clipping and normalize
 
(in-package :om)
 
; these variables might be dispatched into different lisp files (utilities, etc.)
(defvar *sox-path* "path to sox")
(defvar *sox-options* " -q --multi-threaded --buffer 4096 --input-buffer 512 -V0 ")
(defvar *use-om-audio-prefs-in-sox* nil)
(defparameter *sox-audio-device* '-d "default audio device") 
(defparameter *sox-samplerates* '(("100 Hertz" "100") ("1kHz" "1k") ("4kHz" "4k") ("8kHz" "8k") ("16kHz" "16k") ("20kHz" "20k") ("30kHz" "30k") ("44.1kHz" "44.1k") ("48kHz" "48k") ("88.2kHz" "88.2k") ("96kHz" "96k")))
(defparameter *sox-bitdephts* '(("8" 8) ("16" 16) ("24" 24) ("32" 32) ("64" 64))) 
(defparameter *sox-file-formats* '(("aif" "aif") ("wav" "wav") ("flac" "flac") ("ogg" "ogg")))
(defparameter *sox-output-options* '(("new file" nil) ("replace file" "replace file") ("pipe" "pipe") ("realtime" "realtime")))
 
(defun sox-def-vals () '(" -q --multi-threaded --buffer 4096 --input-buffer 512 -V0 " nil)) ; why is this a function and not a variable?
(defparameter *sox-debug* nil "when set to t will print informations to the listener (for debugging)")
(defvar *sox-running-processes* nil "keeps a list of process-ids of currently running sox-processes")
(defvar *sox-temp-recorded-file* nil)
 
; for documentation
(defvar *sox-append-doc* "Append sox-effects/statistics to the processing chain.")
;*sox-append-doc*
(defparameter *sox-unit-doc* "Select unit for bandwidth value (Hz/kHz/Octaves/Q-factor). Defaults to Hz.")
;*sox-unit-doc*
(defparameter *sox-unit-menu* (list (list "Hz" "Hz") (list  "kHz" "kHz") (list "Octaves" "Octaves") (list "Q-factor" "Q-factor")))
;*sox-unit-menu*
(defparameter *sox-filter-types* (list (list "lowpass" "lowpass") (list "highpass" "highpass") (list "bandpass" "bandpass") (list "bandreject" "bandreject")))
;better: *sox-filter-types-fir*
(defparameter *sox-filter-types-all* (list (list "lowpass" "lowpass") (list "highpass" "highpass") (list "bandpass" "bandpass") (list "bandreject" "bandreject") (list "allpass" "allpass"))) ;better: *sox-filter-types-iir*
 
 
(add-external-pref-module 'sox)
 
(defmethod get-external-name ((module (eql 'sox))) "Sox")
(defmethod get-external-icon ((module (eql 'sox))) (and (exist-lib-p "OM-SoX") (list 01 (exist-lib-p "OM-SoX"))))
 
(defmethod get-external-module-path ((module (eql 'sox)) modulepref) (get-pref modulepref :sox-path))
(defmethod set-external-module-path ((module (eql 'sox)) modulepref path) 
  (set-pref modulepref :sox-path path))
 
(defmethod get-external-module-vals ((module (eql 'sox)) modulepref) (get-pref modulepref :sox-options))
(defmethod set-external-module-vals ((module (eql 'sox)) modulepref vals) (set-pref modulepref :sox-options vals))
 
(defmethod get-external-def-vals ((module (eql 'sox))) 
  #+macosx (list :sox-path  (om-make-pathname :directory (append (pathname-directory (lib-pathname (exist-lib-p "OM-SoX"))) '("executables" "macos")) :name "sox")
                 :sox-options (sox-def-vals)
                 )
  #+linux (list :sox-path  (om-make-pathname :directory '(:absolute "usr" "bin") :name "sox")
                :sox-options (sox-def-vals)
                )
  #+win32 (list :sox-path  (om-make-pathname :directory (append (pathname-directory (lib-pathname (exist-lib-p "OM-SoX"))) '("executables" "windows")) :name "sox.exe")
                :sox-options (sox-def-vals)
                )   ;;; HERE INSERT THE DEFAULT VALUES FOR THE SOX OPTIONS
  )
 
 
(defmethod save-external-prefs ((module (eql 'sox))) 
  `(:sox-path ,(om-save-pathname *SOX-PATH*)
    :sox-options (list ,*sox-options* ,*use-om-audio-prefs-in-sox*) 
    ))      ;;; HERE INSERT THE "BACKQUOTED" EXPRESSION FOR GENERATING THE OPTION SAVE CODE
 
(find-pref-module :externals)
 
(defmethod put-external-preferences ((module (eql 'sox)) moduleprefs)
    (when (get-pref moduleprefs :sox-path)
      (setf *SOX-PATH* (find-true-external (get-pref moduleprefs :sox-path))))
    (let ((list-prefs (get-pref moduleprefs :sox-options)))
      (when list-prefs 
        ;;; HERE SET GLOBAL VARIABLES ACCORDING TO THE OPTION LIST
        (setf *sox-options* (nth 0 list-prefs)
              *use-om-audio-prefs-in-sox* (nth 1 list-prefs))
        ;;; etc.
       ))
    t)
 
(put-external-pref-values 'sox)
 
 
(defmethod show-external-prefs-dialog ((module (eql 'sox)) prefvals)
  (let* ((rep-list (copy-list prefvals))
         (dialog (om-make-window 'om-dialog
                                 :window-title "SoX Options"
                                 :size (om-make-point 300 280)
                                 :position :centered
                                 :resizable nil :maximize nil :close nil))
         flag-text prefs-checkbox)
 
    (om-add-subviews dialog
                     (om-make-dialog-item 'om-static-text  (om-make-point 20 20) (om-make-point 200 20) 
                                          "Commamd line flags" :font *controls-font*)
                     (setf flag-text (om-make-dialog-item 'om-editable-text  (om-make-point 20 45) (om-make-point 240 100) 
                                                           (nth 0 prefvals)
                                                          :font *om-default-font1*))
                     (setf prefs-checkbox (om-make-dialog-item 'om-check-box  (om-make-point 20 150) (om-make-point 220 20) 
                                                               "Use OM audio settings" 
                                                               :checked-p (nth 1 prefvals)
                                                               :font *controls-font*))
 
                     (om-make-dialog-item 'om-static-text  (om-make-point 20 170) (om-make-point 300 20) 
                                          "(samplerate, resolution, output format)" 
                                          :font *controls-fonti*)
 
                     
                     ;;; boutons
                     (om-make-dialog-item 'om-button (om-make-point 20 220) (om-make-point 80 20) "Restore"
                                          :di-action (om-dialog-item-act item
                                                       (om-set-dialog-item-text flag-text (number-to-string (nth 0 (sox-def-vals))))
                                                       (om-set-check-box prefs-checkbox (nth 1 (sox-def-vals)))
                                                       ))
      
                     (om-make-dialog-item 'om-button (om-make-point 110 220) (om-make-point 80 20) "Cancel"
                                          :di-action (om-dialog-item-act item
                                                       (om-return-from-modal-dialog dialog nil)))
      
                     (om-make-dialog-item 'om-button (om-make-point 190 220) (om-make-point 80 20) "OK"
                                          :di-action (om-dialog-item-act item
                                                       (let* ((argerror nil)
                                                              (txt1 (om-dialog-item-text flag-text)))
                                                         (setf (nth 0 rep-list) txt1)
                                                         (setf (nth 1 rep-list) (om-checked-p prefs-checkbox))
                                                         (if argerror
                                                             (om-message-dialog (format nil "Error in a SOX option.~% Preferences could not be recorded.")) 
                                                           (om-return-from-modal-dialog dialog rep-list))
                                                         ))
                                          :default-button t :focus t)
                     
                     )
    (om-modal-dialog dialog)))
 
 
; ----------------
; experimental code for querying running audiodevices from the OS
#|
(defun sox-get-audio-device ()
  (if (probe-file *sox-path*)
                ;(let ((outfile (create-path input output filetype)))
                  (let ((str (format nil "~s -V6 -n -t coreaudio unknown 2>devices.txt" (namestring *sox-path*))))
                  (om-cmd-line str *sys-console*)
                  )
              (sox-not-found))
  )
 
 ; sox -V6 infile -t coreaudio junkname
;"/Users/Marlon_MBPro/Dropbox/OM-stuff/OMsox/OMsox 0.1/exectuables/sox" -V4 -n -t coreaudio unknown 2>devices.t
|#
 
(defparameter *additional-audio-formats* nil)
 
(pushnew '(:sox-formats "flac" "3gp" "caf" "au"
"raw" "f32" "f64" "s8" "s16" "s24" "s32" "u8" "u16" "u24" "u32" "ul" "al" "lu" "la"
"cdda" "cdr"
"f4" "f8" "s1" "s2" "s3" "s4"
"u1" "u2" "u3" "u4" "sb" "sw" "sl" "ub" "uw"
"8svx"
"aiffc" "aifc" "amb" "amr-nb"
"amr-w"
"au" "snd"
"avr"
"cvsd" "cvs"
"cvu"
"dat"
"dvms" "vms"
"fap" "paf"
"ffmpeg"
"flac"
"fssd"
"gsm"
"hcom"
"htk"
"ircam"
"ima"
"lpc" "lpc10"
"mat" "mat4" "mat5"
"m3u" "mp3" "mp2" "mp4" "m4a"
"maud" 
"nist" "sph"
"ogg" "vorbis"
"prc" 
"pvf"
"sd2"
"sds"
"sf" 
"sph" "nist"
"smp" "sndr" "sndt"
"sndfile"
"sndio"
"sndr" "sndt"
"sou"
"txw"
"vms" "dvms"
"voc"
"w64" "wav"
"waveaudio"
"wavpcm"
"wv"
"wve"
"xa"
"xi"
)  *additional-audio-formats*)