diff --git a/Makefile b/Makefile index 5f9b9e3..30fba95 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) -CXXFLAGS = -std=c++14 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(TINYALSA_DIR)/include +CXXFLAGS = -std=c++14 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat -O2 LIBS = -L$(TINYALSA_DIR)/lib -LIBS += -lGL `pkg-config --static --libs glfw3` -ltinyalsa +LIBS += -lGL `pkg-config --static --libs glfw3 alsa` -CXXFLAGS += `pkg-config --cflags glfw3` +CXXFLAGS += `pkg-config --cflags glfw3 alsa` CFLAGS = $(CXXFLAGS) ##--------------------------------------------------------------------- diff --git a/flake.nix b/flake.nix index df5bec3..56d4337 100644 --- a/flake.nix +++ b/flake.nix @@ -12,10 +12,9 @@ name = "microsa"; src = self; nativeBuildInputs = [ pkgs.pkg-config ]; - propagatedBuildInputs = [ pkgs.wayland pkgs.glfw-wayland pkgs.libffi pkgs.tinyalsa ]; + propagatedBuildInputs = [ pkgs.wayland pkgs.glfw-wayland pkgs.libffi pkgs.alsa-lib ]; preBuild = '' export IMGUI_DIR=${imgui_dir} - export TINYALSA_DIR=${pkgs.tinyalsa} ''; installPhase = '' mkdir -p $out/bin diff --git a/main.cpp b/main.cpp index 6046c3f..d0c829c 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -13,11 +12,11 @@ #include #include -#include +#include static std::atomic terminate_dsp; -static struct pcm* pcm; +static snd_pcm_t* pcm; static std::mutex waterfall_data_mutex; static int waterfall_width = 1600; @@ -25,30 +24,32 @@ static int waterfall_height = 700; static unsigned int waterfall_data[1600*700]; static void dsp_thread() { - using namespace std::chrono; - - int frame_count = pcm_get_rate(pcm); - std::vector frames(pcm_frames_to_bytes(pcm, frame_count)/4); - int total_read_count = 0; - std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); + std::vector frames(6400); while(!terminate_dsp) { - int read_count = pcm_readi(pcm, frames.data(), frame_count); - total_read_count += read_count; - std::cout << read_count << std::endl; + int read_count = snd_pcm_readi(pcm, frames.data(), 6400); + if(read_count < 0) { + std::cerr << "read from audio interface failed: " << snd_strerror(read_count) << std::endl; + break; + } { std::lock_guard guard(waterfall_data_mutex); std::memmove(&waterfall_data[waterfall_width], &waterfall_data[0], 4*waterfall_width*(waterfall_height - 1)); for(int i=0;i