2013-04-29 17:27:29 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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 "webrtc/common_audio/resampler/include/push_resampler.h"
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <string.h>
|
2013-04-29 17:27:29 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/common_audio/include/audio_util.h"
|
|
|
|
|
#include "webrtc/common_audio/resampler/include/resampler.h"
|
|
|
|
|
#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
template <typename T>
|
|
|
|
|
PushResampler<T>::PushResampler()
|
2013-10-22 12:50:00 +00:00
|
|
|
: src_sample_rate_hz_(0),
|
2013-04-29 17:27:29 +00:00
|
|
|
dst_sample_rate_hz_(0),
|
2014-04-19 00:32:07 +00:00
|
|
|
num_channels_(0) {
|
2013-04-29 17:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
template <typename T>
|
|
|
|
|
PushResampler<T>::~PushResampler() {
|
2013-04-29 17:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
template <typename T>
|
|
|
|
|
int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz,
|
|
|
|
|
int 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
|
|
|
size_t num_channels) {
|
2013-04-29 17:27:29 +00:00
|
|
|
if (src_sample_rate_hz == src_sample_rate_hz_ &&
|
|
|
|
|
dst_sample_rate_hz == dst_sample_rate_hz_ &&
|
2013-07-25 22:04:30 +00:00
|
|
|
num_channels == num_channels_)
|
2013-04-29 17:27:29 +00:00
|
|
|
// No-op if settings haven't changed.
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 ||
|
2013-07-25 22:04:30 +00:00
|
|
|
num_channels <= 0 || num_channels > 2)
|
2013-04-29 17:27:29 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
src_sample_rate_hz_ = src_sample_rate_hz;
|
|
|
|
|
dst_sample_rate_hz_ = dst_sample_rate_hz;
|
|
|
|
|
num_channels_ = num_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
|
|
|
const size_t src_size_10ms_mono =
|
|
|
|
|
static_cast<size_t>(src_sample_rate_hz / 100);
|
|
|
|
|
const size_t dst_size_10ms_mono =
|
|
|
|
|
static_cast<size_t>(dst_sample_rate_hz / 100);
|
2013-04-29 17:27:29 +00:00
|
|
|
sinc_resampler_.reset(new PushSincResampler(src_size_10ms_mono,
|
|
|
|
|
dst_size_10ms_mono));
|
|
|
|
|
if (num_channels_ == 2) {
|
2014-04-19 00:32:07 +00:00
|
|
|
src_left_.reset(new T[src_size_10ms_mono]);
|
|
|
|
|
src_right_.reset(new T[src_size_10ms_mono]);
|
|
|
|
|
dst_left_.reset(new T[dst_size_10ms_mono]);
|
|
|
|
|
dst_right_.reset(new T[dst_size_10ms_mono]);
|
2013-04-29 17:27:29 +00:00
|
|
|
sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono,
|
|
|
|
|
dst_size_10ms_mono));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
template <typename T>
|
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
|
|
|
int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst,
|
|
|
|
|
size_t dst_capacity) {
|
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 src_size_10ms = src_sample_rate_hz_ * num_channels_ / 100;
|
|
|
|
|
const size_t dst_size_10ms = dst_sample_rate_hz_ * num_channels_ / 100;
|
2013-07-25 22:04:30 +00:00
|
|
|
if (src_length != src_size_10ms || dst_capacity < dst_size_10ms)
|
2013-04-29 17:27:29 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (src_sample_rate_hz_ == dst_sample_rate_hz_) {
|
|
|
|
|
// The old resampler provides this memcpy facility in the case of matching
|
|
|
|
|
// sample rates, so reproduce it here for the sinc resampler.
|
2014-04-19 00:32:07 +00:00
|
|
|
memcpy(dst, src, src_length * sizeof(T));
|
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
|
|
|
return static_cast<int>(src_length);
|
2013-04-29 17:27:29 +00:00
|
|
|
}
|
|
|
|
|
if (num_channels_ == 2) {
|
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 src_length_mono = src_length / num_channels_;
|
|
|
|
|
const size_t dst_capacity_mono = dst_capacity / num_channels_;
|
2014-04-19 00:32:07 +00:00
|
|
|
T* deinterleaved[] = {src_left_.get(), src_right_.get()};
|
2013-04-29 17:27:29 +00:00
|
|
|
Deinterleave(src, src_length_mono, num_channels_, deinterleaved);
|
|
|
|
|
|
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 dst_length_mono =
|
2013-04-29 17:27:29 +00:00
|
|
|
sinc_resampler_->Resample(src_left_.get(), src_length_mono,
|
|
|
|
|
dst_left_.get(), dst_capacity_mono);
|
|
|
|
|
sinc_resampler_right_->Resample(src_right_.get(), src_length_mono,
|
|
|
|
|
dst_right_.get(), dst_capacity_mono);
|
|
|
|
|
|
|
|
|
|
deinterleaved[0] = dst_left_.get();
|
|
|
|
|
deinterleaved[1] = dst_right_.get();
|
|
|
|
|
Interleave(deinterleaved, dst_length_mono, num_channels_, dst);
|
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
|
|
|
return static_cast<int>(dst_length_mono * num_channels_);
|
2013-04-29 17:27:29 +00:00
|
|
|
} else {
|
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
|
|
|
return static_cast<int>(
|
|
|
|
|
sinc_resampler_->Resample(src, src_length, dst, dst_capacity));
|
2013-04-29 17:27:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-19 00:32:07 +00:00
|
|
|
// Explictly generate required instantiations.
|
|
|
|
|
template class PushResampler<int16_t>;
|
|
|
|
|
template class PushResampler<float>;
|
|
|
|
|
|
2013-04-29 17:27:29 +00:00
|
|
|
} // namespace webrtc
|