diff --git a/Makefile b/Makefile index f449fb8..2fb10fd 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PROG= sndlock SRCS= imgui_impl_glfw.cpp imgui_impl_opengl3.cpp imgui_draw.cpp imgui_widgets.cpp imgui_tables.cpp imgui.cpp sndlock.cpp CXXOPTS= `pkg-config --cflags glfw3 gl` LDFLAGS= `pkg-config --libs glfw3 gl` +LDADD= -lsndio -lm BINDIR= /usr/local/bin NOMAN= noman diff --git a/sndlock.cpp b/sndlock.cpp index 23fa8dd..c4f3b77 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -1,11 +1,72 @@ #include +#include +#include #include +#include +#include #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" +static std::atomic shutdown_threads; +static std::atomic frequency = 440.0f; + +#define SND_SIG 1 +#define SND_BITS 16 +#define SND_PCHAN 2 +#define SND_RATE 44100 +#define SND_BUFLEN 4096 + +static void dsp_thread() +{ + struct sio_hdl *hdl; + struct sio_par par; + + hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); + if(hdl == nullptr) { + std::cerr << "failed to open sound device" << std::endl; + return; + } + sio_initpar(&par); + par.sig = SND_SIG; + par.bits = SND_BITS; + par.pchan = SND_PCHAN; + par.rate = SND_RATE; + par.le = SIO_LE_NATIVE; + if(!sio_setpar(hdl, &par)) { + std::cerr << "failed to set 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 = 0; + int16_t buf[SND_BUFLEN*SND_PCHAN]; + while(!shutdown_threads) { + uint32_t ftw = frequency*(float)UINT32_MAX/SND_RATE; + for(int i=0;i