From 0acf109ef22ed905b48114f4a471961708089160 Mon Sep 17 00:00:00 2001 From: Nanako <469449812@qq.com> Date: Mon, 4 Mar 2024 01:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emixer=5Ftrack=20ui=5Fbuffer?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=BB=98=E5=88=B6=E6=B7=B7=E9=9F=B3=E5=8F=B0?= =?UTF-8?q?=E8=BD=A8=E9=81=93=E9=9F=B3=E9=87=8F=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=8F=92=E4=BB=B6=E7=AA=97=E5=8F=A3=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=20=E6=96=B0=E5=A2=9Eportaudio=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4asio=E8=BE=93=E5=87=BA=E8=AE=BE=E5=A4=87=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcircular=5Faudio=5Fbuffer=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/application/window_manager.cpp | 2 ++ core/audio/device/port_audio_device.cpp | 4 +++- core/audio/device/port_audio_device.h | 2 +- core/audio/misc/circular_audio_buffer.h | 4 ++-- core/audio/mixer/mixer_track.cpp | 6 ++++++ core/audio/mixer/mixer_track.h | 1 + core/audio/plugin_host/plugin_host.cpp | 5 ++++- core/audio/plugin_host/vst2/vst2_plugin_host.cpp | 1 + third_party/imgui/imgui | 2 +- 9 files changed, 21 insertions(+), 6 deletions(-) diff --git a/core/application/window_manager.cpp b/core/application/window_manager.cpp index e939011..a7f81e2 100644 --- a/core/application/window_manager.cpp +++ b/core/application/window_manager.cpp @@ -51,6 +51,8 @@ GLFWwindow* window_manager::create_plugin_host_window(plugin_host* host) { if (host_window_pos_map_.contains(host)) { auto pos = host_window_pos_map_[host]; glfwSetWindowPos(new_window, pos.x, pos.y); + }else { + glfwSetWindowPos(new_window, 100, 100); } host_window_map_[host] = new_window; glfwShowWindow(new_window); diff --git a/core/audio/device/port_audio_device.cpp b/core/audio/device/port_audio_device.cpp index 4e2a883..9cc37d4 100644 --- a/core/audio/device/port_audio_device.cpp +++ b/core/audio/device/port_audio_device.cpp @@ -37,7 +37,9 @@ void port_audio_device::stop() { void port_audio_device::start() { try { - open_stream(-1, Pa_GetDefaultOutputDevice(), sample_rate(), buffer_size()); + auto host_api_info = Pa_GetHostApiInfo(Pa_HostApiTypeIdToHostApiIndex(paASIO)); + auto device_info = Pa_GetDeviceInfo(host_api_info->defaultOutputDevice); + open_stream(-1, host_api_info->defaultOutputDevice, sample_rate(), buffer_size()); } catch (const std::exception& e) { spdlog::error("Init failed: {}", e.what()); } diff --git a/core/audio/device/port_audio_device.h b/core/audio/device/port_audio_device.h index 9815728..4142bac 100644 --- a/core/audio/device/port_audio_device.h +++ b/core/audio/device/port_audio_device.h @@ -27,7 +27,7 @@ private: void render_thread(); std::thread render_thread_; circular_audio_buffer render_buffer_; - uint32_t render_buffer_size_ = 2048; + uint32_t render_buffer_size_ = 512; std::atomic_bool render_thread_running_ = false; #pragma endregion diff --git a/core/audio/misc/circular_audio_buffer.h b/core/audio/misc/circular_audio_buffer.h index 7a8141e..c109412 100644 --- a/core/audio/misc/circular_audio_buffer.h +++ b/core/audio/misc/circular_audio_buffer.h @@ -30,8 +30,8 @@ public: circular_audio_buffer& operator=(const circular_audio_buffer& InOther) { InternalBuffer = InOther.InternalBuffer; Capacity = InOther.Capacity; - ReadCounter = InOther.ReadCounter; - WriteCounter = InOther.WriteCounter; + ReadCounter.store(InOther.ReadCounter); + WriteCounter.store(InOther.WriteCounter); return *this; } diff --git a/core/audio/mixer/mixer_track.cpp b/core/audio/mixer/mixer_track.cpp index 24b143b..68c2490 100644 --- a/core/audio/mixer/mixer_track.cpp +++ b/core/audio/mixer/mixer_track.cpp @@ -11,6 +11,9 @@ mixer_track::~mixer_track() { void mixer_track::init() { const uint32_t channel_count = g_audio_device_manager.get_output_channel_count(); buffer.resize(channel_count, g_audio_device_manager.get_buffer_size()); + for (int i = 0; i < buffer.get_num_channels(); ++i) { + ui_buffers.emplace_back(g_audio_device_manager.get_buffer_size() * 2); + } channel_interface_ = new mixer_channel_interface(this); } @@ -39,6 +42,9 @@ void mixer_track::process(uint32_t in_frames) { effect->process(in_frames); buffer.multiple(volume); on_processed.broadcast(this); + for (int i = 0; i < buffer.get_num_channels(); ++i) { + ui_buffers[i].Push(buffer.get_headers()[i], in_frames); + } } void instrument_track::rename(const std::string& in_name) { diff --git a/core/audio/mixer/mixer_track.h b/core/audio/mixer/mixer_track.h index 63b99c9..865a9fb 100644 --- a/core/audio/mixer/mixer_track.h +++ b/core/audio/mixer/mixer_track.h @@ -41,6 +41,7 @@ public: [[nodiscard]] channel_interface* get_channel_interface() const { return channel_interface_; } audio_buffer buffer; + std::vector> ui_buffers; std::atomic volume = 1.0f; std::vector effects{}; std::vector children{}; diff --git a/core/audio/plugin_host/plugin_host.cpp b/core/audio/plugin_host/plugin_host.cpp index ee4ebe1..ba2010b 100644 --- a/core/audio/plugin_host/plugin_host.cpp +++ b/core/audio/plugin_host/plugin_host.cpp @@ -5,12 +5,13 @@ plugin_host::~plugin_host() { delete channel; - g_window_manager.destroy_plugin_host_window(this); } void plugin_host::try_open_editor() { if (!has_editor()) return; + if (editor_opened) + return; editor_window = g_window_manager.create_plugin_host_window(this); open_editor(editor_window); editor_opened = true; @@ -19,6 +20,8 @@ void plugin_host::try_open_editor() { void plugin_host::try_close_editor() { if (!has_editor()) return; + if (editor_opened == false) + return; close_editor(); editor_opened = false; g_window_manager.destroy_plugin_host_window(this); diff --git a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp index e14c87e..8fc56d3 100644 --- a/core/audio/plugin_host/vst2/vst2_plugin_host.cpp +++ b/core/audio/plugin_host/vst2/vst2_plugin_host.cpp @@ -134,6 +134,7 @@ vst2_plugin_host::vst2_plugin_host() { vst2_plugin_host::~vst2_plugin_host() { spdlog::info("vst2 plugin {} destroyed", name); + try_close_editor(); if (effect_) { dispatch(effClose); } diff --git a/third_party/imgui/imgui b/third_party/imgui/imgui index 77dff5a..8048b52 160000 --- a/third_party/imgui/imgui +++ b/third_party/imgui/imgui @@ -1 +1 @@ -Subproject commit 77dff5a735afd821fea1ac54dda63ef5d8bded96 +Subproject commit 8048b52498a9bf2a9f87b080d43b0bfd7a5d51d8