- more work to adopt command line aqua-wb for analysis

This commit is contained in:
Dmytro Bogovych 2018-08-20 13:01:42 +03:00
parent 1b6d548448
commit 434fa71937
2 changed files with 187 additions and 72 deletions

View File

@ -158,6 +158,101 @@ float PvqaUtility::process(const std::string& filepath, std::string& outputRepor
return result; return result;
} }
// ---------------- AquaUtility -----------------
AquaUtility::AquaUtility()
{}
AquaUtility::~AquaUtility()
{}
void AquaUtility::setPath(const std::string& path)
{
mAquaPath = path;
}
std::string AquaUtility::getPath() const
{
return mAquaPath;
}
void AquaUtility::setLicensePath(const std::string& path)
{
mLicensePath = path;
}
std::string AquaUtility::getLicensePath() const
{
return mLicensePath;
}
void AquaUtility::setConfigLine(const std::string& line)
{
mConfigLine = line;
}
std::string AquaUtility::getConfigLine() const
{
return mConfigLine;
}
float AquaUtility::compare(const std::string& src_path, const std::string& dst_path, std::string& output_report)
{
float result = 0.0f;
// Generate temporary filename to receive .csv file
char spectrum_filename[L_tmpnam], report_filename[L_tmpnam];
tmpnam(spectrum_filename);
tmpnam(report_filename);
std::string config_line = mConfigLine;
StringHelper::replace(config_line, ":src_file", "\"" + src_path + "\"");
StringHelper::replace(config_line, ":tst_file", "\"" + dst_path + "\"");
StringHelper::replace(config_line, ":spectrum_file", spectrum_filename);
StringHelper::replace(config_line, ":report_file", report_filename);
StringHelper::replace(config_line, ":license_file", "\"" + mLicensePath + "\"");
// Build command line
char cmdbuffer[2048];
sprintf(cmdbuffer, "\"%s\" %s", mAquaPath.c_str(), config_line.c_str());
try
{
std::string output = execCommand(cmdbuffer);
std::string line;
std::istringstream is(output);
std::string estimation;
while (std::getline(is, line))
{
std::string::size_type mosPosition = line.find("MOS value ");
if ( mosPosition != std::string::npos)
{
estimation = line.substr(mosPosition + 6);
estimation = StringHelper::trim(estimation);
}
}
if (!estimation.size())
throw std::runtime_error("Bad response from pvqa: " + output);
result = std::stof(estimation);
// Read intervals report file
std::ifstream t(report_filename);
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
output_report = str;
::remove(report_filename);
::remove(report_filename);
}
catch (std::exception& e)
{
std::cerr << e.what() << "\n";
}
return result;
}
// -------------- SevanaMosUtility -------------- // -------------- SevanaMosUtility --------------
void SevanaMosUtility::run(const std::string& pcmPath, const std::string& intervalPath, void SevanaMosUtility::run(const std::string& pcmPath, const std::string& intervalPath,

View File

@ -24,55 +24,75 @@
namespace MT namespace MT
{ {
enum class ReportType enum class ReportType
{ {
PlainText, PlainText,
Html Html
}; };
class PvqaUtility
{
public:
PvqaUtility();
~PvqaUtility();
void setPath(const std::string& path); class PvqaUtility
std::string getPath() const; {
public:
PvqaUtility();
~PvqaUtility();
void setLicensePath(const std::string& path); void setPath(const std::string& path);
std::string getLicensePath() const; std::string getPath() const;
void setConfigPath(const std::string& path); void setLicensePath(const std::string& path);
std::string getConfigPath() const; std::string getLicensePath() const;
float process(const std::string& filepath, std::string& outputReport); void setConfigPath(const std::string& path);
std::string getConfigPath() const;
private: float process(const std::string& path, std::string& report);
std::string mPvqaPath, mLicensePath, mConfigPath; private:
}; std::string mPvqaPath, mLicensePath, mConfigPath;
};
#if defined(USE_PVQA_LIBRARY) class AquaUtility
class SevanaMosUtility {
{ public:
public: AquaUtility();
~AquaUtility();
void setPath(const std::string& path);
std::string getPath() const;
void setLicensePath(const std::string& path);
std::string getLicensePath() const;
void setConfigLine(const std::string& line);
std::string getConfigLine() const;
float compare(const std::string& src, const std::string& dst, std::string& outputReport);
protected:
std::string mAquaPath, mLicensePath, mConfigLine;
};
#if defined(USE_PVQA_LIBRARY)
class SevanaMosUtility
{
public:
// Returns MOS estimation as text representation of float value or "failed" word. // Returns MOS estimation as text representation of float value or "failed" word.
static void run(const std::string& pcmPath, const std::string& intervalPath, static void run(const std::string& pcmPath, const std::string& intervalPath,
std::string& estimation, std::string& intervals); std::string& estimation, std::string& intervals);
}; };
extern float getSevanaMos(const std::string& audioPath, const std::string& intervalReportPath, extern float getSevanaMos(const std::string& audioPath, const std::string& intervalReportPath,
std::string& intervalReport); std::string& intervalReport);
class SevanaPVQA class SevanaPVQA
{ {
public: public:
enum class Model enum class Model
{ {
Stream, Stream,
Interval Interval
}; };
protected: protected:
static void* mLibraryConfiguration; static void* mLibraryConfiguration;
static int mLibraryErrorCode; static int mLibraryErrorCode;
static std::atomic_int mInstanceCounter; static std::atomic_int mInstanceCounter;
@ -83,20 +103,20 @@ namespace MT
Model mModel = Model::Interval; Model mModel = Model::Interval;
double mIntervalLength = 0.68; double mIntervalLength = 0.68;
uint64_t mProcessedSamples = 0, uint64_t mProcessedSamples = 0,
mProcessedMilliseconds = 0; mProcessedMilliseconds = 0;
bool mAudioLineInitialized = false; bool mAudioLineInitialized = false;
std::string mDumpWavPath; std::string mDumpWavPath;
bool mOpenFailed = false; bool mOpenFailed = false;
public: public:
static std::string getVersion(); static std::string getVersion();
// Required to call before any call to SevanaPVQA instance methods // Required to call before any call to SevanaPVQA instance methods
#if defined(TARGET_ANDROID) #if defined(TARGET_ANDROID)
static void setupAndroidEnvironment(void* environment, void* appcontext); static void setupAndroidEnvironment(void* environment, void* appcontext);
#endif #endif
static bool initializeLibrary(const std::string& pathToLicenseFile, const std::string& pathToConfigFile); static bool initializeLibrary(const std::string& pathToLicenseFile, const std::string& pathToConfigFile);
static bool isInitialized(); static bool isInitialized();
@ -118,15 +138,15 @@ namespace MT
typedef std::vector<std::vector<float>> EchoData; typedef std::vector<std::vector<float>> EchoData;
enum class Codec enum class Codec
{ {
None, None,
G711, G711,
ILBC, ILBC,
G722, G722,
G729, G729,
GSM, GSM,
AMRNB, AMRNB,
AMRWB, AMRWB,
OPUS OPUS
}; };
float getResults(std::string& report, EchoData** echo, int samplerate, Codec codec); float getResults(std::string& report, EchoData** echo, int samplerate, Codec codec);
@ -134,8 +154,8 @@ namespace MT
// Report is interval report. Names are output detector names. startIndex is column's start index in interval report of first detector. // Report is interval report. Names are output detector names. startIndex is column's start index in interval report of first detector.
struct DetectorsList struct DetectorsList
{ {
std::vector<std::string> mNames; std::vector<std::string> mNames;
int mStartIndex = 0; int mStartIndex = 0;
}; };
static DetectorsList getDetectorsNames(const std::string& report); static DetectorsList getDetectorsNames(const std::string& report);
@ -149,20 +169,20 @@ namespace MT
int getSize() const; int getSize() const;
static std::string mosToColor(float mos); static std::string mosToColor(float mos);
}; };
typedef std::shared_ptr<SevanaPVQA> PSevanaPVQA; typedef std::shared_ptr<SevanaPVQA> PSevanaPVQA;
#endif #endif
#if defined(USE_AQUA_LIBRARY) #if defined(USE_AQUA_LIBRARY)
class SevanaAqua class SevanaAqua
{ {
protected: protected:
void* mContext = nullptr; void* mContext = nullptr;
std::mutex mMutex; std::mutex mMutex;
std::string mTempPath; std::string mTempPath;
public: public:
// Returns 0 (zero) on successful initialization, otherwise it is error code // Returns 0 (zero) on successful initialization, otherwise it is error code
static int initializeLibrary(const std::string& pathToLicenseFile); static int initializeLibrary(const std::string& pathToLicenseFile);
static void releaseLibrary(); static void releaseLibrary();
@ -222,21 +242,21 @@ namespace MT
bool isInitialized() const { return mRate > 0 && mChannels > 0 && mData; } bool isInitialized() const { return mRate > 0 && mChannels > 0 && mData; }
}; };
struct FaultsReport struct FaultsReport
{ {
float mSignalAdvancedInMilliseconds = -5000.0; float mSignalAdvancedInMilliseconds = -5000.0;
float mMistimingInPercents = -5000.0; float mMistimingInPercents = -5000.0;
struct Result struct Result
{ {
std::string mSource, mDegrated, mUnit; std::string mSource, mDegrated, mUnit;
}; };
typedef std::map<std::string, Result> ResultMap; typedef std::map<std::string, Result> ResultMap;
ResultMap mResultMap; ResultMap mResultMap;
Json::Value toJson() const; Json::Value toJson() const;
std::string toText() const; std::string toText() const;
}; };
typedef std::shared_ptr<FaultsReport> PFaultsReport; typedef std::shared_ptr<FaultsReport> PFaultsReport;
@ -246,15 +266,15 @@ namespace MT
// Compare in one shot. Report will include text representation of json report. // Compare in one shot. Report will include text representation of json report.
struct CompareResult struct CompareResult
{ {
float mMos = 0.0f; float mMos = 0.0f;
Json::Value mReport; Json::Value mReport;
PFaultsReport mFaults; PFaultsReport mFaults;
}; };
CompareResult compare(AudioBuffer& reference, AudioBuffer& test); CompareResult compare(AudioBuffer& reference, AudioBuffer& test);
}; };
typedef std::shared_ptr<SevanaAqua> PSevanaAqua; typedef std::shared_ptr<SevanaAqua> PSevanaAqua;
#endif #endif
} }
#endif #endif