diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-22 11:31:14 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-22 11:31:14 -0400 |
| commit | 6ee94f4962e7a1624385122d1e756896caced43a (patch) | |
| tree | 7f3ffa34ed67697c2d3ef7f4a43d90b24752a185 /soxresample.bqn | |
| parent | e4ef704ae20e8ba22d38e08394b5c8e412081ab4 (diff) | |
Support resampling via sox if •FFI can load it when requested
Diffstat (limited to 'soxresample.bqn')
| -rw-r--r-- | soxresample.bqn | 19 |
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) 𝕩 +} |
