Random Synth Tone Generator using BASS library in C featuring an alarm based date string and FPS timer
- C23
- CMake
- BASS Library
- a stereo sound card
cmake . --install-prefix=/usr
make install./hintroANYto switch random toneESCto exit sucessfulCTRL+Cto exit failure with cleanup
#include "hintro_bass.h"
DWORD CALLBACK sound_proc(HSTREAM handle, void *buf, DWORD len, void *user)
{
const SOUND* cfg = (SOUND*)user;
static int cur = 0;
memset(buf, 0, len);
for(int c = 0; c < len / sizeof(float); c+=2)
{
const int freq = (cfg->prng + cur + 1) / 10;
const float phase = (freq * cur ) / (float)cfg->info.freq;
((float*)buf)[c ] = sinf(phase * 2 * (float)M_PI);
((float*)buf)[c+1] = cosf(phase * 2 * (float)M_PI);
cur++;
cur %= cfg->info.freq;
}
return len;
}
BOOL sound_loop()
{
int prev = 0;
int cur = 0;
while(cur != 27)
{
if((cur = term_getc()) != prev)
{
prev = cur;
snd.prng = rand();
}
snd.frame.cnt++;
if(snd.frame.fps > 0)
printf("\r%s %s", snd.time.str, snd.frame.str);
}
return TRUE;
}
int main(int argc, char** argv)
{
exit(snd.init(44100) && snd.play(snd.stream, FALSE) && snd.loop() ? EXIT_SUCCESS : EXIT_FAILURE);
}