Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: webrtc/modules/audio_processing/test/vector_based_audio_frame.cc

Issue 1510493004: Bitexactness test for the highpass filter (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Refactored the test not to use fixtures in response to reviewer comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "webrtc/modules/audio_processing/test/vector_based_audio_frame.h"
12
13 namespace webrtc {
14
15 VectorBasedAudioFrame::VectorBasedAudioFrame(size_t frame_length,
16 size_t num_channels,
17 const float* initial_values)
18 : VectorBasedAudioFrame(frame_length, num_channels) {
19 for (size_t ch = 0; ch < num_channels; ++ch) {
hlundin-webrtc 2015/12/10 12:12:17 Do one memcpy for all of the data: memcpy(&frame_[
peah-webrtc 2015/12/22 06:28:10 True. This is now done in the new code. Acknowled
20 memcpy(&frame_[ch][0], &initial_values[ch * frame_length],
21 frame_length_ * sizeof(initial_values[0]));
22 }
23 }
24
25 VectorBasedAudioFrame::VectorBasedAudioFrame(size_t frame_length,
26 size_t num_channels)
27 : frame_length_(frame_length), num_channels_(num_channels) {
28 channels_.resize(num_channels * frame_length_);
hlundin-webrtc 2015/12/10 12:12:17 num_channels_ - or - frame_length
peah-webrtc 2015/12/22 06:28:10 Good catch! Acknowledged.
29 frame_.resize(num_channels);
30 for (size_t ch = 0; ch < num_channels; ++ch) {
31 frame_[ch] = &channels_[ch * frame_length_];
32 }
33 }
34
35 void VectorBasedAudioFrame::Randomize(test::Random* rand_gen_) const {
hlundin-webrtc 2015/12/10 12:12:17 How can this be const when you are in fact modifyi
peah-webrtc 2015/12/22 06:28:10 True! It is really strange that that even compiled
36 for (size_t ch = 0; ch < num_channels_; ++ch) {
hlundin-webrtc 2015/12/10 12:12:17 Do one grand for-loop. Make it range-based over fr
peah-webrtc 2015/12/22 06:28:10 Acknowledged.
37 for (size_t k = 0; k < frame_length_; ++k) {
38 frame_[ch][k] =
39 static_cast<float>(rand_gen_->Rand(0, 32767 + 32768) - 32768) /
the sun 2015/12/10 12:03:53 For testing the HPF, I'd also use an impulse.
peah-webrtc 2015/12/22 06:28:10 Why would that be better than using WGN signal for
40 32768.0f;
41 }
42 }
43 }
44
45 void VectorBasedAudioFrame::CopyToAudioBuffer(StreamConfig stream_config,
46 AudioBuffer* buffer) {
47 buffer->CopyFrom(&frame_[0], stream_config);
48 }
49
50 void VectorBasedAudioFrame::CopyFromAudioBuffer(StreamConfig stream_config,
51 AudioBuffer* buffer) {
hlundin-webrtc 2015/12/10 12:12:17 I would like buffer to be const, but I guess that
peah-webrtc 2015/12/22 06:28:10 True. That is the reason for this. And the reason
52 buffer->CopyTo(stream_config, &frame_[0]);
53 }
54
55 bool VectorBasedAudioFrame::CompareTo(VectorBasedAudioFrame* other_frame,
56 float tolerance) const {
57 if (num_channels_ != other_frame->num_channels()) {
hlundin-webrtc 2015/12/10 12:12:17 Won't you have to check the frame_lengths too? Or,
peah-webrtc 2015/12/22 06:28:10 Agree. This is now replaced with another function.
58 return false;
59 }
60
61 const std::vector<float*>* const other_frame_array = other_frame->get_frame();
62 for (size_t ch = 0; ch < num_channels_; ++ch) {
hlundin-webrtc 2015/12/10 12:12:17 Can you rewrite this to one grand for loop: for (s
peah-webrtc 2015/12/22 06:28:10 Agree. that would be better. This is now replaced
63 for (size_t k = 0; k < other_frame->frame_length(); ++k) {
64 if (fabs(frame_[ch][k] - (*other_frame_array)[ch][k]) > tolerance) {
the sun 2015/12/10 12:03:54 In gtest there's EXPECT_NEAR also.
peah-webrtc 2015/12/22 06:28:10 True, but since I now use EXPECT_PRED_FORMAT2() wh
65 return false;
66 }
67 }
68 }
69 return true;
70 }
71
72 void VectorBasedAudioFrame::PrintValues() {
73 PrintValues(frame_length_);
74 }
75
76 void VectorBasedAudioFrame::PrintValues(size_t num_samples_per_channel) {
77 printf("{");
78 for (size_t ch = 0; ch < num_channels_; ++ch) {
79 printf("{");
80 for (size_t k = 0; k < num_samples_per_channel; ++k) {
81 printf("%ff", frame_[ch][k]);
82 if (k < (num_samples_per_channel - 1)) {
83 printf(", ");
84 }
85 }
86 printf("}");
87 if (ch < (num_channels_ - 1)) {
88 printf(", ");
89 }
90 }
91 printf("}");
92 }
93
94 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698