#include #include #include #include #include #include #include #include #include #include #include #include #include #include static std::atomic terminate_dsp; static snd_pcm_t* pcm; static std::mutex waterfall_data_mutex; static int waterfall_width = 1600; static int waterfall_height = 700; static unsigned int waterfall_data[1600*700]; static void dsp_thread() { size_t len = 6400; std::vector frames(len); std::vector frames_f(len); pocketfft::shape_t shape{len}; pocketfft::stride_t stride(shape.size()); size_t tmp=sizeof(float); for (int i=shape.size()-1; i>=0; --i) { stride[i] = tmp; tmp *= shape[i]; }; pocketfft::shape_t axes; for(size_t i=0; i> frames_ft(len); while(!terminate_dsp) { int read_count = snd_pcm_readi(pcm, frames.data(), len); if(read_count < 0) { std::cerr << "read from audio interface failed: " << snd_strerror(read_count) << std::endl; break; } for(size_t i=0;i guard(waterfall_data_mutex); std::memmove(&waterfall_data[waterfall_width], &waterfall_data[0], sizeof(int)*waterfall_width*(waterfall_height - 1)); for(int i=0;i guard(waterfall_data_mutex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, waterfall_width, waterfall_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, waterfall_data); } ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f)); ImGui::SetNextWindowSize(io.DisplaySize); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::Begin("microsa", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize); ImGui::BeginTable("microsa", 2, ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Resizable); ImGui::TableSetupColumn("", 0, 280.0); ImGui::TableSetupColumn("", 0, 1600.0); ImGui::TableNextColumn(); if(ImGui::Button("Exit")) exit = true; ImGui::TableNextColumn(); ImGui::Image((void*)(intptr_t)waterfall, ImVec2(waterfall_width, waterfall_height)); ImGui::EndTable(); ImGui::End(); ImGui::PopStyleVar(1); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glfwSwapBuffers(window); } return 0; }