修复mixer_track的ui_buffer不正确问题

This commit is contained in:
Nanako 2024-05-26 15:56:09 +08:00
parent 266d45834c
commit 1659c24d4c
7 changed files with 35 additions and 17 deletions

View File

@ -38,7 +38,7 @@ void application::shutdown() {
spdlog::shutdown();
}
bool application::update_window_manager()
bool application::update_application()
{
g_main_thread_hub.process_messages();
g_window_manager.update();

View File

@ -25,7 +25,7 @@ public:
virtual void shutdown();
bool update_window_manager();
bool update_application();
virtual void tick(float delta_time)
{

View File

@ -129,8 +129,8 @@ void mixer::process(uint32_t in_frames) {
return;
e->run(taskflow_).wait();
post_process(in_frames);
dummy_track* master = get_master();
master->buffer.multiple(master->volume);
// dummy_track* master = get_master();
// master->buffer.multiple(master->volume);
}
void mixer::reset() {
@ -168,21 +168,21 @@ void mixer::request_build_process_node() {
});
}
void post_process_internal(mixer_track* track, uint32_t in_frames, std::vector<mixer_track*>& processed_tracks) {
void post_process_internal(mixer_track* track, uint32_t in_frames, std::set<mixer_track*>& processed_tracks) {
if (std::ranges::find(processed_tracks, track) != processed_tracks.end())
return;
for (const auto& link: track->children) {
post_process_internal(link.track, in_frames, processed_tracks);
track->buffer.mix(link.track->buffer, link.send_level);
}
track->post_process(in_frames);
// CalculatePeak ?
processed_tracks.push_back(track);
processed_tracks.emplace(track);
}
void mixer::post_process(uint32_t in_frames) const {
const auto master = get_master();
std::vector<mixer_track*> processed_tracks;
std::set<mixer_track*> processed_tracks;
post_process_internal(master, in_frames, processed_tracks);
}
@ -213,16 +213,23 @@ void mixer::thread_remove_track(mixer_track* track) {
void mixer::update_taskflow(uint32_t in_frames) {
tf::Taskflow taskflow;
tf::Task previous_task = taskflow.emplace([] {});
for (const auto& order: layer_order_) {
std::vector<std::vector<tf::Task>> layer_tasks;
for (int32_t i = layer_order_.size() - 1; i >= 0; --i) {
const auto& order = layer_order_[i];
auto new_layer = std::vector<tf::Task>();
for (const auto& layer = layer_tracks_[order]; const auto& track: layer) {
taskflow.emplace([track, in_frames] {
auto t = taskflow.emplace([track, in_frames] {
track->process(in_frames);
}).succeed(previous_task);
});
new_layer.push_back(t);
}
layer_tasks.push_back(std::move(new_layer));
}
for (int i = layer_tasks.size() - 1; i >= 0; --i) {
tf::Task layer_task = taskflow.emplace([]{});
for (auto& task: layer_tasks[i]) {
task.precede(layer_task);
}
tf::Task new_layer = taskflow.emplace([] {});
new_layer.succeed(previous_task);
previous_task = new_layer;
}
taskflow_ = std::move(taskflow);
}

View File

@ -52,6 +52,9 @@ void mixer_track::process(uint32_t in_frames) {
effect->process(in_frames);
buffer.multiple(volume);
on_processed.broadcast(this);
}
void mixer_track::post_process(uint32_t in_frames) {
for (int i = 0; i < buffer.get_num_channels(); ++i) {
(*ui_buffers)[i].Push(buffer.get_headers()[i], in_frames);
}

View File

@ -32,6 +32,7 @@ public:
void remove_child(mixer_track* in_child);
void process(uint32_t in_frames);
void post_process(uint32_t in_frames);
virtual void rename(const std::string& in_name) = 0;
[[nodiscard]] virtual std::string get_name() const = 0;

View File

@ -0,0 +1,7 @@
//
// Created by 46944 on 24-5-26.
//
#include "thread_message_hubs.h"
thread_message_hub g_main_thread_hub;
thread_message_hub g_audio_thread_hub;

View File

@ -1,7 +1,7 @@
#pragma once
#include "thread_message_hub.h"
inline thread_message_hub g_main_thread_hub;
inline thread_message_hub g_audio_thread_hub;
CORE_API extern thread_message_hub g_main_thread_hub;
CORE_API extern thread_message_hub g_audio_thread_hub;
#define PUSH_MAIN_THREAD(code) g_main_thread_hub.push_message(code);