File: myst.c - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off

01: #include <stdio.h>
02: #include <stdlib.h>
03: #include <math.h>
04: #include <inttypes.h>
05: double mystere2(double c) {
06:    if (c > 6.28319) return mystere2(c - 6.28319);
07:    if (c <= 1.57808) return c/1.57808; else c -= 1.57808;
08:    if (c <= 3.14159) return -(c*0.628319)+1; else c -= 3.14159;
09:    return mystere2(c) - 1; }
10: int32_t mystere(uint32_t n) {
11:     n &= 0xFF;
12:     if (!n) return -21;
13:     if ((n & 0xC0) == 0x40) n &= 0xBF;
14:     if ((n & 0x1F) > 16) return mystere((n ^ 0x1F) + 1);
15:     if (n & 0x1C) return mystere(n - 4) + 12;
16:     if ((n & 0xC3) == 0xC0) return mystere(n & 0xBF) - 1;
17:     if ((n & 3) == 1) return mystere(n - 1) + 2 + ((n >> 7) * (((n & 0x40) >> 6) + 1));
18:     if ((n & 3) == 2) return mystere(n - 1) + 3 + ((((n & 0xC0) == 0x80) << 1) - ((!(n & 0xC0)) * (((n & 0x20) >> 5) + 1)));
19:     if ((n & 3) == 3) return mystere(n - 1) + 4 - ((!(n & 0xE0)) + (((n & 0xC0) == 0x80) << 1));
20:     return mystere(0) - 3 + (((n & 0xE0) == 0xA0) << 1); }
21: int main(void) {
22:     uint32_t i, j;
23:     int16_t *buf = malloc(10584320);
24:     int16_t *p = buf;
25:     FILE *f = fopen("mystere2.bin", "wb");
26:     for (i = 0; i < 320; i++)
27:         for (j = 0; j < 8269; j++)
28:         {
29:             double n = mystere2((double)(j) * 0.062689 * pow(2, (double)mystere(i) / 12.0)) * 16384.0;
30:             double s[2];
31:             n *= exp((double)j * -5E-5);
32:             if (i & 0x100) n *= exp(-(double)(i & 0xFF) * 0.1);
33:             if (j < 441) n *= (double)(j) * 0.002268;
34:             if (j > 7828) n *= (double)(8269 - j) * 0.002268;
35:             s[0] = s[1] = n;
36:             if ((p - buf) > 1999) { s[0] += (double)p[-2000] * 0.3; s[1] += (double)p[-2000] * 0.3; }
37:             if (i > 1) { s[0] += (double)p[-33076] * 0.125; s[1] += (double)p[-33076] * 0.375; }
38:             if (i > 2) { s[0] += (double)p[-49614] * 0.1875; s[1] += (double)p[-49614] *  0.0625; }
39:             *p++ = (int16_t)s[0]; *p++ = (int16_t)s[1];
40:         }
41:     fwrite(buf, 1, 10584320, f);
42:     return 0; }