Added: VST Plugin support. Add and configure plugins via Configuration Editor. The plugin's architecture has to match the OS architecture, so most people will need 64-bit plugins. The subdirectory plugins is offered to put plugins into, but they can be opened from any directory with sufficient permissions.

Fixed: When trying to add a high-pass filter in the Configuration Editor, it was instead configured to be a low-pass filter.
This commit is contained in:
jthedering committed 2017-06-17 13:04:35 +00:00
1 parent 989812ba36
commit a24eaa0cd9
58 files changed
+3334 -151

No files matched your search

+234
View File
@@ -0,0 +1,234 @@
/*
This file is part of Equalizer APO, a system-wide equalizer.
Copyright (C) 2017 Jonas Thedering
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "stdafx.h"
#include "helpers/StringHelper.h"
#include "helpers/LogHelper.h"
#include "VSTPluginFilter.h"
using namespace std;
VSTPluginFilter::VSTPluginFilter(std::shared_ptr<VSTPluginLibrary> library, std::wstring chunkData, std::unordered_map<std::wstring, float> paramMap)
: library(library), chunkData(chunkData), paramMap(paramMap)
{
libPath = library->getLibPath();
}
VSTPluginFilter::~VSTPluginFilter()
{
cleanup();
}
std::vector<std::wstring> VSTPluginFilter::initialize(float sampleRate, unsigned maxFrameCount, std::vector<std::wstring> channelNames)
{
cleanup();
channelCount = channelNames.size();
if (channelCount == 0)
return channelNames;
skipProcessing = false;
void* mem = MemoryHelper::alloc(sizeof(VSTPluginInstance));
VSTPluginInstance* firstEffect = new(mem) VSTPluginInstance(library, 2);
if (!firstEffect->initialize())
{
LogF(L"The VST plugin %s crashed during initialization.", libPath.c_str());
skipProcessing = true;
}
effectChannelCount = max(firstEffect->numInputs(), firstEffect->numOutputs());
// round up
effectCount = (channelCount + (effectChannelCount - 1)) / effectChannelCount;
effects = (VSTPluginInstance**)MemoryHelper::alloc(effectCount * sizeof(VSTPluginInstance*));
effects[0] = firstEffect;
for (unsigned i = 1; i < effectCount; i++)
{
mem = MemoryHelper::alloc(sizeof(VSTPluginInstance));
effects[i] = new(mem) VSTPluginInstance(library, 2);
if (!effects[i]->initialize() && !skipProcessing)
{
LogF(L"The VST plugin %s crashed during initialization.", libPath.c_str());
skipProcessing = true;
}
}
prepareForProcessing(sampleRate, maxFrameCount);
// 2 times for input and output
emptyChannelCount = 2 * (effectCount * effectChannelCount - channelCount);
emptyChannels = (float**)MemoryHelper::alloc(emptyChannelCount * sizeof(float*));
for (unsigned i = 0; i < emptyChannelCount; i++)
{
emptyChannels[i] = (float*)MemoryHelper::alloc(maxFrameCount * sizeof(float));
memset(emptyChannels[i], 0, maxFrameCount * sizeof(float));
}
inputArray = (float**)MemoryHelper::alloc(firstEffect->numInputs() * sizeof(float*));
outputArray = (float**)MemoryHelper::alloc(firstEffect->numOutputs() * sizeof(float*));
return channelNames;
}
void VSTPluginFilter::prepareForProcessing(float sampleRate, unsigned maxFrameCount)
{
__try
{
for (unsigned i = 0; i < effectCount; i++)
{
VSTPluginInstance* effect = effects[i];
if (i == effectCount - 1 && (channelCount % effectChannelCount) != 0)
effect->setUsedChannelCount(channelCount % effectChannelCount);
else
effect->setUsedChannelCount(effectChannelCount);
effect->prepareForProcessing(sampleRate, maxFrameCount);
effect->writeToEffect(chunkData, paramMap);
effect->startProcessing();
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
LogF(L"The VST plugin %s crashed while preparing for processing.", libPath.c_str());
skipProcessing = true;
}
}
#pragma AVRT_CODE_BEGIN
void VSTPluginFilter::process(float** output, float** input, unsigned frameCount)
{
if (skipProcessing)
{
for (unsigned i = 0; i < channelCount; i++)
memcpy(output[i], input[i], frameCount * sizeof(float));
return;
}
__try
{
unsigned channelOffset = 0;
unsigned emptyChannelIndex = 0;
for (unsigned i = 0; i < effectCount; i++)
{
VSTPluginInstance* effect = effects[i];
for (int j = 0; j < effect->numInputs(); j++)
{
if (channelOffset + j < channelCount)
inputArray[j] = input[channelOffset + j];
else
inputArray[j] = emptyChannels[emptyChannelIndex++];
}
for (int j = 0; j < effect->numOutputs(); j++)
{
if (channelOffset + j < channelCount)
outputArray[j] = output[channelOffset + j];
else
outputArray[j] = emptyChannels[emptyChannelIndex++];
}
if (effect->canReplacing())
{
effect->processReplacing(inputArray, outputArray, frameCount);
}
else
{
for (int j = 0; j < effect->numOutputs(); j++)
memset(outputArray[j], 0, frameCount * sizeof(float));
effect->process(inputArray, outputArray, frameCount);
}
if (effect->numOutputs() < effect->numInputs())
{
for (int j = effect->numOutputs(); j < effect->numInputs(); j++)
{
if (channelOffset + j < channelCount)
memset(output[channelOffset + j], 0, frameCount * sizeof(float));
}
}
channelOffset += effectChannelCount;
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
if (reportCrash)
{
LogF(L"The VST plugin %s crashed during audio processing.", libPath.c_str());
reportCrash = false;
}
for (unsigned i = 0; i < channelCount; i++)
memcpy(output[i], input[i], frameCount * sizeof(float));
}
}
#pragma AVRT_CODE_END
std::shared_ptr<VSTPluginLibrary> VSTPluginFilter::getLibrary() const
{
return library;
}
std::wstring VSTPluginFilter::getChunkData() const
{
return chunkData;
}
std::unordered_map<std::wstring, float> VSTPluginFilter::getParamMap() const
{
return paramMap;
}
void VSTPluginFilter::cleanup()
{
if (effects != NULL)
{
for (unsigned i = 0; i < effectCount; i++)
{
VSTPluginInstance* effect = effects[i];
effect->stopProcessing();
effect->~VSTPluginInstance();
MemoryHelper::free(effect);
}
MemoryHelper::free(effects);
effects = NULL;
}
effectCount = 0;
if (emptyChannels != NULL)
{
for (unsigned i = 0; i < emptyChannelCount; i++)
MemoryHelper::free(emptyChannels[i]);
MemoryHelper::free(emptyChannels);
emptyChannels = NULL;
}
emptyChannelCount = 0;
if (inputArray != NULL)
{
MemoryHelper::free(inputArray);
inputArray = NULL;
}
if (outputArray != NULL)
{
MemoryHelper::free(outputArray);
outputArray = NULL;
}
}
+59
View File
@@ -0,0 +1,59 @@
/*
This file is part of Equalizer APO, a system-wide equalizer.
Copyright (C) 2017 Jonas Thedering
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include "IFilter.h"
#include "helpers/VSTPluginLibrary.h"
#pragma AVRT_VTABLES_BEGIN
class VSTPluginFilter : public IFilter
{
public:
VSTPluginFilter(std::shared_ptr<VSTPluginLibrary> library, std::wstring chunkData, std::unordered_map<std::wstring, float> paramMap);
~VSTPluginFilter();
bool getInPlace() override {return false;}
std::vector<std::wstring> initialize(float sampleRate, unsigned maxFrameCount, std::vector<std::wstring> channelNames) override;
void prepareForProcessing(float sampleRate, unsigned maxFrameCount);
void process(float** output, float** input, unsigned frameCount) override;
std::shared_ptr<VSTPluginLibrary> getLibrary() const;
std::wstring getChunkData() const;
std::unordered_map<std::wstring, float> getParamMap() const;
private:
void cleanup();
std::shared_ptr<VSTPluginLibrary> library;
std::wstring libPath;
std::wstring chunkData;
std::unordered_map<std::wstring, float> paramMap;
size_t channelCount;
unsigned effectChannelCount;
size_t effectCount = 0;
VSTPluginInstance** effects = NULL;
size_t emptyChannelCount = 0;
float** emptyChannels = NULL;
float** inputArray = NULL;
float** outputArray = NULL;
bool skipProcessing = false;
bool reportCrash = true;
};
#pragma AVRT_VTABLES_END
+116
View File
@@ -0,0 +1,116 @@
/*
This file is part of Equalizer APO, a system-wide equalizer.
Copyright (C) 2017 Jonas Thedering
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "stdafx.h"
#include "helpers/StringHelper.h"
#include "helpers/VSTPluginLibrary.h"
#include "helpers/LogHelper.h"
#include "VSTPluginFilter.h"
#include "VSTPluginFilterFactory.h"
using namespace std;
vector<IFilter*> VSTPluginFilterFactory::createFilter(const wstring& configPath, wstring& command, wstring& parameters)
{
VSTPluginFilter* filter = NULL;
if (command == L"VSTPlugin")
{
shared_ptr<VSTPluginLibrary> library;
wstring chunkData;
unordered_map<wstring, float> paramMap;
vector<wstring> parts = StringHelper::splitQuoted(parameters, ' ');
for (unsigned i = 0; i + 1 < parts.size(); i += 2)
{
wstring key = parts[i];
wstring value = parts[i + 1];
if (key == L"Library")
{
wstring libPath;
if (PathIsRelativeW(value.c_str()))
{
wchar_t filePath[MAX_PATH];
wstring pluginPath = VSTPluginLibrary::getDefaultPluginPath();
pluginPath._Copy_s(filePath, sizeof(filePath) / sizeof(wchar_t), MAX_PATH);
if (pluginPath.size() < MAX_PATH)
filePath[pluginPath.size()] = L'\0';
else
filePath[MAX_PATH - 1] = L'\0';
PathAppendW(filePath, value.c_str());
libPath = filePath;
}
else
libPath = value;
library = VSTPluginLibrary::getInstance(libPath);
}
else if (key == L"ChunkData")
{
chunkData = value;
}
else
{
float f = wcstof(value.c_str(), NULL);
paramMap[key] = f;
}
}
if (library != NULL)
{
bool create = true;
if (configPath != L"")
{
create = false;
TraceF(L"Adding VST plugin %s", library->getLibPath().c_str());
int res = library->initialize();
if (res < 0)
{
#ifdef _WIN64
int bitDepth = 64;
#else
int bitDepth = 32;
#endif
if (res == AbstractLibrary::FILE_NOT_FOUND)
LogF(L"File %s not found", library->getLibPath());
else if (res == AbstractLibrary::LOADING_FAILED)
LogF(L"Library %s could not be loaded", library->getLibPath());
else if (res == AbstractLibrary::FUNCTIONS_MISSING)
LogF(L"Library %s does not contain needed functions", library->getLibPath());
else if (res == AbstractLibrary::WRONG_ARCHITECTURE)
LogF(L"Library %s has wrong architecture, must be %d-bit", library->getLibPath(), bitDepth);
}
else
{
create = true;
}
}
if (create)
{
void* mem = MemoryHelper::alloc(sizeof(VSTPluginFilter));
filter = new(mem) VSTPluginFilter(library, chunkData, paramMap);
}
}
}
if (filter == NULL)
return vector<IFilter*>(0);
return vector<IFilter*>(1, filter);
}
+31
View File
@@ -0,0 +1,31 @@
/*
This file is part of Equalizer APO, a system-wide equalizer.
Copyright (C) 2017 Jonas Thedering
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <string>
#include "IFilterFactory.h"
#include "IFilter.h"
class VSTPluginFilterFactory : public IFilterFactory
{
public:
std::vector<IFilter*> createFilter(const std::wstring& configPath, std::wstring& command, std::wstring& parameters) override;
};