OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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_LOGGING_APM_DATA_DUMPER_H_ | |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ | |
13 | |
14 #include <stdio.h> | |
15 | |
16 #include <map> | |
17 #include <string> | |
18 | |
19 #include "webrtc/base/array_view.h" | |
20 #include "webrtc/base/constructormagic.h" | |
21 #include "webrtc/common_audio/wav_file.h" | |
22 | |
23 // Check to verify that the define is properly set. | |
24 #if !defined(WEBRTC_AEC_DEBUG_DUMP) || \ | |
25 (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1) | |
26 #error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1" | |
27 #endif | |
28 | |
29 namespace webrtc { | |
30 | |
31 // Class that handles dumping of variables into files. | |
32 class ApmDataDumper { | |
33 public: | |
34 // Constructor that takes an instance index that may | |
35 // be used to distinguish data dumped from different | |
36 // instances of the code. | |
37 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
38 explicit ApmDataDumper(int instance_index) | |
39 : instance_index_(instance_index) {} | |
40 #else | |
41 explicit ApmDataDumper(int instance_index) {} | |
42 #endif | |
43 | |
44 ~ApmDataDumper(); | |
45 | |
46 // Reinitializes the data dumping such that new versions | |
47 // of all files being dumped to are created. | |
48 void InitiateNewSetOfRecordings() { | |
49 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
50 ++recording_set_index_; | |
51 #endif | |
52 } | |
53 | |
54 // Methods for performing dumping of data of various types into | |
55 // various formats. | |
56 void DumpRaw(const std::string& name, int v_length, const float* v) { | |
57 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
58 FILE* file = GetRawFile(name); | |
59 fwrite(v, sizeof(v[0]), v_length, file); | |
60 #endif | |
61 } | |
62 | |
63 void DumpRaw(const std::string& name, rtc::ArrayView<const float> v) { | |
64 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
65 DumpRaw(name, v.size(), v.data()); | |
66 #endif | |
67 } | |
68 | |
69 void DumpWav(const std::string& name, | |
70 int v_length, | |
71 const float* v, | |
72 int sample_rate_hz, | |
73 int num_channels) { | |
74 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
75 WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels); | |
76 file->WriteSamples(v, v_length); | |
77 #endif | |
78 } | |
79 | |
80 void DumpMonoWav(const std::string& name, | |
kwiberg-webrtc
2016/05/03 00:53:01
What's mono about this method?
peah-webrtc
2016/05/03 06:29:22
Nothing, that should be removed.
Done.
| |
81 rtc::ArrayView<const float> v, | |
82 int sample_rate_hz, | |
83 int num_channels) { | |
84 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
85 DumpWav(name, v.size(), v.data(), sample_rate_hz, num_channels); | |
86 #endif | |
87 } | |
88 | |
89 private: | |
90 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
91 const int instance_index_; | |
92 int recording_set_index_ = 0; | |
93 std::map<std::string, FILE*> raw_files_; | |
94 std::map<std::string, WavWriter*> wav_files_; | |
kwiberg-webrtc
2016/05/03 00:53:01
As far as I can tell, these two maps own their val
peah-webrtc
2016/05/03 06:29:22
Great! Nice!!! I ended up with a functor as a cust
| |
95 | |
96 FILE* GetRawFile(const std::string& name); | |
97 WavWriter* GetWavFile(const std::string& name, | |
98 int sample_rate_hz, | |
99 int num_channels); | |
100 #endif | |
101 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ApmDataDumper); | |
102 }; | |
103 | |
104 } // namespace webrtc | |
105 | |
106 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ | |
OLD | NEW |