Files
EqualizerAPO/FilterConfiguration.cpp
T
jthedering b8cdd47f71 Version 1.0
Added: Configuration Editor, which allows to edit configurations in a graphical user interface. Contains GUIs for most commands supported by E-APO, but as lines can also be edited directly, all commands can be used.
Added: Command "GraphicEQ", which can act as a regular, fixed-band graphic equalizer (via the GUI) but also supports variable bands so that any desired frequency response can be specified. Internally, it is implemented via convolution with a generated IR.
Added: Command "Convolution", which allows to convolve the signal with a user-provided impulse response to achieve e.g. equalization or reverberation effects.
Improved: Configurator performs checks for registry values that are needed for the operation of E-APO, which may be changed by driver installations, fixing the values if necessary.
Improved: Configurator shows which is the default device as a hint to the user.
2015-09-27 16:01:21 +00:00

182 lines
5.3 KiB
C++

/*
This file is part of EqualizerAPO, a system-wide equalizer.
Copyright (C) 2014 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 <algorithm>
#include "FilterEngine.h"
#include "helpers/MemoryHelper.h"
#include "FilterConfiguration.h"
using namespace std;
FilterConfiguration::FilterConfiguration(FilterEngine* engine, const vector<FilterInfo*>& filterInfos, unsigned allChannelCount)
{
this->allChannelCount = allChannelCount;
realChannelCount = engine->getRealChannelCount();
outputChannelCount = engine->getOutputChannelCount();
unsigned maxFrameCount = engine->getMaxFrameCount();
allSamples = (float**)MemoryHelper::alloc(allChannelCount * sizeof(float*));
for(size_t i=0; i<allChannelCount; i++)
allSamples[i] = (float*)MemoryHelper::alloc(maxFrameCount * sizeof(float));
allSamples2 = (float**)MemoryHelper::alloc(allChannelCount * sizeof(float*));
for(size_t i=0; i<allChannelCount; i++)
allSamples2[i] = (float*)MemoryHelper::alloc(maxFrameCount * sizeof(float));
currentSamples = (float**)MemoryHelper::alloc(allChannelCount * sizeof(float*));
currentSamples2 = (float**)MemoryHelper::alloc(allChannelCount * sizeof(float*));
filterCount = (unsigned)filterInfos.size();
this->filterInfos = (FilterInfo**)MemoryHelper::alloc(filterCount * sizeof(FilterInfo*));
for(size_t i=0; i<filterCount; i++)
this->filterInfos[i] = filterInfos[i];
}
FilterConfiguration::~FilterConfiguration()
{
MemoryHelper::free(currentSamples2);
MemoryHelper::free(currentSamples);
for(size_t i=0; i<allChannelCount; i++)
MemoryHelper::free(allSamples2[i]);
MemoryHelper::free(allSamples2);
for(size_t i=0; i<allChannelCount; i++)
MemoryHelper::free(allSamples[i]);
MemoryHelper::free(allSamples);
for(size_t i=0; i<filterCount; i++)
{
filterInfos[i]->filter->~IFilter();
MemoryHelper::free(filterInfos[i]->filter);
if(filterInfos[i]->inChannels != NULL)
MemoryHelper::free(filterInfos[i]->inChannels);
if(filterInfos[i]->outChannels != NULL)
MemoryHelper::free(filterInfos[i]->outChannels);
MemoryHelper::free(filterInfos[i]);
}
MemoryHelper::free(filterInfos);
}
#pragma AVRT_CODE_BEGIN
void FilterConfiguration::process(float* input, unsigned frameCount)
{
#define DEINTERLEAVE_MACRO(ccount) \
{\
for (size_t c=0; c<ccount; c++)\
{\
float* sampleChannel = allSamples[c];\
float* i2 = input + c;\
for (size_t i = 0; i < frameCount; i++)\
{\
sampleChannel[i] = i2[i*ccount];\
}\
}\
}
switch(realChannelCount)
{
case 1:
DEINTERLEAVE_MACRO(1)
break;
case 2:
DEINTERLEAVE_MACRO(2)
break;
case 6:
DEINTERLEAVE_MACRO(6)
break;
case 8:
DEINTERLEAVE_MACRO(8)
break;
default:
DEINTERLEAVE_MACRO(realChannelCount)
}
for(unsigned c=realChannelCount; c<allChannelCount; c++)
memset(allSamples[c], 0, frameCount * sizeof(float));
// for real mono input and >= stereo output, upmix to stereo as the Windows audio system would do automatically if no APO was present
if(realChannelCount == 1 && outputChannelCount >= 2)
memcpy(allSamples[1], allSamples[0], frameCount * sizeof(float));
for(size_t i=0; i<filterCount; i++)
{
FilterInfo* filterInfo = filterInfos[i];
for(size_t j=0; j<filterInfo->inChannelCount; j++)
currentSamples[j] = allSamples[filterInfo->inChannels[j]];
if(filterInfo->inPlace)
{
for(size_t j=0; j<filterInfo->outChannelCount; j++)
currentSamples2[j] = allSamples[filterInfo->outChannels[j]];
}
else
{
for(size_t j=0; j<filterInfo->outChannelCount; j++)
currentSamples2[j] = allSamples2[filterInfo->outChannels[j]];
}
filterInfo->filter->process(currentSamples2, currentSamples, frameCount);
if(!filterInfo->inPlace)
{
for(size_t j=0; j<filterInfo->outChannelCount; j++)
swap(allSamples[filterInfo->outChannels[j]], allSamples2[filterInfo->outChannels[j]]);
swap(currentSamples, currentSamples2);
}
}
}
void FilterConfiguration::write(float* output, unsigned frameCount)
{
#define INTERLEAVE_MACRO(ccount) \
for (size_t c=0; c<ccount; c++)\
{\
float* sampleChannel = allSamples[c];\
float* o2 = output + c;\
for (unsigned i = 0; i < frameCount; i++)\
{\
o2[i*ccount] = sampleChannel[i];\
}\
}
switch(outputChannelCount)
{
case 1:
INTERLEAVE_MACRO(1)
break;
case 2:
INTERLEAVE_MACRO(2)
break;
case 6:
INTERLEAVE_MACRO(6)
break;
case 8:
INTERLEAVE_MACRO(8)
break;
default:
INTERLEAVE_MACRO(outputChannelCount)
}
}
#pragma AVRT_CODE_END
bool FilterConfiguration::isEmpty()
{
return filterCount == 0;
}