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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
|
|
|
|
|
#define COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
|
2013-04-29 17:27:29 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
2017-03-09 06:25:06 -08:00
|
|
|
#include <algorithm>
|
2018-02-16 10:42:48 +01:00
|
|
|
#include <cmath>
|
2015-07-23 11:41:39 -07:00
|
|
|
#include <cstring>
|
2018-02-16 10:42:48 +01:00
|
|
|
#include <limits>
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2013-04-29 17:27:29 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2014-03-04 20:58:13 +00:00
|
|
|
typedef std::numeric_limits<int16_t> limits_int16;
|
|
|
|
|
|
2014-10-30 03:40:10 +00:00
|
|
|
// The conversion functions use the following naming convention:
|
|
|
|
|
// S16: int16_t [-32768, 32767]
|
|
|
|
|
// Float: float [-1.0, 1.0]
|
|
|
|
|
// FloatS16: float [-32768.0, 32767.0]
|
2018-02-16 10:42:48 +01:00
|
|
|
// Dbfs: float [-20.0*log(10, 32768), 0] = [-90.3, 0]
|
|
|
|
|
// The ratio conversion functions use this naming convention:
|
|
|
|
|
// Ratio: float (0, +inf)
|
|
|
|
|
// Db: float (-inf, +inf)
|
2014-10-30 03:40:10 +00:00
|
|
|
static inline int16_t FloatToS16(float v) {
|
2014-03-04 20:58:13 +00:00
|
|
|
if (v > 0)
|
2015-07-23 11:41:39 -07:00
|
|
|
return v >= 1 ? limits_int16::max()
|
|
|
|
|
: static_cast<int16_t>(v * limits_int16::max() + 0.5f);
|
|
|
|
|
return v <= -1 ? limits_int16::min()
|
|
|
|
|
: static_cast<int16_t>(-v * limits_int16::min() - 0.5f);
|
2014-02-20 20:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-30 03:40:10 +00:00
|
|
|
static inline float S16ToFloat(int16_t v) {
|
|
|
|
|
static const float kMaxInt16Inverse = 1.f / limits_int16::max();
|
|
|
|
|
static const float kMinInt16Inverse = 1.f / limits_int16::min();
|
2014-03-04 20:58:13 +00:00
|
|
|
return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse);
|
2013-09-06 21:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-30 03:40:10 +00:00
|
|
|
static inline int16_t FloatS16ToS16(float v) {
|
|
|
|
|
static const float kMaxRound = limits_int16::max() - 0.5f;
|
|
|
|
|
static const float kMinRound = limits_int16::min() + 0.5f;
|
|
|
|
|
if (v > 0)
|
2015-07-23 11:41:39 -07:00
|
|
|
return v >= kMaxRound ? limits_int16::max()
|
|
|
|
|
: static_cast<int16_t>(v + 0.5f);
|
|
|
|
|
return v <= kMinRound ? limits_int16::min() : static_cast<int16_t>(v - 0.5f);
|
2014-10-30 03:40:10 +00:00
|
|
|
}
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2014-10-30 03:40:10 +00:00
|
|
|
static inline float FloatToFloatS16(float v) {
|
2014-10-31 04:58:14 +00:00
|
|
|
return v * (v > 0 ? limits_int16::max() : -limits_int16::min());
|
2014-10-30 03:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline float FloatS16ToFloat(float v) {
|
|
|
|
|
static const float kMaxInt16Inverse = 1.f / limits_int16::max();
|
|
|
|
|
static const float kMinInt16Inverse = 1.f / limits_int16::min();
|
|
|
|
|
return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse);
|
|
|
|
|
}
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2014-10-30 03:40:10 +00:00
|
|
|
void FloatToS16(const float* src, size_t size, int16_t* dest);
|
|
|
|
|
void S16ToFloat(const int16_t* src, size_t size, float* dest);
|
|
|
|
|
void FloatS16ToS16(const float* src, size_t size, int16_t* dest);
|
|
|
|
|
void FloatToFloatS16(const float* src, size_t size, float* dest);
|
|
|
|
|
void FloatS16ToFloat(const float* src, size_t size, float* dest);
|
2014-03-04 20:58:13 +00:00
|
|
|
|
2018-02-16 10:42:48 +01:00
|
|
|
inline float DbToRatio(float v) {
|
|
|
|
|
return std::pow(10.0f, v / 20.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float DbfsToFloatS16(float v) {
|
|
|
|
|
static constexpr float kMaximumAbsFloatS16 = -limits_int16::min();
|
|
|
|
|
return DbToRatio(v) * kMaximumAbsFloatS16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float FloatS16ToDbfs(float v) {
|
|
|
|
|
RTC_DCHECK_GE(v, 0);
|
|
|
|
|
|
|
|
|
|
// kMinDbfs is equal to -20.0 * log10(-limits_int16::min())
|
|
|
|
|
static constexpr float kMinDbfs = -90.30899869919436f;
|
|
|
|
|
if (v <= 1.0f) {
|
|
|
|
|
return kMinDbfs;
|
|
|
|
|
}
|
|
|
|
|
// Equal to 20 * log10(v / (-limits_int16::min()))
|
|
|
|
|
return 20.0f * std::log10(v) + kMinDbfs;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
// Copy audio from |src| channels to |dest| channels unless |src| and |dest|
|
|
|
|
|
// point to the same address. |src| and |dest| must have the same number of
|
|
|
|
|
// channels, and there must be sufficient space allocated in |dest|.
|
|
|
|
|
template <typename T>
|
|
|
|
|
void CopyAudioIfNeeded(const T* const* src,
|
|
|
|
|
int num_frames,
|
|
|
|
|
int num_channels,
|
|
|
|
|
T* const* dest) {
|
|
|
|
|
for (int i = 0; i < num_channels; ++i) {
|
|
|
|
|
if (src[i] != dest[i]) {
|
|
|
|
|
std::copy(src[i], src[i] + num_frames, dest[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-29 17:27:29 +00:00
|
|
|
// Deinterleave audio from |interleaved| to the channel buffers pointed to
|
|
|
|
|
// by |deinterleaved|. There must be sufficient space allocated in the
|
|
|
|
|
// |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel|
|
|
|
|
|
// per buffer).
|
2014-03-04 20:58:13 +00:00
|
|
|
template <typename T>
|
2015-07-23 11:41:39 -07:00
|
|
|
void Deinterleave(const T* interleaved,
|
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 samples_per_channel,
|
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,
|
2015-07-23 11:41:39 -07:00
|
|
|
T* const* deinterleaved) {
|
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-03-04 20:58:13 +00:00
|
|
|
T* channel = deinterleaved[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
|
|
|
size_t interleaved_idx = i;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t j = 0; j < samples_per_channel; ++j) {
|
2014-03-04 20:58:13 +00:00
|
|
|
channel[j] = interleaved[interleaved_idx];
|
|
|
|
|
interleaved_idx += num_channels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-29 17:27:29 +00:00
|
|
|
|
|
|
|
|
// Interleave audio from the channel buffers pointed to by |deinterleaved| to
|
|
|
|
|
// |interleaved|. There must be sufficient space allocated in |interleaved|
|
|
|
|
|
// (|samples_per_channel| * |num_channels|).
|
2014-03-04 20:58:13 +00:00
|
|
|
template <typename T>
|
2015-07-23 11:41:39 -07:00
|
|
|
void Interleave(const T* const* 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 samples_per_channel,
|
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,
|
2015-07-23 11:41:39 -07:00
|
|
|
T* interleaved) {
|
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-03-04 20:58:13 +00:00
|
|
|
const T* channel = deinterleaved[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
|
|
|
size_t interleaved_idx = i;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t j = 0; j < samples_per_channel; ++j) {
|
2014-03-04 20:58:13 +00:00
|
|
|
interleaved[interleaved_idx] = channel[j];
|
|
|
|
|
interleaved_idx += num_channels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-29 17:27:29 +00:00
|
|
|
|
2015-08-14 10:35:55 -07:00
|
|
|
// Copies audio from a single channel buffer pointed to by |mono| to each
|
|
|
|
|
// channel of |interleaved|. There must be sufficient space allocated in
|
|
|
|
|
// |interleaved| (|samples_per_channel| * |num_channels|).
|
|
|
|
|
template <typename T>
|
|
|
|
|
void UpmixMonoToInterleaved(const T* mono,
|
|
|
|
|
int num_frames,
|
|
|
|
|
int num_channels,
|
|
|
|
|
T* interleaved) {
|
|
|
|
|
int interleaved_idx = 0;
|
|
|
|
|
for (int i = 0; i < num_frames; ++i) {
|
|
|
|
|
for (int j = 0; j < num_channels; ++j) {
|
|
|
|
|
interleaved[interleaved_idx++] = mono[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:41:39 -07:00
|
|
|
template <typename T, typename Intermediate>
|
|
|
|
|
void DownmixToMono(const T* const* 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 num_frames,
|
2015-07-23 11:41:39 -07:00
|
|
|
int num_channels,
|
|
|
|
|
T* out) {
|
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 < num_frames; ++i) {
|
2015-07-23 11:41:39 -07:00
|
|
|
Intermediate value = input_channels[0][i];
|
|
|
|
|
for (int j = 1; j < num_channels; ++j) {
|
|
|
|
|
value += input_channels[j][i];
|
|
|
|
|
}
|
|
|
|
|
out[i] = value / num_channels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Downmixes an interleaved multichannel signal to a single channel by averaging
|
|
|
|
|
// all channels.
|
|
|
|
|
template <typename T, typename Intermediate>
|
|
|
|
|
void DownmixInterleavedToMonoImpl(const T* interleaved,
|
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 num_frames,
|
2015-07-23 11:41:39 -07:00
|
|
|
int num_channels,
|
|
|
|
|
T* deinterleaved) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_GT(num_channels, 0);
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_DCHECK_GT(num_frames, 0);
|
2015-07-23 11:41:39 -07:00
|
|
|
|
|
|
|
|
const T* const end = interleaved + num_frames * num_channels;
|
|
|
|
|
|
|
|
|
|
while (interleaved < end) {
|
|
|
|
|
const T* const frame_end = interleaved + num_channels;
|
|
|
|
|
|
|
|
|
|
Intermediate value = *interleaved++;
|
|
|
|
|
while (interleaved < frame_end) {
|
|
|
|
|
value += *interleaved++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*deinterleaved++ = value / num_channels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
void DownmixInterleavedToMono(const T* interleaved,
|
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 num_frames,
|
2015-07-23 11:41:39 -07:00
|
|
|
int num_channels,
|
|
|
|
|
T* deinterleaved);
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
|
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 num_frames,
|
2015-07-23 11:41:39 -07:00
|
|
|
int num_channels,
|
|
|
|
|
int16_t* deinterleaved);
|
|
|
|
|
|
2013-04-29 17:27:29 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
|