From e47c1d3ca172e5ea84e59c1e88dbe25664664e54 Mon Sep 17 00:00:00 2001 From: oprypin Date: Thu, 9 Mar 2017 02:43:31 -0800 Subject: [PATCH] Revert of Enable cpplint and fix cpplint errors in webrtc/*audio (patchset #4 id:180001 of https://codereview.webrtc.org/2683033004/ ) Reason for revert: The API change in audio/utility/audio_frame_operations.h caused breakage. Need to keep backward-compatible API. Original issue's description: > Enable cpplint and fix cpplint errors in webrtc/*audio > > Change usage accordingly throughout the codebase > > BUG=webrtc:5268 > > TESTED=Fixed issues reported by: > find webrtc/*audio -type f -name *.cc -o -name *.h | xargs cpplint.py > > Review-Url: https://codereview.webrtc.org/2683033004 > Cr-Commit-Position: refs/heads/master@{#17133} > Committed: https://chromium.googlesource.com/external/webrtc/+/aebe55ca6c2f725c81031722badb297a2fb1d331 TBR=henrika@webrtc.org,henrik.lundin@webrtc.org,kwiberg@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:5268 Review-Url: https://codereview.webrtc.org/2739143002 Cr-Commit-Position: refs/heads/master@{#17138} --- PRESUBMIT.py | 1 - webrtc/audio/audio_transport_proxy.cc | 2 +- .../audio/utility/audio_frame_operations.cc | 24 +- webrtc/audio/utility/audio_frame_operations.h | 4 +- .../audio_frame_operations_unittest.cc | 20 +- webrtc/common_audio/audio_converter.cc | 3 +- webrtc/common_audio/audio_converter.h | 2 +- webrtc/common_audio/blocker.h | 6 +- webrtc/common_audio/channel_buffer.h | 6 +- webrtc/common_audio/include/audio_util.h | 1 - webrtc/common_audio/lapped_transform.h | 10 +- webrtc/common_audio/real_fourier.h | 2 +- .../resampler/include/resampler.h | 117 +- .../common_audio/resampler/push_resampler.cc | 2 +- .../resampler/push_sinc_resampler_unittest.cc | 1 - webrtc/common_audio/resampler/resampler.cc | 1712 +++++++++-------- .../resampler/sinc_resampler_unittest.cc | 1 - webrtc/common_audio/ring_buffer_unittest.cc | 7 +- .../include/signal_processing_library.h | 14 +- .../signal_processing/include/spl_inl.h | 8 +- .../signal_processing/include/spl_inl_armv7.h | 12 +- .../signal_processing/include/spl_inl_mips.h | 42 +- .../signal_processing/real_fft_unittest.cc | 8 +- .../resample_by_2_internal.h | 6 +- .../signal_processing_unittest.cc | 18 +- webrtc/common_audio/vad/vad_core.h | 7 +- webrtc/common_audio/vad/vad_core_unittest.cc | 6 +- .../vad/vad_filterbank_unittest.cc | 6 +- webrtc/common_audio/vad/vad_gmm_unittest.cc | 6 +- webrtc/common_audio/vad/vad_sp_unittest.cc | 6 +- webrtc/common_audio/vad/vad_unittest.cc | 6 +- webrtc/common_audio/vad/vad_unittest.h | 12 +- webrtc/voice_engine/channel.cc | 2 +- 33 files changed, 1068 insertions(+), 1012 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 189be256a1..df4f55fe6b 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -18,7 +18,6 @@ CPPLINT_DIRS = [ 'webrtc/api', 'webrtc/audio', 'webrtc/call', - 'webrtc/common_audio', 'webrtc/common_video', 'webrtc/examples', 'webrtc/modules/audio_mixer', diff --git a/webrtc/audio/audio_transport_proxy.cc b/webrtc/audio/audio_transport_proxy.cc index 4d2f9e30e1..c201d8a490 100644 --- a/webrtc/audio/audio_transport_proxy.cc +++ b/webrtc/audio/audio_transport_proxy.cc @@ -52,7 +52,7 @@ int32_t AudioTransportProxy::RecordedDataIsAvailable( const int32_t clockDrift, const uint32_t currentMicLevel, const bool keyPressed, - uint32_t& newMicLevel) { // NOLINT: to avoid changing APIs + uint32_t& newMicLevel) { // Pass call through to original audio transport instance. return voe_audio_transport_->RecordedDataIsAvailable( audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec, diff --git a/webrtc/audio/utility/audio_frame_operations.cc b/webrtc/audio/utility/audio_frame_operations.cc index 0338b46db0..475539f5b4 100644 --- a/webrtc/audio/utility/audio_frame_operations.cc +++ b/webrtc/audio/utility/audio_frame_operations.cc @@ -280,32 +280,32 @@ void AudioFrameOperations::ApplyHalfGain(AudioFrame* frame) { } } -int AudioFrameOperations::Scale(float left, float right, AudioFrame* frame) { - if (frame->num_channels_ != 2) { +int AudioFrameOperations::Scale(float left, float right, AudioFrame& frame) { + if (frame.num_channels_ != 2) { return -1; } - for (size_t i = 0; i < frame->samples_per_channel_; i++) { - frame->data_[2 * i] = static_cast(left * frame->data_[2 * i]); - frame->data_[2 * i + 1] = - static_cast(right * frame->data_[2 * i + 1]); + for (size_t i = 0; i < frame.samples_per_channel_; i++) { + frame.data_[2 * i] = static_cast(left * frame.data_[2 * i]); + frame.data_[2 * i + 1] = + static_cast(right * frame.data_[2 * i + 1]); } return 0; } -int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame* frame) { +int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame& frame) { int32_t temp_data = 0; // Ensure that the output result is saturated [-32768, +32767]. - for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_; + for (size_t i = 0; i < frame.samples_per_channel_ * frame.num_channels_; i++) { - temp_data = static_cast(scale * frame->data_[i]); + temp_data = static_cast(scale * frame.data_[i]); if (temp_data < -32768) { - frame->data_[i] = -32768; + frame.data_[i] = -32768; } else if (temp_data > 32767) { - frame->data_[i] = 32767; + frame.data_[i] = 32767; } else { - frame->data_[i] = static_cast(temp_data); + frame.data_[i] = static_cast(temp_data); } } return 0; diff --git a/webrtc/audio/utility/audio_frame_operations.h b/webrtc/audio/utility/audio_frame_operations.h index 23c33ec67e..de6fdc472d 100644 --- a/webrtc/audio/utility/audio_frame_operations.h +++ b/webrtc/audio/utility/audio_frame_operations.h @@ -113,9 +113,9 @@ class AudioFrameOperations { // Halve samples in |frame|. static void ApplyHalfGain(AudioFrame* frame); - static int Scale(float left, float right, AudioFrame* frame); + static int Scale(float left, float right, AudioFrame& frame); - static int ScaleWithSat(float scale, AudioFrame* frame); + static int ScaleWithSat(float scale, AudioFrame& frame); }; } // namespace webrtc diff --git a/webrtc/audio/utility/audio_frame_operations_unittest.cc b/webrtc/audio/utility/audio_frame_operations_unittest.cc index 096ea38d9d..af8ae24626 100644 --- a/webrtc/audio/utility/audio_frame_operations_unittest.cc +++ b/webrtc/audio/utility/audio_frame_operations_unittest.cc @@ -426,20 +426,20 @@ TEST_F(AudioFrameOperationsTest, MuteEndStereoShort) { // TODO(andrew): should not allow negative scales. TEST_F(AudioFrameOperationsTest, DISABLED_ScaleFailsWithBadParameters) { frame_.num_channels_ = 1; - EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, &frame_)); + EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, frame_)); frame_.num_channels_ = 3; - EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, &frame_)); + EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, frame_)); frame_.num_channels_ = 2; - EXPECT_EQ(-1, AudioFrameOperations::Scale(-1.0, 1.0, &frame_)); - EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, -1.0, &frame_)); + EXPECT_EQ(-1, AudioFrameOperations::Scale(-1.0, 1.0, frame_)); + EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, -1.0, frame_)); } // TODO(andrew): fix the wraparound bug. We should always saturate. TEST_F(AudioFrameOperationsTest, DISABLED_ScaleDoesNotWrapAround) { SetFrameData(4000, -4000, &frame_); - EXPECT_EQ(0, AudioFrameOperations::Scale(10.0, 10.0, &frame_)); + EXPECT_EQ(0, AudioFrameOperations::Scale(10.0, 10.0, frame_)); AudioFrame clipped_frame; clipped_frame.samples_per_channel_ = 320; @@ -450,7 +450,7 @@ TEST_F(AudioFrameOperationsTest, DISABLED_ScaleDoesNotWrapAround) { TEST_F(AudioFrameOperationsTest, ScaleSucceeds) { SetFrameData(1, -1, &frame_); - EXPECT_EQ(0, AudioFrameOperations::Scale(2.0, 3.0, &frame_)); + EXPECT_EQ(0, AudioFrameOperations::Scale(2.0, 3.0, frame_)); AudioFrame scaled_frame; scaled_frame.samples_per_channel_ = 320; @@ -461,13 +461,13 @@ TEST_F(AudioFrameOperationsTest, ScaleSucceeds) { // TODO(andrew): should fail with a negative scale. TEST_F(AudioFrameOperationsTest, DISABLED_ScaleWithSatFailsWithBadParameters) { - EXPECT_EQ(-1, AudioFrameOperations::ScaleWithSat(-1.0, &frame_)); + EXPECT_EQ(-1, AudioFrameOperations::ScaleWithSat(-1.0, frame_)); } TEST_F(AudioFrameOperationsTest, ScaleWithSatDoesNotWrapAround) { frame_.num_channels_ = 1; SetFrameData(4000, &frame_); - EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, &frame_)); + EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, frame_)); AudioFrame clipped_frame; clipped_frame.samples_per_channel_ = 320; @@ -476,7 +476,7 @@ TEST_F(AudioFrameOperationsTest, ScaleWithSatDoesNotWrapAround) { VerifyFramesAreEqual(clipped_frame, frame_); SetFrameData(-4000, &frame_); - EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, &frame_)); + EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, frame_)); SetFrameData(-32768, &clipped_frame); VerifyFramesAreEqual(clipped_frame, frame_); } @@ -484,7 +484,7 @@ TEST_F(AudioFrameOperationsTest, ScaleWithSatDoesNotWrapAround) { TEST_F(AudioFrameOperationsTest, ScaleWithSatSucceeds) { frame_.num_channels_ = 1; SetFrameData(1, &frame_); - EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(2.0, &frame_)); + EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(2.0, frame_)); AudioFrame scaled_frame; scaled_frame.samples_per_channel_ = 320; diff --git a/webrtc/common_audio/audio_converter.cc b/webrtc/common_audio/audio_converter.cc index e8595333f6..231ba88077 100644 --- a/webrtc/common_audio/audio_converter.cc +++ b/webrtc/common_audio/audio_converter.cc @@ -107,8 +107,7 @@ class ResampleConverter : public AudioConverter { // converters must be provided. class CompositionConverter : public AudioConverter { public: - explicit CompositionConverter( - std::vector> converters) + CompositionConverter(std::vector> converters) : converters_(std::move(converters)) { RTC_CHECK_GE(converters_.size(), 2); // We need an intermediate buffer after every converter. diff --git a/webrtc/common_audio/audio_converter.h b/webrtc/common_audio/audio_converter.h index d3c65acee1..01dad4dfc8 100644 --- a/webrtc/common_audio/audio_converter.h +++ b/webrtc/common_audio/audio_converter.h @@ -31,7 +31,7 @@ class AudioConverter { size_t src_frames, size_t dst_channels, size_t dst_frames); - virtual ~AudioConverter() {} + virtual ~AudioConverter() {}; // Convert |src|, containing |src_size| samples, to |dst|, having a sample // capacity of |dst_capacity|. Both point to a series of buffers containing diff --git a/webrtc/common_audio/blocker.h b/webrtc/common_audio/blocker.h index 38324712fe..d941c2acc0 100644 --- a/webrtc/common_audio/blocker.h +++ b/webrtc/common_audio/blocker.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_COMMON_AUDIO_BLOCKER_H_ -#define WEBRTC_COMMON_AUDIO_BLOCKER_H_ +#ifndef WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ +#define WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ #include @@ -124,4 +124,4 @@ class Blocker { } // namespace webrtc -#endif // WEBRTC_COMMON_AUDIO_BLOCKER_H_ +#endif // WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_ diff --git a/webrtc/common_audio/channel_buffer.h b/webrtc/common_audio/channel_buffer.h index 930dd73553..c4c85d1ef5 100644 --- a/webrtc/common_audio/channel_buffer.h +++ b/webrtc/common_audio/channel_buffer.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_ -#define WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_ +#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ +#define WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ #include @@ -183,4 +183,4 @@ class IFChannelBuffer { } // namespace webrtc -#endif // WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_ +#endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_ diff --git a/webrtc/common_audio/include/audio_util.h b/webrtc/common_audio/include/audio_util.h index 9307c556ad..1601c7fd1e 100644 --- a/webrtc/common_audio/include/audio_util.h +++ b/webrtc/common_audio/include/audio_util.h @@ -11,7 +11,6 @@ #ifndef WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ #define WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ -#include #include #include diff --git a/webrtc/common_audio/lapped_transform.h b/webrtc/common_audio/lapped_transform.h index fc03a9de39..42a103a854 100644 --- a/webrtc/common_audio/lapped_transform.h +++ b/webrtc/common_audio/lapped_transform.h @@ -99,11 +99,11 @@ class LappedTransform { public: explicit BlockThunk(LappedTransform* parent) : parent_(parent) {} - void ProcessBlock(const float* const* input, - size_t num_frames, - size_t num_input_channels, - size_t num_output_channels, - float* const* output) override; + void ProcessBlock(const float* const* input, + size_t num_frames, + size_t num_input_channels, + size_t num_output_channels, + float* const* output) override; private: LappedTransform* const parent_; diff --git a/webrtc/common_audio/real_fourier.h b/webrtc/common_audio/real_fourier.h index 1b851e919e..5e83e37f70 100644 --- a/webrtc/common_audio/real_fourier.h +++ b/webrtc/common_audio/real_fourier.h @@ -35,7 +35,7 @@ class RealFourier { // Construct a wrapper instance for the given input order, which must be // between 1 and kMaxFftOrder, inclusively. static std::unique_ptr Create(int fft_order); - virtual ~RealFourier() {} + virtual ~RealFourier() {}; // Helper to compute the smallest FFT order (a power of 2) which will contain // the given input length. diff --git a/webrtc/common_audio/resampler/include/resampler.h b/webrtc/common_audio/resampler/include/resampler.h index 259349b670..e26ac904c0 100644 --- a/webrtc/common_audio/resampler/include/resampler.h +++ b/webrtc/common_audio/resampler/include/resampler.h @@ -13,8 +13,8 @@ * A wrapper for resampling a numerous amount of sampling combinations. */ -#ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_ -#define WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_ +#ifndef WEBRTC_RESAMPLER_RESAMPLER_H_ +#define WEBRTC_RESAMPLER_RESAMPLER_H_ #include @@ -23,70 +23,73 @@ namespace webrtc { // All methods return 0 on success and -1 on failure. -class Resampler { - public: - Resampler(); - Resampler(int inFreq, int outFreq, size_t num_channels); - ~Resampler(); +class Resampler +{ - // Reset all states - int Reset(int inFreq, int outFreq, size_t num_channels); +public: + Resampler(); + Resampler(int inFreq, int outFreq, size_t num_channels); + ~Resampler(); - // Reset all states if any parameter has changed - int ResetIfNeeded(int inFreq, int outFreq, size_t num_channels); + // Reset all states + int Reset(int inFreq, int outFreq, size_t num_channels); - // Resample samplesIn to samplesOut. - int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut, - size_t maxLen, size_t& outLen); // NOLINT: to avoid changing APIs + // Reset all states if any parameter has changed + int ResetIfNeeded(int inFreq, int outFreq, size_t num_channels); - private: - enum ResamplerMode { - kResamplerMode1To1, - kResamplerMode1To2, - kResamplerMode1To3, - kResamplerMode1To4, - kResamplerMode1To6, - kResamplerMode1To12, - kResamplerMode2To3, - kResamplerMode2To11, - kResamplerMode4To11, - kResamplerMode8To11, - kResamplerMode11To16, - kResamplerMode11To32, - kResamplerMode2To1, - kResamplerMode3To1, - kResamplerMode4To1, - kResamplerMode6To1, - kResamplerMode12To1, - kResamplerMode3To2, - kResamplerMode11To2, - kResamplerMode11To4, - kResamplerMode11To8 - }; + // Resample samplesIn to samplesOut. + int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut, + size_t maxLen, size_t &outLen); - // Generic pointers since we don't know what states we'll need - void* state1_; - void* state2_; - void* state3_; +private: + enum ResamplerMode + { + kResamplerMode1To1, + kResamplerMode1To2, + kResamplerMode1To3, + kResamplerMode1To4, + kResamplerMode1To6, + kResamplerMode1To12, + kResamplerMode2To3, + kResamplerMode2To11, + kResamplerMode4To11, + kResamplerMode8To11, + kResamplerMode11To16, + kResamplerMode11To32, + kResamplerMode2To1, + kResamplerMode3To1, + kResamplerMode4To1, + kResamplerMode6To1, + kResamplerMode12To1, + kResamplerMode3To2, + kResamplerMode11To2, + kResamplerMode11To4, + kResamplerMode11To8 + }; - // Storage if needed - int16_t* in_buffer_; - int16_t* out_buffer_; - size_t in_buffer_size_; - size_t out_buffer_size_; - size_t in_buffer_size_max_; - size_t out_buffer_size_max_; + // Generic pointers since we don't know what states we'll need + void* state1_; + void* state2_; + void* state3_; - int my_in_frequency_khz_; - int my_out_frequency_khz_; - ResamplerMode my_mode_; - size_t num_channels_; + // Storage if needed + int16_t* in_buffer_; + int16_t* out_buffer_; + size_t in_buffer_size_; + size_t out_buffer_size_; + size_t in_buffer_size_max_; + size_t out_buffer_size_max_; - // Extra instance for stereo - Resampler* slave_left_; - Resampler* slave_right_; + int my_in_frequency_khz_; + int my_out_frequency_khz_; + ResamplerMode my_mode_; + size_t num_channels_; + + // Extra instance for stereo + Resampler* slave_left_; + Resampler* slave_right_; }; } // namespace webrtc -#endif // WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_ +#endif // WEBRTC_RESAMPLER_RESAMPLER_H_ diff --git a/webrtc/common_audio/resampler/push_resampler.cc b/webrtc/common_audio/resampler/push_resampler.cc index ec904b81c8..788223d343 100644 --- a/webrtc/common_audio/resampler/push_resampler.cc +++ b/webrtc/common_audio/resampler/push_resampler.cc @@ -53,7 +53,7 @@ void CheckExpectedBufferSizes(size_t src_length, RTC_DCHECK_GE(dst_capacity, dst_size_10ms); #endif } -} // namespace +} template PushResampler::PushResampler() diff --git a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc index eab46efb9b..ab7f141fb4 100644 --- a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc +++ b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include #include #include #include diff --git a/webrtc/common_audio/resampler/resampler.cc b/webrtc/common_audio/resampler/resampler.cc index 8efb16cb31..c91a5de9ce 100644 --- a/webrtc/common_audio/resampler/resampler.cc +++ b/webrtc/common_audio/resampler/resampler.cc @@ -44,860 +44,916 @@ Resampler::Resampler(int inFreq, int outFreq, size_t num_channels) Reset(inFreq, outFreq, num_channels); } -Resampler::~Resampler() { - if (state1_) { - free(state1_); - } - if (state2_) { - free(state2_); - } - if (state3_) { - free(state3_); - } - if (in_buffer_) { - free(in_buffer_); - } - if (out_buffer_) { - free(out_buffer_); - } - if (slave_left_) { - delete slave_left_; - } - if (slave_right_) { - delete slave_right_; - } +Resampler::~Resampler() +{ + if (state1_) + { + free(state1_); + } + if (state2_) + { + free(state2_); + } + if (state3_) + { + free(state3_); + } + if (in_buffer_) + { + free(in_buffer_); + } + if (out_buffer_) + { + free(out_buffer_); + } + if (slave_left_) + { + delete slave_left_; + } + if (slave_right_) + { + delete slave_right_; + } } -int Resampler::ResetIfNeeded(int inFreq, int outFreq, size_t num_channels) { - int tmpInFreq_kHz = inFreq / 1000; - int tmpOutFreq_kHz = outFreq / 1000; +int Resampler::ResetIfNeeded(int inFreq, int outFreq, size_t num_channels) +{ + int tmpInFreq_kHz = inFreq / 1000; + int tmpOutFreq_kHz = outFreq / 1000; - if ((tmpInFreq_kHz != my_in_frequency_khz_) - || (tmpOutFreq_kHz != my_out_frequency_khz_) - || (num_channels != num_channels_)) { - return Reset(inFreq, outFreq, num_channels); - } else { - return 0; - } + if ((tmpInFreq_kHz != my_in_frequency_khz_) || (tmpOutFreq_kHz != my_out_frequency_khz_) + || (num_channels != num_channels_)) + { + return Reset(inFreq, outFreq, num_channels); + } else + { + return 0; + } } -int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) { - if (num_channels != 1 && num_channels != 2) { +int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) +{ + if (num_channels != 1 && num_channels != 2) { return -1; - } - num_channels_ = num_channels; + } + num_channels_ = num_channels; - if (state1_) { - free(state1_); - state1_ = nullptr; - } - if (state2_) { - free(state2_); - state2_ = nullptr; - } - if (state3_) { - free(state3_); - state3_ = nullptr; - } - if (in_buffer_) { - free(in_buffer_); - in_buffer_ = nullptr; - } - if (out_buffer_) { - free(out_buffer_); - out_buffer_ = nullptr; - } - if (slave_left_) { - delete slave_left_; - slave_left_ = nullptr; - } - if (slave_right_) { - delete slave_right_; - slave_right_ = nullptr; - } + if (state1_) + { + free(state1_); + state1_ = nullptr; + } + if (state2_) + { + free(state2_); + state2_ = nullptr; + } + if (state3_) + { + free(state3_); + state3_ = nullptr; + } + if (in_buffer_) + { + free(in_buffer_); + in_buffer_ = nullptr; + } + if (out_buffer_) + { + free(out_buffer_); + out_buffer_ = nullptr; + } + if (slave_left_) + { + delete slave_left_; + slave_left_ = nullptr; + } + if (slave_right_) + { + delete slave_right_; + slave_right_ = nullptr; + } - in_buffer_size_ = 0; - out_buffer_size_ = 0; - in_buffer_size_max_ = 0; - out_buffer_size_max_ = 0; + in_buffer_size_ = 0; + out_buffer_size_ = 0; + in_buffer_size_max_ = 0; + out_buffer_size_max_ = 0; - // Start with a math exercise, Euclid's algorithm to find the gcd: - int a = inFreq; - int b = outFreq; - int c = a % b; - while (c != 0) { - a = b; - b = c; - c = a % b; - } - // b is now the gcd; + // Start with a math exercise, Euclid's algorithm to find the gcd: + int a = inFreq; + int b = outFreq; + int c = a % b; + while (c != 0) + { + a = b; + b = c; + c = a % b; + } + // b is now the gcd; - // We need to track what domain we're in. - my_in_frequency_khz_ = inFreq / 1000; - my_out_frequency_khz_ = outFreq / 1000; + // We need to track what domain we're in. + my_in_frequency_khz_ = inFreq / 1000; + my_out_frequency_khz_ = outFreq / 1000; - // Scale with GCD - inFreq = inFreq / b; - outFreq = outFreq / b; + // Scale with GCD + inFreq = inFreq / b; + outFreq = outFreq / b; - if (num_channels_ == 2) { - // Create two mono resamplers. - slave_left_ = new Resampler(inFreq, outFreq, 1); - slave_right_ = new Resampler(inFreq, outFreq, 1); - } + if (num_channels_ == 2) + { + // Create two mono resamplers. + slave_left_ = new Resampler(inFreq, outFreq, 1); + slave_right_ = new Resampler(inFreq, outFreq, 1); + } - if (inFreq == outFreq) { - my_mode_ = kResamplerMode1To1; - } else if (inFreq == 1) { - switch (outFreq) { - case 2: - my_mode_ = kResamplerMode1To2; - break; - case 3: - my_mode_ = kResamplerMode1To3; - break; - case 4: - my_mode_ = kResamplerMode1To4; - break; - case 6: - my_mode_ = kResamplerMode1To6; - break; - case 12: - my_mode_ = kResamplerMode1To12; - break; - default: + if (inFreq == outFreq) + { + my_mode_ = kResamplerMode1To1; + } else if (inFreq == 1) + { + switch (outFreq) + { + case 2: + my_mode_ = kResamplerMode1To2; + break; + case 3: + my_mode_ = kResamplerMode1To3; + break; + case 4: + my_mode_ = kResamplerMode1To4; + break; + case 6: + my_mode_ = kResamplerMode1To6; + break; + case 12: + my_mode_ = kResamplerMode1To12; + break; + default: + return -1; + } + } else if (outFreq == 1) + { + switch (inFreq) + { + case 2: + my_mode_ = kResamplerMode2To1; + break; + case 3: + my_mode_ = kResamplerMode3To1; + break; + case 4: + my_mode_ = kResamplerMode4To1; + break; + case 6: + my_mode_ = kResamplerMode6To1; + break; + case 12: + my_mode_ = kResamplerMode12To1; + break; + default: + return -1; + } + } else if ((inFreq == 2) && (outFreq == 3)) + { + my_mode_ = kResamplerMode2To3; + } else if ((inFreq == 2) && (outFreq == 11)) + { + my_mode_ = kResamplerMode2To11; + } else if ((inFreq == 4) && (outFreq == 11)) + { + my_mode_ = kResamplerMode4To11; + } else if ((inFreq == 8) && (outFreq == 11)) + { + my_mode_ = kResamplerMode8To11; + } else if ((inFreq == 3) && (outFreq == 2)) + { + my_mode_ = kResamplerMode3To2; + } else if ((inFreq == 11) && (outFreq == 2)) + { + my_mode_ = kResamplerMode11To2; + } else if ((inFreq == 11) && (outFreq == 4)) + { + my_mode_ = kResamplerMode11To4; + } else if ((inFreq == 11) && (outFreq == 16)) + { + my_mode_ = kResamplerMode11To16; + } else if ((inFreq == 11) && (outFreq == 32)) + { + my_mode_ = kResamplerMode11To32; + } else if ((inFreq == 11) && (outFreq == 8)) + { + my_mode_ = kResamplerMode11To8; + } else + { return -1; } - } else if (outFreq == 1) { - switch (inFreq) { - case 2: - my_mode_ = kResamplerMode2To1; - break; - case 3: - my_mode_ = kResamplerMode3To1; - break; - case 4: - my_mode_ = kResamplerMode4To1; - break; - case 6: - my_mode_ = kResamplerMode6To1; - break; - case 12: - my_mode_ = kResamplerMode12To1; - break; - default: - return -1; + + // Now create the states we need + switch (my_mode_) + { + case kResamplerMode1To1: + // No state needed; + break; + case kResamplerMode1To2: + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode1To3: + state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); + WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state1_); + break; + case kResamplerMode1To4: + // 1:2 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + // 2:4 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode1To6: + // 1:2 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + // 2:6 + state2_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); + WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state2_); + break; + case kResamplerMode1To12: + // 1:2 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + // 2:4 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + // 4:12 + state3_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); + WebRtcSpl_ResetResample16khzTo48khz( + (WebRtcSpl_State16khzTo48khz*) state3_); + break; + case kResamplerMode2To3: + // 2:6 + state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); + WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state1_); + // 6:3 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode2To11: + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + + state2_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz)); + WebRtcSpl_ResetResample8khzTo22khz((WebRtcSpl_State8khzTo22khz *)state2_); + break; + case kResamplerMode4To11: + state1_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz)); + WebRtcSpl_ResetResample8khzTo22khz((WebRtcSpl_State8khzTo22khz *)state1_); + break; + case kResamplerMode8To11: + state1_ = malloc(sizeof(WebRtcSpl_State16khzTo22khz)); + WebRtcSpl_ResetResample16khzTo22khz((WebRtcSpl_State16khzTo22khz *)state1_); + break; + case kResamplerMode11To16: + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + + state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); + WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state2_); + break; + case kResamplerMode11To32: + // 11 -> 22 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + + // 22 -> 16 + state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); + WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state2_); + + // 16 -> 32 + state3_ = malloc(8 * sizeof(int32_t)); + memset(state3_, 0, 8 * sizeof(int32_t)); + + break; + case kResamplerMode2To1: + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode3To1: + state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); + WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state1_); + break; + case kResamplerMode4To1: + // 4:2 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + // 2:1 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode6To1: + // 6:2 + state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); + WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state1_); + // 2:1 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode12To1: + // 12:4 + state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); + WebRtcSpl_ResetResample48khzTo16khz( + (WebRtcSpl_State48khzTo16khz*) state1_); + // 4:2 + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + // 2:1 + state3_ = malloc(8 * sizeof(int32_t)); + memset(state3_, 0, 8 * sizeof(int32_t)); + break; + case kResamplerMode3To2: + // 3:6 + state1_ = malloc(8 * sizeof(int32_t)); + memset(state1_, 0, 8 * sizeof(int32_t)); + // 6:2 + state2_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); + WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state2_); + break; + case kResamplerMode11To2: + state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz)); + WebRtcSpl_ResetResample22khzTo8khz((WebRtcSpl_State22khzTo8khz *)state1_); + + state2_ = malloc(8 * sizeof(int32_t)); + memset(state2_, 0, 8 * sizeof(int32_t)); + + break; + case kResamplerMode11To4: + state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz)); + WebRtcSpl_ResetResample22khzTo8khz((WebRtcSpl_State22khzTo8khz *)state1_); + break; + case kResamplerMode11To8: + state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); + WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state1_); + break; + } - } else if ((inFreq == 2) && (outFreq == 3)) { - my_mode_ = kResamplerMode2To3; - } else if ((inFreq == 2) && (outFreq == 11)) { - my_mode_ = kResamplerMode2To11; - } else if ((inFreq == 4) && (outFreq == 11)) { - my_mode_ = kResamplerMode4To11; - } else if ((inFreq == 8) && (outFreq == 11)) { - my_mode_ = kResamplerMode8To11; - } else if ((inFreq == 3) && (outFreq == 2)) { - my_mode_ = kResamplerMode3To2; - } else if ((inFreq == 11) && (outFreq == 2)) { - my_mode_ = kResamplerMode11To2; - } else if ((inFreq == 11) && (outFreq == 4)) { - my_mode_ = kResamplerMode11To4; - } else if ((inFreq == 11) && (outFreq == 16)) { - my_mode_ = kResamplerMode11To16; - } else if ((inFreq == 11) && (outFreq == 32)) { - my_mode_ = kResamplerMode11To32; - } else if ((inFreq == 11) && (outFreq == 8)) { - my_mode_ = kResamplerMode11To8; - } else { - return -1; - } - // Now create the states we need - switch (my_mode_) { - case kResamplerMode1To1: - // No state needed; - break; - case kResamplerMode1To2: - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode1To3: - state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); - WebRtcSpl_ResetResample16khzTo48khz( - static_cast(state1_)); - break; - case kResamplerMode1To4: - // 1:2 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - // 2:4 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode1To6: - // 1:2 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - // 2:6 - state2_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); - WebRtcSpl_ResetResample16khzTo48khz( - static_cast(state2_)); - break; - case kResamplerMode1To12: - // 1:2 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - // 2:4 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - // 4:12 - state3_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); - WebRtcSpl_ResetResample16khzTo48khz( - static_cast(state3_)); - break; - case kResamplerMode2To3: - // 2:6 - state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); - WebRtcSpl_ResetResample16khzTo48khz( - static_cast(state1_)); - // 6:3 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode2To11: - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - - state2_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz)); - WebRtcSpl_ResetResample8khzTo22khz( - static_cast(state2_)); - break; - case kResamplerMode4To11: - state1_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz)); - WebRtcSpl_ResetResample8khzTo22khz( - static_cast(state1_)); - break; - case kResamplerMode8To11: - state1_ = malloc(sizeof(WebRtcSpl_State16khzTo22khz)); - WebRtcSpl_ResetResample16khzTo22khz( - static_cast(state1_)); - break; - case kResamplerMode11To16: - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - - state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); - WebRtcSpl_ResetResample22khzTo16khz( - static_cast(state2_)); - break; - case kResamplerMode11To32: - // 11 -> 22 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - - // 22 -> 16 - state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); - WebRtcSpl_ResetResample22khzTo16khz( - static_cast(state2_)); - - // 16 -> 32 - state3_ = malloc(8 * sizeof(int32_t)); - memset(state3_, 0, 8 * sizeof(int32_t)); - - break; - case kResamplerMode2To1: - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode3To1: - state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); - WebRtcSpl_ResetResample48khzTo16khz( - static_cast(state1_)); - break; - case kResamplerMode4To1: - // 4:2 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - // 2:1 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode6To1: - // 6:2 - state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); - WebRtcSpl_ResetResample48khzTo16khz( - static_cast(state1_)); - // 2:1 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode12To1: - // 12:4 - state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); - WebRtcSpl_ResetResample48khzTo16khz( - static_cast(state1_)); - // 4:2 - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - // 2:1 - state3_ = malloc(8 * sizeof(int32_t)); - memset(state3_, 0, 8 * sizeof(int32_t)); - break; - case kResamplerMode3To2: - // 3:6 - state1_ = malloc(8 * sizeof(int32_t)); - memset(state1_, 0, 8 * sizeof(int32_t)); - // 6:2 - state2_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz)); - WebRtcSpl_ResetResample48khzTo16khz( - static_cast(state2_)); - break; - case kResamplerMode11To2: - state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz)); - WebRtcSpl_ResetResample22khzTo8khz( - static_cast(state1_)); - - state2_ = malloc(8 * sizeof(int32_t)); - memset(state2_, 0, 8 * sizeof(int32_t)); - - break; - case kResamplerMode11To4: - state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz)); - WebRtcSpl_ResetResample22khzTo8khz( - static_cast(state1_)); - break; - case kResamplerMode11To8: - state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz)); - WebRtcSpl_ResetResample22khzTo16khz( - static_cast(state1_)); - break; - } - - return 0; + return 0; } // Synchronous resampling, all output samples are written to samplesOut int Resampler::Push(const int16_t * samplesIn, size_t lengthIn, - int16_t* samplesOut, size_t maxLen, size_t& outLen) { - if (num_channels_ == 2) { - // Split up the signal and call the slave object for each channel - int16_t* left = - static_cast(malloc(lengthIn * sizeof(int16_t) / 2)); - int16_t* right = - static_cast(malloc(lengthIn * sizeof(int16_t) / 2)); - int16_t* out_left = - static_cast(malloc(maxLen / 2 * sizeof(int16_t))); - int16_t* out_right = - static_cast(malloc(maxLen / 2 * sizeof(int16_t))); - int res = 0; - for (size_t i = 0; i < lengthIn; i += 2) { - left[i >> 1] = samplesIn[i]; - right[i >> 1] = samplesIn[i + 1]; + int16_t* samplesOut, size_t maxLen, size_t &outLen) +{ + if (num_channels_ == 2) + { + // Split up the signal and call the slave object for each channel + int16_t* left = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); + int16_t* right = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2); + int16_t* out_left = (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); + int16_t* out_right = + (int16_t*)malloc(maxLen / 2 * sizeof(int16_t)); + int res = 0; + for (size_t i = 0; i < lengthIn; i += 2) + { + left[i >> 1] = samplesIn[i]; + right[i >> 1] = samplesIn[i + 1]; + } + + // It's OK to overwrite the local parameter, since it's just a copy + lengthIn = lengthIn / 2; + + size_t actualOutLen_left = 0; + size_t actualOutLen_right = 0; + // Do resampling for right channel + res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, actualOutLen_left); + res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, actualOutLen_right); + if (res || (actualOutLen_left != actualOutLen_right)) + { + free(left); + free(right); + free(out_left); + free(out_right); + return -1; + } + + // Reassemble the signal + for (size_t i = 0; i < actualOutLen_left; i++) + { + samplesOut[i * 2] = out_left[i]; + samplesOut[i * 2 + 1] = out_right[i]; + } + outLen = 2 * actualOutLen_left; + + free(left); + free(right); + free(out_left); + free(out_right); + + return 0; } - // It's OK to overwrite the local parameter, since it's just a copy - lengthIn = lengthIn / 2; + // Containers for temp samples + int16_t* tmp; + int16_t* tmp_2; + // tmp data for resampling routines + int32_t* tmp_mem; + + switch (my_mode_) + { + case kResamplerMode1To1: + memcpy(samplesOut, samplesIn, lengthIn * sizeof(int16_t)); + outLen = lengthIn; + break; + case kResamplerMode1To2: + if (maxLen < (lengthIn * 2)) + { + return -1; + } + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_); + outLen = lengthIn * 2; + return 0; + case kResamplerMode1To3: + + // We can only handle blocks of 160 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 160) != 0) + { + return -1; + } + if (maxLen < (lengthIn * 3)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 160) + { + WebRtcSpl_Resample16khzTo48khz(samplesIn + i, samplesOut + i * 3, + (WebRtcSpl_State16khzTo48khz *)state1_, + tmp_mem); + } + outLen = lengthIn * 3; + free(tmp_mem); + return 0; + case kResamplerMode1To4: + if (maxLen < (lengthIn * 4)) + { + return -1; + } + + tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); + // 1:2 + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + // 2:4 + WebRtcSpl_UpsampleBy2(tmp, lengthIn * 2, samplesOut, (int32_t*)state2_); + outLen = lengthIn * 4; + free(tmp); + return 0; + case kResamplerMode1To6: + // We can only handle blocks of 80 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 80) != 0) + { + return -1; + } + if (maxLen < (lengthIn * 6)) + { + return -1; + } + + //1:2 + + tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); + tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); + + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + outLen = lengthIn * 2; + + for (size_t i = 0; i < outLen; i += 160) + { + WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, + (WebRtcSpl_State16khzTo48khz *)state2_, + tmp_mem); + } + outLen = outLen * 3; + free(tmp_mem); + free(tmp); + + return 0; + case kResamplerMode1To12: + // We can only handle blocks of 40 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 40) != 0) { + return -1; + } + if (maxLen < (lengthIn * 12)) { + return -1; + } + + tmp_mem = (int32_t*) malloc(336 * sizeof(int32_t)); + tmp = (int16_t*) malloc(sizeof(int16_t) * 4 * lengthIn); + //1:2 + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, + (int32_t*) state1_); + outLen = lengthIn * 2; + //2:4 + WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, (int32_t*) state2_); + outLen = outLen * 2; + // 4:12 + for (size_t i = 0; i < outLen; i += 160) { + // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples + // as input and outputs a resampled block of 480 samples. The + // data is now actually in 32 kHz sampling rate, despite the + // function name, and with a resampling factor of three becomes + // 96 kHz. + WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3, + (WebRtcSpl_State16khzTo48khz*) state3_, + tmp_mem); + } + outLen = outLen * 3; + free(tmp_mem); + free(tmp); + + return 0; + case kResamplerMode2To3: + if (maxLen < (lengthIn * 3 / 2)) + { + return -1; + } + // 2:6 + // We can only handle blocks of 160 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 160) != 0) + { + return -1; + } + tmp = static_cast (malloc(sizeof(int16_t) * lengthIn * 3)); + tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t)); + for (size_t i = 0; i < lengthIn; i += 160) + { + WebRtcSpl_Resample16khzTo48khz(samplesIn + i, tmp + i * 3, + (WebRtcSpl_State16khzTo48khz *)state1_, + tmp_mem); + } + lengthIn = lengthIn * 3; + // 6:3 + WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, (int32_t*)state2_); + outLen = lengthIn / 2; + free(tmp); + free(tmp_mem); + return 0; + case kResamplerMode2To11: + + // We can only handle blocks of 80 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 80) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 11) / 2)) + { + return -1; + } + tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn); + // 1:2 + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + lengthIn *= 2; + + tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 80) + { + WebRtcSpl_Resample8khzTo22khz(tmp + i, samplesOut + (i * 11) / 4, + (WebRtcSpl_State8khzTo22khz *)state2_, + tmp_mem); + } + outLen = (lengthIn * 11) / 4; + free(tmp_mem); + free(tmp); + return 0; + case kResamplerMode4To11: + + // We can only handle blocks of 80 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 80) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 11) / 4)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 80) + { + WebRtcSpl_Resample8khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 4, + (WebRtcSpl_State8khzTo22khz *)state1_, + tmp_mem); + } + outLen = (lengthIn * 11) / 4; + free(tmp_mem); + return 0; + case kResamplerMode8To11: + // We can only handle blocks of 160 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 160) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 11) / 8)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(88 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 160) + { + WebRtcSpl_Resample16khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 8, + (WebRtcSpl_State16khzTo22khz *)state1_, + tmp_mem); + } + outLen = (lengthIn * 11) / 8; + free(tmp_mem); + return 0; + + case kResamplerMode11To16: + // We can only handle blocks of 110 samples + if ((lengthIn % 110) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 16) / 11)) + { + return -1; + } + + tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); + tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); + + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + + for (size_t i = 0; i < (lengthIn * 2); i += 220) + { + WebRtcSpl_Resample22khzTo16khz(tmp + i, samplesOut + (i / 220) * 160, + (WebRtcSpl_State22khzTo16khz *)state2_, + tmp_mem); + } + + outLen = (lengthIn * 16) / 11; + + free(tmp_mem); + free(tmp); + return 0; + + case kResamplerMode11To32: + + // We can only handle blocks of 110 samples + if ((lengthIn % 110) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 32) / 11)) + { + return -1; + } + + tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); + tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2)); + + // 11 -> 22 kHz in samplesOut + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_); + + // 22 -> 16 in tmp + for (size_t i = 0; i < (lengthIn * 2); i += 220) + { + WebRtcSpl_Resample22khzTo16khz(samplesOut + i, tmp + (i / 220) * 160, + (WebRtcSpl_State22khzTo16khz *)state2_, + tmp_mem); + } + + // 16 -> 32 in samplesOut + WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut, + (int32_t*)state3_); + + outLen = (lengthIn * 32) / 11; + + free(tmp_mem); + free(tmp); + return 0; + + case kResamplerMode2To1: + if (maxLen < (lengthIn / 2)) + { + return -1; + } + WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_); + outLen = lengthIn / 2; + return 0; + case kResamplerMode3To1: + // We can only handle blocks of 480 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 480) != 0) + { + return -1; + } + if (maxLen < (lengthIn / 3)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 480) + { + WebRtcSpl_Resample48khzTo16khz(samplesIn + i, samplesOut + i / 3, + (WebRtcSpl_State48khzTo16khz *)state1_, + tmp_mem); + } + outLen = lengthIn / 3; + free(tmp_mem); + return 0; + case kResamplerMode4To1: + if (maxLen < (lengthIn / 4)) + { + return -1; + } + tmp = (int16_t*)malloc(sizeof(int16_t) * lengthIn / 2); + // 4:2 + WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + // 2:1 + WebRtcSpl_DownsampleBy2(tmp, lengthIn / 2, samplesOut, (int32_t*)state2_); + outLen = lengthIn / 4; + free(tmp); + return 0; + + case kResamplerMode6To1: + // We can only handle blocks of 480 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 480) != 0) + { + return -1; + } + if (maxLen < (lengthIn / 6)) + { + return -1; + } + + tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); + tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn) / 3); + + for (size_t i = 0; i < lengthIn; i += 480) + { + WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, + (WebRtcSpl_State48khzTo16khz *)state1_, + tmp_mem); + } + outLen = lengthIn / 3; + free(tmp_mem); + WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut, (int32_t*)state2_); + free(tmp); + outLen = outLen / 2; + return 0; + case kResamplerMode12To1: + // We can only handle blocks of 480 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 480) != 0) { + return -1; + } + if (maxLen < (lengthIn / 12)) { + return -1; + } + + tmp_mem = (int32_t*) malloc(496 * sizeof(int32_t)); + tmp = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 3); + tmp_2 = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 6); + // 12:4 + for (size_t i = 0; i < lengthIn; i += 480) { + // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples + // as input and outputs a resampled block of 160 samples. The + // data is now actually in 96 kHz sampling rate, despite the + // function name, and with a resampling factor of 1/3 becomes + // 32 kHz. + WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3, + (WebRtcSpl_State48khzTo16khz*) state1_, + tmp_mem); + } + outLen = lengthIn / 3; + free(tmp_mem); + // 4:2 + WebRtcSpl_DownsampleBy2(tmp, outLen, tmp_2, (int32_t*) state2_); + outLen = outLen / 2; + free(tmp); + // 2:1 + WebRtcSpl_DownsampleBy2(tmp_2, outLen, samplesOut, + (int32_t*) state3_); + free(tmp_2); + outLen = outLen / 2; + return 0; + case kResamplerMode3To2: + if (maxLen < (lengthIn * 2 / 3)) + { + return -1; + } + // 3:6 + tmp = static_cast (malloc(sizeof(int16_t) * lengthIn * 2)); + WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_); + lengthIn *= 2; + // 6:2 + // We can only handle blocks of 480 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 480) != 0) + { + free(tmp); + return -1; + } + tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t)); + for (size_t i = 0; i < lengthIn; i += 480) + { + WebRtcSpl_Resample48khzTo16khz(tmp + i, samplesOut + i / 3, + (WebRtcSpl_State48khzTo16khz *)state2_, + tmp_mem); + } + outLen = lengthIn / 3; + free(tmp); + free(tmp_mem); + return 0; + case kResamplerMode11To2: + // We can only handle blocks of 220 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 220) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 2) / 11)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); + tmp = (int16_t*)malloc((lengthIn * 4) / 11 * sizeof(int16_t)); + + for (size_t i = 0; i < lengthIn; i += 220) + { + WebRtcSpl_Resample22khzTo8khz(samplesIn + i, tmp + (i * 4) / 11, + (WebRtcSpl_State22khzTo8khz *)state1_, + tmp_mem); + } + lengthIn = (lengthIn * 4) / 11; + + WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, + (int32_t*)state2_); + outLen = lengthIn / 2; + + free(tmp_mem); + free(tmp); + return 0; + case kResamplerMode11To4: + // We can only handle blocks of 220 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 220) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 4) / 11)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 220) + { + WebRtcSpl_Resample22khzTo8khz(samplesIn + i, samplesOut + (i * 4) / 11, + (WebRtcSpl_State22khzTo8khz *)state1_, + tmp_mem); + } + outLen = (lengthIn * 4) / 11; + free(tmp_mem); + return 0; + case kResamplerMode11To8: + // We can only handle blocks of 160 samples + // Can be fixed, but I don't think it's needed + if ((lengthIn % 220) != 0) + { + return -1; + } + if (maxLen < ((lengthIn * 8) / 11)) + { + return -1; + } + tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t)); + + for (size_t i = 0; i < lengthIn; i += 220) + { + WebRtcSpl_Resample22khzTo16khz(samplesIn + i, samplesOut + (i * 8) / 11, + (WebRtcSpl_State22khzTo16khz *)state1_, + tmp_mem); + } + outLen = (lengthIn * 8) / 11; + free(tmp_mem); + return 0; + break; - size_t actualOutLen_left = 0; - size_t actualOutLen_right = 0; - // Do resampling for right channel - res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, - actualOutLen_left); - res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, - actualOutLen_right); - if (res || (actualOutLen_left != actualOutLen_right)) { - free(left); - free(right); - free(out_left); - free(out_right); - return -1; } - - // Reassemble the signal - for (size_t i = 0; i < actualOutLen_left; i++) { - samplesOut[i * 2] = out_left[i]; - samplesOut[i * 2 + 1] = out_right[i]; - } - outLen = 2 * actualOutLen_left; - - free(left); - free(right); - free(out_left); - free(out_right); - return 0; - } - - // Containers for temp samples - int16_t* tmp; - int16_t* tmp_2; - // tmp data for resampling routines - int32_t* tmp_mem; - - switch (my_mode_) { - case kResamplerMode1To1: - memcpy(samplesOut, samplesIn, lengthIn * sizeof(int16_t)); - outLen = lengthIn; - break; - case kResamplerMode1To2: - if (maxLen < (lengthIn * 2)) { - return -1; - } - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, - static_cast(state1_)); - outLen = lengthIn * 2; - return 0; - case kResamplerMode1To3: - - // We can only handle blocks of 160 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 160) != 0) { - return -1; - } - if (maxLen < (lengthIn * 3)) { - return -1; - } - tmp_mem = static_cast(malloc(336 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 160) { - WebRtcSpl_Resample16khzTo48khz( - samplesIn + i, samplesOut + i * 3, - static_cast(state1_), tmp_mem); - } - outLen = lengthIn * 3; - free(tmp_mem); - return 0; - case kResamplerMode1To4: - if (maxLen < (lengthIn * 4)) { - return -1; - } - - tmp = static_cast(malloc(sizeof(int16_t) * 2 * lengthIn)); - // 1:2 - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - // 2:4 - WebRtcSpl_UpsampleBy2(tmp, lengthIn * 2, samplesOut, - static_cast(state2_)); - outLen = lengthIn * 4; - free(tmp); - return 0; - case kResamplerMode1To6: - // We can only handle blocks of 80 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 80) != 0) { - return -1; - } - if (maxLen < (lengthIn * 6)) { - return -1; - } - - // 1:2 - - tmp_mem = static_cast(malloc(336 * sizeof(int32_t))); - tmp = static_cast(malloc(sizeof(int16_t) * 2 * lengthIn)); - - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - outLen = lengthIn * 2; - - for (size_t i = 0; i < outLen; i += 160) { - WebRtcSpl_Resample16khzTo48khz( - tmp + i, samplesOut + i * 3, - static_cast(state2_), tmp_mem); - } - outLen = outLen * 3; - free(tmp_mem); - free(tmp); - - return 0; - case kResamplerMode1To12: - // We can only handle blocks of 40 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 40) != 0) { - return -1; - } - if (maxLen < (lengthIn * 12)) { - return -1; - } - - tmp_mem = static_cast(malloc(336 * sizeof(int32_t))); - tmp = static_cast(malloc(sizeof(int16_t) * 4 * lengthIn)); - // 1:2 - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, - static_cast(state1_)); - outLen = lengthIn * 2; - // 2:4 - WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, - static_cast(state2_)); - outLen = outLen * 2; - // 4:12 - for (size_t i = 0; i < outLen; i += 160) { - // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples - // as input and outputs a resampled block of 480 samples. The - // data is now actually in 32 kHz sampling rate, despite the - // function name, and with a resampling factor of three becomes - // 96 kHz. - WebRtcSpl_Resample16khzTo48khz( - tmp + i, samplesOut + i * 3, - static_cast(state3_), tmp_mem); - } - outLen = outLen * 3; - free(tmp_mem); - free(tmp); - - return 0; - case kResamplerMode2To3: - if (maxLen < (lengthIn * 3 / 2)) { - return -1; - } - // 2:6 - // We can only handle blocks of 160 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 160) != 0) { - return -1; - } - tmp = static_cast (malloc(sizeof(int16_t) * lengthIn * 3)); - tmp_mem = static_cast(malloc(336 * sizeof(int32_t))); - for (size_t i = 0; i < lengthIn; i += 160) { - WebRtcSpl_Resample16khzTo48khz( - samplesIn + i, tmp + i * 3, - static_cast(state1_), tmp_mem); - } - lengthIn = lengthIn * 3; - // 6:3 - WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, - static_cast(state2_)); - outLen = lengthIn / 2; - free(tmp); - free(tmp_mem); - return 0; - case kResamplerMode2To11: - - // We can only handle blocks of 80 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 80) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 11) / 2)) { - return -1; - } - tmp = static_cast(malloc(sizeof(int16_t) * 2 * lengthIn)); - // 1:2 - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - lengthIn *= 2; - - tmp_mem = static_cast(malloc(98 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 80) { - WebRtcSpl_Resample8khzTo22khz( - tmp + i, samplesOut + (i * 11) / 4, - static_cast(state2_), tmp_mem); - } - outLen = (lengthIn * 11) / 4; - free(tmp_mem); - free(tmp); - return 0; - case kResamplerMode4To11: - - // We can only handle blocks of 80 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 80) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 11) / 4)) { - return -1; - } - tmp_mem = static_cast(malloc(98 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 80) { - WebRtcSpl_Resample8khzTo22khz( - samplesIn + i, samplesOut + (i * 11) / 4, - static_cast(state1_), tmp_mem); - } - outLen = (lengthIn * 11) / 4; - free(tmp_mem); - return 0; - case kResamplerMode8To11: - // We can only handle blocks of 160 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 160) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 11) / 8)) { - return -1; - } - tmp_mem = static_cast(malloc(88 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 160) { - WebRtcSpl_Resample16khzTo22khz( - samplesIn + i, samplesOut + (i * 11) / 8, - static_cast(state1_), tmp_mem); - } - outLen = (lengthIn * 11) / 8; - free(tmp_mem); - return 0; - - case kResamplerMode11To16: - // We can only handle blocks of 110 samples - if ((lengthIn % 110) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 16) / 11)) { - return -1; - } - - tmp_mem = static_cast(malloc(104 * sizeof(int32_t))); - tmp = static_cast(malloc((sizeof(int16_t) * lengthIn * 2))); - - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - - for (size_t i = 0; i < (lengthIn * 2); i += 220) { - WebRtcSpl_Resample22khzTo16khz( - tmp + i, samplesOut + (i / 220) * 160, - static_cast(state2_), tmp_mem); - } - - outLen = (lengthIn * 16) / 11; - - free(tmp_mem); - free(tmp); - return 0; - - case kResamplerMode11To32: - - // We can only handle blocks of 110 samples - if ((lengthIn % 110) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 32) / 11)) { - return -1; - } - - tmp_mem = static_cast(malloc(104 * sizeof(int32_t))); - tmp = static_cast(malloc((sizeof(int16_t) * lengthIn * 2))); - - // 11 -> 22 kHz in samplesOut - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, - static_cast(state1_)); - - // 22 -> 16 in tmp - for (size_t i = 0; i < (lengthIn * 2); i += 220) { - WebRtcSpl_Resample22khzTo16khz( - samplesOut + i, tmp + (i / 220) * 160, - static_cast(state2_), tmp_mem); - } - - // 16 -> 32 in samplesOut - WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut, - static_cast(state3_)); - - outLen = (lengthIn * 32) / 11; - - free(tmp_mem); - free(tmp); - return 0; - - case kResamplerMode2To1: - if (maxLen < (lengthIn / 2)) { - return -1; - } - WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, samplesOut, - static_cast(state1_)); - outLen = lengthIn / 2; - return 0; - case kResamplerMode3To1: - // We can only handle blocks of 480 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 480) != 0) { - return -1; - } - if (maxLen < (lengthIn / 3)) { - return -1; - } - tmp_mem = static_cast(malloc(496 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 480) { - WebRtcSpl_Resample48khzTo16khz( - samplesIn + i, samplesOut + i / 3, - static_cast(state1_), tmp_mem); - } - outLen = lengthIn / 3; - free(tmp_mem); - return 0; - case kResamplerMode4To1: - if (maxLen < (lengthIn / 4)) { - return -1; - } - tmp = static_cast(malloc(sizeof(int16_t) * lengthIn / 2)); - // 4:2 - WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - // 2:1 - WebRtcSpl_DownsampleBy2(tmp, lengthIn / 2, samplesOut, - static_cast(state2_)); - outLen = lengthIn / 4; - free(tmp); - return 0; - - case kResamplerMode6To1: - // We can only handle blocks of 480 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 480) != 0) { - return -1; - } - if (maxLen < (lengthIn / 6)) { - return -1; - } - - tmp_mem = static_cast(malloc(496 * sizeof(int32_t))); - tmp = static_cast(malloc((sizeof(int16_t) * lengthIn) / 3)); - - for (size_t i = 0; i < lengthIn; i += 480) { - WebRtcSpl_Resample48khzTo16khz( - samplesIn + i, tmp + i / 3, - static_cast(state1_), tmp_mem); - } - outLen = lengthIn / 3; - free(tmp_mem); - WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut, - static_cast(state2_)); - free(tmp); - outLen = outLen / 2; - return 0; - case kResamplerMode12To1: - // We can only handle blocks of 480 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 480) != 0) { - return -1; - } - if (maxLen < (lengthIn / 12)) { - return -1; - } - - tmp_mem = static_cast(malloc(496 * sizeof(int32_t))); - tmp = static_cast(malloc((sizeof(int16_t) * lengthIn) / 3)); - tmp_2 = static_cast(malloc((sizeof(int16_t) * lengthIn) / 6)); - // 12:4 - for (size_t i = 0; i < lengthIn; i += 480) { - // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples - // as input and outputs a resampled block of 160 samples. The - // data is now actually in 96 kHz sampling rate, despite the - // function name, and with a resampling factor of 1/3 becomes - // 32 kHz. - WebRtcSpl_Resample48khzTo16khz( - samplesIn + i, tmp + i / 3, - static_cast(state1_), tmp_mem); - } - outLen = lengthIn / 3; - free(tmp_mem); - // 4:2 - WebRtcSpl_DownsampleBy2(tmp, outLen, tmp_2, - static_cast(state2_)); - outLen = outLen / 2; - free(tmp); - // 2:1 - WebRtcSpl_DownsampleBy2(tmp_2, outLen, samplesOut, - static_cast(state3_)); - free(tmp_2); - outLen = outLen / 2; - return 0; - case kResamplerMode3To2: - if (maxLen < (lengthIn * 2 / 3)) { - return -1; - } - // 3:6 - tmp = static_cast (malloc(sizeof(int16_t) * lengthIn * 2)); - WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, - static_cast(state1_)); - lengthIn *= 2; - // 6:2 - // We can only handle blocks of 480 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 480) != 0) { - free(tmp); - return -1; - } - tmp_mem = static_cast(malloc(496 * sizeof(int32_t))); - for (size_t i = 0; i < lengthIn; i += 480) { - WebRtcSpl_Resample48khzTo16khz( - tmp + i, samplesOut + i / 3, - static_cast(state2_), tmp_mem); - } - outLen = lengthIn / 3; - free(tmp); - free(tmp_mem); - return 0; - case kResamplerMode11To2: - // We can only handle blocks of 220 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 220) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 2) / 11)) { - return -1; - } - tmp_mem = static_cast(malloc(126 * sizeof(int32_t))); - tmp = static_cast( - malloc((lengthIn * 4) / 11 * sizeof(int16_t))); - - for (size_t i = 0; i < lengthIn; i += 220) { - WebRtcSpl_Resample22khzTo8khz( - samplesIn + i, tmp + (i * 4) / 11, - static_cast(state1_), tmp_mem); - } - lengthIn = (lengthIn * 4) / 11; - - WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, - static_cast(state2_)); - outLen = lengthIn / 2; - - free(tmp_mem); - free(tmp); - return 0; - case kResamplerMode11To4: - // We can only handle blocks of 220 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 220) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 4) / 11)) { - return -1; - } - tmp_mem = static_cast(malloc(126 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 220) { - WebRtcSpl_Resample22khzTo8khz( - samplesIn + i, samplesOut + (i * 4) / 11, - static_cast(state1_), tmp_mem); - } - outLen = (lengthIn * 4) / 11; - free(tmp_mem); - return 0; - case kResamplerMode11To8: - // We can only handle blocks of 160 samples - // Can be fixed, but I don't think it's needed - if ((lengthIn % 220) != 0) { - return -1; - } - if (maxLen < ((lengthIn * 8) / 11)) { - return -1; - } - tmp_mem = static_cast(malloc(104 * sizeof(int32_t))); - - for (size_t i = 0; i < lengthIn; i += 220) { - WebRtcSpl_Resample22khzTo16khz( - samplesIn + i, samplesOut + (i * 8) / 11, - static_cast(state1_), tmp_mem); - } - outLen = (lengthIn * 8) / 11; - free(tmp_mem); - return 0; - break; - } - return 0; } } // namespace webrtc diff --git a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc index 82546d0360..35c5d22b08 100644 --- a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc +++ b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc @@ -16,7 +16,6 @@ #include -#include #include #include "webrtc/base/timeutils.h" diff --git a/webrtc/common_audio/ring_buffer_unittest.cc b/webrtc/common_audio/ring_buffer_unittest.cc index 20fc014279..a5b53b027a 100644 --- a/webrtc/common_audio/ring_buffer_unittest.cc +++ b/webrtc/common_audio/ring_buffer_unittest.cc @@ -58,8 +58,7 @@ static void RandomStressTest(int** data_ptr) { printf("seed=%u\n", seed); srand(seed); for (int i = 0; i < kNumTests; i++) { - // rand_r is not supported on many platforms, so rand is used. - const int buffer_size = std::max(rand() % kMaxBufferSize, 1); // NOLINT + const int buffer_size = std::max(rand() % kMaxBufferSize, 1); std::unique_ptr write_data(new int[buffer_size]); std::unique_ptr read_data(new int[buffer_size]); scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int))); @@ -69,8 +68,8 @@ static void RandomStressTest(int** data_ptr) { int write_element = 0; int read_element = 0; for (int j = 0; j < kNumOps; j++) { - const bool write = rand() % 2 == 0 ? true : false; // NOLINT - const int num_elements = rand() % buffer_size; // NOLINT + const bool write = rand() % 2 == 0 ? true : false; + const int num_elements = rand() % buffer_size; if (write) { const int buffer_available = buffer_size - buffer_consumed; ASSERT_EQ(static_cast(buffer_available), diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h index f4fe8e86a4..f1d605bb27 100644 --- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h +++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h @@ -15,8 +15,8 @@ * For specific function calls, see bottom of file. */ -#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ -#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ +#ifndef WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_ +#define WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_ #include #include "webrtc/common_audio/signal_processing/dot_product_with_scale.h" @@ -60,13 +60,13 @@ #define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \ (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 5) + \ - (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10)) + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10)) #define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \ (WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 2) + \ - (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13)) + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13)) #define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \ ((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 1)) + \ - (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14)) + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14)) #define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \ (WEBRTC_SPL_MUL_16_16(a, b) >> (c)) @@ -77,7 +77,7 @@ // C + the 32 most significant bits of A * B #define WEBRTC_SPL_SCALEDIFF32(A, B, C) \ - (C + (B >> 16) * A + (((uint32_t)(B & 0x0000FFFF) * A) >> 16)) + (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * A) >> 16)) #define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b) @@ -906,7 +906,7 @@ void WebRtcSpl_SynthesisQMF(const int16_t* low_band, #ifdef __cplusplus } #endif // __cplusplus -#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ +#endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_ // // WebRtcSpl_AddSatW16(...) diff --git a/webrtc/common_audio/signal_processing/include/spl_inl.h b/webrtc/common_audio/signal_processing/include/spl_inl.h index 370834e694..90098caaaa 100644 --- a/webrtc/common_audio/signal_processing/include/spl_inl.h +++ b/webrtc/common_audio/signal_processing/include/spl_inl.h @@ -12,8 +12,8 @@ // This header file includes the inline functions in // the fix point signal processing library. -#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_ -#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_ +#ifndef WEBRTC_SPL_SPL_INL_H_ +#define WEBRTC_SPL_SPL_INL_H_ #include "webrtc/system_wrappers/include/compile_assert_c.h" @@ -56,7 +56,7 @@ static __inline int WebRtcSpl_CountLeadingZeros32(uint32_t n) { // Returns the number of leading zero bits in the argument. static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { #ifdef __GNUC__ - COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); // NOLINT + COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); return n == 0 ? 64 : __builtin_clzll(n); #else return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n); @@ -151,4 +151,4 @@ static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { #endif // WEBRTC_ARCH_ARM_V7 -#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_ +#endif // WEBRTC_SPL_SPL_INL_H_ diff --git a/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h b/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h index 634be48263..2718801159 100644 --- a/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h +++ b/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h @@ -13,8 +13,8 @@ * the fix point signal processing library. */ -#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_ -#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_ +#ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_ +#define WEBRTC_SPL_SPL_INL_ARMV7_H_ /* TODO(kma): Replace some assembly code with GCC intrinsics * (e.g. __builtin_clz). @@ -88,7 +88,8 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { if (a == 0) { return 0; - } else if (a < 0) { + } + else if (a < 0) { a ^= 0xFFFFFFFF; } @@ -113,7 +114,8 @@ static __inline int16_t WebRtcSpl_NormW16(int16_t a) { if (a_32 == 0) { return 0; - } else if (a_32 < 0) { + } + else if (a_32 < 0) { a_32 ^= 0xFFFFFFFF; } @@ -131,4 +133,4 @@ static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { return (int16_t)out; } -#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_ +#endif // WEBRTC_SPL_SPL_INL_ARMV7_H_ diff --git a/webrtc/common_audio/signal_processing/include/spl_inl_mips.h b/webrtc/common_audio/signal_processing/include/spl_inl_mips.h index 90fa07a1fe..cd04bddcfa 100644 --- a/webrtc/common_audio/signal_processing/include/spl_inl_mips.h +++ b/webrtc/common_audio/signal_processing/include/spl_inl_mips.h @@ -12,8 +12,8 @@ // This header file includes the inline functions in // the fix point signal processing library. -#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_ -#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_ +#ifndef WEBRTC_SPL_SPL_INL_MIPS_H_ +#define WEBRTC_SPL_SPL_INL_MIPS_H_ static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a, int32_t b) { @@ -33,7 +33,8 @@ static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a, "mul %[value32], %[a1], %[b1] \n\t" : [value32] "=r" (value32), [a1] "=&r" (a1), [b1] "=&r" (b1) : [a] "r" (a), [b] "r" (b) - : "hi", "lo"); + : "hi", "lo" + ); return value32; } @@ -60,7 +61,8 @@ static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, : [value32] "=&r" (value32), [b1] "=&r" (b1), [b2] "=&r" (b2), [a1] "=&r" (a1) : [a] "r" (a), [b] "r" (b) - : "hi", "lo"); + : "hi", "lo" + ); return value32; } @@ -70,7 +72,8 @@ static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { "shll_s.w %[value32], %[value32], 16 \n\t" "sra %[value32], %[value32], 16 \n\t" : [value32] "+r" (value32) - :); + : + ); int16_t out16 = (int16_t)value32; return out16; } @@ -81,7 +84,8 @@ static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { __asm __volatile( "addq_s.ph %[value32], %[a], %[b] \n\t" : [value32] "=r" (value32) - : [a] "r" (a), [b] "r" (b) ); + : [a] "r" (a), [b] "r" (b) + ); return (int16_t)value32; } @@ -91,7 +95,8 @@ static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { __asm __volatile( "addq_s.w %[l_sum], %[l_var1], %[l_var2] \n\t" : [l_sum] "=r" (l_sum) - : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) ); + : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) + ); return l_sum; } @@ -102,7 +107,8 @@ static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { __asm __volatile( "subq_s.ph %[value32], %[var1], %[var2] \n\t" : [value32] "=r" (value32) - : [var1] "r" (var1), [var2] "r" (var2) ); + : [var1] "r" (var1), [var2] "r" (var2) + ); return (int16_t)value32; } @@ -113,7 +119,8 @@ static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { __asm __volatile( "subq_s.w %[l_diff], %[l_var1], %[l_var2] \n\t" : [l_diff] "=r" (l_diff) - : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) ); + : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) + ); return l_diff; } @@ -127,7 +134,8 @@ static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { "clz %[bits], %[n] \n\t" "subu %[bits], %[i32], %[bits] \n\t" : [bits] "=&r" (bits) - : [n] "r" (n), [i32] "r" (i32) ); + : [n] "r" (n), [i32] "r" (i32) + ); return (int16_t)bits; } @@ -149,7 +157,8 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { "2: \n\t" ".set pop \n\t" : [zeros]"=&r"(zeros) - : [a] "r" (a) ); + : [a] "r" (a) + ); return (int16_t)zeros; } @@ -160,7 +169,8 @@ static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { __asm __volatile( "clz %[zeros], %[a] \n\t" : [zeros] "=r" (zeros) - : [a] "r" (a) ); + : [a] "r" (a) + ); return (int16_t)(zeros & 0x1f); } @@ -183,7 +193,8 @@ static __inline int16_t WebRtcSpl_NormW16(int16_t a) { "2: \n\t" ".set pop \n\t" : [zeros]"=&r"(zeros) - : [a0] "r" (a0) ); + : [a0] "r" (a0) + ); return (int16_t)zeros; } @@ -206,8 +217,9 @@ static __inline int32_t WebRtc_MulAccumW16(int16_t a, "addu %[c1], %[c], %[res] \n\t" : [c1] "=r" (c1), [res] "=&r" (res) : [a] "r" (a), [b] "r" (b), [c] "r" (c) - : "hi", "lo"); + : "hi", "lo" + ); return (c1); } -#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_ +#endif // WEBRTC_SPL_SPL_INL_MIPS_H_ diff --git a/webrtc/common_audio/signal_processing/real_fft_unittest.cc b/webrtc/common_audio/signal_processing/real_fft_unittest.cc index fcf11d73c8..282342230f 100644 --- a/webrtc/common_audio/signal_processing/real_fft_unittest.cc +++ b/webrtc/common_audio/signal_processing/real_fft_unittest.cc @@ -35,9 +35,9 @@ const int16_t kRefData[kTimeDataLength] = { class RealFFTTest : public ::testing::Test { protected: - RealFFTTest() { - WebRtcSpl_Init(); - } + RealFFTTest() { + WebRtcSpl_Init(); + } }; TEST_F(RealFFTTest, CreateFailsOnBadInput) { @@ -60,7 +60,7 @@ TEST_F(RealFFTTest, RealAndComplexMatch) { for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) { complex_fft_buff[j] = kRefData[i]; complex_fft_buff[j + 1] = 0; // Insert zero's to imaginary parts. - } + }; // Create and run real forward FFT. RealFFT* fft = WebRtcSpl_CreateRealFFT(kOrder); diff --git a/webrtc/common_audio/signal_processing/resample_by_2_internal.h b/webrtc/common_audio/signal_processing/resample_by_2_internal.h index d0954e5944..5c9533eefa 100644 --- a/webrtc/common_audio/signal_processing/resample_by_2_internal.h +++ b/webrtc/common_audio/signal_processing/resample_by_2_internal.h @@ -14,8 +14,8 @@ * */ -#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_ -#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_ +#ifndef WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ +#define WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ #include "webrtc/typedefs.h" @@ -44,4 +44,4 @@ void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, int32_t* state); -#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_ +#endif // WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_ diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc index da6197ef32..9bf22fe1da 100644 --- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc +++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc @@ -20,11 +20,11 @@ static const int16_t vector16[kVector16Size] = {1, -15511, 4323, 1963, class SplTest : public testing::Test { protected: - SplTest() { - WebRtcSpl_Init(); - } - virtual ~SplTest() { - } + SplTest() { + WebRtcSpl_Init(); + } + virtual ~SplTest() { + } }; TEST_F(SplTest, MacroTest) { @@ -328,8 +328,7 @@ TEST_F(SplTest, VectorOperationsTest) { for (size_t kk = 0; kk < kVectorSize; ++kk) { EXPECT_EQ((B[kk]*3+7)>>2, bTmp16[kk]); } - WebRtcSpl_ScaleAndAddVectorsWithRound(b16, 3, b16, 2, 2, bTmp16, - kVectorSize); + WebRtcSpl_ScaleAndAddVectorsWithRound(b16, 3, b16, 2, 2, bTmp16, kVectorSize); for (size_t kk = 0; kk < kVectorSize; ++kk) { EXPECT_EQ((B[kk]*3+B[kk]*2+2)>>2, bTmp16[kk]); } @@ -356,8 +355,7 @@ TEST_F(SplTest, VectorOperationsTest) { for (size_t kk = 0; kk < kVectorSize; ++kk) { EXPECT_EQ(B[kk] >> 1, bTmp16[kk]); } - WebRtcSpl_ReverseOrderMultArrayElements(bTmp16, a16, &b16[3], - kVectorSize, 2); + WebRtcSpl_ReverseOrderMultArrayElements(bTmp16, a16, &b16[3], kVectorSize, 2); for (size_t kk = 0; kk < kVectorSize; ++kk) { EXPECT_EQ((a16[kk]*b16[3-kk])>>2, bTmp16[kk]); } @@ -560,7 +558,7 @@ TEST_F(SplTest, FFTTest) { // } WebRtcSpl_ComplexBitReverse(B, 3); for (int kk = 0; kk < 16; ++kk) { -// EXPECT_EQ(A[kk], B[kk]); + //EXPECT_EQ(A[kk], B[kk]); } } diff --git a/webrtc/common_audio/vad/vad_core.h b/webrtc/common_audio/vad/vad_core.h index 47e2d8843e..0a76d967dd 100644 --- a/webrtc/common_audio/vad/vad_core.h +++ b/webrtc/common_audio/vad/vad_core.h @@ -24,7 +24,9 @@ enum { kNumGaussians = 2 }; // Number of Gaussians per channel in the GMM. enum { kTableSize = kNumChannels * kNumGaussians }; enum { kMinEnergy = 10 }; // Minimum energy required to trigger audio signal. -typedef struct VadInstT_ { +typedef struct VadInstT_ +{ + int vad; int32_t downsampling_filter_states[4]; WebRtcSpl_State48khzTo8khz state_48_to_8; @@ -34,7 +36,7 @@ typedef struct VadInstT_ { int16_t speech_stds[kTableSize]; // TODO(bjornv): Change to |frame_count|. int32_t frame_counter; - int16_t over_hang; // Over Hang + int16_t over_hang; // Over Hang int16_t num_of_speech; // TODO(bjornv): Change to |age_vector|. int16_t index_vector[16 * kNumChannels]; @@ -50,6 +52,7 @@ typedef struct VadInstT_ { int16_t total[3]; int init_flag; + } VadInstT; // Initializes the core VAD component. The default aggressiveness mode is diff --git a/webrtc/common_audio/vad/vad_core_unittest.cc b/webrtc/common_audio/vad/vad_core_unittest.cc index d922010092..ba53c560e2 100644 --- a/webrtc/common_audio/vad/vad_core_unittest.cc +++ b/webrtc/common_audio/vad/vad_core_unittest.cc @@ -18,8 +18,7 @@ extern "C" { #include "webrtc/common_audio/vad/vad_core.h" } -namespace webrtc { -namespace test { +namespace { TEST_F(VadTest, InitCore) { // Test WebRtcVad_InitCore(). @@ -103,5 +102,4 @@ TEST_F(VadTest, CalcVad) { free(self); } -} // namespace test -} // namespace webrtc +} // namespace diff --git a/webrtc/common_audio/vad/vad_filterbank_unittest.cc b/webrtc/common_audio/vad/vad_filterbank_unittest.cc index d15fc1b487..5b278013e8 100644 --- a/webrtc/common_audio/vad/vad_filterbank_unittest.cc +++ b/webrtc/common_audio/vad/vad_filterbank_unittest.cc @@ -19,8 +19,7 @@ extern "C" { #include "webrtc/common_audio/vad/vad_filterbank.h" } -namespace webrtc { -namespace test { +namespace { const int kNumValidFrameLengths = 3; @@ -90,5 +89,4 @@ TEST_F(VadTest, vad_filterbank) { free(self); } -} // namespace test -} // namespace webrtc +} // namespace diff --git a/webrtc/common_audio/vad/vad_gmm_unittest.cc b/webrtc/common_audio/vad/vad_gmm_unittest.cc index 7d95111846..9de93f67f0 100644 --- a/webrtc/common_audio/vad/vad_gmm_unittest.cc +++ b/webrtc/common_audio/vad/vad_gmm_unittest.cc @@ -16,8 +16,7 @@ extern "C" { #include "webrtc/common_audio/vad/vad_gmm.h" } -namespace webrtc { -namespace test { +namespace { TEST_F(VadTest, vad_gmm) { int16_t delta = 0; @@ -41,5 +40,4 @@ TEST_F(VadTest, vad_gmm) { EXPECT_EQ(0, WebRtcVad_GaussianProbability(105, 0, 128, &delta)); EXPECT_EQ(13440, delta); } -} // namespace test -} // namespace webrtc +} // namespace diff --git a/webrtc/common_audio/vad/vad_sp_unittest.cc b/webrtc/common_audio/vad/vad_sp_unittest.cc index e8413086d3..1e335e362f 100644 --- a/webrtc/common_audio/vad/vad_sp_unittest.cc +++ b/webrtc/common_audio/vad/vad_sp_unittest.cc @@ -19,8 +19,7 @@ extern "C" { #include "webrtc/common_audio/vad/vad_sp.h" } -namespace webrtc { -namespace test { +namespace { TEST_F(VadTest, vad_sp) { VadInstT* self = reinterpret_cast(malloc(sizeof(VadInstT))); @@ -72,5 +71,4 @@ TEST_F(VadTest, vad_sp) { free(self); } -} // namespace test -} // namespace webrtc +} // namespace diff --git a/webrtc/common_audio/vad/vad_unittest.cc b/webrtc/common_audio/vad/vad_unittest.cc index f2210d9784..a03f667b40 100644 --- a/webrtc/common_audio/vad/vad_unittest.cc +++ b/webrtc/common_audio/vad/vad_unittest.cc @@ -52,8 +52,7 @@ bool VadTest::ValidRatesAndFrameLengths(int rate, size_t frame_length) { return false; } -namespace webrtc { -namespace test { +namespace { TEST_F(VadTest, ApiTest) { // This API test runs through the APIs for all possible valid and invalid @@ -153,5 +152,4 @@ TEST_F(VadTest, ValidRatesFrameLengths) { // TODO(bjornv): Add a process test, run on file. -} // namespace test -} // namespace webrtc +} // namespace diff --git a/webrtc/common_audio/vad/vad_unittest.h b/webrtc/common_audio/vad/vad_unittest.h index 7edf585571..55ba5271f3 100644 --- a/webrtc/common_audio/vad/vad_unittest.h +++ b/webrtc/common_audio/vad/vad_unittest.h @@ -8,16 +8,15 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_ -#define WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_ +#ifndef WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H +#define WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H #include // size_t #include "webrtc/test/gtest.h" #include "webrtc/typedefs.h" -namespace webrtc { -namespace test { +namespace { // Modes we support const int kModes[] = { 0, 1, 2, 3 }; @@ -33,8 +32,7 @@ const size_t kFrameLengths[] = { 80, 120, 160, 240, 320, 480, 640, 960, kMaxFrameLength }; const size_t kFrameLengthsSize = sizeof(kFrameLengths) / sizeof(*kFrameLengths); -} // namespace test -} // namespace webrtc +} // namespace class VadTest : public ::testing::Test { protected: @@ -46,4 +44,4 @@ class VadTest : public ::testing::Test { bool ValidRatesAndFrameLengths(int rate, size_t frame_length); }; -#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_ +#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index a9fe6fdfa5..66d66e6191 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -675,7 +675,7 @@ MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( // Output volume scaling if (output_gain < 0.99f || output_gain > 1.01f) { // TODO(solenberg): Combine with mute state - this can cause clicks! - AudioFrameOperations::ScaleWithSat(output_gain, audioFrame); + AudioFrameOperations::ScaleWithSat(output_gain, *audioFrame); } // Mix decoded PCM output with file if file mixing is enabled