Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.random;
- import std.math;
- import std.algorithm;
- import core.sys.linux.sys.sysinfo;
- import core.sys.linux.time;
- void main()
- {
- sysinfo_ info2;
- sysinfo(&info2);
- enum freeConst = 0.000001f;
- float firstFreeRam = info2.freeram * freeConst;
- writeln(firstFreeRam);
- enum sampleRate = 8000;
- float freq = 0f;
- float nextTime = 0f;
- for(int sample = 0; ; sample++) {
- float value = 0f;
- float time = sample / cast(float)sampleRate;
- //writeln("Sample:, ", sample, " Time: ", time);
- //float freq = sample / 100f + 50f;
- if(time > nextTime) {
- nextTime = time + 0.1f;
- sysinfo_ info;
- sysinfo(&info);
- freq = (info.freeram * freeConst - firstFreeRam) * -0.6f + 500f;
- }
- value = sin(2 * PI * time * freq);
- //writeln(cast(int)((clamp(value, -1f, 1f) * 0.5f + 0.5f) * 255f));
- write(cast(char)cast(int)((clamp(value, -1f, 1f) * 0.5f + 0.5f) * 255f));
- if(sample % (sampleRate / 5) == 0) {
- timespec ts;
- ts.tv_nsec = 200_000_000;
- nanosleep(&ts, &ts);
- }
- }
- }
Add Comment
Please, Sign In to add comment