aboutsummaryrefslogtreecommitdiff
path: root/soxresample.bqn
diff options
context:
space:
mode:
Diffstat (limited to 'soxresample.bqn')
-rw-r--r--soxresample.bqn19
1 files changed, 19 insertions, 0 deletions
diff --git a/soxresample.bqn b/soxresample.bqn
new file mode 100644
index 0000000..89fbffc
--- /dev/null
+++ b/soxresample.bqn
@@ -0,0 +1,19 @@
+# Binding for sox's resample library
+
+u ← "u64"
+soxR ← "/usr/lib/libsoxr.so" •FFI ⟨
+ u,"soxr_oneshot","f64","f64","u32"
+ "*f32",u,u
+ "&f32",u,"&u64:u32"
+ u,u,u
+⟩
+
+# Resample pcm data 𝕩 from frequency fIn to frequency fOut.
+{ iFr‿oFr 𝕊 𝕩:
+ {
+ oMax ← ⌈ (oFr÷iFr) × iLen←≠𝕩 # Input and maximum output lengths
+ s‿out‿oLen ← SoxR ⟨iFr,oFr,1, 𝕩,iLen,0, oMax⥊0,oMax,⟨1,0⟩, 0,0,0⟩
+ ! 0 = s
+ (⊑oLen)↑out
+ }⎉1⍟(iFr≠oFr) 𝕩
+}