wav.k 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. / [[https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html]]
  2. \l riff.k
  3. / pi continued fraction A001203
  4. pcf:.'", "\"3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2, 1, 1, 15, 3, 13, 1, 4, 2, 6, 6, 99, 1, 2, 2, 6, 3, 5, 1, 1, 6, 8, 1, 7, 1, 2, 3, 7, 1, 2, 1, 1, 12, 1, 1, 1, 3, 1, 1, 8, 1, 1, 2, 1, 6, 1, 1, 5, 2, 2, 3, 1, 2, 4, 4, 16, 1, 161, 45, 1, 22, 1, 2, 2, 1, 4, 1, 2, 24, 1, 2, 1, 3, 1, 2, 1"
  5. pi:{y+1%x}/|pcf
  6. pi2:2*pi
  7. fspec:`t`nc`ss`abs`ba`bs`es`vb`cm`sf!2 2 4 4 2 2 2 2 4 16
  8. fmt:{((#r)#!fspec)!r:256/'256!|'-1_(<[#x;]_+\0,.fspec)_x}
  9. prsfmt:{((#c)#!fspec)!256/'256!|'(c:0,((#x)>)#+\.fspec)_x}
  10. pcm:{[c;r;l]`t`nc`ss`abs`ba`bs!(1;c;r;r*l*c;l*c;8*l)}
  11. mkfmt:{mkchnk["fmt ";,/(256+&'fspec@!v){|`c$x\y}'v:(^:)_k!x@k:!fspec]}
  12. alaw:{s:1 -1@0>y;s*$[1>r:s*y*x;r;1+`ln r]%1+`ln x}o
  13. alawinv:{s:1 -1@0>y;a:1+`ln x;s*$[1>r:s*y*a;r;`exp@-1+r]%x}
  14. apo:{@[y;+i;*;%[;s]@*i:1((#y)-1+)\!s:_x*#y]}
  15. sin:{[f;a;s;t]a*`sin s+pi2*f*t} / [HZ;AMP;off;ts]
  16. cos:{[f;a;s;t]a*`cos s+pi2*f*t} / [HZ;AMP;off;ts]
  17. qnt:{_x*y+~x>128} / [rng;ys] quantization
  18. ph:{(!_x*y)%x} / [FR;dur] phases
  19. nrm:{x*y%|/{x|-x}(|/;&/)@\:y}
  20. ser:{,/+|`c$(x#256)\y} / [WIDTH;qnt data] serialize
  21. / [[https://en.wikipedia.org/wiki/Equal_temperament]]
  22. note:{`exp y*(`ln 2)%x}
  23. /
  24. sw:,/440#,_128*`sin@(2*pi*!50)%50
  25. mkchnk["RIFF"]@,/("WAVE";mkfmt pcm[1;22000;1];mkchnk["data";`c$sw])