2013-01-29 12:09:21 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Unit tests for Accelerate and PreemptiveExpand classes.
|
|
|
|
|
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/accelerate.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/neteq/preemptive_expand.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2015-05-27 14:33:29 +02:00
|
|
|
#include <map>
|
2016-02-14 09:28:33 -08:00
|
|
|
#include <memory>
|
2015-05-27 14:33:29 +02:00
|
|
|
|
|
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
2014-06-09 08:10:28 +00:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/background_noise.h"
|
2015-05-27 14:33:29 +02:00
|
|
|
#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/checks.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2015-05-27 14:33:29 +02:00
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-05-27 14:33:29 +02:00
|
|
|
namespace {
|
|
|
|
|
const size_t kNumChannels = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
TEST(TimeStretch, CreateAndDestroy) {
|
2014-01-14 10:18:45 +00:00
|
|
|
const int kSampleRate = 8000;
|
2014-04-11 18:47:55 +00:00
|
|
|
const int kOverlapSamples = 5 * kSampleRate / 8000;
|
2014-01-14 10:18:45 +00:00
|
|
|
BackgroundNoise bgn(kNumChannels);
|
|
|
|
|
Accelerate accelerate(kSampleRate, kNumChannels, bgn);
|
2014-04-11 18:47:55 +00:00
|
|
|
PreemptiveExpand preemptive_expand(
|
|
|
|
|
kSampleRate, kNumChannels, bgn, kOverlapSamples);
|
2014-01-14 10:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(TimeStretch, CreateUsingFactory) {
|
|
|
|
|
const int kSampleRate = 8000;
|
2014-04-11 18:47:55 +00:00
|
|
|
const int kOverlapSamples = 5 * kSampleRate / 8000;
|
2014-01-14 10:18:45 +00:00
|
|
|
BackgroundNoise bgn(kNumChannels);
|
|
|
|
|
|
|
|
|
|
AccelerateFactory accelerate_factory;
|
|
|
|
|
Accelerate* accelerate =
|
|
|
|
|
accelerate_factory.Create(kSampleRate, kNumChannels, bgn);
|
|
|
|
|
EXPECT_TRUE(accelerate != NULL);
|
|
|
|
|
delete accelerate;
|
|
|
|
|
|
|
|
|
|
PreemptiveExpandFactory preemptive_expand_factory;
|
2014-04-11 18:47:55 +00:00
|
|
|
PreemptiveExpand* preemptive_expand = preemptive_expand_factory.Create(
|
|
|
|
|
kSampleRate, kNumChannels, bgn, kOverlapSamples);
|
2014-01-14 10:18:45 +00:00
|
|
|
EXPECT_TRUE(preemptive_expand != NULL);
|
|
|
|
|
delete preemptive_expand;
|
2013-01-29 12:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 14:33:29 +02:00
|
|
|
class TimeStretchTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
TimeStretchTest()
|
|
|
|
|
: input_file_(new test::InputAudioFile(
|
|
|
|
|
test::ResourcePath("audio_coding/testfile32kHz", "pcm"))),
|
|
|
|
|
sample_rate_hz_(32000),
|
|
|
|
|
block_size_(30 * sample_rate_hz_ / 1000), // 30 ms
|
|
|
|
|
audio_(new int16_t[block_size_]),
|
|
|
|
|
background_noise_(kNumChannels) {
|
|
|
|
|
WebRtcSpl_Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int16_t* Next30Ms() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(input_file_->Read(block_size_, audio_.get()));
|
2015-05-27 14:33:29 +02:00
|
|
|
return audio_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the total length change (in samples) that the accelerate operation
|
|
|
|
|
// resulted in during the run.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t TestAccelerate(size_t loops, bool fast_mode) {
|
2015-05-27 14:33:29 +02:00
|
|
|
Accelerate accelerate(sample_rate_hz_, kNumChannels, background_noise_);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t total_length_change = 0;
|
|
|
|
|
for (size_t i = 0; i < loops; ++i) {
|
2015-05-27 14:33:29 +02:00
|
|
|
AudioMultiVector output(kNumChannels);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t length_change;
|
2015-05-27 14:33:29 +02:00
|
|
|
UpdateReturnStats(accelerate.Process(Next30Ms(), block_size_, fast_mode,
|
|
|
|
|
&output, &length_change));
|
|
|
|
|
total_length_change += length_change;
|
|
|
|
|
}
|
|
|
|
|
return total_length_change;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateReturnStats(TimeStretch::ReturnCodes ret) {
|
|
|
|
|
switch (ret) {
|
|
|
|
|
case TimeStretch::kSuccess:
|
|
|
|
|
case TimeStretch::kSuccessLowEnergy:
|
|
|
|
|
case TimeStretch::kNoStretch:
|
|
|
|
|
++return_stats_[ret];
|
|
|
|
|
break;
|
|
|
|
|
case TimeStretch::kError:
|
|
|
|
|
FAIL() << "Process returned an error";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<test::InputAudioFile> input_file_;
|
2015-05-27 14:33:29 +02:00
|
|
|
const int sample_rate_hz_;
|
|
|
|
|
const size_t block_size_;
|
2016-02-14 09:28:33 -08:00
|
|
|
std::unique_ptr<int16_t[]> audio_;
|
2015-05-27 14:33:29 +02:00
|
|
|
std::map<TimeStretch::ReturnCodes, int> return_stats_;
|
|
|
|
|
BackgroundNoise background_noise_;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(TimeStretchTest, Accelerate) {
|
2015-05-27 14:33:29 +02:00
|
|
|
// TestAccelerate returns the total length change in samples.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
EXPECT_EQ(15268U, TestAccelerate(100, false));
|
2015-05-27 14:33:29 +02:00
|
|
|
EXPECT_EQ(9, return_stats_[TimeStretch::kSuccess]);
|
|
|
|
|
EXPECT_EQ(58, return_stats_[TimeStretch::kSuccessLowEnergy]);
|
|
|
|
|
EXPECT_EQ(33, return_stats_[TimeStretch::kNoStretch]);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 10:04:20 +02:00
|
|
|
TEST_F(TimeStretchTest, AccelerateFastMode) {
|
2015-05-27 14:33:29 +02:00
|
|
|
// TestAccelerate returns the total length change in samples.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
EXPECT_EQ(21400U, TestAccelerate(100, true));
|
2015-05-27 14:33:29 +02:00
|
|
|
EXPECT_EQ(31, return_stats_[TimeStretch::kSuccess]);
|
|
|
|
|
EXPECT_EQ(58, return_stats_[TimeStretch::kSuccessLowEnergy]);
|
|
|
|
|
EXPECT_EQ(11, return_stats_[TimeStretch::kNoStretch]);
|
|
|
|
|
}
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|