Pachelbel’s Canon in Dmaj in 73 lines of obfuscated C

Simple software synthesizer playing Pachelbel’s Canon in Dmaj in 73 lines of obfuscated C.
Needs Unix-based system with ALSA sound. The noise mostly is due to 8-bit quantization.

http://pastebin.com/2pp48DEv
https://gist.github.com/hypernewbie/74016ce1d225bd1392f9

Run with:
make canon; ./canon | aplay -r 44100 -f U8

    /* make canon; ./canon | aplay -r 44100 -f U8 */
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #define rs (1.0/44100.0)
    #define fr(x) (440*pow(2,(x-57)*(1.0/12)))
    #define s(x, n) sin((x=(x+fr(n)*rs))*6.2831853)
    #define tf (((1.0/rs)*60.)*.25/160.0)
    #define gv(c) (c-(c>'9'?('a'-10):'0'))
    #define gct(i) (gv(ct[(i)*3]) << 8)+(gv(ct[(i)*3+1]) << 4)+(gv(ct[(i)*3+2]))
    const char *cn = "\
    NLJIGEGIJIGECBC@>BECB>B@>;>ECGECB>@IJNQEGCEB>JLJLJLJLJIJIJ>=E@B>JIGINQSONLONLJI\
    GECB@CB@>@BCE@ECBGECECB@>;GIJIGECB@GEGEEECBNLJNSQSUVJIGJJJJOLQQNOQNOQEGIJLNONJL\
    NBCEGECEBCECGECB@B@>@BCEGCGEGIJEGIJLNOQNJLNLJLIJLNLJIJGIJ>@BCB@BJIJGJIGECECBCEG\
    IJGJIJIGIJLJIJGIJIGJ>>>@EEBECBCLNBCB@LNLJB>GE979;GIGE979;GEGI=;=>JLJI=>=;GEGI=B\
    @>JLONBENJONOLECEBEEEEEEEBBBBBBEECCCJJJJJJJGGEELIENNNLLLLJJJJQQQQSSSSQQQQSSSSUI\
    IIJ>@B>=IJLIG;=>;=ECB@>CB@CB>@BECGECB@ECB@BJIJBEEGIEBJLNJNNLJIGGEGIJNLJNOJIGGE@\
    EEEE>ECEC>@>@>@>@>=>JIGE>@BG@@BNNONLJJJLJIGJJHGHEEEQQSQONNNONLJHGHEECCJIIJJIGEC\
    B@@BNLJVTSVQSQQECBNLJJJIJ>=IG;9ECONB@G@LN", *ct = "\
    08008f09009f0a00af0b00bf0c00d00d00df0e00ef0f00ff10010f11011f12012f13013f14014f\
    15015f16016f17018018018718818f19019719819f1a01a71a81af1b01b71b81bf1c01c71c81cf\
    1d01d71d81df1e01e71e81ef1f01f71f81ff20020720820f21021721821f22022722822f230237\
    23824024024724824f25025725825f26026726826f270271271271272272273273274274275275\
    27627727727b27c27f28028328428728828b28c28f29029329429729829c29c29f2a02a32a42a7\
    2a82ab2ac2af2b02b32b42b72b82bb2bc2bf2c02c32c42c72c82cb2cc2cf2d02d32d42d72d82db\
    2dc2df2e02e32e42e72e82eb2ec2ef2f02f32f42f72f82fb2fc2ff30030330430730830b30c30f\
    31031331431731831b31c31f32032332432732832b32c32f33033333433733833b33c33f340343\
    34434734834b34c34f35035335435735835b35c35f36036336436736836b36c36f370373374377\
    37837837837837b37b37c37f38038738838f39039b3a83af3b03bf3c03cf3d03df3e03ef3f03ff\
    40040740841041041f42842f43043c44045645845e46046746846f47047747847e480483484485\
    48648748848b48c48d48e48f49049149249349449549649749849949a49b49c49d49e49f4a04a3\
    4a44a54a64a74a84a94ac4ad4ae4af4b04b14b24b34b44b54b64b74b84b94ba4bb4bc4bd4be4bf\
    4c04c34c44c54c64c74c84ca4cc4cd4ce4cf4d04d14d24d34d44d54d64d74d84d94da4db4dc4dd\
    4de4df4e04e34e44e54e64e74e84eb4ec4ed4ee4ef4f04f14f24f34f44f54f64f74f84f94fa4fc\
    4fc4fd4fe4ff50050350450550650750850b50c50d50e50f510511512513514515516517518519\
    51a51b51c51d51e51f52052352452552652752852a52c52d52e52f530531532533534535536537\
    53853a53a53b53c53d53e53f54054354454554654754854b54c54d54e54f550551552553554555\
    55655755855955a55b55c55d55e55f56056356456556656756856b56c56d56e56f570571572573\
    57457557657757857957a57b57c57d57e57f5805875905985a05a85b05b85c05c75d05d75e05e8\
    5f05f860860f61862062862f63863f64864f65865f66866f67867f68068368468768868b68c68f\
    69069369469769869b69c69f6a06a36a46a76a86ab6ac6af6b06b36b46b76b86bb6bc6bf6c06c3\
    6c46c76c86cb6cc6cf6d06d36d46d76d86db6dc6df6e06e36e46e76e86eb6ec6ef6f06f36f46f7\
    6f86fb6fc6ff70070370470770870b70c70f71071371471771871b71c71f72072372472772872b\
    72c72f73073373473773873b73c73f74074374474774874b74c74f75075375475775875b75c75f\
    76076376476776876b76c76f77077377477877877b77c77f78078378478678878978c78e790792\
    79479679879979c79d7a07a27a47a57a87a97ac7ad7b07b27b47b67b87ba7bc7be7c07c27c47c6\
    7c87ca7cc7cd7d07d27d47d67d87d97dc7dd7e07e27e47e67e87ea7ec7ee7f07f27f47f67f87fa\
    7fc7fe80080280480580880a80c80e81081281481681881981c81e82082282482582882a82c82e\
    83083383483583883983c83e84084284484584884984c84e85085285485585885985c85d860862\
    86486586886986c86d87087287487687887a87c87e88088288488588688788888b88c88e890891\
    89489589689789889b89c89f8a08a38a48a58a68a78a88ab8ac8af8b08b28b48b58b68b78b88bb\
    8bc8bf8c08c38c48c58c68c88c88cb8cc8cf8d08d28d48d58d68d78d88db8dc8df8e08e28e48e5\
    8e68e78e88eb8ec8f08f08f48f48f58f68f78f88fb8fc8ff90090390490590690790890b90c90f\
    91091291491591691791891b91c91f92092192492592692792892b92c92f930932934935936937\
    93893b93c93f94094294494594694794894b94c94f95095395495595695795895b95c960960963\
    96496596696796896a96c96e97097397497797897a97c97d98099699899f9a09b69b89bf9c09cf\
    9d09df9e09e79e89ee9f09f19f19f19f29f29f39f49f49f49f59f59f69f79f79fc9fc9ffa00a07\
    a08a0fa10a1fa20a2fa30a3fa40a4ba4ca50a50a5fa60a6fa70a7aa7ca7fa80a8ba8ca8ea90a94\
    a94a97a98a9ba9ca9faa0aaaaacaafab0ab3ab4ab7ab8abbabcabfac0ad0ad0adeae0ae3ae4ae7\
    ae8aebaecaefaf0afaafcafdb00b0bb0cb0eb10b13b14b17b18b1bb1cb1fb20b2ab2cb2eb30b33\
    b34b37b38b3bb3cb3fb40b43b44b47b48b4bb4cb4fb50b5ab5cb5fb60b60b67b67b68b6fb70b7a\
    b7cb7fb80b86b88b97b98ba8ba8bb7bb8bc7bc8bd7bd8bebbecbeebf0bffc00c07c08c17c18c1f\
    c20c27c28c38c38c3fc40c4fc50c57c58c60c60c70c70c7ec80c8fc90c9bc9cc9fca0cafcb0cbb\
    cbccbfcc0cd5cd8cddce0cefcf0cffd00d07d08d0fd10d17d18d1fd20d27d28d2fd30d37d38d3f\
    d40d47d48d4fd50d57d58d5fd60d67d68d6fd70d77d78d7fd80d8f", *bn = ">9;67279";
    double x[4], y, z; int q[4];
    int main() {                                          http://www.hypernewbie.com
        for(y=z=q[0]=q[1]=q[2]=q[3]=0;q[0]<594;y++) {
        z = s(x[3], bn[((int)(y/(tf*16)))%8]-12)*0.2;
        for(int c=0; c<3; c++) { z += s(x1, cn[q1]-12)*0.12*
            ((int)(y/tf-(c<<7))>=(int)(gct(q1<<1)));
            q1+=(int)(y/tf-(c<<7))>(int)(gct((q1<<1)+1)); }
            fputc((unsigned char)((z*0.5+0.5) * 230) + 10, stdout);} goto http;}
Share Button

Leave a Reply