diff --git a/core/audio/mixer/mixer.cpp b/core/audio/mixer/mixer.cpp index 55c2f94..ea91520 100644 --- a/core/audio/mixer/mixer.cpp +++ b/core/audio/mixer/mixer.cpp @@ -58,6 +58,7 @@ void build_instrument_process_node(const plugin_host* host, std::map::init(initliazer); null_channel_node::init(); + executor_ = new tf::Executor(std::thread::hardware_concurrency()); auto device_manager = initliazer.require(); zero_track = new dummy_track(); @@ -78,6 +79,7 @@ void mixer::release(singleton_release_guard& release_guard) { delete track; } delete zero_track; + delete executor_; } dummy_track* mixer::create_dummy_track(const std::string& in_name) { @@ -120,33 +122,27 @@ void mixer::remove_track(mixer_track* track) { void mixer::process(uint32_t in_frames) { { - query_timer timer("mixer process"); - // tf::Executor executor; - // tf::Taskflow taskflow; - - // tf::Task previous_task = taskflow.emplace([] {}); + tf::Taskflow taskflow; + tf::Task previous_task = taskflow.emplace([] {}); for (const auto& order: layer_order_) { for (const auto& layer = layer_tracks_[order]; const auto& track: layer) { - // taskflow.emplace([track, in_frames] { + taskflow.emplace([track, in_frames] { track->process(in_frames); - // }).succeed(previous_task); + }).succeed(previous_task); } - // tf::Task new_layer = taskflow.emplace([] {}); - // new_layer.succeed(previous_task); - // previous_task = new_layer; + tf::Task new_layer = taskflow.emplace([] {}); + new_layer.succeed(previous_task); + previous_task = new_layer; } - // executor.run(taskflow).wait(); - } - { - query_timer timer("mixer post process"); - post_process(in_frames); + + executor_->run(taskflow).wait(); } + post_process(in_frames); dummy_track* master = get_master(); master->buffer.multiple(master->volume); } void mixer::reset() { - query_timer timer("mixer reset"); for (const auto track: tracks_) { track->buffer.clear(); } diff --git a/core/audio/mixer/mixer.h b/core/audio/mixer/mixer.h index 9adc637..dc2b84a 100644 --- a/core/audio/mixer/mixer.h +++ b/core/audio/mixer/mixer.h @@ -46,6 +46,7 @@ private: std::vector tracks_; std::map> layer_tracks_; std::vector layer_order_; + tf::Executor* executor_; }; DEFINE_SINGLETON_INSTANCE(mixer) diff --git a/core/audio/plugin_host/plugin_host_manager.cpp b/core/audio/plugin_host/plugin_host_manager.cpp index 9cfbbfc..5ecc28a 100644 --- a/core/audio/plugin_host/plugin_host_manager.cpp +++ b/core/audio/plugin_host/plugin_host_manager.cpp @@ -1,6 +1,5 @@ #include "plugin_host_manager.h" -#include "taskflow/taskflow.hpp" #include "plugin_host.h" #include "audio/device/audio_device_manager.h" @@ -17,6 +16,7 @@ void plugin_host_manager::init(singleton_initliazer& initliazer) { singleton_t::init(initliazer); auto* mixer_ptr = initliazer.require(); mixer_ptr->on_remove_track.add_raw(this, &plugin_host_manager::on_mixer_track_removed); + executor_ = new tf::Executor(std::thread::hardware_concurrency()); } void plugin_host_manager::release(singleton_release_guard& release_guard) { @@ -26,6 +26,7 @@ void plugin_host_manager::release(singleton_release_guard& release_guard) { for (const plugin_host* host: plugin_hosts_) { delete host; } + delete executor_; } plugin_host* plugin_host_manager::create_instrument_plugin_host(const char* path) { @@ -82,15 +83,14 @@ void plugin_host_manager::register_instrument_plugin(plugin_host* host) { } void plugin_host_manager::process(uint32_t in_frames) const { - query_timer timer("host process"); - // tf::Executor executor; - // tf::Taskflow taskflow; + tf::Taskflow taskflow; for (auto host : plugin_hosts_) { - // taskflow.emplace([host, in_frames] { + taskflow.emplace([host, in_frames] { host->process(in_frames); - // }); + }); } - // executor.run(taskflow).wait(); + + executor_->run(taskflow).wait(); } void plugin_host_manager::on_mixer_track_removed(mixer_track* track) { diff --git a/core/audio/plugin_host/plugin_host_manager.h b/core/audio/plugin_host/plugin_host_manager.h index dd727cc..31a50cb 100644 --- a/core/audio/plugin_host/plugin_host_manager.h +++ b/core/audio/plugin_host/plugin_host_manager.h @@ -1,6 +1,7 @@ #pragma once #include "misc/delegates.h" #include "misc/singleton/singleton.h" +#include "taskflow/taskflow.hpp" class plugin_host; class mixer_track; @@ -28,6 +29,8 @@ private: std::vector instrument_plugins_{}; std::vector plugin_hosts_{}; + + tf::Executor* executor_; }; DEFINE_SINGLETON_INSTANCE(plugin_host_manager)