teknoraver icon

awk sounds

teknoraver | PRO | 10/30/14 11:42:54 AM UTC | 0 ⭐ | 12076 👁️ | Never ⏰ | []
Awk |

1.15 KB

|

None

|

0 👍

/

0 👎

#!/bin/sh
mawk '
function wl() {
    rate = 32000
    return (rate / 160) * 2^(-int(rand() * 10) / 5)
}
 
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 = -ca
            }
            if (b > wlb) {
                b = 0
                cb = -cb
            }
            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
 
#oneline:
# 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

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎