2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
12 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h"
13 #include "webrtc/test/testsupport/fileutils.h"
15 using google::RegisterFlagValidator;
16 using google::ParseCommandLineFlags;
18 using testing::InitGoogleTest;
23 static const int kIsacBlockDurationMs = 30;
24 static const int kIsacInputSamplingKhz = 16;
25 static const int kIsacOutputSamplingKhz = 16;
27 // Define switch for input file name.
28 static bool ValidateInFilename(const char* flagname, const string& value) {
29 FILE* fid = fopen(value.c_str(), "rb");
34 printf("Invalid input filename.");
38 DEFINE_string(in_filename,
39 ResourcePath("audio_coding/speech_mono_16kHz", "pcm"),
40 "Filename for input audio (should be 16 kHz sampled mono).");
42 static const bool in_filename_dummy =
43 RegisterFlagValidator(&FLAGS_in_filename, &ValidateInFilename);
45 // Define switch for output file name.
46 static bool ValidateOutFilename(const char* flagname, const string& value) {
47 FILE* fid = fopen(value.c_str(), "wb");
52 printf("Invalid output filename.");
56 DEFINE_string(out_filename, OutputPath() + "neteq4_isac_quality_test.pcm",
57 "Name of output audio file.");
59 static const bool out_filename_dummy =
60 RegisterFlagValidator(&FLAGS_out_filename, &ValidateOutFilename);
62 // Define switch for bir rate.
63 static bool ValidateBitRate(const char* flagname, int32_t value) {
64 if (value >= 10 && value <= 32)
66 printf("Invalid bit rate, should be between 10 and 32 kbps.");
70 DEFINE_int32(bit_rate_kbps, 32, "Target bit rate (kbps).");
72 static const bool bit_rate_dummy =
73 RegisterFlagValidator(&FLAGS_bit_rate_kbps, &ValidateBitRate);
75 // Define switch for runtime.
76 static bool ValidateRuntime(const char* flagname, int32_t value) {
79 printf("Invalid runtime, should be greater than 0.");
83 DEFINE_int32(runtime_ms, 10000, "Simulated runtime (milliseconds).");
85 static const bool runtime_dummy =
86 RegisterFlagValidator(&FLAGS_runtime_ms, &ValidateRuntime);
88 class NetEqIsacQualityTest : public NetEqQualityTest {
90 NetEqIsacQualityTest();
91 virtual void SetUp() OVERRIDE;
92 virtual void TearDown() OVERRIDE;
93 virtual int EncodeBlock(int16_t* in_data, int block_size_samples,
94 uint8_t* payload, int max_bytes);
96 ISACFIX_MainStruct* isac_encoder_;
100 NetEqIsacQualityTest::NetEqIsacQualityTest()
101 : NetEqQualityTest(kIsacBlockDurationMs, kIsacInputSamplingKhz,
102 kIsacOutputSamplingKhz,
108 bit_rate_kbps_(FLAGS_bit_rate_kbps) {
111 void NetEqIsacQualityTest::SetUp() {
112 // Create encoder memory.
113 WebRtcIsacfix_Create(&isac_encoder_);
114 ASSERT_TRUE(isac_encoder_ != NULL);
115 EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(isac_encoder_, 1));
116 // Set bitrate and block length.
117 EXPECT_EQ(0, WebRtcIsacfix_Control(isac_encoder_, bit_rate_kbps_ * 1000,
118 kIsacBlockDurationMs));
119 NetEqQualityTest::SetUp();
122 void NetEqIsacQualityTest::TearDown() {
124 EXPECT_EQ(0, WebRtcIsacfix_Free(isac_encoder_));
125 NetEqQualityTest::TearDown();
128 int NetEqIsacQualityTest::EncodeBlock(int16_t* in_data,
129 int block_size_samples,
130 uint8_t* payload, int max_bytes) {
131 // ISAC takes 10 ms for every call.
132 const int subblocks = kIsacBlockDurationMs / 10;
133 const int subblock_length = 10 * kIsacInputSamplingKhz;
137 for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) {
138 // The Isac encoder does not perform encoding (and returns 0) until it
139 // receives a sequence of sub-blocks that amount to the frame duration.
141 value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer], payload);
147 TEST_F(NetEqIsacQualityTest, Test) {
148 Simulate(FLAGS_runtime_ms);
152 } // namespace webrtc