Index: webrtc/modules/audio_processing/test/debug_dump_test.h |
diff --git a/webrtc/modules/audio_processing/test/debug_dump_test.h b/webrtc/modules/audio_processing/test/debug_dump_test.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a3b2ca13fd512090a6a5f5572ea731407e4cbf36 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/test/debug_dump_test.h |
@@ -0,0 +1,142 @@ |
+/* |
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ |
+#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ |
+ |
+#include <stddef.h> // size_t |
+#include <string> |
+#include <vector> |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "webrtc/base/scoped_ptr.h" |
+#include "webrtc/common_audio/channel_buffer.h" |
+#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
+#include "webrtc/modules/audio_processing/include/audio_processing.h" |
+ |
+#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
+#include "webrtc/audio_processing/debug.pb.h" |
+#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
+ |
+namespace webrtc { |
+namespace test { |
+ |
+class DebugDumpGenerator { |
Andrew MacDonald
2015/10/20 01:22:09
Do you foresee anything else ever using this? If n
minyue-webrtc
2015/10/23 08:44:46
I thought that cc is too large and therefore put t
|
+ public: |
+ DebugDumpGenerator(std::string input_file_name, |
+ int input_file_rate_hz, |
+ size_t input_channels, |
Andrew MacDonald
2015/10/20 01:22:09
Since these values are ints in the protobuf genera
minyue-webrtc
2015/10/23 08:44:46
Done.
|
+ std::string reverse_file_name, |
+ int reverse_file_rate_hz, |
+ size_t reverse_channels, |
+ const Config& config, |
+ std::string dump_file_name); |
+ |
+ // Changes the sample rate of the input audio to the APM. |
+ void SetInputRate(int rate_hz); |
+ |
+ // Sets if converts stereo input signal to mono by discarding other channels. |
+ void ForceInputMono(bool mono); |
+ |
+ // Changes the sample rate of the reverse audio to the APM. |
+ void SetReverseRate(int rate_hz); |
+ |
+ // Sets if converts stereo reverse signal to mono by discarding other |
+ // channels. |
+ void ForceReverseMono(bool mono); |
+ |
+ // Sets the required sample rate of the APM output. |
+ void set_output_rate_hz(int rate_hz) { |
+ output_rate_hz_ = rate_hz; |
+ } |
+ |
+ // Sets the required channels of the APM output. |
+ void set_output_channels(int channels) { |
+ output_channels_ = channels; |
+ } |
+ |
+ void StartRecording(); |
+ void Process(size_t num_blocks); |
+ void StopRecording(); |
+ AudioProcessing* apm() const { return apm_.get(); } |
+ |
+ private: |
+ void ReadAndDeinterleave(ResampleInputAudioFile* audio, size_t channels, |
+ size_t frames_per_channel, bool force_mono, |
+ float* const* buffer); |
+ |
+ // APM input/output settings. |
+ int input_rate_hz_; |
Andrew MacDonald
2015/10/20 01:22:09
Can any of these be const?
minyue-webrtc
2015/10/23 08:44:46
No. We want to change sample rate in the middle, t
|
+ bool input_mono_; |
+ int reverse_rate_hz_; |
+ bool reverse_mono_; |
+ int output_rate_hz_; |
+ size_t output_channels_; |
+ |
+ // Input file format. |
+ rtc::scoped_ptr<ResampleInputAudioFile> input_audio_; |
Andrew MacDonald
2015/10/20 01:22:09
You initialize the ResampleInputAudioFiles in the
minyue-webrtc
2015/10/23 08:44:46
Done.
|
+ size_t input_channels_; |
Andrew MacDonald
2015/10/20 01:22:09
const?
minyue-webrtc
2015/10/23 08:44:46
Yes, this can be const
|
+ |
+ // Reverse file format. |
+ rtc::scoped_ptr<ResampleInputAudioFile> reverse_audio_; |
+ size_t reverse_channels_; |
+ |
+ // Buffer for APM input/output. |
+ rtc::scoped_ptr<ChannelBuffer<float>> input_; |
+ rtc::scoped_ptr<ChannelBuffer<float>> reverse_; |
+ rtc::scoped_ptr<ChannelBuffer<float>> output_; |
+ |
+ rtc::scoped_ptr<AudioProcessing> apm_; |
+ |
+ std::string dump_file_name_; |
Andrew MacDonald
2015/10/20 01:22:09
const
minyue-webrtc
2015/10/23 08:44:46
Done.
|
+ |
+ // Buffer for reading audio files. |
+ std::vector<int16_t> signal_; |
+}; |
+ |
+class DebugDumpTest : public ::testing::Test { |
Andrew MacDonald
2015/10/20 01:22:09
This should definitely go in the cc file.
minyue-webrtc
2015/10/23 08:44:46
Done.
|
+ public: |
+ DebugDumpTest(); |
+ |
+ // VerifyDebugDump replays a debug dump using APM and verifies that the result |
+ // is bit-exact identical to the output channel in the dump. This is only |
+ // guaranteed if the debug dump is started on the first frame. |
+ void VerifyDebugDump(std::string dump_file_name); |
+ |
+ private: |
+ // Following functions are facilities for replaying debug dumps. |
+ void OnInitEvent(const audioproc::Init& msg); |
+ void OnStreamEvent(const audioproc::Stream& msg); |
+ void OnReverseStreamEvent(const audioproc::ReverseStream& msg); |
+ void OnConfigEvent(const audioproc::Config& msg); |
+ void MaybeRecreateApm(const audioproc::Config& msg); |
+ void ConfigurateApm(const audioproc::Config& msg); |
+ |
+ int input_rate_hz_; |
+ size_t input_channels_; |
+ |
+ int output_rate_hz_; |
+ size_t output_channels_; |
+ |
+ int reverse_rate_hz_; |
+ size_t reverse_channels_; |
+ |
+ // Buffer for APM input/output. |
+ rtc::scoped_ptr<ChannelBuffer<float>> input_; |
+ rtc::scoped_ptr<ChannelBuffer<float>> reverse_; |
+ rtc::scoped_ptr<ChannelBuffer<float>> output_; |
+ |
+ rtc::scoped_ptr<AudioProcessing> apm_; |
+}; |
+ |
+} // namespace test |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ |