Bez tytułu

z milek, 5 lata temu, napisane w Plain Text, wyświetlone 418 razy.
URL https://pastebin.k4be.pl/view/7cbba207 Udostępnij
Pobierz wklejkę lub Pokaż surowy tekst
  1. #define SAMPLERATE 44100
  2. #define NOTE_DURATION 500
  3.  
  4. #define SAMPLERATE_DIV (SAMPLERATE / 1000)
  5. #define TIME(t) (t / SAMPLERATE_DIV)
  6. #define OUTPUT(x) 128 + ((x) * 120.0)
  7. #define CURRENT_NOTE_RAW(SONG, t) ((SONG [(TIME(t) / NOTE_DURATION) % (sizeof(SONG) - 1)]))
  8. #define CURRENT_NOTE(SONG, t) (CURRENT_NOTE_RAW(SONG, t) & 0xf)
  9. #define CURRENT_NOTE_MOD(SONG, t) (CURRENT_NOTE_RAW(SONG, t) & 0xf0)
  10. #define INSTRUMENT(t, SONG, ADSR, WAVEFORM) (ADSR((TIME(t) % NOTE_DURATION), CURRENT_NOTE_MOD(SONG, t)) * WAVEFORM(t, CURRENT_NOTE(SONG, t)))
  11. #define PLAY(SONG, A, B) ((CURRENT_NOTE_RAW(SONG, t) != ' ') ? INSTRUMENT(t, SONG, A, B) : 0.0)
  12. #define FREQ(n) (SAMPLERATE / (440.0 * pow(1.059463, n)))
  13.  
  14. #define A_VAL(t, A_TIME, A_LEVEL)          ((t) / (A_TIME / A_LEVEL))
  15. #define D_VAL(t, D_TIME, A_LEVEL, S_LEVEL) (A_LEVEL - (t) / (D_TIME / (A_LEVEL - S_LEVEL)))
  16. #define R_VAL(t, R_TIME, S_LEVEL)          (t <= R_TIME ? (S_LEVEL - (t) / (R_TIME / S_LEVEL)) : 0.0)
  17.  
  18. #define ADSR(t, mod, A_TIME, A_LEVEL, D_TIME, S_TIME, S_LEVEL, R_TIME) \
  19.         (t <= A_TIME                            ? ((mod & 0x20) ? A_VAL(t, A_TIME, A_LEVEL) : S_LEVEL) : \
  20.         (t <= A_TIME + D_TIME                   ? ((mod & 0x20) ? D_VAL(t - A_TIME, D_TIME, A_LEVEL, S_LEVEL) : S_LEVEL) : \
  21.         (t <= A_TIME + D_TIME + S_TIME          ? S_LEVEL : \
  22.         ((mod & 0x10) ? R_VAL(t - A_TIME - D_TIME - S_TIME, R_TIME, S_LEVEL) : S_LEVEL))))
  23.  
  24. #define ADSR1(t, mod) ADSR(t, mod, 87, 1.0, 25, 87, 0.7, 200)
  25.  
  26. #define SINE(t, NOTE) (sin(t * M_PI * 2 / FREQ(NOTE)))
  27. #define SQUARE(t, NOTE) (fmod(t, FREQ(NOTE)) > FREQ(NOTE) / 2.0 ? 1.0 : -1.0)
  28. #define SAWTOOTH(t, NOTE) (fmod(t, FREQ(NOTE)) / FREQ(NOTE) * 2.0 - 1.0)
  29. #define TRIANGLE(t, NOTE) ((fmod(t, FREQ(NOTE)) > FREQ(NOTE) / 2.0 ? SAWTOOTH(t, NOTE) : -SAWTOOTH(t, NOTE)) * 2.0 - 1.0)
  30.  
  31. OUTPUT(PLAY("rst             ", ADSR1, SINE)
  32.      + PLAY("   uvw(HX       ", ADSR1, SQUARE)
  33.      + PLAY("         wvut   ", ADSR1, SAWTOOTH)
  34.      + PLAY("             srq", ADSR1, TRIANGLE))

odpowiedź "Bez tytułu"

Tutaj możesz odpowiedzieć na wklejkę z góry

captcha