From 928146f546193cfd56256aa828e2e19a013012cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Tue, 20 Aug 2019 09:19:21 +0200 Subject: Removing all external access to the integer sample data in AudioBuffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Henrik Lundin Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#28912} --- common_audio/audio_util.cc | 10 ++++++++++ common_audio/include/audio_util.h | 9 +++++++++ common_audio/resampler/push_sinc_resampler_unittest.cc | 12 ------------ 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'common_audio') 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(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(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(src[i] * 32767.5f); - } -} - } // namespace class PushSincResamplerTest : public ::testing::TestWithParam< -- cgit v1.2.3