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/codecs/isac/fix/source/settings.h"
13 #include "webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_test.h"
19 static const int kIsacBlockDurationMs = 30;
20 static const int kIsacInputSamplingKhz = 16;
21 static const int kIsacOutputSamplingKhz = 16;
23 class IsacSpeedTest : public AudioCodecSpeedTest {
26 virtual void SetUp() OVERRIDE;
27 virtual void TearDown() OVERRIDE;
28 virtual float EncodeABlock(int16_t* in_data, uint8_t* bit_stream,
29 int max_bytes, int* encoded_bytes);
30 virtual float DecodeABlock(const uint8_t* bit_stream, int encoded_bytes,
32 ISACFIX_MainStruct *ISACFIX_main_inst_;
35 IsacSpeedTest::IsacSpeedTest()
36 : AudioCodecSpeedTest(kIsacBlockDurationMs,
37 kIsacInputSamplingKhz,
38 kIsacOutputSamplingKhz),
39 ISACFIX_main_inst_(NULL) {
42 void IsacSpeedTest::SetUp() {
43 AudioCodecSpeedTest::SetUp();
45 // Check whether the allocated buffer for the bit stream is large enough.
46 EXPECT_GE(max_bytes_, STREAM_MAXW16_60MS);
48 // Create encoder memory.
49 EXPECT_EQ(0, WebRtcIsacfix_Create(&ISACFIX_main_inst_));
50 EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(ISACFIX_main_inst_, 1));
51 EXPECT_EQ(0, WebRtcIsacfix_DecoderInit(ISACFIX_main_inst_));
52 // Set bitrate and block length.
53 EXPECT_EQ(0, WebRtcIsacfix_Control(ISACFIX_main_inst_, bit_rate_,
57 void IsacSpeedTest::TearDown() {
58 AudioCodecSpeedTest::TearDown();
60 EXPECT_EQ(0, WebRtcIsacfix_Free(ISACFIX_main_inst_));
63 float IsacSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream,
64 int max_bytes, int* encoded_bytes) {
65 // ISAC takes 10 ms everycall
66 const int subblocks = block_duration_ms_ / 10;
67 const int subblock_length = 10 * input_sampling_khz_;
70 clock_t clocks = clock();
72 for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) {
73 value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer],
76 clocks = clock() - clocks;
78 assert(value <= max_bytes);
79 *encoded_bytes = value;
80 return 1000.0 * clocks / CLOCKS_PER_SEC;
83 float IsacSpeedTest::DecodeABlock(const uint8_t* bit_stream, int encoded_bytes,
87 clock_t clocks = clock();
88 value = WebRtcIsacfix_Decode(ISACFIX_main_inst_,
89 reinterpret_cast<const uint16_t*>(bit_stream),
90 encoded_bytes, out_data, &audio_type);
91 clocks = clock() - clocks;
92 EXPECT_EQ(output_length_sample_, value);
93 return 1000.0 * clocks / CLOCKS_PER_SEC;
96 TEST_P(IsacSpeedTest, IsacEncodeDecodeTest) {
97 size_t kDurationSec = 400; // Test audio length in second.
98 EncodeDecode(kDurationSec);
101 const coding_param param_set[] =
102 {::std::tr1::make_tuple(1, 32000, string("audio_coding/speech_mono_16kHz"),
103 string("pcm"), true)};
105 INSTANTIATE_TEST_CASE_P(AllTest, IsacSpeedTest,
106 ::testing::ValuesIn(param_set));
108 } // namespace webrtc