Switch py_quality_assessment to ABSL_FLAG.

Bug: webrtc:10616
Change-Id: I051d5706576d5684d82e3e42fb1b40ea755864d4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144054
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28464}
This commit is contained in:
Mirko Bonadei
2019-07-03 13:48:25 +02:00
committed by Commit Bot
parent b60141b14f
commit 9eee121a8f
4 changed files with 60 additions and 51 deletions

View File

@ -122,16 +122,20 @@ rtc_executable("fake_polqa") {
}
rtc_executable("vad") {
testonly = true
sources = [
"quality_assessment/vad.cc",
]
deps = [
"../../../../common_audio",
"../../../../rtc_base:rtc_base_approved",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}
rtc_executable("apm_vad") {
testonly = true
sources = [
"quality_assessment/apm_vad.cc",
]
@ -140,10 +144,13 @@ rtc_executable("apm_vad") {
"../../../../common_audio",
"../../../../rtc_base:rtc_base_approved",
"../../vad",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}
rtc_executable("sound_level") {
testonly = true
sources = [
"quality_assessment/sound_level.cc",
]
@ -151,6 +158,8 @@ rtc_executable("sound_level") {
"../..",
"../../../../common_audio",
"../../../../rtc_base:rtc_base_approved",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]
}

View File

@ -10,11 +10,16 @@
#include <fstream>
#include <memory>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "common_audio/wav_file.h"
#include "modules/audio_processing/vad/voice_activity_detector.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
ABSL_FLAG(std::string, i, "", "Input wav file");
ABSL_FLAG(std::string, o_probs, "", "VAD probabilities output file");
ABSL_FLAG(std::string, o_rms, "", "VAD output file");
namespace webrtc {
namespace test {
namespace {
@ -24,16 +29,13 @@ constexpr int kMaxSampleRate = 48000;
constexpr size_t kMaxFrameLen =
kAudioFrameLengthMilliseconds * kMaxSampleRate / 1000;
WEBRTC_DEFINE_string(i, "", "Input wav file");
WEBRTC_DEFINE_string(o_probs, "", "VAD probabilities output file");
WEBRTC_DEFINE_string(o_rms, "", "VAD output file");
int main(int argc, char* argv[]) {
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true))
return 1;
absl::ParseCommandLine(argc, argv);
const std::string input_file = absl::GetFlag(FLAGS_i);
const std::string output_probs_file = absl::GetFlag(FLAGS_o_probs);
const std::string output_file = absl::GetFlag(FLAGS_o_rms);
// Open wav input file and check properties.
WavReader wav_reader(FLAG_i);
WavReader wav_reader(input_file);
if (wav_reader.num_channels() != 1) {
RTC_LOG(LS_ERROR) << "Only mono wav files supported";
return 1;
@ -51,8 +53,8 @@ int main(int argc, char* argv[]) {
}
// Create output file and write header.
std::ofstream out_probs_file(FLAG_o_probs, std::ofstream::binary);
std::ofstream out_rms_file(FLAG_o_rms, std::ofstream::binary);
std::ofstream out_probs_file(output_probs_file, std::ofstream::binary);
std::ofstream out_rms_file(output_file, std::ofstream::binary);
// Run VAD and write decisions.
VoiceActivityDetector vad;

View File

@ -11,11 +11,19 @@
#include <cmath>
#include <fstream>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "common_audio/include/audio_util.h"
#include "common_audio/wav_file.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
ABSL_FLAG(std::string, i, "", "Input wav file");
ABSL_FLAG(std::string, oc, "", "Config output file");
ABSL_FLAG(std::string, ol, "", "Levels output file");
ABSL_FLAG(float, a, 5.f, "Attack (ms)");
ABSL_FLAG(float, d, 20.f, "Decay (ms)");
ABSL_FLAG(int, f, 10, "Frame length (ms)");
namespace webrtc {
namespace test {
namespace {
@ -26,37 +34,24 @@ constexpr size_t kMaxFrameLen = kMaxFrameLenMs * kMaxSampleRate / 1000;
const double kOneDbReduction = DbToRatio(-1.0);
WEBRTC_DEFINE_string(i, "", "Input wav file");
WEBRTC_DEFINE_string(oc, "", "Config output file");
WEBRTC_DEFINE_string(ol, "", "Levels output file");
WEBRTC_DEFINE_float(a, 5.f, "Attack (ms)");
WEBRTC_DEFINE_float(d, 20.f, "Decay (ms)");
WEBRTC_DEFINE_int(f, 10, "Frame length (ms)");
WEBRTC_DEFINE_bool(help, false, "prints this message");
int main(int argc, char* argv[]) {
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
rtc::FlagList::Print(nullptr, false);
return 1;
}
if (FLAG_help) {
rtc::FlagList::Print(nullptr, false);
return 0;
}
absl::ParseCommandLine(argc, argv);
// Check parameters.
if (FLAG_f < 1 || FLAG_f > kMaxFrameLenMs) {
if (absl::GetFlag(FLAGS_f) < 1 || absl::GetFlag(FLAGS_f) > kMaxFrameLenMs) {
RTC_LOG(LS_ERROR) << "Invalid frame length (min: 1, max: " << kMaxFrameLenMs
<< ")";
return 1;
}
if (FLAG_a < 0 || FLAG_d < 0) {
if (absl::GetFlag(FLAGS_a) < 0 || absl::GetFlag(FLAGS_d) < 0) {
RTC_LOG(LS_ERROR) << "Attack and decay must be non-negative";
return 1;
}
// Open wav input file and check properties.
WavReader wav_reader(FLAG_i);
const std::string input_file = absl::GetFlag(FLAGS_i);
const std::string config_output_file = absl::GetFlag(FLAGS_oc);
const std::string levels_output_file = absl::GetFlag(FLAGS_ol);
WavReader wav_reader(input_file);
if (wav_reader.num_channels() != 1) {
RTC_LOG(LS_ERROR) << "Only mono wav files supported";
return 1;
@ -68,24 +63,26 @@ int main(int argc, char* argv[]) {
}
// Map from milliseconds to samples.
const size_t audio_frame_length =
rtc::CheckedDivExact(FLAG_f * wav_reader.sample_rate(), 1000);
const size_t audio_frame_length = rtc::CheckedDivExact(
absl::GetFlag(FLAGS_f) * wav_reader.sample_rate(), 1000);
auto time_const = [](double c) {
return std::pow(kOneDbReduction, FLAG_f / c);
return std::pow(kOneDbReduction, absl::GetFlag(FLAGS_f) / c);
};
const float attack = FLAG_a == 0.0 ? 0.0 : time_const(FLAG_a);
const float decay = FLAG_d == 0.0 ? 0.0 : time_const(FLAG_d);
const float attack =
absl::GetFlag(FLAGS_a) == 0.0 ? 0.0 : time_const(absl::GetFlag(FLAGS_a));
const float decay =
absl::GetFlag(FLAGS_d) == 0.0 ? 0.0 : time_const(absl::GetFlag(FLAGS_d));
// Write config to file.
std::ofstream out_config(FLAG_oc);
std::ofstream out_config(config_output_file);
out_config << "{"
<< "'frame_len_ms': " << FLAG_f << ", "
<< "'attack_ms': " << FLAG_a << ", "
<< "'decay_ms': " << FLAG_d << "}\n";
<< "'frame_len_ms': " << absl::GetFlag(FLAGS_f) << ", "
<< "'attack_ms': " << absl::GetFlag(FLAGS_a) << ", "
<< "'decay_ms': " << absl::GetFlag(FLAGS_d) << "}\n";
out_config.close();
// Measure level frame-by-frame.
std::ofstream out_levels(FLAG_ol, std::ofstream::binary);
std::ofstream out_levels(levels_output_file, std::ofstream::binary);
std::array<int16_t, kMaxFrameLen> samples;
float level_prev = 0.f;
while (true) {

View File

@ -10,11 +10,15 @@
#include <fstream>
#include <memory>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "common_audio/vad/include/vad.h"
#include "common_audio/wav_file.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
ABSL_FLAG(std::string, i, "", "Input wav file");
ABSL_FLAG(std::string, o, "", "VAD output file");
namespace webrtc {
namespace test {
namespace {
@ -27,15 +31,12 @@ constexpr size_t kMaxFrameLen =
constexpr uint8_t kBitmaskBuffSize = 8;
WEBRTC_DEFINE_string(i, "", "Input wav file");
WEBRTC_DEFINE_string(o, "", "VAD output file");
int main(int argc, char* argv[]) {
if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true))
return 1;
absl::ParseCommandLine(argc, argv);
const std::string input_file = absl::GetFlag(FLAGS_i);
const std::string output_file = absl::GetFlag(FLAGS_o);
// Open wav input file and check properties.
WavReader wav_reader(FLAG_i);
WavReader wav_reader(input_file);
if (wav_reader.num_channels() != 1) {
RTC_LOG(LS_ERROR) << "Only mono wav files supported";
return 1;
@ -53,7 +54,7 @@ int main(int argc, char* argv[]) {
}
// Create output file and write header.
std::ofstream out_file(FLAG_o, std::ofstream::binary);
std::ofstream out_file(output_file, std::ofstream::binary);
const char audio_frame_length_ms = kAudioFrameLengthMilliseconds;
out_file.write(&audio_frame_length_ms, 1); // Header.