summaryrefslogtreecommitdiff
path: root/common_audio
diff options
context:
space:
mode:
authorAndroid Chromium Automerger <chromium-automerger@android>2014-09-02 10:58:28 +0000
committerAndroid Chromium Automerger <chromium-automerger@android>2014-09-02 10:58:28 +0000
commit95d21956ea7256c2f1c25dace55f9ba16b096258 (patch)
tree27a4fd56bdf6fd3242fcb4295fda2dc60bdc32fd /common_audio
parent2b1b7b7c52a3d793730c0e3b7b5935aa2e31c288 (diff)
parentf8698ce1dacfdcf804809638483adb702760469c (diff)
downloadwebrtc-95d21956ea7256c2f1c25dace55f9ba16b096258.tar.gz
Merge third_party/webrtc from https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git at f8698ce1dacfdcf804809638483adb702760469c
This commit was generated by merge_from_chromium.py. Change-Id: If6328cd0f1a485164c204accf41b23892a162235
Diffstat (limited to 'common_audio')
-rw-r--r--common_audio/common_audio.gyp9
-rw-r--r--common_audio/resampler/Android.mk47
-rw-r--r--common_audio/signal_processing/Android.mk126
-rw-r--r--common_audio/signal_processing/auto_corr_to_refl_coef.c6
-rw-r--r--common_audio/signal_processing/include/signal_processing_library.h10
-rw-r--r--common_audio/signal_processing/include/spl_inl.h80
-rw-r--r--common_audio/signal_processing/include/spl_inl_armv7.h5
-rw-r--r--common_audio/signal_processing/signal_processing_unittest.cc13
-rw-r--r--common_audio/vad/Android.mk51
-rw-r--r--common_audio/wav_writer.cc48
-rw-r--r--common_audio/wav_writer.h9
-rw-r--r--common_audio/wav_writer_unittest.cc21
12 files changed, 105 insertions, 320 deletions
diff --git a/common_audio/common_audio.gyp b/common_audio/common_audio.gyp
index 58b9bb98..ae3bacb7 100644
--- a/common_audio/common_audio.gyp
+++ b/common_audio/common_audio.gyp
@@ -184,6 +184,15 @@
'signal_processing/min_max_operations_neon.S',
'signal_processing/vector_scaling_operations_neon.S',
],
+ 'conditions': [
+ # Disable LTO in common_audio_neon target due to compiler bug
+ ['use_lto==1', {
+ 'cflags!': [
+ '-flto',
+ '-ffat-lto-objects',
+ ],
+ }],
+ ],
},
], # targets
}],
diff --git a/common_audio/resampler/Android.mk b/common_audio/resampler/Android.mk
deleted file mode 100644
index b1d630aa..00000000
--- a/common_audio/resampler/Android.mk
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (c) 2011 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/../../../android-webrtc.mk
-
-LOCAL_ARM_MODE := arm
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_MODULE := libwebrtc_resampler
-LOCAL_MODULE_TAGS := optional
-LOCAL_CPP_EXTENSION := .cc
-LOCAL_SRC_FILES := resampler.cc
-
-# Flags passed to both C and C++ files.
-LOCAL_CFLAGS := \
- $(MY_WEBRTC_COMMON_DEFS)
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/include \
- $(LOCAL_PATH)/../.. \
- $(LOCAL_PATH)/../signal_processing/include
-
-LOCAL_SHARED_LIBRARIES := \
- libcutils \
- libdl \
- libstlport
-
-ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
-LOCAL_LDLIBS += -ldl -lpthread
-endif
-
-ifneq ($(TARGET_SIMULATOR),true)
-LOCAL_SHARED_LIBRARIES += libdl
-endif
-
-ifndef NDK_ROOT
-include external/stlport/libstlport.mk
-endif
-include $(BUILD_STATIC_LIBRARY)
diff --git a/common_audio/signal_processing/Android.mk b/common_audio/signal_processing/Android.mk
deleted file mode 100644
index aed7e73b..00000000
--- a/common_audio/signal_processing/Android.mk
+++ /dev/null
@@ -1,126 +0,0 @@
-# Copyright (c) 2012 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/../../../android-webrtc.mk
-
-LOCAL_ARM_MODE := arm
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_MODULE := libwebrtc_spl
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := \
- auto_corr_to_refl_coef.c \
- auto_correlation.c \
- complex_fft.c \
- copy_set_operations.c \
- cross_correlation.c \
- division_operations.c \
- dot_product_with_scale.c \
- downsample_fast.c \
- energy.c \
- filter_ar.c \
- filter_ma_fast_q12.c \
- get_hanning_window.c \
- get_scaling_square.c \
- ilbc_specific_functions.c \
- levinson_durbin.c \
- lpc_to_refl_coef.c \
- min_max_operations.c \
- randomization_functions.c \
- real_fft.c \
- refl_coef_to_lpc.c \
- resample.c \
- resample_48khz.c \
- resample_by_2.c \
- resample_by_2_internal.c \
- resample_fractional.c \
- spl_init.c \
- spl_sqrt.c \
- spl_version.c \
- splitting_filter.c \
- sqrt_of_one_minus_x_squared.c \
- vector_scaling_operations.c
-
-# Flags passed to both C and C++ files.
-LOCAL_CFLAGS := \
- $(MY_WEBRTC_COMMON_DEFS)
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/include \
- $(LOCAL_PATH)/../.. \
- external/webrtc
-
-ifeq ($(ARCH_ARM_HAVE_ARMV7A),true)
-LOCAL_SRC_FILES += \
- filter_ar_fast_q12_armv7.S
-else
-LOCAL_SRC_FILES += \
- filter_ar_fast_q12.c
-endif
-
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += \
- complex_bit_reverse_arm.S \
- spl_sqrt_floor_arm.S
-else
-LOCAL_SRC_FILES += \
- complex_bit_reverse.c \
- spl_sqrt_floor.c
-endif
-
-LOCAL_SHARED_LIBRARIES := libstlport
-
-ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
-LOCAL_LDLIBS += -ldl -lpthread
-endif
-
-ifneq ($(TARGET_SIMULATOR),true)
-LOCAL_SHARED_LIBRARIES += libdl
-endif
-
-ifndef NDK_ROOT
-include external/stlport/libstlport.mk
-endif
-include $(BUILD_STATIC_LIBRARY)
-
-#########################
-# Build the neon library.
-ifeq ($(WEBRTC_BUILD_NEON_LIBS),true)
-
-include $(CLEAR_VARS)
-
-LOCAL_ARM_MODE := arm
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_MODULE := libwebrtc_spl_neon
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := \
- cross_correlation_neon.S \
- downsample_fast_neon.S \
- min_max_operations_neon.S \
- vector_scaling_operations_neon.S
-
-# Flags passed to both C and C++ files.
-LOCAL_CFLAGS := \
- $(MY_WEBRTC_COMMON_DEFS) \
- $(MY_ARM_CFLAGS_NEON)
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/include \
- $(LOCAL_PATH)/../.. \
- external/webrtc
-
-ifndef NDK_ROOT
-include external/stlport/libstlport.mk
-endif
-include $(BUILD_STATIC_LIBRARY)
-
-endif # ifeq ($(WEBRTC_BUILD_NEON_LIBS),true)
-
diff --git a/common_audio/signal_processing/auto_corr_to_refl_coef.c b/common_audio/signal_processing/auto_corr_to_refl_coef.c
index daffd936..f99dd62b 100644
--- a/common_audio/signal_processing/auto_corr_to_refl_coef.c
+++ b/common_audio/signal_processing/auto_corr_to_refl_coef.c
@@ -88,15 +88,15 @@ void WebRtcSpl_AutoCorrToReflCoef(const int32_t *R, int use_order, int16_t *K)
pptr = P;
wptr = w1ptr;
tmp = (int16_t)(((int32_t)*p1ptr * (int32_t)*K + 16384) >> 15);
- *pptr = WEBRTC_SPL_ADD_SAT_W16( *pptr, tmp );
+ *pptr = WebRtcSpl_AddSatW16(*pptr, tmp);
pptr++;
for (i = 1; i <= use_order - n; i++)
{
tmp = (int16_t)(((int32_t)*wptr * (int32_t)*K + 16384) >> 15);
- *pptr = WEBRTC_SPL_ADD_SAT_W16( *(pptr+1), tmp );
+ *pptr = WebRtcSpl_AddSatW16(*(pptr + 1), tmp);
pptr++;
tmp = (int16_t)(((int32_t)*pptr * (int32_t)*K + 16384) >> 15);
- *wptr = WEBRTC_SPL_ADD_SAT_W16( *wptr, tmp );
+ *wptr = WebRtcSpl_AddSatW16(*wptr, tmp);
wptr++;
}
}
diff --git a/common_audio/signal_processing/include/signal_processing_library.h b/common_audio/signal_processing/include/signal_processing_library.h
index 33a41ba2..56bbbe66 100644
--- a/common_audio/signal_processing/include/signal_processing_library.h
+++ b/common_audio/signal_processing/include/signal_processing_library.h
@@ -46,10 +46,6 @@
((uint32_t) ((uint32_t)(a) * (uint16_t)(b)))
#define WEBRTC_SPL_MUL_16_U16(a, b) \
((int32_t)(int16_t)(a) * (uint16_t)(b))
-#define WEBRTC_SPL_DIV(a, b) \
- ((int32_t) ((int32_t)(a) / (int32_t)(b)))
-#define WEBRTC_SPL_UDIV(a, b) \
- ((uint32_t) ((uint32_t)(a) / (uint32_t)(b)))
#ifndef WEBRTC_ARCH_ARM_V7
// For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
@@ -84,11 +80,7 @@
#define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
(C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16))
-#define WEBRTC_SPL_ADD_SAT_W32(a, b) WebRtcSpl_AddSatW32(a, b)
#define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b)
-#define WEBRTC_SPL_MUL_32_16(a, b) ((a) * (b))
-
-#define WEBRTC_SPL_ADD_SAT_W16(a, b) WebRtcSpl_AddSatW16(a, b)
// Shifting with negative numbers allowed
// Positive means left shift
@@ -112,8 +104,6 @@
extern "C" {
#endif
-#define WEBRTC_SPL_MEMCPY_W8(v1, v2, length) \
- memcpy(v1, v2, (length) * sizeof(char))
#define WEBRTC_SPL_MEMCPY_W16(v1, v2, length) \
memcpy(v1, v2, (length) * sizeof(int16_t))
diff --git a/common_audio/signal_processing/include/spl_inl.h b/common_audio/signal_processing/include/spl_inl.h
index a4ddb3fa..8bf452fe 100644
--- a/common_audio/signal_processing/include/spl_inl.h
+++ b/common_audio/signal_processing/include/spl_inl.h
@@ -35,6 +35,44 @@ static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
return out16;
}
+static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
+ int32_t l_sum;
+
+ // Perform long addition
+ l_sum = l_var1 + l_var2;
+
+ if (l_var1 < 0) { // Check for underflow.
+ if ((l_var2 < 0) && (l_sum >= 0)) {
+ l_sum = (int32_t)0x80000000;
+ }
+ } else { // Check for overflow.
+ if ((l_var2 > 0) && (l_sum < 0)) {
+ l_sum = (int32_t)0x7FFFFFFF;
+ }
+ }
+
+ return l_sum;
+}
+
+static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
+ int32_t l_diff;
+
+ // Perform subtraction.
+ l_diff = l_var1 - l_var2;
+
+ if (l_var1 < 0) { // Check for underflow.
+ if ((l_var2 > 0) && (l_diff > 0)) {
+ l_diff = (int32_t)0x80000000;
+ }
+ } else { // Check for overflow.
+ if ((l_var2 < 0) && (l_diff < 0)) {
+ l_diff = (int32_t)0x7FFFFFFF;
+ }
+ }
+
+ return l_diff;
+}
+
static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b);
}
@@ -132,46 +170,4 @@ static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
#endif // WEBRTC_ARCH_ARM_V7
-// The following functions have no optimized versions.
-// TODO(kma): Consider saturating add/sub instructions in X86 platform.
-#if !defined(MIPS_DSP_R1_LE)
-static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
- int32_t l_sum;
-
- // Perform long addition
- l_sum = l_var1 + l_var2;
-
- if (l_var1 < 0) { // Check for underflow.
- if ((l_var2 < 0) && (l_sum >= 0)) {
- l_sum = (int32_t)0x80000000;
- }
- } else { // Check for overflow.
- if ((l_var2 > 0) && (l_sum < 0)) {
- l_sum = (int32_t)0x7FFFFFFF;
- }
- }
-
- return l_sum;
-}
-
-static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
- int32_t l_diff;
-
- // Perform subtraction.
- l_diff = l_var1 - l_var2;
-
- if (l_var1 < 0) { // Check for underflow.
- if ((l_var2 > 0) && (l_diff > 0)) {
- l_diff = (int32_t)0x80000000;
- }
- } else { // Check for overflow.
- if ((l_var2 < 0) && (l_diff < 0)) {
- l_diff = (int32_t)0x7FFFFFFF;
- }
- }
-
- return l_diff;
-}
-#endif // #if !defined(MIPS_DSP_R1_LE)
-
#endif // WEBRTC_SPL_SPL_INL_H_
diff --git a/common_audio/signal_processing/include/spl_inl_armv7.h b/common_audio/signal_processing/include/spl_inl_armv7.h
index 0f505471..3854715d 100644
--- a/common_audio/signal_processing/include/spl_inl_armv7.h
+++ b/common_audio/signal_processing/include/spl_inl_armv7.h
@@ -51,10 +51,6 @@ static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
return (int16_t) s_sum;
}
-/* TODO(kma): find the cause of unittest errors by the next two functions:
- * http://code.google.com/p/webrtc/issues/detail?id=740.
- */
-#if 0
static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
int32_t l_sum = 0;
@@ -70,7 +66,6 @@ static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
return l_sub;
}
-#endif
static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
int32_t s_sub = 0;
diff --git a/common_audio/signal_processing/signal_processing_unittest.cc b/common_audio/signal_processing/signal_processing_unittest.cc
index 146afae5..6a70a02e 100644
--- a/common_audio/signal_processing/signal_processing_unittest.cc
+++ b/common_audio/signal_processing/signal_processing_unittest.cc
@@ -47,8 +47,6 @@ TEST_F(SplTest, MacroTest) {
a = b;
b = -3;
- EXPECT_EQ(-5461, WEBRTC_SPL_DIV(a, b));
- EXPECT_EQ(0u, WEBRTC_SPL_UDIV(a, b));
EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT16(a, b));
EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT15(a, b));
@@ -58,12 +56,8 @@ TEST_F(SplTest, MacroTest) {
EXPECT_EQ(-12288, WEBRTC_SPL_MUL_16_16_RSFT(a, b, 2));
EXPECT_EQ(-12287, WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, 2));
- EXPECT_EQ(16380, WEBRTC_SPL_ADD_SAT_W32(a, b));
EXPECT_EQ(21, WEBRTC_SPL_SAT(a, A, B));
EXPECT_EQ(21, WEBRTC_SPL_SAT(a, B, A));
- EXPECT_EQ(-49149, WEBRTC_SPL_MUL_32_16(a, b));
-
- EXPECT_EQ(16380, WEBRTC_SPL_ADD_SAT_W16(a, b));
// Shifting with negative numbers allowed
int shift_amount = 1; // Workaround compiler warning using variable here.
@@ -168,11 +162,9 @@ TEST_F(SplTest, MathOperationsTest) {
TEST_F(SplTest, BasicArrayOperationsTest) {
const int kVectorSize = 4;
int B[] = {4, 12, 133, 1100};
- uint8_t b8[kVectorSize];
int16_t b16[kVectorSize];
int32_t b32[kVectorSize];
- uint8_t bTmp8[kVectorSize];
int16_t bTmp16[kVectorSize];
int32_t bTmp32[kVectorSize];
@@ -201,14 +193,9 @@ TEST_F(SplTest, BasicArrayOperationsTest) {
EXPECT_EQ(1, b32[kk]);
}
for (int kk = 0; kk < kVectorSize; ++kk) {
- bTmp8[kk] = (int8_t)kk;
bTmp16[kk] = (int16_t)kk;
bTmp32[kk] = (int32_t)kk;
}
- WEBRTC_SPL_MEMCPY_W8(b8, bTmp8, kVectorSize);
- for (int kk = 0; kk < kVectorSize; ++kk) {
- EXPECT_EQ(b8[kk], bTmp8[kk]);
- }
WEBRTC_SPL_MEMCPY_W16(b16, bTmp16, kVectorSize);
for (int kk = 0; kk < kVectorSize; ++kk) {
EXPECT_EQ(b16[kk], bTmp16[kk]);
diff --git a/common_audio/vad/Android.mk b/common_audio/vad/Android.mk
deleted file mode 100644
index ed5de6b9..00000000
--- a/common_audio/vad/Android.mk
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (c) 2011 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/../../../android-webrtc.mk
-
-LOCAL_ARM_MODE := arm
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_MODULE := libwebrtc_vad
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := \
- webrtc_vad.c \
- vad_core.c \
- vad_filterbank.c \
- vad_gmm.c \
- vad_sp.c
-
-# Flags passed to both C and C++ files.
-LOCAL_CFLAGS := \
- $(MY_WEBRTC_COMMON_DEFS)
-
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)/include \
- $(LOCAL_PATH)/../.. \
- $(LOCAL_PATH)/../signal_processing/include \
- external/webrtc
-
-LOCAL_SHARED_LIBRARIES := \
- libdl \
- libstlport
-
-ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
-LOCAL_LDLIBS += -ldl -lpthread
-endif
-
-ifneq ($(TARGET_SIMULATOR),true)
-LOCAL_SHARED_LIBRARIES += libdl
-endif
-
-ifndef NDK_ROOT
-include external/stlport/libstlport.mk
-endif
-include $(BUILD_STATIC_LIBRARY)
diff --git a/common_audio/wav_writer.cc b/common_audio/wav_writer.cc
index e5714735..30a220c2 100644
--- a/common_audio/wav_writer.cc
+++ b/common_audio/wav_writer.cc
@@ -29,17 +29,17 @@ WavFile::WavFile(const std::string& filename, int sample_rate, int num_channels)
num_channels_(num_channels),
num_samples_(0),
file_handle_(fopen(filename.c_str(), "wb")) {
- FATAL_ERROR_IF(!CheckWavParameters(num_channels_,
- sample_rate_,
- kWavFormat,
- kBytesPerSample,
- num_samples_));
- FATAL_ERROR_IF(!file_handle_);
+ CHECK(file_handle_);
+ CHECK(CheckWavParameters(num_channels_,
+ sample_rate_,
+ kWavFormat,
+ kBytesPerSample,
+ num_samples_));
// Write a blank placeholder header, since we need to know the total number
// of samples before we can fill in the real data.
static const uint8_t blank_header[kWavHeaderSize] = {0};
- FATAL_ERROR_IF(fwrite(blank_header, kWavHeaderSize, 1, file_handle_) != 1);
+ CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_));
}
WavFile::~WavFile() {
@@ -52,15 +52,15 @@ void WavFile::WriteSamples(const int16_t* samples, size_t num_samples) {
#endif
const size_t written =
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
- FATAL_ERROR_IF(written != num_samples);
+ CHECK_EQ(num_samples, written);
num_samples_ += static_cast<uint32_t>(written);
- FATAL_ERROR_IF(written > std::numeric_limits<uint32_t>::max() ||
- num_samples_ < written); // detect uint32_t overflow
- FATAL_ERROR_IF(!CheckWavParameters(num_channels_,
- sample_rate_,
- kWavFormat,
- kBytesPerSample,
- num_samples_));
+ CHECK(written <= std::numeric_limits<uint32_t>::max() ||
+ num_samples_ >= written); // detect uint32_t overflow
+ CHECK(CheckWavParameters(num_channels_,
+ sample_rate_,
+ kWavFormat,
+ kBytesPerSample,
+ num_samples_));
}
void WavFile::WriteSamples(const float* samples, size_t num_samples) {
@@ -74,12 +74,12 @@ void WavFile::WriteSamples(const float* samples, size_t num_samples) {
}
void WavFile::Close() {
- FATAL_ERROR_IF(fseek(file_handle_, 0, SEEK_SET) != 0);
+ CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET));
uint8_t header[kWavHeaderSize];
WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat,
kBytesPerSample, num_samples_);
- FATAL_ERROR_IF(fwrite(header, kWavHeaderSize, 1, file_handle_) != 1);
- FATAL_ERROR_IF(fclose(file_handle_) != 0);
+ CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_));
+ CHECK_EQ(0, fclose(file_handle_));
file_handle_ = NULL;
}
@@ -101,3 +101,15 @@ void rtc_WavWriteSamples(rtc_WavFile* wf,
size_t num_samples) {
reinterpret_cast<webrtc::WavFile*>(wf)->WriteSamples(samples, num_samples);
}
+
+int rtc_WavSampleRate(const rtc_WavFile* wf) {
+ return reinterpret_cast<const webrtc::WavFile*>(wf)->sample_rate();
+}
+
+int rtc_WavNumChannels(const rtc_WavFile* wf) {
+ return reinterpret_cast<const webrtc::WavFile*>(wf)->num_channels();
+}
+
+uint32_t rtc_WavNumSamples(const rtc_WavFile* wf) {
+ return reinterpret_cast<const webrtc::WavFile*>(wf)->num_samples();
+}
diff --git a/common_audio/wav_writer.h b/common_audio/wav_writer.h
index a8fee51e..45bcbac5 100644
--- a/common_audio/wav_writer.h
+++ b/common_audio/wav_writer.h
@@ -20,7 +20,7 @@
namespace webrtc {
// Simple C++ class for writing 16-bit PCM WAV files. All error handling is
-// by calls to FATAL_ERROR(), making it unsuitable for anything but debug code.
+// by calls to CHECK(), making it unsuitable for anything but debug code.
class WavFile {
public:
// Open a new WAV file for writing.
@@ -34,6 +34,10 @@ class WavFile {
// interleaved channels.
void WriteSamples(const float* samples, size_t num_samples);
+ int sample_rate() const { return sample_rate_; }
+ int num_channels() const { return num_channels_; }
+ uint32_t num_samples() const { return num_samples_; }
+
private:
void WriteSamples(const int16_t* samples, size_t num_samples);
void Close();
@@ -57,6 +61,9 @@ void rtc_WavClose(rtc_WavFile* wf);
void rtc_WavWriteSamples(rtc_WavFile* wf,
const float* samples,
size_t num_samples);
+int rtc_WavSampleRate(const rtc_WavFile* wf);
+int rtc_WavNumChannels(const rtc_WavFile* wf);
+uint32_t rtc_WavNumSamples(const rtc_WavFile* wf);
#ifdef __cplusplus
} // extern "C"
diff --git a/common_audio/wav_writer_unittest.cc b/common_audio/wav_writer_unittest.cc
index 9efe96e3..9c593be6 100644
--- a/common_audio/wav_writer_unittest.cc
+++ b/common_audio/wav_writer_unittest.cc
@@ -25,10 +25,14 @@ static const float kSamples[] = {0.0, 10.0, 4e4, -1e9};
// Write a tiny WAV file with the C++ interface and verify the result.
TEST(WavWriterTest, CPP) {
const std::string outfile = webrtc::test::OutputPath() + "wavtest1.wav";
- static const int kNumSamples = 3;
+ static const uint32_t kNumSamples = 3;
{
webrtc::WavFile w(outfile, 14099, 1);
+ EXPECT_EQ(14099, w.sample_rate());
+ EXPECT_EQ(1, w.num_channels());
+ EXPECT_EQ(0u, w.num_samples());
w.WriteSamples(kSamples, kNumSamples);
+ EXPECT_EQ(kNumSamples, w.num_samples());
}
static const uint8_t kExpectedContents[] = {
'R', 'I', 'F', 'F',
@@ -64,9 +68,14 @@ TEST(WavWriterTest, CPP) {
TEST(WavWriterTest, C) {
const std::string outfile = webrtc::test::OutputPath() + "wavtest2.wav";
rtc_WavFile *w = rtc_WavOpen(outfile.c_str(), 11904, 2);
- static const int kNumSamples = 4;
+ EXPECT_EQ(11904, rtc_WavSampleRate(w));
+ EXPECT_EQ(2, rtc_WavNumChannels(w));
+ EXPECT_EQ(0u, rtc_WavNumSamples(w));
+ static const uint32_t kNumSamples = 4;
rtc_WavWriteSamples(w, &kSamples[0], 2);
+ EXPECT_EQ(2u, rtc_WavNumSamples(w));
rtc_WavWriteSamples(w, &kSamples[2], kNumSamples - 2);
+ EXPECT_EQ(kNumSamples, rtc_WavNumSamples(w));
rtc_WavClose(w);
static const uint8_t kExpectedContents[] = {
'R', 'I', 'F', 'F',
@@ -104,9 +113,9 @@ TEST(WavWriterTest, LargeFile) {
std::string outfile = webrtc::test::OutputPath() + "wavtest3.wav";
static const int kSampleRate = 8000;
static const int kNumChannels = 2;
- static const int kNumSamples = 3 * kSampleRate * kNumChannels;
+ static const uint32_t kNumSamples = 3 * kSampleRate * kNumChannels;
float samples[kNumSamples];
- for (int i = 0; i < kNumSamples; i += kNumChannels) {
+ for (uint32_t i = 0; i < kNumSamples; i += kNumChannels) {
// A nice periodic beeping sound.
static const double kToneHz = 440;
const double t = static_cast<double>(i) / (kNumChannels * kSampleRate);
@@ -117,7 +126,11 @@ TEST(WavWriterTest, LargeFile) {
}
{
webrtc::WavFile w(outfile, kSampleRate, kNumChannels);
+ EXPECT_EQ(kSampleRate, w.sample_rate());
+ EXPECT_EQ(kNumChannels, w.num_channels());
+ EXPECT_EQ(0u, w.num_samples());
w.WriteSamples(samples, kNumSamples);
+ EXPECT_EQ(kNumSamples, w.num_samples());
}
EXPECT_EQ(sizeof(int16_t) * kNumSamples + webrtc::kWavHeaderSize,
webrtc::test::GetFileSize(outfile));