#include #include #include #include #include #include #include #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #define SND_BITS 16 #define SND_PCHAN 2 #define SND_RATE 44100 #define SND_BUFLEN 4096 static std::atomic shutdown_threads; static std::atomic frequency[SND_PCHAN]; static void dsp_thread() { struct sio_hdl *hdl; struct sio_par par; hdl = sio_open(SIO_DEVANY, SIO_PLAY|SIO_REC, 1); if(hdl == nullptr) { std::cerr << "failed to open sound device" << std::endl; return; } sio_initpar(&par); par.sig = 1; par.bits = SND_BITS; par.pchan = SND_PCHAN; par.rchan = 1; par.rate = SND_RATE; par.le = SIO_LE_NATIVE; par.xrun = SIO_ERROR; if(!sio_setpar(hdl, &par)) { std::cerr << "failed to set sound device parameters" << std::endl; sio_close(hdl); return; } if(!sio_getpar(hdl, &par)) { std::cerr << "failed to get back sound device parameters" << std::endl; sio_close(hdl); return; } if(!sio_start(hdl)) { std::cerr << "failed to start sound device" << std::endl; sio_close(hdl); return; } uint32_t phase_out[SND_PCHAN] = { 0 }; int16_t buf_out[SND_BUFLEN*SND_PCHAN]; size_t buf_out_idx = SND_BUFLEN*SND_PCHAN; nfds_t nfds = sio_nfds(hdl); struct pollfd pfd[nfds]; while(!shutdown_threads) { sio_pollfd(hdl, pfd, POLLOUT|POLLIN); poll(pfd, nfds, INFTIM); int revents = sio_revents(hdl, pfd); uint32_t ftw[SND_PCHAN]; for(int i=0;i