diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-01-06 21:12:24 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-01-06 21:12:24 -0500 |
| commit | e422b17036294501a850232ef7e99fed56ee7a68 (patch) | |
| tree | 5fe55bc5b42b4e1fedff4fb06c2f93dafc4f6dff /wav.bqn | |
| parent | ae27931f4f5ce843cb0bc95925ee4630db94b33b (diff) | |
Possibly faster base expansion
Diffstat (limited to 'wav.bqn')
| -rw-r--r-- | wav.bqn | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -60,6 +60,8 @@ wh ← { makeNS ⇐ •BQN "{"∾(1↓∾"‿"⊸∾¨name)∾"⇐𝕩}" } +_be_ ← {1(-⊸↓-𝕗×↓)⌊∘÷⟜𝕗⍟(↕1+𝕘)} # Base expansion + # Return an undoable (⁼) function to convert bytes to PCM data. _audioConvert ← { audioFormat‿bitsPerSample ← 𝕗 @@ -70,7 +72,7 @@ _audioConvert ← { # Convert 𝕗-byte sequences to ints _int ← { b ← 256 - (+⟜(b⊸×)˝˜⟜(-(b÷2)≤¯1⊸⊏)·⍉⌊‿𝕗⥊⊢) _withInv_ (⥊∘⍉∘>b|⌊∘÷⟜b⍟(↕𝕗)) + (+⟜(b⊸×)˝˜⟜(-(b÷2)≤¯1⊸⊏)·⍉⌊‿𝕗⥊⊢) _withInv_ (⥊∘⍉∘> b _be_ 𝕗) } # Convert int to float _float ← {e‿m‿b←𝕗 # exponent and mantissa length in bits; bias @@ -167,7 +169,7 @@ Encode ← { rate‿fmt‿pcm: { val ↩ (⊑{𝕎𝕩⊏val}1⊸↓)⌾(𝕩⊸⊑) val }¨ wh.order - hdr ← ∾ (wh.len×wh.typ='i') 256{@+𝕗|⌊∘÷⟜𝕗⍟(↕𝕨)𝕩}⍟(>⟜0)¨ val + hdr ← ∾ (wh.len×wh.typ='i') 256{@+𝕗_be_𝕨 𝕩}⍟(>⟜0)¨ val hdr ∾ dat } |
