From 79151350650b58232a1db7c2b1359993575544ff Mon Sep 17 00:00:00 2001
From: Alexander Nguyen <alexander.nguyen@stud.hfm-karlsruhe.de>
Date: Sat, 25 Jan 2025 19:01:40 +0100
Subject: [PATCH] First implementation

---
 sources/sox-process.lisp |   99 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/sources/sox-process.lisp b/sources/sox-process.lisp
index 337a9f3..4f54088 100644
--- a/sources/sox-process.lisp
+++ b/sources/sox-process.lisp
@@ -178,6 +178,105 @@
               (sox-not-found))
             )
 
+; === sox-hoaencode =============
+
+(defmethod! sox-process ((sox-input sox-hoaencode) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)
+    (if (probe-file *sox-path*)
+        (progn
+            (let* 
+                (
+                    (sound 
+                        (if (> (length (positions sox-input)) (length (list! (sound sox-input)))) 
+                            (repeat-n (first (list! (sound sox-input))) (length (positions sox-input)))
+                            (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* 
+                    (
+                        (outfile (create-path nil output filetype))
+                        (filenames (loop for soundfile in sound collect (namestring soundfile)))
+                    )
+                    (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))
+                            )
+                            (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))))
+                                )
+                            )
+                        )
+                        ; case: multiple files
+                        (if (= (order sox-input) 0)
+                            ; case: order = 0
+                            (progn 
+                                (setf str (string+ str " -m"))
+                                (loop for filename in filenames do
+                                    (setf str (string+ str (format nil " ~s" filename)))
+                                )
+                            )
+                            ; case: order > 0
+                            (progn
+                                (setf str (string+ str " -m"))
+                                
+                                ; Create components 
+                                (setf component_idx 0)
+                                (loop 
+                                    for filename in filenames
+                                    for position in positions-ae do
+                                    (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)))
+                                        )
+                                        (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)
+
+                                        (setf component_idx (1+ component_idx))
+
+                                        ; Add component path to <str>
+                                        (setf str (string+ str (format nil " ~s" outfile_tmp)))
+                                    )
+                                )
+                            )
+                        )
+                    )
+                    (setf str 
+                        (cond 
+                            ((equal output "realtime") (sox-samplebits (string+ str " -q ") bitdepth samplerate *sox-audio-device*))
+                            ((equal output "pipe") (sox-samplebits str bitdepth samplerate "-p"))
+                            (t (sox-samplebits str bitdepth samplerate outfile))
+                        )
+                    )
+                    (setf str (string+ str sox-effect))
+                    (print str)
+                    (sox-out str sox-input output outfile recursive)
+                )
+            )
+        )
+        (sox-not-found)
+    )
+)
+
 ; === sox-mix =============
 
 (defmethod! sox-process ((sox-input sox-mix) (sox-effect string) &key output filetype samplerate bitdepth recursive batch-mode)

--
Gitblit v1.9.1