Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ | |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ | |
| 13 | |
| 14 #include <stddef.h> // size_t | |
| 15 #include <string> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 #include "webrtc/base/scoped_ptr.h" | |
| 20 #include "webrtc/common_audio/channel_buffer.h" | |
| 21 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" | |
| 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" | |
| 23 | |
| 24 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
| 25 #include "webrtc/audio_processing/debug.pb.h" | |
| 26 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | |
| 27 | |
| 28 namespace webrtc { | |
| 29 namespace test { | |
| 30 | |
| 31 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
| |
| 32 public: | |
| 33 DebugDumpGenerator(std::string input_file_name, | |
| 34 int input_file_rate_hz, | |
| 35 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.
| |
| 36 std::string reverse_file_name, | |
| 37 int reverse_file_rate_hz, | |
| 38 size_t reverse_channels, | |
| 39 const Config& config, | |
| 40 std::string dump_file_name); | |
| 41 | |
| 42 // Changes the sample rate of the input audio to the APM. | |
| 43 void SetInputRate(int rate_hz); | |
| 44 | |
| 45 // Sets if converts stereo input signal to mono by discarding other channels. | |
| 46 void ForceInputMono(bool mono); | |
| 47 | |
| 48 // Changes the sample rate of the reverse audio to the APM. | |
| 49 void SetReverseRate(int rate_hz); | |
| 50 | |
| 51 // Sets if converts stereo reverse signal to mono by discarding other | |
| 52 // channels. | |
| 53 void ForceReverseMono(bool mono); | |
| 54 | |
| 55 // Sets the required sample rate of the APM output. | |
| 56 void set_output_rate_hz(int rate_hz) { | |
| 57 output_rate_hz_ = rate_hz; | |
| 58 } | |
| 59 | |
| 60 // Sets the required channels of the APM output. | |
| 61 void set_output_channels(int channels) { | |
| 62 output_channels_ = channels; | |
| 63 } | |
| 64 | |
| 65 void StartRecording(); | |
| 66 void Process(size_t num_blocks); | |
| 67 void StopRecording(); | |
| 68 AudioProcessing* apm() const { return apm_.get(); } | |
| 69 | |
| 70 private: | |
| 71 void ReadAndDeinterleave(ResampleInputAudioFile* audio, size_t channels, | |
| 72 size_t frames_per_channel, bool force_mono, | |
| 73 float* const* buffer); | |
| 74 | |
| 75 // APM input/output settings. | |
| 76 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
| |
| 77 bool input_mono_; | |
| 78 int reverse_rate_hz_; | |
| 79 bool reverse_mono_; | |
| 80 int output_rate_hz_; | |
| 81 size_t output_channels_; | |
| 82 | |
| 83 // Input file format. | |
| 84 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.
| |
| 85 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
| |
| 86 | |
| 87 // Reverse file format. | |
| 88 rtc::scoped_ptr<ResampleInputAudioFile> reverse_audio_; | |
| 89 size_t reverse_channels_; | |
| 90 | |
| 91 // Buffer for APM input/output. | |
| 92 rtc::scoped_ptr<ChannelBuffer<float>> input_; | |
| 93 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; | |
| 94 rtc::scoped_ptr<ChannelBuffer<float>> output_; | |
| 95 | |
| 96 rtc::scoped_ptr<AudioProcessing> apm_; | |
| 97 | |
| 98 std::string dump_file_name_; | |
|
Andrew MacDonald
2015/10/20 01:22:09
const
minyue-webrtc
2015/10/23 08:44:46
Done.
| |
| 99 | |
| 100 // Buffer for reading audio files. | |
| 101 std::vector<int16_t> signal_; | |
| 102 }; | |
| 103 | |
| 104 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.
| |
| 105 public: | |
| 106 DebugDumpTest(); | |
| 107 | |
| 108 // VerifyDebugDump replays a debug dump using APM and verifies that the result | |
| 109 // is bit-exact identical to the output channel in the dump. This is only | |
| 110 // guaranteed if the debug dump is started on the first frame. | |
| 111 void VerifyDebugDump(std::string dump_file_name); | |
| 112 | |
| 113 private: | |
| 114 // Following functions are facilities for replaying debug dumps. | |
| 115 void OnInitEvent(const audioproc::Init& msg); | |
| 116 void OnStreamEvent(const audioproc::Stream& msg); | |
| 117 void OnReverseStreamEvent(const audioproc::ReverseStream& msg); | |
| 118 void OnConfigEvent(const audioproc::Config& msg); | |
| 119 void MaybeRecreateApm(const audioproc::Config& msg); | |
| 120 void ConfigurateApm(const audioproc::Config& msg); | |
| 121 | |
| 122 int input_rate_hz_; | |
| 123 size_t input_channels_; | |
| 124 | |
| 125 int output_rate_hz_; | |
| 126 size_t output_channels_; | |
| 127 | |
| 128 int reverse_rate_hz_; | |
| 129 size_t reverse_channels_; | |
| 130 | |
| 131 // Buffer for APM input/output. | |
| 132 rtc::scoped_ptr<ChannelBuffer<float>> input_; | |
| 133 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; | |
| 134 rtc::scoped_ptr<ChannelBuffer<float>> output_; | |
| 135 | |
| 136 rtc::scoped_ptr<AudioProcessing> apm_; | |
| 137 }; | |
| 138 | |
| 139 } // namespace test | |
| 140 } // namespace webrtc | |
| 141 | |
| 142 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_DEBUG_DUMP_TEST_H_ | |
| OLD | NEW |