2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-05-02 23:56:37 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-28 08:11:59 +00:00
|
|
|
#include "webrtc/modules/audio_processing/audio_buffer.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-20 14:39:39 -07:00
|
|
|
#include "webrtc/common_audio/include/audio_util.h"
|
2014-04-22 21:00:04 +00:00
|
|
|
#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
|
2013-05-28 08:11:59 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
2015-01-28 19:57:00 +00:00
|
|
|
#include "webrtc/common_audio/channel_buffer.h"
|
2014-11-27 23:40:25 +00:00
|
|
|
#include "webrtc/modules/audio_processing/common.h"
|
2011-11-15 16:57:56 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace {
|
|
|
|
|
|
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 kSamplesPer16kHzChannel = 160;
|
|
|
|
|
const size_t kSamplesPer32kHzChannel = 320;
|
|
|
|
|
const size_t kSamplesPer48kHzChannel = 480;
|
2015-04-27 11:34:45 -07:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
int KeyboardChannelIndex(const StreamConfig& stream_config) {
|
|
|
|
|
if (!stream_config.has_keyboard()) {
|
|
|
|
|
assert(false);
|
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
|
|
|
return 0;
|
2014-04-24 18:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
return stream_config.num_channels();
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +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
|
|
|
size_t NumBandsFromSamplesPerChannel(size_t num_frames) {
|
|
|
|
|
size_t num_bands = 1;
|
2015-02-10 22:52:15 +00:00
|
|
|
if (num_frames == kSamplesPer32kHzChannel ||
|
|
|
|
|
num_frames == kSamplesPer48kHzChannel) {
|
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
|
|
|
num_bands = rtc::CheckedDivExact(num_frames, kSamplesPer16kHzChannel);
|
2015-02-10 22:52:15 +00:00
|
|
|
}
|
|
|
|
|
return num_bands;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
} // namespace
|
2011-07-07 08:21:25 +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
|
|
|
AudioBuffer::AudioBuffer(size_t input_num_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
|
|
|
size_t num_input_channels,
|
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 process_num_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
|
|
|
size_t num_process_channels,
|
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 output_num_frames)
|
2015-02-10 22:52:15 +00:00
|
|
|
: input_num_frames_(input_num_frames),
|
2014-04-22 21:00:04 +00:00
|
|
|
num_input_channels_(num_input_channels),
|
2015-02-10 22:52:15 +00:00
|
|
|
proc_num_frames_(process_num_frames),
|
2014-04-22 21:00:04 +00:00
|
|
|
num_proc_channels_(num_process_channels),
|
2015-02-10 22:52:15 +00:00
|
|
|
output_num_frames_(output_num_frames),
|
2014-12-11 17:09:21 +00:00
|
|
|
num_channels_(num_process_channels),
|
2015-02-10 22:52:15 +00:00
|
|
|
num_bands_(NumBandsFromSamplesPerChannel(proc_num_frames_)),
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
num_split_frames_(rtc::CheckedDivExact(proc_num_frames_, num_bands_)),
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_(false),
|
2011-09-19 15:28:51 +00:00
|
|
|
reference_copied_(false),
|
|
|
|
|
activity_(AudioFrame::kVadUnknown),
|
2014-04-24 18:28:56 +00:00
|
|
|
keyboard_data_(NULL),
|
2015-02-10 22:52:15 +00:00
|
|
|
data_(new IFChannelBuffer(proc_num_frames_, num_proc_channels_)) {
|
|
|
|
|
assert(input_num_frames_ > 0);
|
|
|
|
|
assert(proc_num_frames_ > 0);
|
|
|
|
|
assert(output_num_frames_ > 0);
|
2015-07-23 11:41:39 -07:00
|
|
|
assert(num_input_channels_ > 0);
|
2015-02-10 22:52:15 +00:00
|
|
|
assert(num_proc_channels_ > 0 && num_proc_channels_ <= num_input_channels_);
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2015-02-10 22:52:15 +00:00
|
|
|
if (input_num_frames_ != proc_num_frames_ ||
|
|
|
|
|
output_num_frames_ != proc_num_frames_) {
|
2014-04-22 21:00:04 +00:00
|
|
|
// Create an intermediate buffer for resampling.
|
2015-02-10 22:52:15 +00:00
|
|
|
process_buffer_.reset(new ChannelBuffer<float>(proc_num_frames_,
|
2014-04-22 21:00:04 +00:00
|
|
|
num_proc_channels_));
|
|
|
|
|
|
2015-02-10 22:52:15 +00:00
|
|
|
if (input_num_frames_ != proc_num_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
|
|
|
for (size_t i = 0; i < num_proc_channels_; ++i) {
|
2016-03-31 10:24:26 -07:00
|
|
|
input_resamplers_.push_back(std::unique_ptr<PushSincResampler>(
|
|
|
|
|
new PushSincResampler(input_num_frames_, proc_num_frames_)));
|
2015-02-10 22:52:15 +00:00
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-10 22:52:15 +00:00
|
|
|
if (output_num_frames_ != proc_num_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
|
|
|
for (size_t i = 0; i < num_proc_channels_; ++i) {
|
2016-03-31 10:24:26 -07:00
|
|
|
output_resamplers_.push_back(std::unique_ptr<PushSincResampler>(
|
|
|
|
|
new PushSincResampler(proc_num_frames_, output_num_frames_)));
|
2015-02-10 22:52:15 +00:00
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 22:52:15 +00:00
|
|
|
if (num_bands_ > 1) {
|
|
|
|
|
split_data_.reset(new IFChannelBuffer(proc_num_frames_,
|
|
|
|
|
num_proc_channels_,
|
|
|
|
|
num_bands_));
|
2015-04-27 11:34:45 -07:00
|
|
|
splitting_filter_.reset(new SplittingFilter(num_proc_channels_,
|
|
|
|
|
num_bands_,
|
|
|
|
|
proc_num_frames_));
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
AudioBuffer::~AudioBuffer() {}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
void AudioBuffer::CopyFrom(const float* const* data,
|
2015-07-23 11:41:39 -07:00
|
|
|
const StreamConfig& stream_config) {
|
|
|
|
|
assert(stream_config.num_frames() == input_num_frames_);
|
|
|
|
|
assert(stream_config.num_channels() == num_input_channels_);
|
2014-04-22 21:00:04 +00:00
|
|
|
InitForNewData();
|
2015-05-20 14:39:39 -07:00
|
|
|
// Initialized lazily because there's a different condition in
|
|
|
|
|
// DeinterleaveFrom.
|
2015-07-23 11:41:39 -07:00
|
|
|
const bool need_to_downmix =
|
|
|
|
|
num_input_channels_ > 1 && num_proc_channels_ == 1;
|
|
|
|
|
if (need_to_downmix && !input_buffer_) {
|
2015-05-20 14:39:39 -07:00
|
|
|
input_buffer_.reset(
|
|
|
|
|
new IFChannelBuffer(input_num_frames_, num_proc_channels_));
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
if (stream_config.has_keyboard()) {
|
|
|
|
|
keyboard_data_ = data[KeyboardChannelIndex(stream_config)];
|
2014-04-24 18:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
// Downmix.
|
|
|
|
|
const float* const* data_ptr = data;
|
2015-07-23 11:41:39 -07:00
|
|
|
if (need_to_downmix) {
|
|
|
|
|
DownmixToMono<float, float>(data, input_num_frames_, num_input_channels_,
|
|
|
|
|
input_buffer_->fbuf()->channels()[0]);
|
2015-05-20 14:39:39 -07:00
|
|
|
data_ptr = input_buffer_->fbuf_const()->channels();
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample.
|
2015-02-10 22:52:15 +00:00
|
|
|
if (input_num_frames_ != proc_num_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
|
|
|
for (size_t i = 0; i < num_proc_channels_; ++i) {
|
2014-04-22 21:00:04 +00:00
|
|
|
input_resamplers_[i]->Resample(data_ptr[i],
|
2015-02-10 22:52:15 +00:00
|
|
|
input_num_frames_,
|
|
|
|
|
process_buffer_->channels()[i],
|
|
|
|
|
proc_num_frames_);
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
data_ptr = process_buffer_->channels();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 04:58:14 +00:00
|
|
|
// Convert to the S16 range.
|
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_proc_channels_; ++i) {
|
2015-02-10 22:52:15 +00:00
|
|
|
FloatToFloatS16(data_ptr[i],
|
|
|
|
|
proc_num_frames_,
|
|
|
|
|
data_->fbuf()->channels()[i]);
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
void AudioBuffer::CopyTo(const StreamConfig& stream_config,
|
2014-04-22 21:00:04 +00:00
|
|
|
float* const* data) {
|
2015-07-23 11:41:39 -07:00
|
|
|
assert(stream_config.num_frames() == output_num_frames_);
|
2016-01-11 20:32:29 -08:00
|
|
|
assert(stream_config.num_channels() == num_channels_ || num_channels_ == 1);
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2014-10-31 04:58:14 +00:00
|
|
|
// Convert to the float range.
|
2014-04-22 21:00:04 +00:00
|
|
|
float* const* data_ptr = data;
|
2015-02-10 22:52:15 +00:00
|
|
|
if (output_num_frames_ != proc_num_frames_) {
|
2014-04-22 21:00:04 +00:00
|
|
|
// Convert to an intermediate buffer for subsequent resampling.
|
|
|
|
|
data_ptr = process_buffer_->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) {
|
2015-02-10 22:52:15 +00:00
|
|
|
FloatS16ToFloat(data_->fbuf()->channels()[i],
|
|
|
|
|
proc_num_frames_,
|
2014-10-31 04:58:14 +00:00
|
|
|
data_ptr[i]);
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample.
|
2015-02-10 22:52:15 +00:00
|
|
|
if (output_num_frames_ != proc_num_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
|
|
|
for (size_t i = 0; i < num_channels_; ++i) {
|
2014-04-22 21:00:04 +00:00
|
|
|
output_resamplers_[i]->Resample(data_ptr[i],
|
2015-02-10 22:52:15 +00:00
|
|
|
proc_num_frames_,
|
2014-04-22 21:00:04 +00:00
|
|
|
data[i],
|
2015-02-10 22:52:15 +00:00
|
|
|
output_num_frames_);
|
2014-04-22 21:00:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2016-01-11 20:32:29 -08:00
|
|
|
|
|
|
|
|
// Upmix.
|
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 = num_channels_; i < stream_config.num_channels(); ++i) {
|
2016-01-11 20:32:29 -08:00
|
|
|
memcpy(data[i], data[0], output_num_frames_ * sizeof(**data));
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 21:00:04 +00:00
|
|
|
void AudioBuffer::InitForNewData() {
|
2014-04-24 18:28:56 +00:00
|
|
|
keyboard_data_ = NULL;
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2014-03-04 20:58:13 +00:00
|
|
|
reference_copied_ = false;
|
|
|
|
|
activity_ = AudioFrame::kVadUnknown;
|
2014-12-11 17:09:21 +00:00
|
|
|
num_channels_ = num_proc_channels_;
|
2014-03-04 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
const int16_t* const* AudioBuffer::channels_const() const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return data_->ibuf_const()->channels();
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t* const* AudioBuffer::channels() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
return data_->ibuf()->channels();
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
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 int16_t* const* AudioBuffer::split_bands_const(size_t channel) const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return split_data_.get() ?
|
|
|
|
|
split_data_->ibuf_const()->bands(channel) :
|
|
|
|
|
data_->ibuf_const()->bands(channel);
|
2014-05-15 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
int16_t* const* AudioBuffer::split_bands(size_t channel) {
|
2014-12-10 19:30:57 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
return split_data_.get() ?
|
|
|
|
|
split_data_->ibuf()->bands(channel) :
|
|
|
|
|
data_->ibuf()->bands(channel);
|
2014-07-03 09:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
const int16_t* const* AudioBuffer::split_channels_const(Band band) const {
|
2015-02-10 22:52:15 +00:00
|
|
|
if (split_data_.get()) {
|
|
|
|
|
return split_data_->ibuf_const()->channels(band);
|
2014-12-03 01:06:35 +00:00
|
|
|
} else {
|
2015-02-10 22:52:15 +00:00
|
|
|
return band == kBand0To8kHz ? data_->ibuf_const()->channels() : nullptr;
|
2014-12-03 01:06:35 +00:00
|
|
|
}
|
2014-09-25 20:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
int16_t* const* AudioBuffer::split_channels(Band band) {
|
2014-09-25 20:52:08 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
if (split_data_.get()) {
|
|
|
|
|
return split_data_->ibuf()->channels(band);
|
2014-12-03 01:06:35 +00:00
|
|
|
} else {
|
2015-02-10 22:52:15 +00:00
|
|
|
return band == kBand0To8kHz ? data_->ibuf()->channels() : nullptr;
|
2014-12-03 01:06:35 +00:00
|
|
|
}
|
2014-09-25 20:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 21:52:20 +00:00
|
|
|
ChannelBuffer<int16_t>* AudioBuffer::data() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return data_->ibuf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ChannelBuffer<int16_t>* AudioBuffer::data() const {
|
|
|
|
|
return data_->ibuf_const();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChannelBuffer<int16_t>* AudioBuffer::split_data() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return split_data_.get() ? split_data_->ibuf() : data_->ibuf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ChannelBuffer<int16_t>* AudioBuffer::split_data() const {
|
|
|
|
|
return split_data_.get() ? split_data_->ibuf_const() : data_->ibuf_const();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
const float* const* AudioBuffer::channels_const_f() const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return data_->fbuf_const()->channels();
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
float* const* AudioBuffer::channels_f() {
|
2014-11-14 22:18:10 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
return data_->fbuf()->channels();
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
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 float* const* AudioBuffer::split_bands_const_f(size_t channel) const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return split_data_.get() ?
|
|
|
|
|
split_data_->fbuf_const()->bands(channel) :
|
|
|
|
|
data_->fbuf_const()->bands(channel);
|
2014-05-15 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
float* const* AudioBuffer::split_bands_f(size_t channel) {
|
2014-12-10 19:30:57 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
return split_data_.get() ?
|
|
|
|
|
split_data_->fbuf()->bands(channel) :
|
|
|
|
|
data_->fbuf()->bands(channel);
|
2014-07-03 09:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
const float* const* AudioBuffer::split_channels_const_f(Band band) const {
|
2015-02-10 22:52:15 +00:00
|
|
|
if (split_data_.get()) {
|
|
|
|
|
return split_data_->fbuf_const()->channels(band);
|
2014-12-03 01:06:35 +00:00
|
|
|
} else {
|
2015-02-10 22:52:15 +00:00
|
|
|
return band == kBand0To8kHz ? data_->fbuf_const()->channels() : nullptr;
|
2014-12-03 01:06:35 +00:00
|
|
|
}
|
2014-09-25 20:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-03 01:06:35 +00:00
|
|
|
float* const* AudioBuffer::split_channels_f(Band band) {
|
2014-09-25 20:52:08 +00:00
|
|
|
mixed_low_pass_valid_ = false;
|
2015-02-10 22:52:15 +00:00
|
|
|
if (split_data_.get()) {
|
|
|
|
|
return split_data_->fbuf()->channels(band);
|
2014-12-03 01:06:35 +00:00
|
|
|
} else {
|
2015-02-10 22:52:15 +00:00
|
|
|
return band == kBand0To8kHz ? data_->fbuf()->channels() : nullptr;
|
2014-12-03 01:06:35 +00:00
|
|
|
}
|
2014-11-17 23:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 21:52:20 +00:00
|
|
|
ChannelBuffer<float>* AudioBuffer::data_f() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return data_->fbuf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ChannelBuffer<float>* AudioBuffer::data_f() const {
|
|
|
|
|
return data_->fbuf_const();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChannelBuffer<float>* AudioBuffer::split_data_f() {
|
|
|
|
|
mixed_low_pass_valid_ = false;
|
|
|
|
|
return split_data_.get() ? split_data_->fbuf() : data_->fbuf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ChannelBuffer<float>* AudioBuffer::split_data_f() const {
|
|
|
|
|
return split_data_.get() ? split_data_->fbuf_const() : data_->fbuf_const();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 08:27:39 +00:00
|
|
|
const int16_t* AudioBuffer::mixed_low_pass_data() {
|
|
|
|
|
if (num_proc_channels_ == 1) {
|
2014-12-10 19:30:57 +00:00
|
|
|
return split_bands_const(0)[kBand0To8kHz];
|
2014-07-17 08:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixed_low_pass_valid_) {
|
|
|
|
|
if (!mixed_low_pass_channels_.get()) {
|
|
|
|
|
mixed_low_pass_channels_.reset(
|
2015-02-10 22:52:15 +00:00
|
|
|
new ChannelBuffer<int16_t>(num_split_frames_, 1));
|
2014-07-17 08:27:39 +00:00
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
|
|
|
|
|
DownmixToMono<int16_t, int32_t>(split_channels_const(kBand0To8kHz),
|
|
|
|
|
num_split_frames_, num_channels_,
|
|
|
|
|
mixed_low_pass_channels_->channels()[0]);
|
2014-07-17 08:27:39 +00:00
|
|
|
mixed_low_pass_valid_ = true;
|
|
|
|
|
}
|
2015-02-10 22:52:15 +00:00
|
|
|
return mixed_low_pass_channels_->channels()[0];
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:13 +00:00
|
|
|
const int16_t* AudioBuffer::low_pass_reference(int channel) const {
|
2011-07-07 08:21:25 +00:00
|
|
|
if (!reference_copied_) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 22:52:15 +00:00
|
|
|
return low_pass_reference_channels_->channels()[channel];
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-24 18:28:56 +00:00
|
|
|
const float* AudioBuffer::keyboard_data() const {
|
|
|
|
|
return keyboard_data_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-19 15:28:51 +00:00
|
|
|
void AudioBuffer::set_activity(AudioFrame::VADActivity activity) {
|
|
|
|
|
activity_ = activity;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 16:57:56 +00:00
|
|
|
AudioFrame::VADActivity AudioBuffer::activity() const {
|
2011-09-19 15:28:51 +00:00
|
|
|
return activity_;
|
|
|
|
|
}
|
|
|
|
|
|
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 AudioBuffer::num_channels() const {
|
2014-12-11 17:09:21 +00:00
|
|
|
return 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
|
|
|
void AudioBuffer::set_num_channels(size_t num_channels) {
|
2014-12-11 17:09:21 +00:00
|
|
|
num_channels_ = num_channels;
|
2011-07-07 08:21:25 +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
|
|
|
size_t AudioBuffer::num_frames() const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return proc_num_frames_;
|
2011-07-07 08:21:25 +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
|
|
|
size_t AudioBuffer::num_frames_per_band() const {
|
2015-02-10 22:52:15 +00:00
|
|
|
return num_split_frames_;
|
2011-07-07 08:21:25 +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
|
|
|
size_t AudioBuffer::num_keyboard_frames() const {
|
2014-04-24 18:28:56 +00:00
|
|
|
// We don't resample the keyboard channel.
|
2015-02-10 22:52:15 +00:00
|
|
|
return input_num_frames_;
|
2014-04-24 18:28:56 +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
|
|
|
size_t AudioBuffer::num_bands() const {
|
2014-12-10 19:30:57 +00:00
|
|
|
return num_bands_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-20 14:39:39 -07:00
|
|
|
// The resampler is only for supporting 48kHz to 16kHz in the reverse stream.
|
2011-09-19 15:28:51 +00:00
|
|
|
void AudioBuffer::DeinterleaveFrom(AudioFrame* frame) {
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
assert(frame->num_channels_ == num_input_channels_);
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
assert(frame->samples_per_channel_ == input_num_frames_);
|
2014-04-22 21:00:04 +00:00
|
|
|
InitForNewData();
|
2015-05-20 14:39:39 -07:00
|
|
|
// Initialized lazily because there's a different condition in CopyFrom.
|
|
|
|
|
if ((input_num_frames_ != proc_num_frames_) && !input_buffer_) {
|
|
|
|
|
input_buffer_.reset(
|
|
|
|
|
new IFChannelBuffer(input_num_frames_, num_proc_channels_));
|
|
|
|
|
}
|
2012-05-02 23:56:37 +00:00
|
|
|
activity_ = frame->vad_activity_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-20 14:39:39 -07:00
|
|
|
int16_t* const* deinterleaved;
|
|
|
|
|
if (input_num_frames_ == proc_num_frames_) {
|
|
|
|
|
deinterleaved = data_->ibuf()->channels();
|
|
|
|
|
} else {
|
|
|
|
|
deinterleaved = input_buffer_->ibuf()->channels();
|
|
|
|
|
}
|
2015-07-23 11:41:39 -07:00
|
|
|
if (num_proc_channels_ == 1) {
|
|
|
|
|
// Downmix and deinterleave simultaneously.
|
|
|
|
|
DownmixInterleavedToMono(frame->data_, input_num_frames_,
|
|
|
|
|
num_input_channels_, deinterleaved[0]);
|
Enable render downmixing to mono in AudioProcessing.
In practice, we have been doing this since time immemorial, but have
relied on the user to do the downmixing (first voice engine then
Chromium). It's more logical for this burden to fall on AudioProcessing,
however, who can be expected to know that this is a reasonable approach
for AEC. Permitting two render channels results in running two AECs
serially.
Critically, in my recent change to have Chromium adopt the float
interface:
https://codereview.chromium.org/420603004
I removed the downmixing by Chromium, forgetting that we hadn't yet
enabled this feature in AudioProcessing. This corrects that oversight.
The change in paths hit by production users is very minor. As commented
it required adding downmixing to the int16_t path to satisfy
bit-exactness tests.
For reference, find the ApmTest.Process errors here:
https://paste.googleplex.com/6372007910309888
BUG=webrtc:3853
TESTED=listened to the files output from the Process test, and verified
that they sound as expected: higher echo while the AEC is adapting, but
afterwards very close.
R=aluebs@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/31459004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7292 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-24 20:06:23 +00:00
|
|
|
} else {
|
|
|
|
|
assert(num_proc_channels_ == num_input_channels_);
|
2015-05-20 14:39:39 -07:00
|
|
|
Deinterleave(frame->data_,
|
|
|
|
|
input_num_frames_,
|
|
|
|
|
num_proc_channels_,
|
|
|
|
|
deinterleaved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resample.
|
|
|
|
|
if (input_num_frames_ != proc_num_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
|
|
|
for (size_t i = 0; i < num_proc_channels_; ++i) {
|
2015-05-20 14:39:39 -07:00
|
|
|
input_resamplers_[i]->Resample(input_buffer_->fbuf_const()->channels()[i],
|
|
|
|
|
input_num_frames_,
|
|
|
|
|
data_->fbuf()->channels()[i],
|
|
|
|
|
proc_num_frames_);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
void AudioBuffer::InterleaveTo(AudioFrame* frame, bool data_changed) {
|
2012-05-02 23:56:37 +00:00
|
|
|
frame->vad_activity_ = activity_;
|
2011-11-15 16:57:56 +00:00
|
|
|
if (!data_changed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
assert(frame->num_channels_ == num_channels_ || num_channels_ == 1);
|
|
|
|
|
assert(frame->samples_per_channel_ == output_num_frames_);
|
|
|
|
|
|
|
|
|
|
// Resample if necessary.
|
|
|
|
|
IFChannelBuffer* data_ptr = data_.get();
|
|
|
|
|
if (proc_num_frames_ != output_num_frames_) {
|
|
|
|
|
if (!output_buffer_) {
|
|
|
|
|
output_buffer_.reset(
|
|
|
|
|
new IFChannelBuffer(output_num_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) {
|
2015-08-14 10:35:55 -07:00
|
|
|
output_resamplers_[i]->Resample(
|
|
|
|
|
data_->fbuf()->channels()[i], proc_num_frames_,
|
|
|
|
|
output_buffer_->fbuf()->channels()[i], output_num_frames_);
|
|
|
|
|
}
|
|
|
|
|
data_ptr = output_buffer_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (frame->num_channels_ == num_channels_) {
|
|
|
|
|
Interleave(data_ptr->ibuf()->channels(), proc_num_frames_, num_channels_,
|
|
|
|
|
frame->data_);
|
|
|
|
|
} else {
|
|
|
|
|
UpmixMonoToInterleaved(data_ptr->ibuf()->channels()[0], proc_num_frames_,
|
|
|
|
|
frame->num_channels_, frame->data_);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioBuffer::CopyLowPassToReference() {
|
|
|
|
|
reference_copied_ = true;
|
2014-12-11 17:09:21 +00:00
|
|
|
if (!low_pass_reference_channels_.get() ||
|
|
|
|
|
low_pass_reference_channels_->num_channels() != num_channels_) {
|
2014-04-22 21:00:04 +00:00
|
|
|
low_pass_reference_channels_.reset(
|
2015-02-10 22:52:15 +00:00
|
|
|
new ChannelBuffer<int16_t>(num_split_frames_,
|
2014-04-22 21:00:04 +00:00
|
|
|
num_proc_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_proc_channels_; i++) {
|
2015-02-10 22:52:15 +00:00
|
|
|
memcpy(low_pass_reference_channels_->channels()[i],
|
|
|
|
|
split_bands_const(i)[kBand0To8kHz],
|
|
|
|
|
low_pass_reference_channels_->num_frames_per_band() *
|
|
|
|
|
sizeof(split_bands_const(i)[kBand0To8kHz][0]));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-22 21:00:04 +00:00
|
|
|
|
2014-11-14 22:18:10 +00:00
|
|
|
void AudioBuffer::SplitIntoFrequencyBands() {
|
2015-02-10 22:52:15 +00:00
|
|
|
splitting_filter_->Analysis(data_.get(), split_data_.get());
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioBuffer::MergeFrequencyBands() {
|
2015-02-10 22:52:15 +00:00
|
|
|
splitting_filter_->Synthesis(split_data_.get(), data_.get());
|
2014-11-14 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|