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 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
12 | |
13 namespace webrtc { | |
14 namespace { | |
15 | |
16 std::string FormRawFileName(std::string name, | |
hlundin-webrtc
2016/04/11 11:58:29
const std::string&
kwiberg-webrtc
2016/04/11 12:59:11
+1. Good point.
peah-webrtc
2016/04/12 21:46:38
Good find!
Done.
peah-webrtc
2016/04/12 21:46:38
Acknowledged.
| |
17 int instance_index, | |
18 int reinit_index) { | |
19 return name + "_" + std::to_string(instance_index) + "-" + | |
hlundin-webrtc
2016/04/11 11:58:29
std::to_string is currently not allowed in Chrome.
peah-webrtc
2016/04/12 21:46:39
Ah, great find! Too bad. Will do this in another w
| |
20 std::to_string(reinit_index) + ".dat"; | |
21 } | |
22 | |
23 std::string FormWavFileName(std::string name, | |
24 int instance_index, | |
25 int reinit_index) { | |
26 return name + "_" + std::to_string(instance_index) + "-" + | |
27 std::to_string(reinit_index) + ".wav"; | |
28 } | |
kwiberg-webrtc
2016/04/11 10:43:37
You can probably unify these two.
hlundin-webrtc
2016/04/11 11:58:29
Agree. I see (at least) two options:
1. std::strin
peah-webrtc
2016/04/12 21:46:38
Done.
peah-webrtc
2016/04/12 21:46:38
Done.
| |
29 | |
30 } // namespace | |
31 | |
32 void ApmDataDumper::Initialize() { | |
33 ++reinit_counter_; | |
34 } | |
35 | |
36 ApmDataDumper::~ApmDataDumper() { | |
37 #ifdef WEBRTC_AEC_DEBUG_DUMP | |
38 for (auto& raw_files_element : raw_files_) { | |
39 FILE** file = &raw_files_element.second; | |
hlundin-webrtc
2016/04/11 11:58:29
Can you not just call
fclose(raw_files_element.sec
peah-webrtc
2016/04/12 21:46:38
True.
Done.
| |
40 fclose(*file); | |
41 } | |
42 | |
43 for (auto& wav_files_element : wav_files_) { | |
44 rtc_WavWriter** file = &wav_files_element.second; | |
hlundin-webrtc
2016/04/11 11:58:29
Similar as above?
peah-webrtc
2016/04/12 21:46:38
Done.
| |
45 rtc_WavClose(*file); | |
46 } | |
47 #endif | |
48 } | |
49 | |
50 FILE* ApmDataDumper::GetRawFile(const std::string& name) { | |
51 std::string filename = | |
52 FormRawFileName(name, instance_index_, reinit_counter_); | |
53 auto search = raw_files_.find(filename); | |
54 if (search != raw_files_.end()) { | |
55 return search->second; | |
56 } | |
57 FILE* file = fopen(filename.c_str(), "wb"); | |
58 raw_files_[filename] = file; | |
59 return file; | |
60 } | |
61 | |
62 rtc_WavWriter* ApmDataDumper::GetWavFile(const std::string& name, | |
63 int sample_rate_hz) { | |
64 std::string filename = | |
65 FormWavFileName(name, instance_index_, reinit_counter_); | |
66 auto search = wav_files_.find(filename); | |
67 if (search != wav_files_.end()) { | |
68 return search->second; | |
69 } | |
70 rtc_WavWriter* file = rtc_WavOpen(filename.c_str(), sample_rate_hz, 1); | |
71 wav_files_[filename] = file; | |
72 return file; | |
73 } | |
74 | |
75 void ApmDataDumper::DumpRaw(const std::string& name, | |
76 rtc::ArrayView<const float> v) { | |
hlundin-webrtc
2016/04/11 11:58:29
Is "pass-by-value" just as good as passing const r
kwiberg-webrtc
2016/04/11 12:59:11
Yes (ArrayView is just a pointer + a length), and
peah-webrtc
2016/04/12 21:46:38
Acknowledged.
peah-webrtc
2016/04/12 21:46:39
Acknowledged.
| |
77 #ifdef WEBRTC_AEC_DEBUG_DUMP | |
78 FILE* file = GetRawFile(name); | |
79 fwrite(v.data(), sizeof(v[0]), v.size(), file); | |
kwiberg-webrtc
2016/04/11 10:43:36
Do floats suffer from the same endian problems as
peah-webrtc
2016/04/12 21:46:39
Yes, they do suffer from the same problem. But I d
| |
80 #endif | |
81 } | |
82 | |
83 void ApmDataDumper::DumpRaw(const std::string& name, int v_length, float* v) { | |
hlundin-webrtc
2016/04/11 11:58:28
const float* v
hlundin-webrtc
2016/04/11 11:58:29
Order of methods should be the same in h and cpp f
peah-webrtc
2016/04/12 21:46:39
Good point! I now anyway moved these to the header
peah-webrtc
2016/04/12 21:46:39
Done.
| |
84 #ifdef WEBRTC_AEC_DEBUG_DUMP | |
85 FILE* file = GetRawFile(name); | |
86 fwrite(v, sizeof(v[0]), v_length, file); | |
87 #endif | |
kwiberg-webrtc
2016/04/11 10:43:37
Implement one DumpRaw in terms of the other?
hlundin-webrtc
2016/04/11 11:58:29
Acknowledged.
peah-webrtc
2016/04/12 21:46:39
Done.
peah-webrtc
2016/04/12 21:46:39
Done.
| |
88 } | |
89 | |
90 void ApmDataDumper::DumpWav(const std::string& name, | |
91 rtc::ArrayView<const float> v, | |
92 int sample_rate_hz) { | |
93 #ifdef WEBRTC_AEC_DEBUG_DUMP | |
94 rtc_WavWriter* file = GetWavFile(name, sample_rate_hz); | |
95 rtc_WavWriteSamples(file, v.data(), v.size()); | |
96 #endif | |
97 } | |
98 | |
99 void ApmDataDumper::DumpWav(const std::string& name, | |
hlundin-webrtc
2016/04/11 11:58:29
Order of methods should be the same in h and cpp f
peah-webrtc
2016/04/12 21:46:39
Good point! I now anyway moved these to the header
| |
100 int v_length, | |
101 float* v, | |
hlundin-webrtc
2016/04/11 11:58:29
const float* v
peah-webrtc
2016/04/12 21:46:38
Done.
| |
102 int sample_rate_hz) { | |
103 #ifdef WEBRTC_AEC_DEBUG_DUMP | |
104 rtc_WavWriter* file = GetWavFile(name, sample_rate_hz); | |
105 rtc_WavWriteSamples(file, v, v_length); | |
106 #endif | |
kwiberg-webrtc
2016/04/11 10:43:37
Implement one DumpWav in terms of the other?
peah-webrtc
2016/04/12 21:46:39
Done.
| |
107 } | |
108 | |
109 } // namespace webrtc | |
OLD | NEW |