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

Unified Diff: webrtc/voice_engine/utility_unittest.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/voice_engine/utility.cc ('k') | webrtc/voice_engine/voe_base_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/voice_engine/utility_unittest.cc
diff --git a/webrtc/voice_engine/utility_unittest.cc b/webrtc/voice_engine/utility_unittest.cc
index 94abc0f510c0c9980f6a496532ef79d63f86d970..992cb71ec7e17da5d0f1d58682c3e2b39f98480f 100644
--- a/webrtc/voice_engine/utility_unittest.cc
+++ b/webrtc/voice_engine/utility_unittest.cc
@@ -47,12 +47,13 @@ class UtilityTest : public ::testing::Test {
// used so non-integer values result in rounding error, but not an accumulating
// error.
void SetMonoFrame(float data, int sample_rate_hz, AudioFrame* frame) {
- memset(frame->data_, 0, sizeof(frame->data_));
+ frame->Mute();
frame->num_channels_ = 1;
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100);
+ int16_t* frame_data = frame->mutable_data();
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
- frame->data_[i] = static_cast<int16_t>(data * i);
+ frame_data[i] = static_cast<int16_t>(data * i);
}
}
@@ -67,13 +68,14 @@ void SetStereoFrame(float left,
float right,
int sample_rate_hz,
AudioFrame* frame) {
- memset(frame->data_, 0, sizeof(frame->data_));
+ frame->Mute();
frame->num_channels_ = 2;
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100);
+ int16_t* frame_data = frame->mutable_data();
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
- frame->data_[i * 2] = static_cast<int16_t>(left * i);
- frame->data_[i * 2 + 1] = static_cast<int16_t>(right * i);
+ frame_data[i * 2] = static_cast<int16_t>(left * i);
+ frame_data[i * 2 + 1] = static_cast<int16_t>(right * i);
}
}
@@ -90,15 +92,16 @@ void SetQuadFrame(float ch1,
float ch4,
int sample_rate_hz,
AudioFrame* frame) {
- memset(frame->data_, 0, sizeof(frame->data_));
+ frame->Mute();
frame->num_channels_ = 4;
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = rtc::CheckedDivExact(sample_rate_hz, 100);
+ int16_t* frame_data = frame->mutable_data();
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
- frame->data_[i * 4] = static_cast<int16_t>(ch1 * i);
- frame->data_[i * 4 + 1] = static_cast<int16_t>(ch2 * i);
- frame->data_[i * 4 + 2] = static_cast<int16_t>(ch3 * i);
- frame->data_[i * 4 + 3] = static_cast<int16_t>(ch4 * i);
+ frame_data[i * 4] = static_cast<int16_t>(ch1 * i);
+ frame_data[i * 4 + 1] = static_cast<int16_t>(ch2 * i);
+ frame_data[i * 4 + 2] = static_cast<int16_t>(ch3 * i);
+ frame_data[i * 4 + 3] = static_cast<int16_t>(ch4 * i);
}
}
@@ -119,11 +122,13 @@ float ComputeSNR(const AudioFrame& ref_frame, const AudioFrame& test_frame,
for (size_t delay = 0; delay <= max_delay; delay++) {
float mse = 0;
float variance = 0;
+ const int16_t* ref_frame_data = ref_frame.data();
+ const int16_t* test_frame_data = test_frame.data();
for (size_t i = 0; i < ref_frame.samples_per_channel_ *
ref_frame.num_channels_ - delay; i++) {
- int error = ref_frame.data_[i] - test_frame.data_[i + delay];
+ int error = ref_frame_data[i] - test_frame_data[i + delay];
mse += error * error;
- variance += ref_frame.data_[i] * ref_frame.data_[i];
+ variance += ref_frame_data[i] * ref_frame_data[i];
}
float snr = 100; // We assign 100 dB to the zero-error case.
if (mse > 0)
@@ -140,9 +145,11 @@ float ComputeSNR(const AudioFrame& ref_frame, const AudioFrame& test_frame,
void VerifyFramesAreEqual(const AudioFrame& ref_frame,
const AudioFrame& test_frame) {
VerifyParams(ref_frame, test_frame);
+ const int16_t* ref_frame_data = ref_frame.data();
+ const int16_t* test_frame_data = test_frame.data();
for (size_t i = 0;
i < ref_frame.samples_per_channel_ * ref_frame.num_channels_; i++) {
- EXPECT_EQ(ref_frame.data_[i], test_frame.data_[i]);
+ EXPECT_EQ(ref_frame_data[i], test_frame_data[i]);
}
}
« no previous file with comments | « webrtc/voice_engine/utility.cc ('k') | webrtc/voice_engine/voe_base_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698