diff options
author | Chih-hung Hsieh <chh@google.com> | 2016-01-20 17:50:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-01-20 17:50:13 +0000 |
commit | b3cb8ab4ede8bb77f0bdef2715efc2c1e6267072 (patch) | |
tree | 28c4cf735dd5bd9cc8f1ccd06fff8a173b20d1cb /webrtc/modules/audio_processing/test/audioproc_float.cc | |
parent | a4acd9d6bc9b3b033d7d274316e75ee067df8d20 (diff) | |
parent | 9a337512d97e37afc142dee4fd50a41b741a87d2 (diff) | |
download | webrtc-nougat-mr0.5-release.tar.gz |
Merge "Merge upstream SHA 04cb763"android-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-cts-7.0_r9android-cts-7.0_r8android-cts-7.0_r7android-cts-7.0_r6android-cts-7.0_r5android-cts-7.0_r4android-cts-7.0_r33android-cts-7.0_r32android-cts-7.0_r31android-cts-7.0_r30android-cts-7.0_r3android-cts-7.0_r29android-cts-7.0_r28android-cts-7.0_r27android-cts-7.0_r26android-cts-7.0_r25android-cts-7.0_r24android-cts-7.0_r23android-cts-7.0_r22android-cts-7.0_r21android-cts-7.0_r20android-cts-7.0_r2android-cts-7.0_r19android-cts-7.0_r18android-cts-7.0_r17android-cts-7.0_r16android-cts-7.0_r15android-cts-7.0_r14android-cts-7.0_r13android-cts-7.0_r12android-cts-7.0_r11android-cts-7.0_r10android-cts-7.0_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1android-7.0.0_r9android-7.0.0_r8android-7.0.0_r7android-7.0.0_r6android-7.0.0_r5android-7.0.0_r4android-7.0.0_r36android-7.0.0_r35android-7.0.0_r34android-7.0.0_r33android-7.0.0_r32android-7.0.0_r31android-7.0.0_r30android-7.0.0_r3android-7.0.0_r29android-7.0.0_r28android-7.0.0_r27android-7.0.0_r24android-7.0.0_r21android-7.0.0_r19android-7.0.0_r17android-7.0.0_r15android-7.0.0_r14android-7.0.0_r13android-7.0.0_r12android-7.0.0_r11android-7.0.0_r10android-7.0.0_r1nougat-releasenougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-mr0.5-releasenougat-dr1-releasenougat-devnougat-cts-releasenougat-bugfix-release
am: 9a337512d9
* commit '9a337512d97e37afc142dee4fd50a41b741a87d2': (797 commits)
Add tests for verifying transport feedback for audio and video.
Eliminate defines in talk/
Revert of Update with new default boringssl no-aes cipher suites. Re-enable tests. (patchset #3 id:40001 of https://codereview.webrtc.org/1550773002/ )
Remove assert which was incorrectly added to TcpPort::OnSentPacket.
Reland Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Update with new default boringssl no-aes cipher suites. Re-enable tests.
Revert of Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket. (patchset #3 id:40001 of https://codereview.webrtc.org/1577873003/ )
Re-land: "Use an explicit identifier in Config"
Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Revert of Delete remnants of non-square pixel support from cricket::VideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/1586613002/ )
Remove libfuzzer trybot from default trybot set.
Add ramp-up tests for transport sequence number with and w/o audio.
Delete remnants of non-square pixel support from cricket::VideoFrame.
Fix IPAddress::ToSensitiveString() to avoid dependency on inet_ntop().
Revert of Storing raw audio sink for default audio track. (patchset #7 id:120001 of https://codereview.chromium.org/1551813002/ )
Re-enable tests that failed under Linux_Msan.
Revert of Use an explicit identifier in Config (patchset #4 id:60001 of https://codereview.webrtc.org/1538643004/ )
Roll chromium_revision 346fea9..099be58 (369082:369139)
Disable WebRtcVideoChannel2BaseTest.SendManyResizeOnce for TSan
Add build_protobuf variable.
...
Diffstat (limited to 'webrtc/modules/audio_processing/test/audioproc_float.cc')
-rw-r--r-- | webrtc/modules/audio_processing/test/audioproc_float.cc | 217 |
1 files changed, 70 insertions, 147 deletions
diff --git a/webrtc/modules/audio_processing/test/audioproc_float.cc b/webrtc/modules/audio_processing/test/audioproc_float.cc index 811e9070fa..a489d255c8 100644 --- a/webrtc/modules/audio_processing/test/audioproc_float.cc +++ b/webrtc/modules/audio_processing/test/audioproc_float.cc @@ -9,35 +9,50 @@ */ #include <stdio.h> +#include <iostream> #include <sstream> #include <string> +#include <utility> #include "gflags/gflags.h" #include "webrtc/base/checks.h" +#include "webrtc/base/format_macros.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_audio/channel_buffer.h" #include "webrtc/common_audio/wav_file.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" +#include "webrtc/modules/audio_processing/test/audio_file_processor.h" #include "webrtc/modules/audio_processing/test/protobuf_utils.h" #include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/trace_to_stderr.h" -DEFINE_string(dump, "", "The name of the debug dump file to read from."); -DEFINE_string(i, "", "The name of the input file to read from."); -DEFINE_string(i_rev, "", "The name of the reverse input file to read from."); -DEFINE_string(o, "out.wav", "Name of the output file to write to."); -DEFINE_string(o_rev, - "out_rev.wav", - "Name of the reverse output file to write to."); -DEFINE_int32(out_channels, 0, "Number of output channels. Defaults to input."); -DEFINE_int32(out_sample_rate, 0, - "Output sample rate in Hz. Defaults to input."); +namespace { + +bool ValidateOutChannels(const char* flagname, int32_t value) { + return value >= 0; +} + +} // namespace + +DEFINE_string(dump, "", "Name of the aecdump debug file to read from."); +DEFINE_string(i, "", "Name of the capture input stream file to read from."); +DEFINE_string( + o, + "out.wav", + "Name of the output file to write the processed capture stream to."); +DEFINE_int32(out_channels, 1, "Number of output channels."); +const bool out_channels_dummy = + google::RegisterFlagValidator(&FLAGS_out_channels, &ValidateOutChannels); +DEFINE_int32(out_sample_rate, 48000, "Output sample rate in Hz."); DEFINE_string(mic_positions, "", "Space delimited cartesian coordinates of microphones in meters. " "The coordinates of each point are contiguous. " "For a two element array: \"x1 y1 z1 x2 y2 z2\""); -DEFINE_double(target_angle_degrees, 90, "The azimuth of the target in radians"); +DEFINE_double( + target_angle_degrees, + 90, + "The azimuth of the target in degrees. Only applies to beamforming."); DEFINE_bool(aec, false, "Enable echo cancellation."); DEFINE_bool(agc, false, "Enable automatic gain control."); @@ -64,15 +79,6 @@ const char kUsage[] = "All components are disabled by default. If any bi-directional components\n" "are enabled, only debug dump files are permitted."; -// Returns a StreamConfig corresponding to wav_file if it's non-nullptr. -// Otherwise returns a default initialized StreamConfig. -StreamConfig MakeStreamConfig(const WavFile* wav_file) { - if (wav_file) { - return {wav_file->sample_rate(), wav_file->num_channels()}; - } - return {}; -} - } // namespace int main(int argc, char* argv[]) { @@ -84,158 +90,75 @@ int main(int argc, char* argv[]) { "An input file must be specified with either -i or -dump.\n"); return 1; } - if (!FLAGS_dump.empty()) { - fprintf(stderr, "FIXME: the -dump option is not yet implemented.\n"); + if (FLAGS_dump.empty() && (FLAGS_aec || FLAGS_ie)) { + fprintf(stderr, "-aec and -ie require a -dump file.\n"); + return 1; + } + if (FLAGS_ie) { + fprintf(stderr, + "FIXME(ajm): The intelligibility enhancer output is not dumped.\n"); return 1; } test::TraceToStderr trace_to_stderr(true); - WavReader in_file(FLAGS_i); - // If the output format is uninitialized, use the input format. - const int out_channels = - FLAGS_out_channels ? FLAGS_out_channels : in_file.num_channels(); - const int out_sample_rate = - FLAGS_out_sample_rate ? FLAGS_out_sample_rate : in_file.sample_rate(); - WavWriter out_file(FLAGS_o, out_sample_rate, out_channels); - Config config; - config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); - config.Set<Intelligibility>(new Intelligibility(FLAGS_ie || FLAGS_all)); - if (FLAGS_bf || FLAGS_all) { - const size_t num_mics = in_file.num_channels(); - const std::vector<Point> array_geometry = - ParseArrayGeometry(FLAGS_mic_positions, num_mics); - RTC_CHECK_EQ(array_geometry.size(), num_mics); - + if (FLAGS_mic_positions.empty()) { + fprintf(stderr, "-mic_positions must be specified when -bf is used.\n"); + return 1; + } config.Set<Beamforming>(new Beamforming( - true, array_geometry, + true, ParseArrayGeometry(FLAGS_mic_positions), SphericalPointf(DegreesToRadians(FLAGS_target_angle_degrees), 0.f, 1.f))); } + config.Set<ExperimentalNs>(new ExperimentalNs(FLAGS_ts || FLAGS_all)); + config.Set<Intelligibility>(new Intelligibility(FLAGS_ie || FLAGS_all)); rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create(config)); - if (!FLAGS_dump.empty()) { - RTC_CHECK_EQ(kNoErr, - ap->echo_cancellation()->Enable(FLAGS_aec || FLAGS_all)); - } else if (FLAGS_aec) { - fprintf(stderr, "-aec requires a -dump file.\n"); - return -1; - } - bool process_reverse = !FLAGS_i_rev.empty(); + RTC_CHECK_EQ(kNoErr, ap->echo_cancellation()->Enable(FLAGS_aec || FLAGS_all)); RTC_CHECK_EQ(kNoErr, ap->gain_control()->Enable(FLAGS_agc || FLAGS_all)); - RTC_CHECK_EQ(kNoErr, - ap->gain_control()->set_mode(GainControl::kFixedDigital)); RTC_CHECK_EQ(kNoErr, ap->high_pass_filter()->Enable(FLAGS_hpf || FLAGS_all)); RTC_CHECK_EQ(kNoErr, ap->noise_suppression()->Enable(FLAGS_ns || FLAGS_all)); - if (FLAGS_ns_level != -1) + if (FLAGS_ns_level != -1) { RTC_CHECK_EQ(kNoErr, ap->noise_suppression()->set_level( static_cast<NoiseSuppression::Level>(FLAGS_ns_level))); - - printf("Input file: %s\nChannels: %d, Sample rate: %d Hz\n\n", - FLAGS_i.c_str(), in_file.num_channels(), in_file.sample_rate()); - printf("Output file: %s\nChannels: %d, Sample rate: %d Hz\n\n", - FLAGS_o.c_str(), out_file.num_channels(), out_file.sample_rate()); - - ChannelBuffer<float> in_buf( - rtc::CheckedDivExact(in_file.sample_rate(), kChunksPerSecond), - in_file.num_channels()); - ChannelBuffer<float> out_buf( - rtc::CheckedDivExact(out_file.sample_rate(), kChunksPerSecond), - out_file.num_channels()); - - std::vector<float> in_interleaved(in_buf.size()); - std::vector<float> out_interleaved(out_buf.size()); - - rtc::scoped_ptr<WavReader> in_rev_file; - rtc::scoped_ptr<WavWriter> out_rev_file; - rtc::scoped_ptr<ChannelBuffer<float>> in_rev_buf; - rtc::scoped_ptr<ChannelBuffer<float>> out_rev_buf; - std::vector<float> in_rev_interleaved; - std::vector<float> out_rev_interleaved; - if (process_reverse) { - in_rev_file.reset(new WavReader(FLAGS_i_rev)); - out_rev_file.reset(new WavWriter(FLAGS_o_rev, in_rev_file->sample_rate(), - in_rev_file->num_channels())); - printf("In rev file: %s\nChannels: %d, Sample rate: %d Hz\n\n", - FLAGS_i_rev.c_str(), in_rev_file->num_channels(), - in_rev_file->sample_rate()); - printf("Out rev file: %s\nChannels: %d, Sample rate: %d Hz\n\n", - FLAGS_o_rev.c_str(), out_rev_file->num_channels(), - out_rev_file->sample_rate()); - in_rev_buf.reset(new ChannelBuffer<float>( - rtc::CheckedDivExact(in_rev_file->sample_rate(), kChunksPerSecond), - in_rev_file->num_channels())); - in_rev_interleaved.resize(in_rev_buf->size()); - out_rev_buf.reset(new ChannelBuffer<float>( - rtc::CheckedDivExact(out_rev_file->sample_rate(), kChunksPerSecond), - out_rev_file->num_channels())); - out_rev_interleaved.resize(out_rev_buf->size()); + } + ap->set_stream_key_pressed(FLAGS_ts); + + rtc::scoped_ptr<AudioFileProcessor> processor; + auto out_file = rtc_make_scoped_ptr(new WavWriter( + FLAGS_o, FLAGS_out_sample_rate, static_cast<size_t>(FLAGS_out_channels))); + std::cout << FLAGS_o << ": " << out_file->FormatAsString() << std::endl; + if (FLAGS_dump.empty()) { + auto in_file = rtc_make_scoped_ptr(new WavReader(FLAGS_i)); + std::cout << FLAGS_i << ": " << in_file->FormatAsString() << std::endl; + processor.reset(new WavFileProcessor(std::move(ap), std::move(in_file), + std::move(out_file))); + + } else { + processor.reset(new AecDumpFileProcessor( + std::move(ap), fopen(FLAGS_dump.c_str(), "rb"), std::move(out_file))); } - TickTime processing_start_time; - TickInterval accumulated_time; int num_chunks = 0; - - const auto input_config = MakeStreamConfig(&in_file); - const auto output_config = MakeStreamConfig(&out_file); - const auto reverse_input_config = MakeStreamConfig(in_rev_file.get()); - const auto reverse_output_config = MakeStreamConfig(out_rev_file.get()); - - while (in_file.ReadSamples(in_interleaved.size(), - &in_interleaved[0]) == in_interleaved.size()) { - // Have logs display the file time rather than wallclock time. + while (processor->ProcessChunk()) { trace_to_stderr.SetTimeSeconds(num_chunks * 1.f / kChunksPerSecond); - FloatS16ToFloat(&in_interleaved[0], in_interleaved.size(), - &in_interleaved[0]); - Deinterleave(&in_interleaved[0], in_buf.num_frames(), - in_buf.num_channels(), in_buf.channels()); - if (process_reverse) { - in_rev_file->ReadSamples(in_rev_interleaved.size(), - in_rev_interleaved.data()); - FloatS16ToFloat(in_rev_interleaved.data(), in_rev_interleaved.size(), - in_rev_interleaved.data()); - Deinterleave(in_rev_interleaved.data(), in_rev_buf->num_frames(), - in_rev_buf->num_channels(), in_rev_buf->channels()); - } - - if (FLAGS_perf) { - processing_start_time = TickTime::Now(); - } - RTC_CHECK_EQ(kNoErr, ap->ProcessStream(in_buf.channels(), input_config, - output_config, out_buf.channels())); - if (process_reverse) { - RTC_CHECK_EQ(kNoErr, ap->ProcessReverseStream( - in_rev_buf->channels(), reverse_input_config, - reverse_output_config, out_rev_buf->channels())); - } - if (FLAGS_perf) { - accumulated_time += TickTime::Now() - processing_start_time; - } - - Interleave(out_buf.channels(), out_buf.num_frames(), - out_buf.num_channels(), &out_interleaved[0]); - FloatToFloatS16(&out_interleaved[0], out_interleaved.size(), - &out_interleaved[0]); - out_file.WriteSamples(&out_interleaved[0], out_interleaved.size()); - if (process_reverse) { - Interleave(out_rev_buf->channels(), out_rev_buf->num_frames(), - out_rev_buf->num_channels(), out_rev_interleaved.data()); - FloatToFloatS16(out_rev_interleaved.data(), out_rev_interleaved.size(), - out_rev_interleaved.data()); - out_rev_file->WriteSamples(out_rev_interleaved.data(), - out_rev_interleaved.size()); - } - num_chunks++; + ++num_chunks; } + if (FLAGS_perf) { - int64_t execution_time_ms = accumulated_time.Milliseconds(); - printf("\nExecution time: %.3f s\nFile time: %.2f s\n" - "Time per chunk: %.3f ms\n", - execution_time_ms * 0.001f, num_chunks * 1.f / kChunksPerSecond, - execution_time_ms * 1.f / num_chunks); + const auto& proc_time = processor->proc_time(); + int64_t exec_time_us = proc_time.sum.Microseconds(); + printf( + "\nExecution time: %.3f s, File time: %.2f s\n" + "Time per chunk (mean, max, min):\n%.0f us, %.0f us, %.0f us\n", + exec_time_us * 1e-6, num_chunks * 1.f / kChunksPerSecond, + exec_time_us * 1.f / num_chunks, 1.f * proc_time.max.Microseconds(), + 1.f * proc_time.min.Microseconds()); } + return 0; } |