Files
EqualizerAPO/helpers/StringHelper.cpp
T
jthedering 90ee2b0aa9 Version 0.9
Added: Filter type "IIR", which allows to specify a user-defined IIR filter of arbitrary order with custom coefficients.
Improved: For playback devices, the APO is now installed both as GFX (post-mix) and LFX (pre-mix) APO. Normally the filtering happens in GFX, but the command "Stage" allows to select LFX to apply effects based on the number of input channels.
Added: Expression language. The commands "If", "ElseIf", "Else", "EndIf", "Eval" and inline expressions allow to change the filter behaviour based on runtime conditions.
Added: Command "Copy", which copies audio data between channels.
Added: Command "Delay", which delays the audio on the currently selected channels.
Improved: Configuration files are now locked exclusively for writing while reading them.
Improved: There is now a transition (10 ms) from old to new configuration after loading.
Improved: Substantial internal restructuring to improve extensibility and maintainability. Filtering commands now work exactly in the order they were specified.
Fixed: When the microphone input was in stereo but the application requested a mono stream, the audio was heavily distorted.
Fixed: The sine sweep generated by the Benchmark application had floating-point precision issues leading to severe artifacts when certain filters were applied.
2014-08-10 18:35:59 +00:00

146 lines
3.5 KiB
C++

/*
This file is part of EqualizerAPO, a system-wide equalizer.
Copyright (C) 2013 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 <string>
#include <sstream>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "StringHelper.h"
using namespace std;
wstring StringHelper::replaceCharacters(const wstring& s, const wstring& chars, const wstring& replacement)
{
wstring result;
result.reserve(s.length());
for(unsigned i=0; i<s.length(); i++)
{
wchar_t c = s[i];
if(chars.find(c) == -1)
result += c;
else
result += replacement;
}
return result;
}
wstring StringHelper::replaceIllegalCharacters(const wstring& filename)
{
return replaceCharacters(filename, L"<>:\"/\\|?*", L"_");
}
wstring StringHelper::toWString(const string& s, unsigned codepage)
{
int length = MultiByteToWideChar(codepage, 0, s.c_str(), -1, NULL, 0);
wchar_t* charBuf = new wchar_t[length];
MultiByteToWideChar(codepage, 0, s.c_str(), -1, charBuf, length);
wstring result = charBuf;
delete charBuf;
return result;
}
wstring StringHelper::toLowerCase(const wstring& s)
{
wchar_t* charBuf = new wchar_t[s.length() + 1];
memcpy(charBuf, s.c_str(), (s.length() + 1) * sizeof(wchar_t));
errno_t err = _wcslwr_s(charBuf, s.length() + 1);
wstring result = charBuf;
delete charBuf;
if(err == 0)
return result;
else
return s;
}
wstring StringHelper::toUpperCase(const wstring& s)
{
wchar_t* charBuf = new wchar_t[s.length() + 1];
memcpy(charBuf, s.c_str(), (s.length() + 1) * sizeof(wchar_t));
errno_t err = _wcsupr_s(charBuf, s.length() + 1);
wstring result = charBuf;
delete charBuf;
if(err == 0)
return result;
else
return s;
}
wstring StringHelper::trim(const wstring& s)
{
int firstNonSpace = -1;
int lastNonSpace = -1;
for(unsigned i=0;i<s.length();i++)
{
wchar_t c = s[i];
if(!iswspace(c))
{
if(firstNonSpace == -1)
firstNonSpace = i;
lastNonSpace = i;
}
}
if(firstNonSpace == -1)
return L"";
else
return s.substr(firstNonSpace, lastNonSpace-firstNonSpace+1);
}
vector<wstring> StringHelper::split(const wstring& s, wchar_t splitChar, bool skipEmpty)
{
vector<wstring> result;
size_t prevPos = 0;
size_t pos = 0;
while((pos = s.find(splitChar, pos)) != wstring::npos)
{
wstring part = s.substr(prevPos, pos-prevPos);
if(part.length() > 0 || !skipEmpty)
result.push_back(part);
prevPos = ++pos;
}
wstring part = s.substr(prevPos);
if(part.length() > 0 || !skipEmpty)
result.push_back(part);
return result;
}
wstring StringHelper::getSystemErrorString(long status)
{
wchar_t* buf;
if(FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, status, 0, (LPTSTR)&buf, 0, NULL) != 0)
{
wstring result(buf);
LocalFree(buf);
return result;
}
else
return L"";
}