2014-10-27 18:18:17 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-05 19:08:33 +02:00
|
|
|
#include "common_audio/audio_converter.h"
|
|
|
|
|
|
2014-10-27 18:18:17 +00:00
|
|
|
#include <algorithm>
|
2018-06-19 15:03:05 +02:00
|
|
|
#include <cmath>
|
2016-02-24 05:22:32 -08:00
|
|
|
#include <memory>
|
2014-10-27 18:18:17 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/channel_buffer.h"
|
|
|
|
|
#include "common_audio/resampler/push_sinc_resampler.h"
|
|
|
|
|
#include "rtc_base/arraysize.h"
|
|
|
|
|
#include "rtc_base/format_macros.h"
|
|
|
|
|
#include "test/gtest.h"
|
2014-10-27 18:18:17 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-02-24 05:22:32 -08:00
|
|
|
typedef std::unique_ptr<ChannelBuffer<float>> ScopedBuffer;
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2021-07-26 12:15:29 +02:00
|
|
|
// Sets the signal value to increase by `data` with every sample.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
ScopedBuffer CreateBuffer(const std::vector<float>& data, size_t frames) {
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t num_channels = data.size();
|
2014-10-27 18:18:17 +00:00
|
|
|
ScopedBuffer sb(new ChannelBuffer<float>(frames, num_channels));
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
for (size_t i = 0; i < num_channels; ++i)
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
for (size_t j = 0; j < frames; ++j)
|
2015-02-10 22:52:15 +00:00
|
|
|
sb->channels()[i][j] = data[i] * j;
|
2014-10-27 18:18:17 +00:00
|
|
|
return sb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerifyParams(const ChannelBuffer<float>& ref,
|
|
|
|
|
const ChannelBuffer<float>& test) {
|
|
|
|
|
EXPECT_EQ(ref.num_channels(), test.num_channels());
|
2015-02-10 22:52:15 +00:00
|
|
|
EXPECT_EQ(ref.num_frames(), test.num_frames());
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:15:29 +02:00
|
|
|
// Computes the best SNR based on the error between `ref_frame` and
|
|
|
|
|
// `test_frame`. It searches around `expected_delay` in samples between the
|
2014-10-27 18:18:17 +00:00
|
|
|
// signals to compensate for the resampling delay.
|
|
|
|
|
float ComputeSNR(const ChannelBuffer<float>& ref,
|
|
|
|
|
const ChannelBuffer<float>& test,
|
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 expected_delay) {
|
2014-10-27 18:18:17 +00:00
|
|
|
VerifyParams(ref, test);
|
|
|
|
|
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;
|
2014-10-27 18:18:17 +00:00
|
|
|
|
|
|
|
|
// Search within one sample of the expected 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
|
|
|
for (size_t delay = std::max(expected_delay, static_cast<size_t>(1)) - 1;
|
2018-06-19 15:03:05 +02:00
|
|
|
delay <= std::min(expected_delay + 1, ref.num_frames()); ++delay) {
|
2014-10-27 18:18:17 +00:00
|
|
|
float mse = 0;
|
|
|
|
|
float variance = 0;
|
|
|
|
|
float mean = 0;
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
for (size_t i = 0; i < ref.num_channels(); ++i) {
|
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 j = 0; j < ref.num_frames() - delay; ++j) {
|
2015-02-10 22:52:15 +00:00
|
|
|
float error = ref.channels()[i][j] - test.channels()[i][j + delay];
|
2014-10-27 18:18:17 +00:00
|
|
|
mse += error * error;
|
2015-02-10 22:52:15 +00:00
|
|
|
variance += ref.channels()[i][j] * ref.channels()[i][j];
|
|
|
|
|
mean += ref.channels()[i][j];
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-11 01:09:50 +00:00
|
|
|
|
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
|
|
|
const size_t length = ref.num_channels() * (ref.num_frames() - delay);
|
2014-10-27 18:18:17 +00:00
|
|
|
mse /= length;
|
|
|
|
|
variance /= length;
|
|
|
|
|
mean /= length;
|
|
|
|
|
variance -= mean * mean;
|
|
|
|
|
float snr = 100; // We assign 100 dB to the zero-error case.
|
|
|
|
|
if (mse > 0)
|
2015-02-11 01:09:50 +00:00
|
|
|
snr = 10 * std::log10(variance / mse);
|
2014-10-27 18:18:17 +00:00
|
|
|
if (snr > best_snr) {
|
|
|
|
|
best_snr = snr;
|
|
|
|
|
best_delay = delay;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-02 09:36:47 +02:00
|
|
|
printf("SNR=%.1f dB at delay=%" RTC_PRIuS "\n", best_snr, best_delay);
|
2014-10-27 18:18:17 +00:00
|
|
|
return best_snr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sets the source to a linearly increasing signal for which we can easily
|
|
|
|
|
// generate a reference. Runs the AudioConverter and ensures the output has
|
|
|
|
|
// sufficiently high SNR relative to the reference.
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
void RunAudioConverterTest(size_t src_channels,
|
2014-10-27 18:18:17 +00:00
|
|
|
int src_sample_rate_hz,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t dst_channels,
|
2014-10-27 18:18:17 +00:00
|
|
|
int dst_sample_rate_hz) {
|
|
|
|
|
const float kSrcLeft = 0.0002f;
|
|
|
|
|
const float kSrcRight = 0.0001f;
|
2018-06-19 15:03:05 +02:00
|
|
|
const float resampling_factor =
|
|
|
|
|
(1.f * src_sample_rate_hz) / dst_sample_rate_hz;
|
2014-10-27 18:18:17 +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;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
const size_t src_frames = static_cast<size_t>(src_sample_rate_hz / 100);
|
|
|
|
|
const size_t dst_frames = static_cast<size_t>(dst_sample_rate_hz / 100);
|
2014-10-27 18:18:17 +00:00
|
|
|
|
|
|
|
|
std::vector<float> src_data(1, kSrcLeft);
|
|
|
|
|
if (src_channels == 2)
|
|
|
|
|
src_data.push_back(kSrcRight);
|
|
|
|
|
ScopedBuffer src_buffer = CreateBuffer(src_data, src_frames);
|
|
|
|
|
|
|
|
|
|
std::vector<float> dst_data(1, 0);
|
|
|
|
|
std::vector<float> ref_data;
|
|
|
|
|
if (dst_channels == 1) {
|
|
|
|
|
if (src_channels == 1)
|
|
|
|
|
ref_data.push_back(dst_left);
|
|
|
|
|
else
|
|
|
|
|
ref_data.push_back(dst_mono);
|
|
|
|
|
} else {
|
|
|
|
|
dst_data.push_back(0);
|
|
|
|
|
ref_data.push_back(dst_left);
|
|
|
|
|
if (src_channels == 1)
|
|
|
|
|
ref_data.push_back(dst_left);
|
|
|
|
|
else
|
|
|
|
|
ref_data.push_back(dst_right);
|
|
|
|
|
}
|
|
|
|
|
ScopedBuffer dst_buffer = CreateBuffer(dst_data, dst_frames);
|
|
|
|
|
ScopedBuffer ref_buffer = CreateBuffer(ref_data, dst_frames);
|
|
|
|
|
|
|
|
|
|
// The sinc resampler has a known delay, which we compute here.
|
2018-06-19 15:03:05 +02:00
|
|
|
const size_t delay_frames =
|
|
|
|
|
src_sample_rate_hz == dst_sample_rate_hz
|
|
|
|
|
? 0
|
|
|
|
|
: static_cast<size_t>(
|
|
|
|
|
PushSincResampler::AlgorithmicDelaySeconds(src_sample_rate_hz) *
|
|
|
|
|
dst_sample_rate_hz);
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
// SNR reported on the same line later.
|
2019-08-02 09:36:47 +02:00
|
|
|
printf("(%" RTC_PRIuS ", %d Hz) -> (%" RTC_PRIuS ", %d Hz) ", src_channels,
|
2018-06-19 15:03:05 +02:00
|
|
|
src_sample_rate_hz, dst_channels, dst_sample_rate_hz);
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2016-02-24 05:22:32 -08:00
|
|
|
std::unique_ptr<AudioConverter> converter = AudioConverter::Create(
|
2015-02-26 14:34:55 +00:00
|
|
|
src_channels, src_frames, dst_channels, dst_frames);
|
2015-02-11 01:09:50 +00:00
|
|
|
converter->Convert(src_buffer->channels(), src_buffer->size(),
|
|
|
|
|
dst_buffer->channels(), dst_buffer->size());
|
2014-10-27 18:18:17 +00:00
|
|
|
|
|
|
|
|
EXPECT_LT(43.f,
|
|
|
|
|
ComputeSNR(*ref_buffer.get(), *dst_buffer.get(), delay_frames));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioConverterTest, ConversionsPassSNRThreshold) {
|
|
|
|
|
const int kSampleRates[] = {8000, 16000, 32000, 44100, 48000};
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t kChannels[] = {1, 2};
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
for (size_t src_rate = 0; src_rate < arraysize(kSampleRates); ++src_rate) {
|
|
|
|
|
for (size_t dst_rate = 0; dst_rate < arraysize(kSampleRates); ++dst_rate) {
|
|
|
|
|
for (size_t src_channel = 0; src_channel < arraysize(kChannels);
|
|
|
|
|
++src_channel) {
|
|
|
|
|
for (size_t dst_channel = 0; dst_channel < arraysize(kChannels);
|
|
|
|
|
++dst_channel) {
|
2014-10-27 18:18:17 +00:00
|
|
|
RunAudioConverterTest(kChannels[src_channel], kSampleRates[src_rate],
|
|
|
|
|
kChannels[dst_channel], kSampleRates[dst_rate]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|