Work-in-progress repo for ambisonics extensions for OM-SoX
Marlon Schumacher
9 days ago b36c86db50ccd3ff51725fabf59c6e5723b7b2aa
fix: removed limitation that sound arg must be provided as a list
2 files modified
69 ■■■■■ changed files
sources/classes/sox-hoaencode.lisp 6 ●●●●● patch | view | raw | blame | history
sources/sox-process.lisp 63 ●●●●● patch | view | raw | blame | history
sources/classes/sox-hoaencode.lisp
@@ -1,4 +1,6 @@
;Authors: A. Nguyen, 2025.
;Authors:
; A. Nguyen, 2025
; M. Schumacher, 2025
; Design limitations:
; 1) Sounds must have identical sample rate; otherwise, SoX fails silently, literally.
@@ -184,7 +186,7 @@
(defmethod initialize-instance :after ((self sox-hoaencode) &rest l)
    (declare (ignore l))
    (when (sound self)
        (sox-init-sound self 'list)
        (sox-init-sound self 'atom)
    )
)
sources/sox-process.lisp
@@ -189,51 +189,39 @@
    (if (probe-file *sox-path*)
        (progn
            (when 
                (not (listp (sound sox-input)))
                (om-message-abort "sound must be a list.") ; use list! instead
            )
            (when
                (not 
                    (or 
                        (subtypep (type-of (positions sox-input)) '3dc)
                        (and (subtypep (type-of (positions sox-input)) 'list) (> (length (positions sox-input)) 0) (subtypep (type-of (first (positions sox-input))) 'list) (> (length (first (positions sox-input))) 1)))
                (and (subtypep (type-of (positions sox-input)) 'list)
                     (> (length (positions sox-input)) 0)
                     (subtypep (type-of (first (positions sox-input))) 'list)
                     (> (length (first (positions sox-input))) 1))
                )
                )
                (om-message-abort "positions must be of type 3dc, or a list of lists.")
            )
            (let*
                (
                    (sound
                        (sound sox-input)
                    )
                    (positions-ae
                        (sox-hoaencode-auto-convert-positions (positions sox-input))
                    )
                )
                (when
                    (and (find-if 'stringp sound) (equal output "pipe"))
                    (om-message-abort "Pipe output not possible with this type of input.")
                )
                (let*
                    (
                        (filenames (loop for soundfile in sound collect (namestring soundfile)))
                        (outfile (create-path nil output filetype))
                    )
          (let* ((sound (list! (sound sox-input)))
                 (positions-ae (sox-hoaencode-auto-convert-positions (positions sox-input))))
            (when (and (find-if 'stringp sound) (equal output "pipe"))
              (om-message-abort "Pipe output not possible with this type of input."))
            (let* ((filenames (loop for soundfile in sound collect (namestring soundfile)))
                   (outfile (create-path nil output filetype)))
                    (setf str (format nil " ~s ~a" (namestring *sox-path*) *sox-options*))
                    (if (= (length filenames) 1)
                        ; case: one file 
                        (let*
                            (
                                (filename (first filenames))
                                (position (first positions-ae))
                            )
                  (let* ((filename (first filenames))
                         (position (first positions-ae)))
                            (if (= (order sox-input) 0) 
                                ; case: order = 0
                                (setf str (string+ str (format nil " ~s" filename)))
                                ; case: order > 0
                                (progn
                                    (setf str (string+ str " -M"))
                                    (loop for gain in (sox-hoaencode-gains-up-to-order (order sox-input) (first position) (second position)) do
                                        (setf str (string+ str (format nil " -v~d ~s" gain filename))))
                        (loop for gain in (sox-hoaencode-gains-up-to-order (order sox-input) (first position) (second position))
                              do (setf str (string+ str (format nil " -v~d ~s" gain filename))))
                                )
                            )
                        )
@@ -242,9 +230,8 @@
                            ; case: order = 0
                            (progn 
                                (setf str (string+ str " -m")) ; this is the mixer. e.g. sox-mix
                                (loop for filename in filenames do
                                    (setf str (string+ str (format nil " ~s" filename)))
                                )
                                (loop for filename in filenames
                                      do (setf str (string+ str (format nil " ~s" filename))))
                            )
                            ; case: order > 0
                            (progn
@@ -254,7 +241,8 @@
                                (setf component_idx 0)
                                (loop 
                                    for filename in filenames
                                    for position in positions-ae do
                       for position in positions-ae
                       do
                                                                   ; in Object-Oriented Programming we would call-next-method i.e. set a sox-merge input class with the corresponding params. 
                                                                   ; e.g. (make-instance 'sox-merge ... (more redundancy and compactness, less error-prone) ... possible?
@@ -262,10 +250,9 @@
                                    (progn  
                                        (setf str_component (format nil " ~s ~a -M" (namestring *sox-path*) *sox-options*))
                                        (loop
                                            for gain in (sox-hoaencode-gains-up-to-order (order sox-input) (first position) (second position)) do
                                            (setf str_component (string+ str_component (format nil " -v~d ~s" gain filename)))
                                        )
                           (loop for gain in (sox-hoaencode-gains-up-to-order (order sox-input) (first position) (second position))
                                 do (setf str_component (string+ str_component (format nil " -v~d ~s" gain filename))))
                                        (setf outfile_tmp (format nil "~a~a-~d.~a" (directory-namestring outfile) (pathname-name outfile) component_idx (pathname-type outfile)))
                                        (setf str_component (sox-samplebits str_component bitdepth samplerate outfile_tmp))
                                        (sox-out str_component filename "new file" outfile_tmp nil)