Advertisement
teknoraver

awk sounds

Oct 30th, 2014
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.15 KB | None | 0 0
  1. #!/bin/sh
  2. mawk '
  3. function wl() {
  4.     rate = 32000
  5.     return (rate / 160) * 2^(-int(rand() * 10) / 5)
  6. }
  7.  
  8. BEGIN {
  9.     srand()
  10.     wla = wl()
  11.     while(1) {
  12.         wlb = wla
  13.         wla = wl()
  14.         if (wla == wlb)
  15.             wla *= 2
  16.         d = (rand() * 10 + 5) * rate / 4
  17.         a = b = 0
  18.         c = 128
  19.         ca = 40 / wla
  20.         cb = 20 / wlb
  21.         de = rate / 10
  22.         di = 0
  23.         for (i = 0; i < d; i++) {
  24.             a++
  25.             b++
  26.             di++
  27.             c += ca + cb
  28.             if (a > wla) {
  29.                 a = 0
  30.                 ca = -ca
  31.             }
  32.             if (b > wlb) {
  33.                 b = 0
  34.                 cb = -cb
  35.             }
  36.             if (di > de) {
  37.                 di = 0
  38.                 ca *= 0.9
  39.                 cb *= 0.9
  40.             }
  41.             printf("%c", (c - 127) * 4)
  42.         }
  43.         c = int(c)
  44.         while(c != 128) {
  45.             c < 128 ? c++ : c--
  46.             printf("%c", (c - 127) * 4)
  47.         }
  48.     }
  49. }' |aplay -r 44100
  50.  
  51. #oneline:
  52. # mawk 'function wl(){rate=32000;return(rate/160)*(0.87055^(int(rand()*10)))};BEGIN{srand();wla=wl();while(1){wlb=wla;wla=wl();if(wla==wlb){wla*=2;};d=(rand()*10+5)*rate/4;a=b=0;c=128;ca=40/wla;cb=20/wlb;de=rate/10;di=0;for(i=0;i<d;i++){a++;b++;di++;c+=ca+cb;if(a>wla){a=0;ca*=-1};if(b>wlb){b=0;cb*=-1};if(di>de){di=0;ca*=0.9;cb*=0.9};printf("%c",(c-127)*4)};c=int(c);while(c!=128){c<128?c++:c--;printf("%c",(c-127)*4)};};}' |aplay -r 44100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement