Skip to content

Commit

Permalink
Refactor code to pass full config for offline processing (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
RinoReyns authored Nov 12, 2024
1 parent 68fa681 commit 15657d8
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 150 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ is why this repository was created. I know that it will take a lot of work but i
VstHostTool.exe --help
```
1. Dump an empty configuration needed to run the tool:
```VstHostTool.exe -dump_vst_host_config -vst_host_config config.json```
```VstHostTool.exe -dump_app_config -config config.json```
1. Dump an empty configuration for VST plugin/plugins that will be used be.
```VstHostTool.exe -dump_plugins_config -vst_host_config config.json```
```VstHostTool.exe -dump_plugins_config -config config.json```
1. Run Audio Processing with Vst Plugin.
```VstHostTool.exe -vst_host_config config.json```
```VstHostTool.exe -config config.json```

## Features list
1. **Platform Agnostic Features**
Expand All @@ -122,18 +122,21 @@ is why this repository was created. I know that it will take a lot of work but i
- [x] Generate Documentation
- [x] AudioProcessing Class that can wrap different non-vst algorithms
- [x] Cross-Platform Audio Endpoint Render-Capture with RtAudio (Validated only for Windows)
- **TODO** (ordered by priority):
- [x] Create and pass config for AudioProcessing Class
- **TODO**:
- [ ] Implement simple Vst plugin that allows to process data in real-time (e.g. context buffering). Start from
delay validation implemented in VST SDK.
- [ ] Enable streaming processing (one frame in, one frame out)
- [ ] Integrate Open Vino to process audio with AI based Audio Algorithms
- [ ] Enable Apple Silicon AI acceleration
- [ ] Add more advanced python-based Vst Host Lib utilization
- [ ] Add more UT for python and Android
- [ ] Integrate better wave reader
- [ ] Build solution for ARM
- [ ] Handle different audio formats e.g. sampling rate, bit depth etc.
- [ ] Create and pass config for AudioProcessing Class
- [ ] Validate RtAudio for different OSes
- [ ] Move *vst_host_config_* from *WaveProcessingPipeline* class to *AudioProcessingVstHost* class.
- [ ] Rename ** to *AudioProcessingTool*

1. Android
- TODO:
Expand Down
58 changes: 45 additions & 13 deletions VstHost_VisualC++/modules/ArgParser/header/VstHostConfigGenerator.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef VST_HOST_CONFIG_GENERATOR_H
#define VST_HOST_CONFIG_GENERATOR_H

#define PROCESSING_CONFIG_PARAM_STR "processing_config"
#define VST_HOST_CONFIG_PARAM_STR "vst_host"

#include "easylogging++.h"
#include "enums.h"
#include "JsonUtils.h"
Expand All @@ -15,10 +12,10 @@ class VstHostConfigGenerator
explicit VstHostConfigGenerator() = default;
~VstHostConfigGenerator() = default;

VST_ERROR_STATUS DumpEmptyVstHostConfig(std::string config_path);
VST_ERROR_STATUS DumpEmptyVstHostConfig(nlohmann::json plugin_config_json, std::string config_path);
VST_ERROR_STATUS ReadAndDumpVstHostConfig(std::string config_path);
nlohmann::json ReadVstHostConfig(std::string config_path);
VST_ERROR_STATUS DumpEmptyAppConfig(std::string config_path);
VST_ERROR_STATUS DumpEmptyAppConfig(nlohmann::json plugin_config_json, std::string config_path);
VST_ERROR_STATUS ReadAndDumpAppConfig(std::string config_path);
nlohmann::json ReadAppConfig(std::string config_path);
nlohmann::json GetConfigDict();
// TODO:
// validate config
Expand All @@ -27,19 +24,54 @@ class VstHostConfigGenerator
std::vector<std::string> params_list);

nlohmann::json plugin_config_json_;
std::vector<std::string> single_params_list
{
"input_wave",
"output_wave",
};

std::vector<std::string> dict_params_list
const std::vector<std::string> main_config_sections_list_
{
"input_wave",
"output_wave",
"preprocessing",
"vst_host",
"postprocessing"
};

const nlohmann::json sub_sections_params_
{
{"preprocessing",
{
{"filter",
{
{"enable", false}
}
}
}
},

{"vst_host",
{
{"enable", false},
{"processing_config",
{
{"plugin_1",
{
{"config", ""},
{"plugin", ""}
}
},
}
}
}
},

{"postprocessing",
{
{"filter",
{
{"enable", false}
}
}
}
},
};
};

#endif //VST_HOST_CONFIG_GENERATOR_H
2 changes: 1 addition & 1 deletion VstHost_VisualC++/modules/ArgParser/header/arg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArgParser
uint8_t GetPluginVerbosity();
std::string GetOutputWavePath();
bool GetDumpPluginParams();
config_type GetProcessingConfig();
nlohmann::json GetProcessingConfig();
bool GetEnableAudioEndpoint();
bool GetDumpToolConfigParam();

Expand Down
45 changes: 13 additions & 32 deletions VstHost_VisualC++/modules/ArgParser/src/VstHostConfigGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
#include "VstHostConfigGenerator.h"

VST_ERROR_STATUS VstHostConfigGenerator::DumpEmptyVstHostConfig(
VST_ERROR_STATUS VstHostConfigGenerator::DumpEmptyAppConfig(
nlohmann::json plugin_config_json,
std::string config_path)
{
AddParametersFromList(plugin_config_json, single_params_list);
AddParametersFromList(plugin_config_json, dict_params_list);

if (JsonUtils::CheckIfParamInDict(plugin_config_json[VST_HOST_CONFIG_PARAM_STR],
PROCESSING_CONFIG_PARAM_STR))
{
plugin_config_json[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR] = {};
plugin_config_json[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR]["plugin_1"] = {};
plugin_config_json[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR]["plugin_1"]["config"] = "";
plugin_config_json[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR]["plugin_1"]["plugin"] = "";
}

if (JsonUtils::CheckIfParamInDict(plugin_config_json["postprocessing"], "filter"))
{
plugin_config_json["postprocessing"]["filter"] = {};
plugin_config_json["postprocessing"]["filter"]["enable"] = false;
}

if (JsonUtils::CheckIfParamInDict(plugin_config_json["preprocessing"], "filter"))
{
plugin_config_json["preprocessing"]["filter"] = {};
plugin_config_json["preprocessing"]["filter"]["enable"] = false;
}

AddParametersFromList(plugin_config_json, main_config_sections_list_);
plugin_config_json_ = plugin_config_json;
return JsonUtils::DumpJson(plugin_config_json, config_path);
}

VST_ERROR_STATUS VstHostConfigGenerator::DumpEmptyVstHostConfig(std::string config_path)
VST_ERROR_STATUS VstHostConfigGenerator::DumpEmptyAppConfig(std::string config_path)
{
nlohmann::json plugin_config_json;
return DumpEmptyVstHostConfig(plugin_config_json, config_path);
return DumpEmptyAppConfig(plugin_config_json, config_path);
}


VST_ERROR_STATUS VstHostConfigGenerator::ReadAndDumpVstHostConfig(std::string config_path)
VST_ERROR_STATUS VstHostConfigGenerator::ReadAndDumpAppConfig(std::string config_path)
{
nlohmann::json plugin_config_json = ReadVstHostConfig(config_path);
return DumpEmptyVstHostConfig(plugin_config_json, config_path);
nlohmann::json plugin_config_json = ReadAppConfig(config_path);
return DumpEmptyAppConfig(plugin_config_json, config_path);
}

nlohmann::json VstHostConfigGenerator::ReadVstHostConfig(std::string config_path)
nlohmann::json VstHostConfigGenerator::ReadAppConfig(std::string config_path)
{
nlohmann::json plugin_config_json;
RETURN_ERROR_IF_NOT_SUCCESS(JsonUtils::LoadJson(config_path, &plugin_config_json));
Expand All @@ -63,9 +40,13 @@ VST_ERROR_STATUS VstHostConfigGenerator::AddParametersFromList(
{
for (auto param_name : params_list)
{
if (JsonUtils::CheckIfParamInDict(plugin_config_json, param_name))
if (JsonUtils::CheckIfParamNotInDict(plugin_config_json, param_name))
{
plugin_config_json[param_name] = { };
if (!JsonUtils::CheckIfParamNotInDict(sub_sections_params_, param_name))
{
plugin_config_json[param_name] = sub_sections_params_.at(param_name);
}
}
}
return VST_ERROR_STATUS::SUCCESS;
Expand Down
37 changes: 19 additions & 18 deletions VstHost_VisualC++/modules/ArgParser/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "VstHostMacro.h"
#include "VstHostConfigGenerator.h"

#define DUMP_CMD_PARAM_STR "-dump_vst_host_config"
#define VST_HOST_CMD_PARAM_STR "-vst_host_config"
#define DUMP_CMD_PARAM_STR "-dump_app_config"
#define VST_HOST_CMD_PARAM_STR "-config"
#define DUMP_PLUGINS_CONFIGS "-dump_plugins_config"
#define APP_NAME "VstHostTool"

ArgParser::ArgParser()
{
arg_parser_.reset(new argparse::ArgumentParser("audiohost"));
arg_parser_.reset(new argparse::ArgumentParser(APP_NAME));

arg_parser_->add_argument("-verbosity")
.help("Possible values:\n"
Expand All @@ -22,15 +23,15 @@ ArgParser::ArgParser()
.default_value(0);

arg_parser_->add_argument(VST_HOST_CMD_PARAM_STR)
.help("path to the application config run.");
.help("path to the application config needed to proper execution.");

arg_parser_->add_argument(DUMP_CMD_PARAM_STR)
.help("allows to dump empty configuration file for VST Host Application that needs to be fill with parameters.\nThis parameter needes to be commbined with " + std::string(VST_HOST_CMD_PARAM_STR) + ".")
.help("allows to dump empty configuration file for VST Host Application that needs to be fill with parameters. This parameter needes to be commbined with " + std::string(VST_HOST_CMD_PARAM_STR) + ".")
.implicit_value(true)
.default_value(false);

arg_parser_->add_argument(DUMP_PLUGINS_CONFIGS)
.help("allows to dump empty configuration for all plugins defined in VST Host Application config.\nThis parameter needes to be commbined with " + std::string(VST_HOST_CMD_PARAM_STR) + ".")
.help("allows to dump empty configuration for all plugins defined in VST Host Application config. This parameter needes to be commbined with " + std::string(VST_HOST_CMD_PARAM_STR) + ".")
.implicit_value(true)
.default_value(false);

Expand All @@ -46,7 +47,7 @@ int ArgParser::CheckInputArgsFormat(std::vector<std::string> args)
if (arg.find('=') != std::string::npos)
{
LOG(INFO) << "VST Host Tool doesn't accept parameter definition with '='. "
"Please pass parameters in convetion without '=' e.g. '-vst_host_config config.json'.";
"Please pass parameters in convetion without '=' e.g." + std::string(VST_HOST_CMD_PARAM_STR) + "'-vst_host_config config.json'.";
return VST_ERROR_STATUS::WRONG_PARAMETER_FORMAT;
}
std::cout << arg << std::endl;
Expand Down Expand Up @@ -92,12 +93,13 @@ int ArgParser::ParsParameters(std::vector<std::string> args)
}
return status;
}
else if (dump_plugin_params_)

if (dump_plugin_params_)
{
status = this->DumpVstHostConfig();
RETURN_ERROR_IF_NOT_SUCCESS(status);

for(nlohmann::json params : main_config_["vst_host"]["processing_config"])
for(nlohmann::json params : main_config_[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR])
{
for(auto single_param : params.items())
{
Expand All @@ -110,12 +112,13 @@ int ArgParser::ParsParameters(std::vector<std::string> args)
}
return status;
}
else if (!enable_audio_capture_)

if (!enable_audio_capture_)
{
status = this->ValidateVstHostConfigParam();

std::unique_ptr<VstHostConfigGenerator> config_generator(new VstHostConfigGenerator());
main_config_ = config_generator->ReadVstHostConfig(vst_host_config_);
main_config_ = config_generator->ReadAppConfig(vst_host_config_);

// input_wave_path_
status = CheckIfPathExists(main_config_["input_wave"]);
Expand All @@ -133,8 +136,6 @@ int ArgParser::ParsParameters(std::vector<std::string> args)
return VST_ERROR_STATUS::VST_HOST_ERROR;
}
verbosity_ = static_cast<uint8_t>(arg_parser_->get<int>("-verbosity"));



return status;
}
Expand Down Expand Up @@ -175,10 +176,10 @@ int ArgParser::DumpVstHostConfig()
std::unique_ptr<VstHostConfigGenerator> config_generator(new VstHostConfigGenerator());
if (status != VST_ERROR_STATUS::SUCCESS)
{
return config_generator->DumpEmptyVstHostConfig(vst_host_config_);
return config_generator->DumpEmptyAppConfig(vst_host_config_);
}

status = config_generator->ReadAndDumpVstHostConfig(vst_host_config_);
status = config_generator->ReadAndDumpAppConfig(vst_host_config_);
RETURN_ERROR_IF_NOT_SUCCESS(status);

main_config_ = config_generator->GetConfigDict();
Expand Down Expand Up @@ -226,9 +227,9 @@ bool ArgParser::GetDumpPluginParams()
return dump_plugin_params_;
}

config_type ArgParser::GetProcessingConfig()
nlohmann::json ArgParser::GetProcessingConfig()
{
return main_config_[VST_HOST_CONFIG_PARAM_STR][PROCESSING_CONFIG_PARAM_STR];
return main_config_;
}

bool ArgParser::GetEnableAudioEndpoint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@

#include "easylogging++.h"
#include "enums.h"
#include "filter.h"
#include "FilterWrapper.h"
#include "audiohost.h"
#include "JsonUtils.h"

class WaveProcessingPipeline
{
public:
explicit WaveProcessingPipeline(uint8_t verbosity);

~WaveProcessingPipeline() = default;
int Init(config_type vst_host_config);
int Init(nlohmann::json vst_host_config);
int GetConfig();
int Run(std::string input_path, std::string output_path);

private:
BWLowPass* bw_low_pass_filter_ = nullptr;
int CreateVstHost();
int ProcessingVstHost();

int CreatePreprocessingModule();
int CreatePostprocessingModule();
int SwapInOutBuffers();

private:
uint8_t verbosity_ = 0;
config_type vst_host_config_{};
nlohmann::json pipeline_config_{};
std::unique_ptr<AudioProcessingVstHost> vst_host_;
std::unique_ptr<WaveDataContainer> input_wave_;
std::unique_ptr<WaveDataContainer> output_wave_;
};

#endif //WAVE_PROCESSING_PIPELINE_H
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FilterWrapper::~FilterWrapper()
if (bw_low_pass_filter_ != nullptr)
{
free_bw_low_pass(bw_low_pass_filter_);
LOG(INFO) << "bw_low_pass_filter released sucessfully." << std::endl;
LOG(DEBUG) << "bw_low_pass_filter released sucessfully." << std::endl;
}
}

Expand Down
Loading

0 comments on commit 15657d8

Please sign in to comment.