aboutsummaryrefslogtreecommitdiff
path: root/common_audio
diff options
context:
space:
mode:
authorPer Åhgren <peah@webrtc.org>2019-08-20 09:19:21 +0200
committerCommit Bot <commit-bot@chromium.org>2019-08-20 08:36:47 +0000
commit928146f546193cfd56256aa828e2e19a013012cd (patch)
treeb056461bef570a89f9cb4d27aeca021458969a76 /common_audio
parent93d4c10ffccc2faf2e38bab74ba14414751bae91 (diff)
downloadwebrtc-928146f546193cfd56256aa828e2e19a013012cd.tar.gz
Removing all external access to the integer sample data in AudioBuffer
This CL removes all external access to the integer sample data in the AudioBuffer class. It also removes the API in AudioBuffer that provides this. The purpose of this is to pave the way for removing the sample duplicating and implicit conversions between integer and floating point sample formats which is done inside the AudioBuffer. Bug: webrtc:10882 Change-Id: I1438b691bcef98278aef8e3c63624c367c2d12e9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/149162 Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org> Commit-Queue: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28912}
Diffstat (limited to 'common_audio')
-rw-r--r--common_audio/audio_util.cc10
-rw-r--r--common_audio/include/audio_util.h9
-rw-r--r--common_audio/resampler/push_sinc_resampler_unittest.cc12
3 files changed, 19 insertions, 12 deletions
diff --git a/common_audio/audio_util.cc b/common_audio/audio_util.cc
index eb132ca633..b1e4d9ac3c 100644
--- a/common_audio/audio_util.cc
+++ b/common_audio/audio_util.cc
@@ -12,11 +12,21 @@
namespace webrtc {
+void FloatToS16(const float* src, size_t size, int16_t* dest) {
+ for (size_t i = 0; i < size; ++i)
+ dest[i] = FloatToS16(src[i]);
+}
+
void S16ToFloat(const int16_t* src, size_t size, float* dest) {
for (size_t i = 0; i < size; ++i)
dest[i] = S16ToFloat(src[i]);
}
+void S16ToFloatS16(const int16_t* src, size_t size, float* dest) {
+ for (size_t i = 0; i < size; ++i)
+ dest[i] = src[i];
+}
+
void FloatS16ToS16(const float* src, size_t size, int16_t* dest) {
for (size_t i = 0; i < size; ++i)
dest[i] = FloatS16ToS16(src[i]);
diff --git a/common_audio/include/audio_util.h b/common_audio/include/audio_util.h
index 9925e54b02..f6b6bfdcd6 100644
--- a/common_audio/include/audio_util.h
+++ b/common_audio/include/audio_util.h
@@ -43,6 +43,13 @@ static inline int16_t FloatS16ToS16(float v) {
return static_cast<int16_t>(v + std::copysign(0.5f, v));
}
+static inline int16_t FloatToS16(float v) {
+ v *= 32768.f;
+ v = std::min(v, 32767.f);
+ v = std::max(v, -32768.f);
+ return static_cast<int16_t>(v + std::copysign(0.5f, v));
+}
+
static inline float FloatToFloatS16(float v) {
v = std::min(v, 1.f);
v = std::max(v, -1.f);
@@ -56,7 +63,9 @@ static inline float FloatS16ToFloat(float v) {
return v * kScaling;
}
+void FloatToS16(const float* src, size_t size, int16_t* dest);
void S16ToFloat(const int16_t* src, size_t size, float* dest);
+void S16ToFloatS16(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);
diff --git a/common_audio/resampler/push_sinc_resampler_unittest.cc b/common_audio/resampler/push_sinc_resampler_unittest.cc
index f9943b3cc8..dc7cdec141 100644
--- a/common_audio/resampler/push_sinc_resampler_unittest.cc
+++ b/common_audio/resampler/push_sinc_resampler_unittest.cc
@@ -33,18 +33,6 @@ T DBFS(T x) {
return 20 * std::log10(x);
}
-void FloatToS16(const float* src, size_t size, int16_t* dest) {
- for (size_t i = 0; i < size; ++i) {
- RTC_DCHECK_GE(32767.f, src[i]);
- RTC_DCHECK_LE(-32768.f, src[i]);
- if (src[i] >= 1.f)
- dest[i] = 32767;
- if (src[i] <= -1.f)
- dest[i] = -32768;
- dest[i] = static_cast<int16_t>(src[i] * 32767.5f);
- }
-}
-
} // namespace
class PushSincResamplerTest : public ::testing::TestWithParam<