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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_audio/audio_converter.h"
|
2015-02-11 01:09:50 +00:00
|
|
|
|
|
|
|
|
#include <cstring>
|
2016-03-31 10:24:26 -07:00
|
|
|
#include <memory>
|
2015-12-17 03:04:15 -08:00
|
|
|
#include <utility>
|
2016-03-31 10:24:26 -07:00
|
|
|
#include <vector>
|
2015-02-11 01:09:50 +00:00
|
|
|
|
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/checks.h"
|
2017-11-22 10:42:26 +01:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
2015-02-11 01:09:50 +00:00
|
|
|
|
2014-10-27 18:18:17 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-02-11 01:09:50 +00:00
|
|
|
class CopyConverter : public AudioConverter {
|
|
|
|
|
public:
|
2018-06-19 15:03:05 +02:00
|
|
|
CopyConverter(size_t src_channels,
|
|
|
|
|
size_t src_frames,
|
|
|
|
|
size_t dst_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 dst_frames)
|
2015-02-11 01:09:50 +00:00
|
|
|
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {}
|
2019-02-20 10:13:16 -05:00
|
|
|
~CopyConverter() override {}
|
2015-02-11 01:09:50 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Convert(const float* const* src,
|
|
|
|
|
size_t src_size,
|
|
|
|
|
float* const* dst,
|
2015-02-11 01:09:50 +00:00
|
|
|
size_t dst_capacity) override {
|
|
|
|
|
CheckSizes(src_size, dst_capacity);
|
|
|
|
|
if (src != dst) {
|
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 < src_channels(); ++i)
|
2015-02-11 01:09:50 +00:00
|
|
|
std::memcpy(dst[i], src[i], dst_frames() * sizeof(*dst[i]));
|
|
|
|
|
}
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
2015-02-11 01:09:50 +00:00
|
|
|
};
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2015-02-11 01:09:50 +00:00
|
|
|
class UpmixConverter : public AudioConverter {
|
|
|
|
|
public:
|
2018-06-19 15:03:05 +02:00
|
|
|
UpmixConverter(size_t src_channels,
|
|
|
|
|
size_t src_frames,
|
|
|
|
|
size_t dst_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 dst_frames)
|
2015-02-11 01:09:50 +00:00
|
|
|
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {}
|
2019-02-20 10:13:16 -05:00
|
|
|
~UpmixConverter() override {}
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Convert(const float* const* src,
|
|
|
|
|
size_t src_size,
|
|
|
|
|
float* const* dst,
|
2015-02-11 01:09:50 +00:00
|
|
|
size_t dst_capacity) override {
|
|
|
|
|
CheckSizes(src_size, dst_capacity);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t i = 0; i < dst_frames(); ++i) {
|
2015-02-11 01:09:50 +00:00
|
|
|
const float value = src[0][i];
|
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 j = 0; j < dst_channels(); ++j)
|
2015-02-11 01:09:50 +00:00
|
|
|
dst[j][i] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DownmixConverter : public AudioConverter {
|
|
|
|
|
public:
|
2018-06-19 15:03:05 +02:00
|
|
|
DownmixConverter(size_t src_channels,
|
|
|
|
|
size_t src_frames,
|
|
|
|
|
size_t dst_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 dst_frames)
|
2018-06-19 15:03:05 +02:00
|
|
|
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {}
|
2019-02-20 10:13:16 -05:00
|
|
|
~DownmixConverter() override {}
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Convert(const float* const* src,
|
|
|
|
|
size_t src_size,
|
|
|
|
|
float* const* dst,
|
2015-02-11 01:09:50 +00:00
|
|
|
size_t dst_capacity) override {
|
|
|
|
|
CheckSizes(src_size, dst_capacity);
|
|
|
|
|
float* dst_mono = dst[0];
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t i = 0; i < src_frames(); ++i) {
|
2015-02-11 01:09:50 +00:00
|
|
|
float sum = 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 j = 0; j < src_channels(); ++j)
|
2015-02-11 01:09:50 +00:00
|
|
|
sum += src[j][i];
|
|
|
|
|
dst_mono[i] = sum / src_channels();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2015-02-11 01:09:50 +00:00
|
|
|
class ResampleConverter : public AudioConverter {
|
|
|
|
|
public:
|
2018-06-19 15:03:05 +02:00
|
|
|
ResampleConverter(size_t src_channels,
|
|
|
|
|
size_t src_frames,
|
|
|
|
|
size_t dst_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 dst_frames)
|
2015-02-11 01:09:50 +00:00
|
|
|
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {
|
|
|
|
|
resamplers_.reserve(src_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 < src_channels; ++i)
|
2016-03-31 10:24:26 -07:00
|
|
|
resamplers_.push_back(std::unique_ptr<PushSincResampler>(
|
|
|
|
|
new PushSincResampler(src_frames, dst_frames)));
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
2019-02-20 10:13:16 -05:00
|
|
|
~ResampleConverter() override {}
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Convert(const float* const* src,
|
|
|
|
|
size_t src_size,
|
|
|
|
|
float* const* dst,
|
2015-02-11 01:09:50 +00:00
|
|
|
size_t dst_capacity) override {
|
|
|
|
|
CheckSizes(src_size, dst_capacity);
|
|
|
|
|
for (size_t i = 0; i < resamplers_.size(); ++i)
|
|
|
|
|
resamplers_[i]->Resample(src[i], src_frames(), dst[i], dst_frames());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2016-03-31 10:24:26 -07:00
|
|
|
std::vector<std::unique_ptr<PushSincResampler>> resamplers_;
|
2015-02-11 01:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Apply a vector of converters in serial, in the order given. At least two
|
|
|
|
|
// converters must be provided.
|
|
|
|
|
class CompositionConverter : public AudioConverter {
|
|
|
|
|
public:
|
2017-03-09 06:25:06 -08:00
|
|
|
explicit CompositionConverter(
|
2018-06-19 15:03:05 +02:00
|
|
|
std::vector<std::unique_ptr<AudioConverter>> converters)
|
2015-12-17 03:04:15 -08:00
|
|
|
: converters_(std::move(converters)) {
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_CHECK_GE(converters_.size(), 2);
|
2015-02-11 01:09:50 +00:00
|
|
|
// We need an intermediate buffer after every converter.
|
|
|
|
|
for (auto it = converters_.begin(); it != converters_.end() - 1; ++it)
|
2016-03-31 10:24:26 -07:00
|
|
|
buffers_.push_back(
|
|
|
|
|
std::unique_ptr<ChannelBuffer<float>>(new ChannelBuffer<float>(
|
|
|
|
|
(*it)->dst_frames(), (*it)->dst_channels())));
|
2015-02-11 01:09:50 +00:00
|
|
|
}
|
2019-02-20 10:13:16 -05:00
|
|
|
~CompositionConverter() override {}
|
2015-02-11 01:09:50 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Convert(const float* const* src,
|
|
|
|
|
size_t src_size,
|
|
|
|
|
float* const* dst,
|
2015-02-11 01:09:50 +00:00
|
|
|
size_t dst_capacity) override {
|
|
|
|
|
converters_.front()->Convert(src, src_size, buffers_.front()->channels(),
|
|
|
|
|
buffers_.front()->size());
|
|
|
|
|
for (size_t i = 2; i < converters_.size(); ++i) {
|
2016-03-31 10:24:26 -07:00
|
|
|
auto& src_buffer = buffers_[i - 2];
|
|
|
|
|
auto& dst_buffer = buffers_[i - 1];
|
2018-06-19 15:03:05 +02:00
|
|
|
converters_[i]->Convert(src_buffer->channels(), src_buffer->size(),
|
|
|
|
|
dst_buffer->channels(), dst_buffer->size());
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
2015-02-11 01:09:50 +00:00
|
|
|
converters_.back()->Convert(buffers_.back()->channels(),
|
|
|
|
|
buffers_.back()->size(), dst, dst_capacity);
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-11 01:09:50 +00:00
|
|
|
private:
|
2016-03-31 10:24:26 -07:00
|
|
|
std::vector<std::unique_ptr<AudioConverter>> converters_;
|
|
|
|
|
std::vector<std::unique_ptr<ChannelBuffer<float>>> buffers_;
|
2015-02-11 01:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
2016-02-24 05:22:32 -08:00
|
|
|
std::unique_ptr<AudioConverter> AudioConverter::Create(size_t src_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 src_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 dst_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 dst_frames) {
|
2016-02-24 05:22:32 -08:00
|
|
|
std::unique_ptr<AudioConverter> sp;
|
2015-02-11 01:09:50 +00:00
|
|
|
if (src_channels > dst_channels) {
|
2014-10-27 18:18:17 +00:00
|
|
|
if (src_frames != dst_frames) {
|
2016-03-31 10:24:26 -07:00
|
|
|
std::vector<std::unique_ptr<AudioConverter>> converters;
|
|
|
|
|
converters.push_back(std::unique_ptr<AudioConverter>(new DownmixConverter(
|
|
|
|
|
src_channels, src_frames, dst_channels, src_frames)));
|
|
|
|
|
converters.push_back(
|
|
|
|
|
std::unique_ptr<AudioConverter>(new ResampleConverter(
|
|
|
|
|
dst_channels, src_frames, dst_channels, dst_frames)));
|
2015-12-17 03:04:15 -08:00
|
|
|
sp.reset(new CompositionConverter(std::move(converters)));
|
2015-02-11 01:09:50 +00:00
|
|
|
} else {
|
|
|
|
|
sp.reset(new DownmixConverter(src_channels, src_frames, dst_channels,
|
|
|
|
|
dst_frames));
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
2015-02-11 01:09:50 +00:00
|
|
|
} else if (src_channels < dst_channels) {
|
|
|
|
|
if (src_frames != dst_frames) {
|
2016-03-31 10:24:26 -07:00
|
|
|
std::vector<std::unique_ptr<AudioConverter>> converters;
|
|
|
|
|
converters.push_back(
|
|
|
|
|
std::unique_ptr<AudioConverter>(new ResampleConverter(
|
|
|
|
|
src_channels, src_frames, src_channels, dst_frames)));
|
|
|
|
|
converters.push_back(std::unique_ptr<AudioConverter>(new UpmixConverter(
|
|
|
|
|
src_channels, dst_frames, dst_channels, dst_frames)));
|
2015-12-17 03:04:15 -08:00
|
|
|
sp.reset(new CompositionConverter(std::move(converters)));
|
2015-02-11 01:09:50 +00:00
|
|
|
} else {
|
|
|
|
|
sp.reset(new UpmixConverter(src_channels, src_frames, dst_channels,
|
|
|
|
|
dst_frames));
|
|
|
|
|
}
|
|
|
|
|
} else if (src_frames != dst_frames) {
|
|
|
|
|
sp.reset(new ResampleConverter(src_channels, src_frames, dst_channels,
|
|
|
|
|
dst_frames));
|
|
|
|
|
} else {
|
2018-06-19 15:03:05 +02:00
|
|
|
sp.reset(
|
|
|
|
|
new CopyConverter(src_channels, src_frames, dst_channels, dst_frames));
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-17 03:04:15 -08:00
|
|
|
return sp;
|
2015-02-11 01:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For CompositionConverter.
|
|
|
|
|
AudioConverter::AudioConverter()
|
2018-06-19 15:03:05 +02:00
|
|
|
: src_channels_(0), src_frames_(0), dst_channels_(0), dst_frames_(0) {}
|
2015-02-11 01:09:50 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
AudioConverter::AudioConverter(size_t src_channels,
|
|
|
|
|
size_t src_frames,
|
|
|
|
|
size_t dst_channels,
|
|
|
|
|
size_t dst_frames)
|
2015-02-11 01:09:50 +00:00
|
|
|
: src_channels_(src_channels),
|
|
|
|
|
src_frames_(src_frames),
|
|
|
|
|
dst_channels_(dst_channels),
|
|
|
|
|
dst_frames_(dst_frames) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(dst_channels == src_channels || dst_channels == 1 ||
|
|
|
|
|
src_channels == 1);
|
2015-02-11 01:09:50 +00:00
|
|
|
}
|
2014-10-27 18:18:17 +00:00
|
|
|
|
2015-02-11 01:09:50 +00:00
|
|
|
void AudioConverter::CheckSizes(size_t src_size, size_t dst_capacity) const {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(src_size, src_channels() * src_frames());
|
|
|
|
|
RTC_CHECK_GE(dst_capacity, dst_channels() * dst_frames());
|
2014-10-27 18:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|