2012-06-27 03:25:31 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
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
|
|
|
#include "webrtc/base/format_macros.h"
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
#include "webrtc/common_audio/resampler/include/push_resampler.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
#include "webrtc/voice_engine/utility.h"
|
|
|
|
|
#include "webrtc/voice_engine/voice_engine_defines.h"
|
2012-06-27 03:25:31 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace voe {
|
|
|
|
|
namespace {
|
|
|
|
|
|
2014-04-08 23:09:28 +00:00
|
|
|
class UtilityTest : public ::testing::Test {
|
2012-06-27 03:25:31 +00:00
|
|
|
protected:
|
2014-04-08 23:09:28 +00:00
|
|
|
UtilityTest() {
|
2012-06-27 03:25:31 +00:00
|
|
|
src_frame_.sample_rate_hz_ = 16000;
|
|
|
|
|
src_frame_.samples_per_channel_ = src_frame_.sample_rate_hz_ / 100;
|
|
|
|
|
src_frame_.num_channels_ = 1;
|
2013-01-22 04:44:30 +00:00
|
|
|
dst_frame_.CopyFrom(src_frame_);
|
|
|
|
|
golden_frame_.CopyFrom(src_frame_);
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-23 12:49:12 -07:00
|
|
|
void RunResampleTest(int src_channels,
|
|
|
|
|
int src_sample_rate_hz,
|
|
|
|
|
int dst_channels,
|
|
|
|
|
int dst_sample_rate_hz);
|
2012-06-27 03:25:31 +00:00
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
PushResampler<int16_t> resampler_;
|
2012-06-27 03:25:31 +00:00
|
|
|
AudioFrame src_frame_;
|
|
|
|
|
AudioFrame dst_frame_;
|
|
|
|
|
AudioFrame golden_frame_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Sets the signal value to increase by |data| with every sample. Floats are
|
|
|
|
|
// used so non-integer values result in rounding error, but not an accumulating
|
|
|
|
|
// error.
|
|
|
|
|
void SetMonoFrame(AudioFrame* frame, float data, int sample_rate_hz) {
|
2013-04-29 17:27:29 +00:00
|
|
|
memset(frame->data_, 0, sizeof(frame->data_));
|
2012-06-27 03:25:31 +00:00
|
|
|
frame->num_channels_ = 1;
|
|
|
|
|
frame->sample_rate_hz_ = sample_rate_hz;
|
|
|
|
|
frame->samples_per_channel_ = sample_rate_hz / 100;
|
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
|
|
|
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
frame->data_[i] = static_cast<int16_t>(data * i);
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep the existing sample rate.
|
|
|
|
|
void SetMonoFrame(AudioFrame* frame, float data) {
|
|
|
|
|
SetMonoFrame(frame, data, frame->sample_rate_hz_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sets the signal value to increase by |left| and |right| with every sample in
|
|
|
|
|
// each channel respectively.
|
|
|
|
|
void SetStereoFrame(AudioFrame* frame, float left, float right,
|
|
|
|
|
int sample_rate_hz) {
|
2013-04-29 17:27:29 +00:00
|
|
|
memset(frame->data_, 0, sizeof(frame->data_));
|
2012-06-27 03:25:31 +00:00
|
|
|
frame->num_channels_ = 2;
|
|
|
|
|
frame->sample_rate_hz_ = sample_rate_hz;
|
|
|
|
|
frame->samples_per_channel_ = sample_rate_hz / 100;
|
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
|
|
|
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
frame->data_[i * 2] = static_cast<int16_t>(left * i);
|
|
|
|
|
frame->data_[i * 2 + 1] = static_cast<int16_t>(right * i);
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep the existing sample rate.
|
|
|
|
|
void SetStereoFrame(AudioFrame* frame, float left, float right) {
|
|
|
|
|
SetStereoFrame(frame, left, right, frame->sample_rate_hz_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerifyParams(const AudioFrame& ref_frame, const AudioFrame& test_frame) {
|
|
|
|
|
EXPECT_EQ(ref_frame.num_channels_, test_frame.num_channels_);
|
|
|
|
|
EXPECT_EQ(ref_frame.samples_per_channel_, test_frame.samples_per_channel_);
|
|
|
|
|
EXPECT_EQ(ref_frame.sample_rate_hz_, test_frame.sample_rate_hz_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Computes the best SNR based on the error between |ref_frame| and
|
2013-04-29 17:27:29 +00:00
|
|
|
// |test_frame|. It allows for up to a |max_delay| in samples between the
|
|
|
|
|
// signals to compensate for the resampling delay.
|
|
|
|
|
float ComputeSNR(const AudioFrame& ref_frame, const AudioFrame& test_frame,
|
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 max_delay) {
|
2012-06-27 03:25:31 +00:00
|
|
|
VerifyParams(ref_frame, test_frame);
|
|
|
|
|
float best_snr = 0;
|
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 best_delay = 0;
|
|
|
|
|
for (size_t delay = 0; delay <= max_delay; delay++) {
|
2012-06-27 03:25:31 +00:00
|
|
|
float mse = 0;
|
|
|
|
|
float variance = 0;
|
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
|
|
|
for (size_t i = 0; i < ref_frame.samples_per_channel_ *
|
2012-06-27 03:25:31 +00:00
|
|
|
ref_frame.num_channels_ - delay; i++) {
|
|
|
|
|
int error = ref_frame.data_[i] - test_frame.data_[i + delay];
|
|
|
|
|
mse += error * error;
|
|
|
|
|
variance += ref_frame.data_[i] * ref_frame.data_[i];
|
|
|
|
|
}
|
|
|
|
|
float snr = 100; // We assign 100 dB to the zero-error case.
|
|
|
|
|
if (mse > 0)
|
|
|
|
|
snr = 10 * log10(variance / mse);
|
|
|
|
|
if (snr > best_snr) {
|
|
|
|
|
best_snr = snr;
|
|
|
|
|
best_delay = delay;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
printf("SNR=%.1f dB at delay=%" PRIuS "\n", best_snr, best_delay);
|
2012-06-27 03:25:31 +00:00
|
|
|
return best_snr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerifyFramesAreEqual(const AudioFrame& ref_frame,
|
|
|
|
|
const AudioFrame& test_frame) {
|
|
|
|
|
VerifyParams(ref_frame, test_frame);
|
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
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < ref_frame.samples_per_channel_ * ref_frame.num_channels_; i++) {
|
2012-06-27 03:25:31 +00:00
|
|
|
EXPECT_EQ(ref_frame.data_[i], test_frame.data_[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 23:09:28 +00:00
|
|
|
void UtilityTest::RunResampleTest(int src_channels,
|
2014-04-19 00:32:07 +00:00
|
|
|
int src_sample_rate_hz,
|
|
|
|
|
int dst_channels,
|
2015-09-23 12:49:12 -07:00
|
|
|
int dst_sample_rate_hz) {
|
2014-04-19 00:32:07 +00:00
|
|
|
PushResampler<int16_t> resampler; // Create a new one with every test.
|
2013-04-29 17:27:29 +00:00
|
|
|
const int16_t kSrcLeft = 30; // Shouldn't overflow for any used sample rate.
|
|
|
|
|
const int16_t kSrcRight = 15;
|
|
|
|
|
const float resampling_factor = (1.0 * src_sample_rate_hz) /
|
2012-06-27 03:25:31 +00:00
|
|
|
dst_sample_rate_hz;
|
2013-04-29 17:27:29 +00:00
|
|
|
const float dst_left = resampling_factor * kSrcLeft;
|
|
|
|
|
const float dst_right = resampling_factor * kSrcRight;
|
|
|
|
|
const float dst_mono = (dst_left + dst_right) / 2;
|
2012-06-27 03:25:31 +00:00
|
|
|
if (src_channels == 1)
|
|
|
|
|
SetMonoFrame(&src_frame_, kSrcLeft, src_sample_rate_hz);
|
|
|
|
|
else
|
|
|
|
|
SetStereoFrame(&src_frame_, kSrcLeft, kSrcRight, src_sample_rate_hz);
|
|
|
|
|
|
|
|
|
|
if (dst_channels == 1) {
|
|
|
|
|
SetMonoFrame(&dst_frame_, 0, dst_sample_rate_hz);
|
|
|
|
|
if (src_channels == 1)
|
2013-04-29 17:27:29 +00:00
|
|
|
SetMonoFrame(&golden_frame_, dst_left, dst_sample_rate_hz);
|
2012-06-27 03:25:31 +00:00
|
|
|
else
|
2013-04-29 17:27:29 +00:00
|
|
|
SetMonoFrame(&golden_frame_, dst_mono, dst_sample_rate_hz);
|
2012-06-27 03:25:31 +00:00
|
|
|
} else {
|
|
|
|
|
SetStereoFrame(&dst_frame_, 0, 0, dst_sample_rate_hz);
|
|
|
|
|
if (src_channels == 1)
|
2013-04-29 17:27:29 +00:00
|
|
|
SetStereoFrame(&golden_frame_, dst_left, dst_left, dst_sample_rate_hz);
|
2012-06-27 03:25:31 +00:00
|
|
|
else
|
2013-04-29 17:27:29 +00:00
|
|
|
SetStereoFrame(&golden_frame_, dst_left, dst_right, dst_sample_rate_hz);
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-29 17:27:29 +00:00
|
|
|
// The sinc resampler has a known delay, which we compute here. Multiplying by
|
|
|
|
|
// two gives us a crude maximum for any resampling, as the old resampler
|
|
|
|
|
// typically (but not always) has lower delay.
|
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
|
|
|
static const size_t kInputKernelDelaySamples = 16;
|
|
|
|
|
const size_t max_delay = static_cast<size_t>(
|
|
|
|
|
static_cast<double>(dst_sample_rate_hz) / src_sample_rate_hz *
|
|
|
|
|
kInputKernelDelaySamples * dst_channels * 2);
|
2012-06-27 03:25:31 +00:00
|
|
|
printf("(%d, %d Hz) -> (%d, %d Hz) ", // SNR reported on the same line later.
|
|
|
|
|
src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz);
|
2015-09-23 12:49:12 -07:00
|
|
|
RemixAndResample(src_frame_, &resampler, &dst_frame_);
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
|
2013-06-03 19:00:29 +00:00
|
|
|
if (src_sample_rate_hz == 96000 && dst_sample_rate_hz == 8000) {
|
|
|
|
|
// The sinc resampler gives poor SNR at this extreme conversion, but we
|
|
|
|
|
// expect to see this rarely in practice.
|
|
|
|
|
EXPECT_GT(ComputeSNR(golden_frame_, dst_frame_, max_delay), 14.0f);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_GT(ComputeSNR(golden_frame_, dst_frame_, max_delay), 46.0f);
|
|
|
|
|
}
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-08 23:09:28 +00:00
|
|
|
TEST_F(UtilityTest, RemixAndResampleCopyFrameSucceeds) {
|
2012-06-27 03:25:31 +00:00
|
|
|
// Stereo -> stereo.
|
|
|
|
|
SetStereoFrame(&src_frame_, 10, 10);
|
|
|
|
|
SetStereoFrame(&dst_frame_, 0, 0);
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
RemixAndResample(src_frame_, &resampler_, &dst_frame_);
|
2012-06-27 03:25:31 +00:00
|
|
|
VerifyFramesAreEqual(src_frame_, dst_frame_);
|
|
|
|
|
|
|
|
|
|
// Mono -> mono.
|
|
|
|
|
SetMonoFrame(&src_frame_, 20);
|
|
|
|
|
SetMonoFrame(&dst_frame_, 0);
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
RemixAndResample(src_frame_, &resampler_, &dst_frame_);
|
2012-06-27 03:25:31 +00:00
|
|
|
VerifyFramesAreEqual(src_frame_, dst_frame_);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 23:09:28 +00:00
|
|
|
TEST_F(UtilityTest, RemixAndResampleMixingOnlySucceeds) {
|
2012-06-27 03:25:31 +00:00
|
|
|
// Stereo -> mono.
|
|
|
|
|
SetStereoFrame(&dst_frame_, 0, 0);
|
|
|
|
|
SetMonoFrame(&src_frame_, 10);
|
|
|
|
|
SetStereoFrame(&golden_frame_, 10, 10);
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
RemixAndResample(src_frame_, &resampler_, &dst_frame_);
|
2012-06-27 03:25:31 +00:00
|
|
|
VerifyFramesAreEqual(dst_frame_, golden_frame_);
|
|
|
|
|
|
|
|
|
|
// Mono -> stereo.
|
|
|
|
|
SetMonoFrame(&dst_frame_, 0);
|
|
|
|
|
SetStereoFrame(&src_frame_, 10, 20);
|
|
|
|
|
SetMonoFrame(&golden_frame_, 15);
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
RemixAndResample(src_frame_, &resampler_, &dst_frame_);
|
2012-06-27 03:25:31 +00:00
|
|
|
VerifyFramesAreEqual(golden_frame_, dst_frame_);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 23:09:28 +00:00
|
|
|
TEST_F(UtilityTest, RemixAndResampleSucceeds) {
|
2013-04-29 17:27:29 +00:00
|
|
|
const int kSampleRates[] = {8000, 16000, 32000, 44100, 48000, 96000};
|
2012-06-27 03:25:31 +00:00
|
|
|
const int kSampleRatesSize = sizeof(kSampleRates) / sizeof(*kSampleRates);
|
|
|
|
|
const int kChannels[] = {1, 2};
|
|
|
|
|
const int kChannelsSize = sizeof(kChannels) / sizeof(*kChannels);
|
|
|
|
|
for (int src_rate = 0; src_rate < kSampleRatesSize; src_rate++) {
|
|
|
|
|
for (int dst_rate = 0; dst_rate < kSampleRatesSize; dst_rate++) {
|
|
|
|
|
for (int src_channel = 0; src_channel < kChannelsSize; src_channel++) {
|
|
|
|
|
for (int dst_channel = 0; dst_channel < kChannelsSize; dst_channel++) {
|
|
|
|
|
RunResampleTest(kChannels[src_channel], kSampleRates[src_rate],
|
2015-09-23 12:49:12 -07:00
|
|
|
kChannels[dst_channel], kSampleRates[dst_rate]);
|
2012-06-27 03:25:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace voe
|
|
|
|
|
} // namespace webrtc
|