/* 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 #include "FilterEngine.h" #include "helpers/MemoryHelper.h" #include "FilterConfiguration.h" using namespace std; FilterConfiguration::FilterConfiguration(FilterEngine* engine, const vector& 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; ifilterInfos = (FilterInfo**)MemoryHelper::alloc(filterCount * sizeof(FilterInfo*)); for(size_t i=0; ifilterInfos[i] = filterInfos[i]; } FilterConfiguration::~FilterConfiguration() { MemoryHelper::free(currentSamples2); MemoryHelper::free(currentSamples); for(size_t i=0; ifilter->~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= 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; iinChannelCount; j++) currentSamples[j] = allSamples[filterInfo->inChannels[j]]; if(filterInfo->inPlace) { for(size_t j=0; joutChannelCount; j++) currentSamples2[j] = allSamples[filterInfo->outChannels[j]]; } else { for(size_t j=0; joutChannelCount; j++) currentSamples2[j] = allSamples2[filterInfo->outChannels[j]]; } filterInfo->filter->process(currentSamples2, currentSamples, frameCount); if(!filterInfo->inPlace) { for(size_t j=0; joutChannelCount; 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