diff options
author | Yves Gerey <yvesg@webrtc.org> | 2018-06-19 15:03:05 +0200 |
---|---|---|
committer | Yves Gerey <yvesg@webrtc.org> | 2018-06-19 14:00:39 +0000 |
commit | 665174fdbb4e0540eccb27cf7412348f1b65534c (patch) | |
tree | 34a9eb770e6de54c282f62ad0b65d2cd69c917f6 /common_audio | |
parent | b602123a5aae1a9f0b6b581e611acf44eb525c08 (diff) | |
download | webrtc-665174fdbb4e0540eccb27cf7412348f1b65534c.tar.gz |
Reformat the WebRTC code base
Running clang-format with chromium's style guide.
The goal is n-fold:
* providing consistency and readability (that's what code guidelines are for)
* preventing noise with presubmit checks and git cl format
* building on the previous point: making it easier to automatically fix format issues
* you name it
Please consider using git-hyper-blame to ignore this commit.
Bug: webrtc:9340
Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87
Reviewed-on: https://webrtc-review.googlesource.com/81185
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23660}
Diffstat (limited to 'common_audio')
66 files changed, 1210 insertions, 1282 deletions
diff --git a/common_audio/audio_converter.cc b/common_audio/audio_converter.cc index 47d2be280e..0f97abb86a 100644 --- a/common_audio/audio_converter.cc +++ b/common_audio/audio_converter.cc @@ -26,12 +26,16 @@ namespace webrtc { class CopyConverter : public AudioConverter { public: - CopyConverter(size_t src_channels, size_t src_frames, size_t dst_channels, + CopyConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, size_t dst_frames) : AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {} - ~CopyConverter() override {}; + ~CopyConverter() override{}; - void Convert(const float* const* src, size_t src_size, float* const* dst, + void Convert(const float* const* src, + size_t src_size, + float* const* dst, size_t dst_capacity) override { CheckSizes(src_size, dst_capacity); if (src != dst) { @@ -43,12 +47,16 @@ class CopyConverter : public AudioConverter { class UpmixConverter : public AudioConverter { public: - UpmixConverter(size_t src_channels, size_t src_frames, size_t dst_channels, + UpmixConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, size_t dst_frames) : AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {} - ~UpmixConverter() override {}; + ~UpmixConverter() override{}; - void Convert(const float* const* src, size_t src_size, float* const* dst, + void Convert(const float* const* src, + size_t src_size, + float* const* dst, size_t dst_capacity) override { CheckSizes(src_size, dst_capacity); for (size_t i = 0; i < dst_frames(); ++i) { @@ -61,13 +69,16 @@ class UpmixConverter : public AudioConverter { class DownmixConverter : public AudioConverter { public: - DownmixConverter(size_t src_channels, size_t src_frames, size_t dst_channels, + DownmixConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, size_t dst_frames) - : AudioConverter(src_channels, src_frames, dst_channels, dst_frames) { - } - ~DownmixConverter() override {}; + : AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {} + ~DownmixConverter() override{}; - void Convert(const float* const* src, size_t src_size, float* const* dst, + void Convert(const float* const* src, + size_t src_size, + float* const* dst, size_t dst_capacity) override { CheckSizes(src_size, dst_capacity); float* dst_mono = dst[0]; @@ -82,7 +93,9 @@ class DownmixConverter : public AudioConverter { class ResampleConverter : public AudioConverter { public: - ResampleConverter(size_t src_channels, size_t src_frames, size_t dst_channels, + ResampleConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, size_t dst_frames) : AudioConverter(src_channels, src_frames, dst_channels, dst_frames) { resamplers_.reserve(src_channels); @@ -90,9 +103,11 @@ class ResampleConverter : public AudioConverter { resamplers_.push_back(std::unique_ptr<PushSincResampler>( new PushSincResampler(src_frames, dst_frames))); } - ~ResampleConverter() override {}; + ~ResampleConverter() override{}; - void Convert(const float* const* src, size_t src_size, float* const* dst, + void Convert(const float* const* src, + size_t src_size, + float* const* dst, size_t dst_capacity) override { CheckSizes(src_size, dst_capacity); for (size_t i = 0; i < resamplers_.size(); ++i) @@ -108,7 +123,7 @@ class ResampleConverter : public AudioConverter { class CompositionConverter : public AudioConverter { public: explicit CompositionConverter( - std::vector<std::unique_ptr<AudioConverter>> converters) + std::vector<std::unique_ptr<AudioConverter>> converters) : converters_(std::move(converters)) { RTC_CHECK_GE(converters_.size(), 2); // We need an intermediate buffer after every converter. @@ -117,19 +132,19 @@ class CompositionConverter : public AudioConverter { std::unique_ptr<ChannelBuffer<float>>(new ChannelBuffer<float>( (*it)->dst_frames(), (*it)->dst_channels()))); } - ~CompositionConverter() override {}; + ~CompositionConverter() override{}; - void Convert(const float* const* src, size_t src_size, float* const* dst, + void Convert(const float* const* src, + size_t src_size, + float* const* dst, size_t dst_capacity) override { converters_.front()->Convert(src, src_size, buffers_.front()->channels(), buffers_.front()->size()); for (size_t i = 2; i < converters_.size(); ++i) { auto& src_buffer = buffers_[i - 2]; auto& dst_buffer = buffers_[i - 1]; - converters_[i]->Convert(src_buffer->channels(), - src_buffer->size(), - dst_buffer->channels(), - dst_buffer->size()); + converters_[i]->Convert(src_buffer->channels(), src_buffer->size(), + dst_buffer->channels(), dst_buffer->size()); } converters_.back()->Convert(buffers_.back()->channels(), buffers_.back()->size(), dst, dst_capacity); @@ -175,8 +190,8 @@ std::unique_ptr<AudioConverter> AudioConverter::Create(size_t src_channels, sp.reset(new ResampleConverter(src_channels, src_frames, dst_channels, dst_frames)); } else { - sp.reset(new CopyConverter(src_channels, src_frames, dst_channels, - dst_frames)); + sp.reset( + new CopyConverter(src_channels, src_frames, dst_channels, dst_frames)); } return sp; @@ -184,13 +199,12 @@ std::unique_ptr<AudioConverter> AudioConverter::Create(size_t src_channels, // For CompositionConverter. AudioConverter::AudioConverter() - : src_channels_(0), - src_frames_(0), - dst_channels_(0), - dst_frames_(0) {} + : src_channels_(0), src_frames_(0), dst_channels_(0), dst_frames_(0) {} -AudioConverter::AudioConverter(size_t src_channels, size_t src_frames, - size_t dst_channels, size_t dst_frames) +AudioConverter::AudioConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, + size_t dst_frames) : src_channels_(src_channels), src_frames_(src_frames), dst_channels_(dst_channels), diff --git a/common_audio/audio_converter.h b/common_audio/audio_converter.h index 3f7b9a852c..769d724e2f 100644 --- a/common_audio/audio_converter.h +++ b/common_audio/audio_converter.h @@ -37,8 +37,10 @@ class AudioConverter { // capacity of |dst_capacity|. Both point to a series of buffers containing // the samples for each channel. The sizes must correspond to the format // passed to Create(). - virtual void Convert(const float* const* src, size_t src_size, - float* const* dst, size_t dst_capacity) = 0; + virtual void Convert(const float* const* src, + size_t src_size, + float* const* dst, + size_t dst_capacity) = 0; size_t src_channels() const { return src_channels_; } size_t src_frames() const { return src_frames_; } @@ -47,7 +49,9 @@ class AudioConverter { protected: AudioConverter(); - AudioConverter(size_t src_channels, size_t src_frames, size_t dst_channels, + AudioConverter(size_t src_channels, + size_t src_frames, + size_t dst_channels, size_t dst_frames); // Helper to RTC_CHECK that inputs are correctly sized. diff --git a/common_audio/audio_converter_unittest.cc b/common_audio/audio_converter_unittest.cc index e9937fd8cc..b99d825c2b 100644 --- a/common_audio/audio_converter_unittest.cc +++ b/common_audio/audio_converter_unittest.cc @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include <cmath> #include <algorithm> +#include <cmath> #include <memory> #include <vector> @@ -52,8 +52,7 @@ float ComputeSNR(const ChannelBuffer<float>& ref, // Search within one sample of the expected delay. for (size_t delay = std::max(expected_delay, static_cast<size_t>(1)) - 1; - delay <= std::min(expected_delay + 1, ref.num_frames()); - ++delay) { + delay <= std::min(expected_delay + 1, ref.num_frames()); ++delay) { float mse = 0; float variance = 0; float mean = 0; @@ -92,8 +91,8 @@ void RunAudioConverterTest(size_t src_channels, int dst_sample_rate_hz) { const float kSrcLeft = 0.0002f; const float kSrcRight = 0.0001f; - const float resampling_factor = (1.f * src_sample_rate_hz) / - dst_sample_rate_hz; + const float resampling_factor = + (1.f * src_sample_rate_hz) / dst_sample_rate_hz; const float dst_left = resampling_factor * kSrcLeft; const float dst_right = resampling_factor * kSrcRight; const float dst_mono = (dst_left + dst_right) / 2; @@ -124,13 +123,15 @@ void RunAudioConverterTest(size_t src_channels, ScopedBuffer ref_buffer = CreateBuffer(ref_data, dst_frames); // The sinc resampler has a known delay, which we compute here. - const size_t delay_frames = src_sample_rate_hz == dst_sample_rate_hz ? 0 : - static_cast<size_t>( - PushSincResampler::AlgorithmicDelaySeconds(src_sample_rate_hz) * - dst_sample_rate_hz); + const size_t delay_frames = + src_sample_rate_hz == dst_sample_rate_hz + ? 0 + : static_cast<size_t>( + PushSincResampler::AlgorithmicDelaySeconds(src_sample_rate_hz) * + dst_sample_rate_hz); // SNR reported on the same line later. - printf("(%" PRIuS ", %d Hz) -> (%" PRIuS ", %d Hz) ", - src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz); + printf("(%" PRIuS ", %d Hz) -> (%" PRIuS ", %d Hz) ", src_channels, + src_sample_rate_hz, dst_channels, dst_sample_rate_hz); std::unique_ptr<AudioConverter> converter = AudioConverter::Create( src_channels, src_frames, dst_channels, dst_frames); diff --git a/common_audio/audio_ring_buffer.cc b/common_audio/audio_ring_buffer.cc index e7b5d81ac6..ed4a5dd562 100644 --- a/common_audio/audio_ring_buffer.cc +++ b/common_audio/audio_ring_buffer.cc @@ -28,7 +28,8 @@ AudioRingBuffer::~AudioRingBuffer() { WebRtc_FreeBuffer(buf); } -void AudioRingBuffer::Write(const float* const* data, size_t channels, +void AudioRingBuffer::Write(const float* const* data, + size_t channels, size_t frames) { RTC_DCHECK_EQ(buffers_.size(), channels); for (size_t i = 0; i < channels; ++i) { diff --git a/common_audio/audio_ring_buffer_unittest.cc b/common_audio/audio_ring_buffer_unittest.cc index 2fcf80035f..d411195aa7 100644 --- a/common_audio/audio_ring_buffer_unittest.cc +++ b/common_audio/audio_ring_buffer_unittest.cc @@ -17,8 +17,8 @@ namespace webrtc { -class AudioRingBufferTest : - public ::testing::TestWithParam< ::testing::tuple<int, int, int, int> > { +class AudioRingBufferTest + : public ::testing::TestWithParam< ::testing::tuple<int, int, int, int> > { }; void ReadAndWriteTest(const ChannelBuffer<float>& input, @@ -72,10 +72,8 @@ TEST_P(AudioRingBufferTest, ReadDataMatchesWrittenData) { input.channels()[i][j] = (i + 1) * (j + 1); ChannelBuffer<float> output(kFrames, static_cast<int>(num_channels)); - ReadAndWriteTest(input, - ::testing::get<0>(GetParam()), - ::testing::get<1>(GetParam()), - ::testing::get<2>(GetParam()), + ReadAndWriteTest(input, ::testing::get<0>(GetParam()), + ::testing::get<1>(GetParam()), ::testing::get<2>(GetParam()), &output); // Verify the read data matches the input. @@ -85,7 +83,8 @@ TEST_P(AudioRingBufferTest, ReadDataMatchesWrittenData) { } INSTANTIATE_TEST_CASE_P( - AudioRingBufferTest, AudioRingBufferTest, + AudioRingBufferTest, + AudioRingBufferTest, ::testing::Combine(::testing::Values(10, 20, 42), // num_write_chunk_frames ::testing::Values(1, 10, 17), // num_read_chunk_frames ::testing::Values(100, 256), // buffer_frames diff --git a/common_audio/blocker.cc b/common_audio/blocker.cc index 7d09d21ea8..3dc8ed8040 100644 --- a/common_audio/blocker.cc +++ b/common_audio/blocker.cc @@ -41,8 +41,7 @@ void CopyFrames(const float* const* src, float* const* dst, size_t dst_start_index) { for (size_t i = 0; i < num_channels; ++i) { - memcpy(&dst[i][dst_start_index], - &src[i][src_start_index], + memcpy(&dst[i][dst_start_index], &src[i][src_start_index], num_frames * sizeof(dst[i][dst_start_index])); } } @@ -55,8 +54,7 @@ void MoveFrames(const float* const* src, float* const* dst, size_t dst_start_index) { for (size_t i = 0; i < num_channels; ++i) { - memmove(&dst[i][dst_start_index], - &src[i][src_start_index], + memmove(&dst[i][dst_start_index], &src[i][src_start_index], num_frames * sizeof(dst[i][dst_start_index])); } } @@ -87,9 +85,9 @@ void ApplyWindow(const float* window, size_t gcd(size_t a, size_t b) { size_t tmp; while (b) { - tmp = a; - a = b; - b = tmp % b; + tmp = a; + a = b; + b = tmp % b; } return a; } @@ -184,51 +182,30 @@ void Blocker::ProcessChunk(const float* const* input, block_size_); input_buffer_.MoveReadPositionBackward(block_size_ - shift_amount_); - ApplyWindow(window_.get(), - block_size_, - num_input_channels_, + ApplyWindow(window_.get(), block_size_, num_input_channels_, input_block_.channels()); - callback_->ProcessBlock(input_block_.channels(), - block_size_, - num_input_channels_, - num_output_channels_, + callback_->ProcessBlock(input_block_.channels(), block_size_, + num_input_channels_, num_output_channels_, output_block_.channels()); - ApplyWindow(window_.get(), - block_size_, - num_output_channels_, + ApplyWindow(window_.get(), block_size_, num_output_channels_, output_block_.channels()); - AddFrames(output_buffer_.channels(), - first_frame_in_block, - output_block_.channels(), - 0, - block_size_, - num_output_channels_, - output_buffer_.channels(), - first_frame_in_block); + AddFrames(output_buffer_.channels(), first_frame_in_block, + output_block_.channels(), 0, block_size_, num_output_channels_, + output_buffer_.channels(), first_frame_in_block); first_frame_in_block += shift_amount_; } // Copy output buffer to output - CopyFrames(output_buffer_.channels(), - 0, - chunk_size_, - num_output_channels_, - output, - 0); + CopyFrames(output_buffer_.channels(), 0, chunk_size_, num_output_channels_, + output, 0); // Copy output buffer [chunk_size_, chunk_size_ + initial_delay] // to output buffer [0, initial_delay], zero the rest. - MoveFrames(output_buffer_.channels(), - chunk_size, - initial_delay_, - num_output_channels_, - output_buffer_.channels(), - 0); - ZeroOut(output_buffer_.channels(), - initial_delay_, - chunk_size_, + MoveFrames(output_buffer_.channels(), chunk_size, initial_delay_, + num_output_channels_, output_buffer_.channels(), 0); + ZeroOut(output_buffer_.channels(), initial_delay_, chunk_size_, num_output_channels_); // Calculate new starting frames. diff --git a/common_audio/blocker_unittest.cc b/common_audio/blocker_unittest.cc index 296efab15b..85a24f6847 100644 --- a/common_audio/blocker_unittest.cc +++ b/common_audio/blocker_unittest.cc @@ -71,11 +71,8 @@ class BlockerTest : public ::testing::Test { size_t end = chunk_size - 1; while (end < num_frames) { CopyTo(input_chunk, 0, start, num_input_channels, chunk_size, input); - blocker->ProcessChunk(input_chunk, - chunk_size, - num_input_channels, - num_output_channels, - output_chunk); + blocker->ProcessChunk(input_chunk, chunk_size, num_input_channels, + num_output_channels, output_chunk); CopyTo(output, start, 0, num_output_channels, chunk_size, output_chunk); start += chunk_size; @@ -116,8 +113,7 @@ class BlockerTest : public ::testing::Test { size_t num_frames, const float* const* src) { for (size_t i = 0; i < num_channels; ++i) { - memcpy(&dst[i][start_index_dst], - &src[i][start_index_src], + memcpy(&dst[i][start_index_dst], &src[i][start_index_src], num_frames * sizeof(float)); } } @@ -152,27 +148,15 @@ TEST_F(BlockerTest, TestBlockerMutuallyPrimeChunkandBlockSize) { ChannelBuffer<float> output_chunk_cb(kChunkSize, kNumOutputChannels); PlusThreeBlockerCallback callback; - Blocker blocker(kChunkSize, - kBlockSize, - kNumInputChannels, - kNumOutputChannels, - kWindow, - kShiftAmount, - &callback); - - RunTest(&blocker, - kChunkSize, - kNumFrames, - input_cb.channels(), - input_chunk_cb.channels(), - actual_output_cb.channels(), - output_chunk_cb.channels(), - kNumInputChannels, - kNumOutputChannels); + Blocker blocker(kChunkSize, kBlockSize, kNumInputChannels, kNumOutputChannels, + kWindow, kShiftAmount, &callback); + + RunTest(&blocker, kChunkSize, kNumFrames, input_cb.channels(), + input_chunk_cb.channels(), actual_output_cb.channels(), + output_chunk_cb.channels(), kNumInputChannels, kNumOutputChannels); ValidateSignalEquality(expected_output_cb.channels(), - actual_output_cb.channels(), - kNumOutputChannels, + actual_output_cb.channels(), kNumOutputChannels, kNumFrames); } @@ -205,27 +189,15 @@ TEST_F(BlockerTest, TestBlockerMutuallyPrimeShiftAndBlockSize) { ChannelBuffer<float> output_chunk_cb(kChunkSize, kNumOutputChannels); PlusThreeBlockerCallback callback; - Blocker blocker(kChunkSize, - kBlockSize, - kNumInputChannels, - kNumOutputChannels, - kWindow, - kShiftAmount, - &callback); - - RunTest(&blocker, - kChunkSize, - kNumFrames, - input_cb.channels(), - input_chunk_cb.channels(), - actual_output_cb.channels(), - output_chunk_cb.channels(), - kNumInputChannels, - kNumOutputChannels); + Blocker blocker(kChunkSize, kBlockSize, kNumInputChannels, kNumOutputChannels, + kWindow, kShiftAmount, &callback); + + RunTest(&blocker, kChunkSize, kNumFrames, input_cb.channels(), + input_chunk_cb.channels(), actual_output_cb.channels(), + output_chunk_cb.channels(), kNumInputChannels, kNumOutputChannels); ValidateSignalEquality(expected_output_cb.channels(), - actual_output_cb.channels(), - kNumOutputChannels, + actual_output_cb.channels(), kNumOutputChannels, kNumFrames); } @@ -258,27 +230,15 @@ TEST_F(BlockerTest, TestBlockerNoOverlap) { ChannelBuffer<float> output_chunk_cb(kChunkSize, kNumOutputChannels); PlusThreeBlockerCallback callback; - Blocker blocker(kChunkSize, - kBlockSize, - kNumInputChannels, - kNumOutputChannels, - kWindow, - kShiftAmount, - &callback); - - RunTest(&blocker, - kChunkSize, - kNumFrames, - input_cb.channels(), - input_chunk_cb.channels(), - actual_output_cb.channels(), - output_chunk_cb.channels(), - kNumInputChannels, - kNumOutputChannels); + Blocker blocker(kChunkSize, kBlockSize, kNumInputChannels, kNumOutputChannels, + kWindow, kShiftAmount, &callback); + + RunTest(&blocker, kChunkSize, kNumFrames, input_cb.channels(), + input_chunk_cb.channels(), actual_output_cb.channels(), + output_chunk_cb.channels(), kNumInputChannels, kNumOutputChannels); ValidateSignalEquality(expected_output_cb.channels(), - actual_output_cb.channels(), - kNumOutputChannels, + actual_output_cb.channels(), kNumOutputChannels, kNumFrames); } @@ -286,14 +246,14 @@ TEST_F(BlockerTest, InitialDelaysAreMinimum) { const size_t kNumInputChannels = 3; const size_t kNumOutputChannels = 2; const size_t kNumFrames = 1280; - const size_t kChunkSize[] = - {80, 80, 80, 80, 80, 80, 160, 160, 160, 160, 160, 160}; - const size_t kBlockSize[] = - {64, 64, 64, 128, 128, 128, 128, 128, 128, 256, 256, 256}; - const size_t kShiftAmount[] = - {16, 32, 64, 32, 64, 128, 32, 64, 128, 64, 128, 256}; - const size_t kInitialDelay[] = - {48, 48, 48, 112, 112, 112, 96, 96, 96, 224, 224, 224}; + const size_t kChunkSize[] = {80, 80, 80, 80, 80, 80, + 160, 160, 160, 160, 160, 160}; + const size_t kBlockSize[] = {64, 64, 64, 128, 128, 128, + 128, 128, 128, 256, 256, 256}; + const size_t kShiftAmount[] = {16, 32, 64, 32, 64, 128, + 32, 64, 128, 64, 128, 256}; + const size_t kInitialDelay[] = {48, 48, 48, 112, 112, 112, + 96, 96, 96, 224, 224, 224}; float input[kNumInputChannels][kNumFrames]; for (size_t i = 0; i < kNumInputChannels; ++i) { @@ -317,27 +277,15 @@ TEST_F(BlockerTest, InitialDelaysAreMinimum) { ChannelBuffer<float> input_chunk_cb(kChunkSize[i], kNumInputChannels); ChannelBuffer<float> output_chunk_cb(kChunkSize[i], kNumOutputChannels); - Blocker blocker(kChunkSize[i], - kBlockSize[i], - kNumInputChannels, - kNumOutputChannels, - window.get(), - kShiftAmount[i], + Blocker blocker(kChunkSize[i], kBlockSize[i], kNumInputChannels, + kNumOutputChannels, window.get(), kShiftAmount[i], &callback); - RunTest(&blocker, - kChunkSize[i], - kNumFrames, - input_cb.channels(), - input_chunk_cb.channels(), - output_cb.channels(), - output_chunk_cb.channels(), - kNumInputChannels, - kNumOutputChannels); - - ValidateInitialDelay(output_cb.channels(), - kNumOutputChannels, - kNumFrames, + RunTest(&blocker, kChunkSize[i], kNumFrames, input_cb.channels(), + input_chunk_cb.channels(), output_cb.channels(), + output_chunk_cb.channels(), kNumInputChannels, kNumOutputChannels); + + ValidateInitialDelay(output_cb.channels(), kNumOutputChannels, kNumFrames, kInitialDelay[i]); } } diff --git a/common_audio/channel_buffer.cc b/common_audio/channel_buffer.cc index df45f6d0f6..38d231e09d 100644 --- a/common_audio/channel_buffer.cc +++ b/common_audio/channel_buffer.cc @@ -68,9 +68,7 @@ void IFChannelBuffer::RefreshI() const { ibuf_.set_num_channels(fbuf_.num_channels()); const float* const* float_channels = fbuf_.channels(); for (size_t i = 0; i < fbuf_.num_channels(); ++i) { - FloatS16ToS16(float_channels[i], - ibuf_.num_frames(), - int_channels[i]); + FloatS16ToS16(float_channels[i], ibuf_.num_frames(), int_channels[i]); } ivalid_ = true; } diff --git a/common_audio/channel_buffer.h b/common_audio/channel_buffer.h index 024868c46c..3f9ba9c0e1 100644 --- a/common_audio/channel_buffer.h +++ b/common_audio/channel_buffer.h @@ -40,9 +40,7 @@ namespace webrtc { template <typename T> class ChannelBuffer { public: - ChannelBuffer(size_t num_frames, - size_t num_channels, - size_t num_bands = 1) + ChannelBuffer(size_t num_frames, size_t num_channels, size_t num_bands = 1) : data_(new T[num_frames * num_channels]()), channels_(new T*[num_channels * num_bands]), bands_(new T*[num_channels * num_bands]), @@ -119,7 +117,7 @@ class ChannelBuffer { size_t num_frames_per_band() const { return num_frames_per_band_; } size_t num_channels() const { return num_channels_; } size_t num_bands() const { return num_bands_; } - size_t size() const {return num_frames_ * num_allocated_channels_; } + size_t size() const { return num_frames_ * num_allocated_channels_; } void set_num_channels(size_t num_channels) { RTC_DCHECK_LE(num_channels, num_allocated_channels_); diff --git a/common_audio/fft4g.h b/common_audio/fft4g.h index 1f0e29dd5c..1750e27853 100644 --- a/common_audio/fft4g.h +++ b/common_audio/fft4g.h @@ -16,7 +16,7 @@ extern "C" { #endif // Refer to fft4g.c for documentation. -void WebRtc_rdft(size_t n, int isgn, float *a, size_t *ip, float *w); +void WebRtc_rdft(size_t n, int isgn, float* a, size_t* ip, float* w); #if defined(__cplusplus) } diff --git a/common_audio/fir_filter_c.cc b/common_audio/fir_filter_c.cc index 6fe247011b..3418434672 100644 --- a/common_audio/fir_filter_c.cc +++ b/common_audio/fir_filter_c.cc @@ -20,8 +20,7 @@ namespace webrtc { -FIRFilterC::~FIRFilterC() { -} +FIRFilterC::~FIRFilterC() {} FIRFilterC::FIRFilterC(const float* coefficients, size_t coefficients_length) : coefficients_length_(coefficients_length), @@ -52,11 +51,10 @@ void FIRFilterC::Filter(const float* in, size_t length, float* out) { // Update current state. if (length >= state_length_) { - memcpy( - state_.get(), &in[length - state_length_], state_length_ * sizeof(*in)); + memcpy(state_.get(), &in[length - state_length_], + state_length_ * sizeof(*in)); } else { - memmove(state_.get(), - &state_[length], + memmove(state_.get(), &state_[length], (state_length_ - length) * sizeof(state_[0])); memcpy(&state_[state_length_ - length], in, length * sizeof(*in)); } diff --git a/common_audio/fir_filter_c.h b/common_audio/fir_filter_c.h index ffce838a67..d263e1ba60 100644 --- a/common_audio/fir_filter_c.h +++ b/common_audio/fir_filter_c.h @@ -20,8 +20,7 @@ namespace webrtc { class FIRFilterC : public FIRFilter { public: - FIRFilterC(const float* coefficients, - size_t coefficients_length); + FIRFilterC(const float* coefficients, size_t coefficients_length); ~FIRFilterC() override; void Filter(const float* in, size_t length, float* out) override; diff --git a/common_audio/fir_filter_factory.h b/common_audio/fir_filter_factory.h index 2e7ca9b89c..a952541035 100644 --- a/common_audio/fir_filter_factory.h +++ b/common_audio/fir_filter_factory.h @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license diff --git a/common_audio/fir_filter_neon.cc b/common_audio/fir_filter_neon.cc index e27f21b28c..f668841be6 100644 --- a/common_audio/fir_filter_neon.cc +++ b/common_audio/fir_filter_neon.cc @@ -18,8 +18,7 @@ namespace webrtc { -FIRFilterNEON::~FIRFilterNEON() { -} +FIRFilterNEON::~FIRFilterNEON() {} FIRFilterNEON::FIRFilterNEON(const float* coefficients, size_t coefficients_length, @@ -40,8 +39,7 @@ FIRFilterNEON::FIRFilterNEON(const float* coefficients, for (size_t i = 0; i < coefficients_length; ++i) { coefficients_[i + padding] = coefficients[coefficients_length - i - 1]; } - memset(state_.get(), - 0.f, + memset(state_.get(), 0.f, (max_input_length + state_length_) * sizeof(state_[0])); } @@ -60,8 +58,8 @@ void FIRFilterNEON::Filter(const float* in, size_t length, float* out) { float32x4_t m_in; for (size_t j = 0; j < coefficients_length_; j += 4) { - m_in = vld1q_f32(in_ptr + j); - m_sum = vmlaq_f32(m_sum, m_in, vld1q_f32(coef_ptr + j)); + m_in = vld1q_f32(in_ptr + j); + m_sum = vmlaq_f32(m_sum, m_in, vld1q_f32(coef_ptr + j)); } float32x2_t m_half = vadd_f32(vget_high_f32(m_sum), vget_low_f32(m_sum)); diff --git a/common_audio/fir_filter_sse.cc b/common_audio/fir_filter_sse.cc index 0da23fcbb3..ee75fb38ad 100644 --- a/common_audio/fir_filter_sse.cc +++ b/common_audio/fir_filter_sse.cc @@ -19,8 +19,7 @@ namespace webrtc { -FIRFilterSSE2::~FIRFilterSSE2() { -} +FIRFilterSSE2::~FIRFilterSSE2() {} FIRFilterSSE2::FIRFilterSSE2(const float* coefficients, size_t coefficients_length, @@ -41,8 +40,7 @@ FIRFilterSSE2::FIRFilterSSE2(const float* coefficients, for (size_t i = 0; i < coefficients_length; ++i) { coefficients_[i + padding] = coefficients[coefficients_length - i - 1]; } - memset(state_.get(), - 0, + memset(state_.get(), 0, (max_input_length + state_length_) * sizeof(state_[0])); } diff --git a/common_audio/fir_filter_unittest.cc b/common_audio/fir_filter_unittest.cc index 46966217d7..07abf2094f 100644 --- a/common_audio/fir_filter_unittest.cc +++ b/common_audio/fir_filter_unittest.cc @@ -21,20 +21,18 @@ namespace webrtc { namespace { static const float kCoefficients[] = {0.2f, 0.3f, 0.5f, 0.7f, 0.11f}; -static const size_t kCoefficientsLength = sizeof(kCoefficients) / - sizeof(kCoefficients[0]); +static const size_t kCoefficientsLength = + sizeof(kCoefficients) / sizeof(kCoefficients[0]); -static const float kInput[] = {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, - 8.f, 9.f, 10.f}; -static const size_t kInputLength = sizeof(kInput) / - sizeof(kInput[0]); +static const float kInput[] = {1.f, 2.f, 3.f, 4.f, 5.f, + 6.f, 7.f, 8.f, 9.f, 10.f}; +static const size_t kInputLength = sizeof(kInput) / sizeof(kInput[0]); void VerifyOutput(const float* expected_output, const float* output, size_t length) { - EXPECT_EQ(0, memcmp(expected_output, - output, - length * sizeof(expected_output[0]))); + EXPECT_EQ( + 0, memcmp(expected_output, output, length * sizeof(expected_output[0]))); } } // namespace @@ -97,8 +95,8 @@ TEST(FIRFilterTest, FilterInLengthLesserOrEqualToCoefficientsLength) { EXPECT_FLOAT_EQ(0.2f, output[0]); EXPECT_FLOAT_EQ(0.7f, output[1]); - filter.reset(CreateFirFilter( - kCoefficients, kCoefficientsLength, kCoefficientsLength)); + filter.reset( + CreateFirFilter(kCoefficients, kCoefficientsLength, kCoefficientsLength)); filter->Filter(kInput, kCoefficientsLength, output); EXPECT_FLOAT_EQ(0.2f, output[0]); @@ -149,19 +147,17 @@ TEST(FIRFilterTest, VerifySampleBasedVsBlockBasedFiltering) { filter->Filter(&kInput[i], 1, &output_sample_based[i]); } - EXPECT_EQ(0, memcmp(output_sample_based, - output_block_based, - kInputLength)); + EXPECT_EQ(0, memcmp(output_sample_based, output_block_based, kInputLength)); } TEST(FIRFilterTest, SimplestHighPassFilter) { const float kCoefficients[] = {1.f, -1.f}; - const size_t kCoefficientsLength = sizeof(kCoefficients) / - sizeof(kCoefficients[0]); + const size_t kCoefficientsLength = + sizeof(kCoefficients) / sizeof(kCoefficients[0]); float kConstantInput[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; - const size_t kConstantInputLength = sizeof(kConstantInput) / - sizeof(kConstantInput[0]); + const size_t kConstantInputLength = + sizeof(kConstantInput) / sizeof(kConstantInput[0]); float output[kConstantInputLength]; std::unique_ptr<FIRFilter> filter(CreateFirFilter( @@ -175,12 +171,12 @@ TEST(FIRFilterTest, SimplestHighPassFilter) { TEST(FIRFilterTest, SimplestLowPassFilter) { const float kCoefficients[] = {1.f, 1.f}; - const size_t kCoefficientsLength = sizeof(kCoefficients) / - sizeof(kCoefficients[0]); + const size_t kCoefficientsLength = + sizeof(kCoefficients) / sizeof(kCoefficients[0]); float kHighFrequencyInput[] = {-1.f, 1.f, -1.f, 1.f, -1.f, 1.f, -1.f, 1.f}; - const size_t kHighFrequencyInputLength = sizeof(kHighFrequencyInput) / - sizeof(kHighFrequencyInput[0]); + const size_t kHighFrequencyInputLength = + sizeof(kHighFrequencyInput) / sizeof(kHighFrequencyInput[0]); float output[kHighFrequencyInputLength]; std::unique_ptr<FIRFilter> filter(CreateFirFilter( @@ -195,16 +191,16 @@ TEST(FIRFilterTest, SimplestLowPassFilter) { TEST(FIRFilterTest, SameOutputWhenSwapedCoefficientsAndInput) { float output[kCoefficientsLength]; float output_swaped[kCoefficientsLength]; - std::unique_ptr<FIRFilter> filter(CreateFirFilter( - kCoefficients, kCoefficientsLength, kCoefficientsLength)); + std::unique_ptr<FIRFilter> filter( + CreateFirFilter(kCoefficients, kCoefficientsLength, kCoefficientsLength)); // Use kCoefficientsLength for in_length to get same-length outputs. filter->Filter(kInput, kCoefficientsLength, output); - filter.reset(CreateFirFilter( - kInput, kCoefficientsLength, kCoefficientsLength)); + filter.reset( + CreateFirFilter(kInput, kCoefficientsLength, kCoefficientsLength)); filter->Filter(kCoefficients, kCoefficientsLength, output_swaped); - for (size_t i = 0 ; i < kCoefficientsLength; ++i) { + for (size_t i = 0; i < kCoefficientsLength; ++i) { EXPECT_FLOAT_EQ(output[i], output_swaped[i]); } } diff --git a/common_audio/lapped_transform.cc b/common_audio/lapped_transform.cc index 517709f462..72c2ad79f6 100644 --- a/common_audio/lapped_transform.cc +++ b/common_audio/lapped_transform.cc @@ -29,20 +29,17 @@ void LappedTransform::BlockThunk::ProcessBlock(const float* const* input, RTC_CHECK_EQ(parent_->block_length_, num_frames); for (size_t i = 0; i < num_input_channels; ++i) { - memcpy(parent_->real_buf_.Row(i), input[i], - num_frames * sizeof(*input[0])); + memcpy(parent_->real_buf_.Row(i), input[i], num_frames * sizeof(*input[0])); parent_->fft_->Forward(parent_->real_buf_.Row(i), parent_->cplx_pre_.Row(i)); } - size_t block_length = RealFourier::ComplexLength( - RealFourier::FftOrder(num_frames)); + size_t block_length = + RealFourier::ComplexLength(RealFourier::FftOrder(num_frames)); RTC_CHECK_EQ(parent_->cplx_length_, block_length); - parent_->block_processor_->ProcessAudioBlock(parent_->cplx_pre_.Array(), - num_input_channels, - parent_->cplx_length_, - num_output_channels, - parent_->cplx_post_.Array()); + parent_->block_processor_->ProcessAudioBlock( + parent_->cplx_pre_.Array(), num_input_channels, parent_->cplx_length_, + num_output_channels, parent_->cplx_post_.Array()); for (size_t i = 0; i < num_output_channels; ++i) { parent_->fft_->Inverse(parent_->cplx_post_.Row(i), diff --git a/common_audio/lapped_transform.h b/common_audio/lapped_transform.h index c97cd1684c..1ab2a9fee7 100644 --- a/common_audio/lapped_transform.h +++ b/common_audio/lapped_transform.h @@ -35,7 +35,8 @@ class LappedTransform { virtual ~Callback() {} virtual void ProcessAudioBlock(const std::complex<float>* const* in_block, - size_t num_in_channels, size_t frames, + size_t num_in_channels, + size_t frames, size_t num_out_channels, std::complex<float>* const* out_block) = 0; }; @@ -128,4 +129,3 @@ class LappedTransform { } // namespace webrtc #endif // COMMON_AUDIO_LAPPED_TRANSFORM_H_ - diff --git a/common_audio/lapped_transform_unittest.cc b/common_audio/lapped_transform_unittest.cc index d6a312db51..7f3d19f806 100644 --- a/common_audio/lapped_transform_unittest.cc +++ b/common_audio/lapped_transform_unittest.cc @@ -36,9 +36,7 @@ class NoopCallback : public webrtc::LappedTransform::Callback { ++block_num_; } - size_t block_num() { - return block_num_; - } + size_t block_num() { return block_num_; } private: size_t block_num_; @@ -69,9 +67,7 @@ class FftCheckerCallback : public webrtc::LappedTransform::Callback { } } - size_t block_num() { - return block_num_; - } + size_t block_num() { return block_num_; } private: size_t block_num_; @@ -150,8 +146,7 @@ TEST(LappedTransformTest, IdentityProcessor) { trans.ProcessChunk(&in_chunk, &out_chunk); for (size_t i = 0; i < kChunkLength; ++i) { - ASSERT_NEAR(out_chunk[i], - (i < kBlockLength - kShiftAmount) ? 0.0f : 2.0f, + ASSERT_NEAR(out_chunk[i], (i < kBlockLength - kShiftAmount) ? 0.0f : 2.0f, 1e-5f); } @@ -167,8 +162,8 @@ TEST(LappedTransformTest, Callbacks) { float window[kBlockLength]; std::fill(window, &window[kBlockLength], 1.0f); - LappedTransform trans(1, 1, kChunkLength, window, kBlockLength, - kBlockLength, &call); + LappedTransform trans(1, 1, kChunkLength, window, kBlockLength, kBlockLength, + &call); float in_buffer[kChunkLength]; float* in_chunk = in_buffer; float out_buffer[kChunkLength]; diff --git a/common_audio/real_fourier.h b/common_audio/real_fourier.h index d16149b365..a3e4dd16a8 100644 --- a/common_audio/real_fourier.h +++ b/common_audio/real_fourier.h @@ -72,4 +72,3 @@ class RealFourier { } // namespace webrtc #endif // COMMON_AUDIO_REAL_FOURIER_H_ - diff --git a/common_audio/real_fourier_ooura.cc b/common_audio/real_fourier_ooura.cc index ca043e4e13..a3dfbd6811 100644 --- a/common_audio/real_fourier_ooura.cc +++ b/common_audio/real_fourier_ooura.cc @@ -10,8 +10,8 @@ #include "common_audio/real_fourier_ooura.h" -#include <cmath> #include <algorithm> +#include <cmath> #include "common_audio/fft4g.h" #include "rtc_base/checks.h" @@ -28,8 +28,8 @@ void Conjugate(complex<float>* array, size_t complex_length) { } size_t ComputeWorkIpSize(size_t fft_length) { - return static_cast<size_t>(2 + std::ceil(std::sqrt( - static_cast<float>(fft_length)))); + return static_cast<size_t>( + 2 + std::ceil(std::sqrt(static_cast<float>(fft_length)))); } } // namespace @@ -73,8 +73,8 @@ void RealFourierOoura::Inverse(const complex<float>* src, float* dest) const { // Restore Ooura's conjugate definition. Conjugate(dest_complex, dest_complex_length); // Restore real[n/2] to imag[0]. - dest_complex[0] = complex<float>(dest_complex[0].real(), - src[complex_length_ - 1].real()); + dest_complex[0] = + complex<float>(dest_complex[0].real(), src[complex_length_ - 1].real()); } WebRtc_rdft(length_, -1, dest, work_ip_.get(), work_w_.get()); diff --git a/common_audio/real_fourier_unittest.cc b/common_audio/real_fourier_unittest.cc index d5b6942fc5..132488747a 100644 --- a/common_audio/real_fourier_unittest.cc +++ b/common_audio/real_fourier_unittest.cc @@ -60,8 +60,7 @@ class RealFourierTest : public ::testing::Test { real_buffer_(RealFourier::AllocRealBuffer(4)), cplx_buffer_(RealFourier::AllocCplxBuffer(3)) {} - ~RealFourierTest() { - } + ~RealFourierTest() {} T rf_; const RealFourier::fft_real_scoper real_buffer_; diff --git a/common_audio/resampler/include/push_resampler.h b/common_audio/resampler/include/push_resampler.h index 046415b87e..05b93d1909 100644 --- a/common_audio/resampler/include/push_resampler.h +++ b/common_audio/resampler/include/push_resampler.h @@ -29,7 +29,8 @@ class PushResampler { // Must be called whenever the parameters change. Free to be called at any // time as it is a no-op if parameters have not changed since the last call. - int InitializeIfNeeded(int src_sample_rate_hz, int dst_sample_rate_hz, + int InitializeIfNeeded(int src_sample_rate_hz, + int dst_sample_rate_hz, size_t num_channels); // Returns the total number of samples provided in destination (e.g. 32 kHz, diff --git a/common_audio/resampler/include/resampler.h b/common_audio/resampler/include/resampler.h index fec2c1a7bf..f923b464d8 100644 --- a/common_audio/resampler/include/resampler.h +++ b/common_audio/resampler/include/resampler.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* * A wrapper for resampling a numerous amount of sampling combinations. */ @@ -36,8 +35,11 @@ class Resampler { int ResetIfNeeded(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 + int Push(const int16_t* samplesIn, + size_t lengthIn, + int16_t* samplesOut, + size_t maxLen, + size_t& outLen); // NOLINT: to avoid changing APIs private: enum ResamplerMode { diff --git a/common_audio/resampler/push_resampler.cc b/common_audio/resampler/push_resampler.cc index 3930624b2a..cc24c4b3f6 100644 --- a/common_audio/resampler/push_resampler.cc +++ b/common_audio/resampler/push_resampler.cc @@ -25,7 +25,8 @@ namespace { // caused the compiler to generate code that threw off the linker. // TODO(tommi): Re-enable when we've figured out what the problem is. // http://crbug.com/615050 -void CheckValidInitParams(int src_sample_rate_hz, int dst_sample_rate_hz, +void CheckValidInitParams(int src_sample_rate_hz, + int dst_sample_rate_hz, size_t num_channels) { // The below checks are temporarily disabled on WEBRTC_WIN due to problems // with clang debug builds. @@ -57,14 +58,10 @@ void CheckExpectedBufferSizes(size_t src_length, template <typename T> PushResampler<T>::PushResampler() - : src_sample_rate_hz_(0), - dst_sample_rate_hz_(0), - num_channels_(0) { -} + : src_sample_rate_hz_(0), dst_sample_rate_hz_(0), num_channels_(0) {} template <typename T> -PushResampler<T>::~PushResampler() { -} +PushResampler<T>::~PushResampler() {} template <typename T> int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz, @@ -92,22 +89,24 @@ int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz, static_cast<size_t>(src_sample_rate_hz / 100); const size_t dst_size_10ms_mono = static_cast<size_t>(dst_sample_rate_hz / 100); - sinc_resampler_.reset(new PushSincResampler(src_size_10ms_mono, - dst_size_10ms_mono)); + sinc_resampler_.reset( + new PushSincResampler(src_size_10ms_mono, dst_size_10ms_mono)); if (num_channels_ == 2) { src_left_.reset(new T[src_size_10ms_mono]); src_right_.reset(new T[src_size_10ms_mono]); dst_left_.reset(new T[dst_size_10ms_mono]); dst_right_.reset(new T[dst_size_10ms_mono]); - sinc_resampler_right_.reset(new PushSincResampler(src_size_10ms_mono, - dst_size_10ms_mono)); + sinc_resampler_right_.reset( + new PushSincResampler(src_size_10ms_mono, dst_size_10ms_mono)); } return 0; } template <typename T> -int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst, +int PushResampler<T>::Resample(const T* src, + size_t src_length, + T* dst, size_t dst_capacity) { CheckExpectedBufferSizes(src_length, dst_capacity, num_channels_, src_sample_rate_hz_, dst_sample_rate_hz_); @@ -124,9 +123,8 @@ int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst, T* deinterleaved[] = {src_left_.get(), src_right_.get()}; Deinterleave(src, src_length_mono, num_channels_, deinterleaved); - size_t dst_length_mono = - sinc_resampler_->Resample(src_left_.get(), src_length_mono, - dst_left_.get(), dst_capacity_mono); + size_t dst_length_mono = sinc_resampler_->Resample( + src_left_.get(), src_length_mono, dst_left_.get(), dst_capacity_mono); sinc_resampler_right_->Resample(src_right_.get(), src_length_mono, dst_right_.get(), dst_capacity_mono); diff --git a/common_audio/resampler/push_sinc_resampler.cc b/common_audio/resampler/push_sinc_resampler.cc index 14ab330cdf..3bfead26e7 100644 --- a/common_audio/resampler/push_sinc_resampler.cc +++ b/common_audio/resampler/push_sinc_resampler.cc @@ -28,8 +28,7 @@ PushSincResampler::PushSincResampler(size_t source_frames, first_pass_(true), source_available_(0) {} -PushSincResampler::~PushSincResampler() { -} +PushSincResampler::~PushSincResampler() {} size_t PushSincResampler::Resample(const int16_t* source, size_t source_length, diff --git a/common_audio/resampler/push_sinc_resampler.h b/common_audio/resampler/push_sinc_resampler.h index bdc03a2c00..ad51471294 100644 --- a/common_audio/resampler/push_sinc_resampler.h +++ b/common_audio/resampler/push_sinc_resampler.h @@ -36,8 +36,10 @@ class PushSincResampler : public SincResamplerCallback { // at least as large as |destination_frames|. Returns the number of samples // provided in destination (for convenience, since this will always be equal // to |destination_frames|). - size_t Resample(const int16_t* source, size_t source_frames, - int16_t* destination, size_t destination_capacity); + size_t Resample(const int16_t* source, + size_t source_frames, + int16_t* destination, + size_t destination_capacity); size_t Resample(const float* source, size_t source_frames, float* destination, diff --git a/common_audio/resampler/push_sinc_resampler_unittest.cc b/common_audio/resampler/push_sinc_resampler_unittest.cc index 3be7c0a365..042b5f3959 100644 --- a/common_audio/resampler/push_sinc_resampler_unittest.cc +++ b/common_audio/resampler/push_sinc_resampler_unittest.cc @@ -36,14 +36,13 @@ T DBFS(T x) { } // namespace class PushSincResamplerTest : public ::testing::TestWithParam< - ::testing::tuple<int, int, double, double>> { + ::testing::tuple<int, int, double, double>> { public: PushSincResamplerTest() : input_rate_(::testing::get<0>(GetParam())), output_rate_(::testing::get<1>(GetParam())), rms_error_(::testing::get<2>(GetParam())), - low_freq_error_(::testing::get<3>(GetParam())) { - } + low_freq_error_(::testing::get<3>(GetParam())) {} ~PushSincResamplerTest() override {} @@ -82,8 +81,8 @@ void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) { source_int[i] = static_cast<int16_t>(floor(32767 * source[i] + 0.5)); } - printf("Benchmarking %d iterations of %d Hz -> %d Hz:\n", - kResampleIterations, input_rate_, output_rate_); + printf("Benchmarking %d iterations of %d Hz -> %d Hz:\n", kResampleIterations, + input_rate_, output_rate_); const double io_ratio = input_rate_ / static_cast<double>(output_rate_); SincResampler sinc_resampler(io_ratio, SincResampler::kDefaultRequestSize, &resampler_source); @@ -101,25 +100,23 @@ void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) { if (int_format) { for (int i = 0; i < kResampleIterations; ++i) { EXPECT_EQ(output_samples, - resampler.Resample(source_int.get(), - input_samples, - destination_int.get(), - output_samples)); + resampler.Resample(source_int.get(), input_samples, + destination_int.get(), output_samples)); } } else { for (int i = 0; i < kResampleIterations; ++i) { - EXPECT_EQ(output_samples, - resampler.Resample(source.get(), - input_samples, - resampled_destination.get(), - output_samples)); + EXPECT_EQ(output_samples, resampler.Resample(source.get(), input_samples, + resampled_destination.get(), + output_samples)); } } double total_time_us = (rtc::TimeNanos() - start) / rtc::kNumNanosecsPerMicrosec; - printf("PushSincResampler took %.2f us per frame; which is a %.1f%% overhead " - "on SincResampler.\n\n", total_time_us / kResampleIterations, - (total_time_us - total_time_sinc_us) / total_time_sinc_us * 100); + printf( + "PushSincResampler took %.2f us per frame; which is a %.1f%% overhead " + "on SincResampler.\n\n", + total_time_us / kResampleIterations, + (total_time_us - total_time_sinc_us) / total_time_sinc_us * 100); } // Disabled because it takes too long to run routinely. Use for performance @@ -149,8 +146,8 @@ void PushSincResamplerTest::ResampleTest(bool int_format) { const double input_nyquist_freq = 0.5 * input_rate_; // Source for data to be resampled. - SinusoidalLinearChirpSource resampler_source( - input_rate_, input_samples, input_nyquist_freq, 0); + SinusoidalLinearChirpSource resampler_source(input_rate_, input_samples, + input_nyquist_freq, 0); PushSincResampler resampler(input_block_size, output_block_size); @@ -168,8 +165,8 @@ void PushSincResamplerTest::ResampleTest(bool int_format) { // deal with it in the test by delaying the "pure" source to match. It must be // checked before the first call to Resample(), because ChunkSize() will // change afterwards. - const size_t output_delay_samples = output_block_size - - resampler.get_resampler_for_testing()->ChunkSize(); + const size_t output_delay_samples = + output_block_size - resampler.get_resampler_for_testing()->ChunkSize(); // Generate resampled signal. // With the PushSincResampler, we produce the signal block-by-10ms-block @@ -178,21 +175,18 @@ void PushSincResamplerTest::ResampleTest(bool int_format) { if (int_format) { for (size_t i = 0; i < kNumBlocks; ++i) { FloatToS16(&source[i * input_block_size], input_block_size, - source_int.get()); + source_int.get()); EXPECT_EQ(output_block_size, - resampler.Resample(source_int.get(), - input_block_size, - destination_int.get(), - output_block_size)); + resampler.Resample(source_int.get(), input_block_size, + destination_int.get(), output_block_size)); S16ToFloat(destination_int.get(), output_block_size, - &resampled_destination[i * output_block_size]); + &resampled_destination[i * output_block_size]); } } else { for (size_t i = 0; i < kNumBlocks; ++i) { EXPECT_EQ( output_block_size, - resampler.Resample(&source[i * input_block_size], - input_block_size, + resampler.Resample(&source[i * input_block_size], input_block_size, &resampled_destination[i * output_block_size], output_block_size)); } @@ -252,9 +246,13 @@ void PushSincResamplerTest::ResampleTest(bool int_format) { EXPECT_LE(high_freq_max_error, kHighFrequencyMaxError); } -TEST_P(PushSincResamplerTest, ResampleInt) { ResampleTest(true); } +TEST_P(PushSincResamplerTest, ResampleInt) { + ResampleTest(true); +} -TEST_P(PushSincResamplerTest, ResampleFloat) { ResampleTest(false); } +TEST_P(PushSincResamplerTest, ResampleFloat) { + ResampleTest(false); +} // Thresholds chosen arbitrarily based on what each resampling reported during // testing. All thresholds are in dbFS, http://en.wikipedia.org/wiki/DBFS. diff --git a/common_audio/resampler/resampler.cc b/common_audio/resampler/resampler.cc index ea85d827e0..aa3a4bac2a 100644 --- a/common_audio/resampler/resampler.cc +++ b/common_audio/resampler/resampler.cc @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* * A wrapper for resampling a numerous amount of sampling combinations. */ @@ -37,8 +36,7 @@ Resampler::Resampler() my_mode_(kResamplerMode1To1), num_channels_(0), slave_left_(nullptr), - slave_right_(nullptr) { -} + slave_right_(nullptr) {} Resampler::Resampler(int inFreq, int outFreq, size_t num_channels) : Resampler() { @@ -73,9 +71,9 @@ 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_)) { + 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; @@ -191,7 +189,7 @@ int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) { // 2:6 state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz)); WebRtcSpl_ResetResample16khzTo48khz( - static_cast<WebRtcSpl_State16khzTo48khz*>(state1_)); + static_cast<WebRtcSpl_State16khzTo48khz*>(state1_)); // 6:3 state2_ = malloc(8 * sizeof(int32_t)); memset(state2_, 0, 8 * sizeof(int32_t)); @@ -395,8 +393,11 @@ int Resampler::ComputeResamplerMode(int in_freq_hz, } // 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) { +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 = @@ -575,7 +576,7 @@ int Resampler::Push(const int16_t * samplesIn, size_t lengthIn, if ((lengthIn % 160) != 0) { return -1; } - tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 3)); + tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * lengthIn * 3)); tmp_mem = static_cast<int32_t*>(malloc(336 * sizeof(int32_t))); for (size_t i = 0; i < lengthIn; i += 160) { WebRtcSpl_Resample16khzTo48khz( @@ -827,7 +828,7 @@ int Resampler::Push(const int16_t * samplesIn, size_t lengthIn, return -1; } // 3:6 - tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 2)); + tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * lengthIn * 2)); WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, static_cast<int32_t*>(state1_)); lengthIn *= 2; @@ -858,8 +859,8 @@ int Resampler::Push(const int16_t * samplesIn, size_t lengthIn, return -1; } tmp_mem = static_cast<int32_t*>(malloc(126 * sizeof(int32_t))); - tmp = static_cast<int16_t*>( - malloc((lengthIn * 4) / 11 * sizeof(int16_t))); + tmp = + static_cast<int16_t*>(malloc((lengthIn * 4) / 11 * sizeof(int16_t))); for (size_t i = 0; i < lengthIn; i += 220) { WebRtcSpl_Resample22khzTo8khz( diff --git a/common_audio/resampler/resampler_unittest.cc b/common_audio/resampler/resampler_unittest.cc index 0300719637..d992d5064b 100644 --- a/common_audio/resampler/resampler_unittest.cc +++ b/common_audio/resampler/resampler_unittest.cc @@ -23,17 +23,10 @@ const size_t kNumChannelsSize = sizeof(kNumChannels) / sizeof(*kNumChannels); // Rates we must support. const int kMaxRate = 96000; -const int kRates[] = { - 8000, - 16000, - 32000, - 44000, - 48000, - kMaxRate -}; +const int kRates[] = {8000, 16000, 32000, 44000, 48000, kMaxRate}; const size_t kRatesSize = sizeof(kRates) / sizeof(*kRates); const int kMaxChannels = 2; -const size_t kDataSize = static_cast<size_t> (kMaxChannels * kMaxRate / 100); +const size_t kDataSize = static_cast<size_t>(kMaxChannels * kMaxRate / 100); // TODO(andrew): should we be supporting these combinations? bool ValidRates(int in_rate, int out_rate) { @@ -99,7 +92,7 @@ TEST_F(ResamplerTest, Reset) { for (size_t k = 0; k < kNumChannelsSize; ++k) { std::ostringstream ss; ss << "Input rate: " << kRates[i] << ", output rate: " << kRates[j] - << ", channels: " << kNumChannels[k]; + << ", channels: " << kNumChannels[k]; SCOPED_TRACE(ss.str()); if (ValidRates(kRates[i], kRates[j])) EXPECT_EQ(0, rs_.Reset(kRates[i], kRates[j], kNumChannels[k])); @@ -124,8 +117,8 @@ TEST_F(ResamplerTest, Mono) { size_t in_length = static_cast<size_t>(kRates[i] / 100); size_t out_length = 0; EXPECT_EQ(0, rs_.Reset(kRates[i], kRates[j], kChannels)); - EXPECT_EQ(0, rs_.Push(data_in_, in_length, data_out_, kDataSize, - out_length)); + EXPECT_EQ( + 0, rs_.Push(data_in_, in_length, data_out_, kDataSize, out_length)); EXPECT_EQ(static_cast<size_t>(kRates[j] / 100), out_length); } else { EXPECT_EQ(-1, rs_.Reset(kRates[i], kRates[j], kChannels)); @@ -145,14 +138,12 @@ TEST_F(ResamplerTest, Stereo) { if (ValidRates(kRates[i], kRates[j])) { size_t in_length = static_cast<size_t>(kChannels * kRates[i] / 100); size_t out_length = 0; - EXPECT_EQ(0, rs_.Reset(kRates[i], kRates[j], - kChannels)); - EXPECT_EQ(0, rs_.Push(data_in_, in_length, data_out_, kDataSize, - out_length)); + EXPECT_EQ(0, rs_.Reset(kRates[i], kRates[j], kChannels)); + EXPECT_EQ( + 0, rs_.Push(data_in_, in_length, data_out_, kDataSize, out_length)); EXPECT_EQ(static_cast<size_t>(kChannels * kRates[j] / 100), out_length); } else { - EXPECT_EQ(-1, rs_.Reset(kRates[i], kRates[j], - kChannels)); + EXPECT_EQ(-1, rs_.Reset(kRates[i], kRates[j], kChannels)); } } } diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc index 2ea91963e8..c3d1ea466a 100644 --- a/common_audio/resampler/sinc_resampler.cc +++ b/common_audio/resampler/sinc_resampler.cc @@ -217,23 +217,23 @@ void SincResampler::InitializeKernel() { for (size_t i = 0; i < kKernelSize; ++i) { const size_t idx = i + offset_idx * kKernelSize; - const float pre_sinc = static_cast<float>(M_PI * - (static_cast<int>(i) - static_cast<int>(kKernelSize / 2) - - subsample_offset)); + const float pre_sinc = static_cast<float>( + M_PI * (static_cast<int>(i) - static_cast<int>(kKernelSize / 2) - + subsample_offset)); kernel_pre_sinc_storage_[idx] = pre_sinc; // Compute Blackman window, matching the offset of the sinc(). const float x = (i - subsample_offset) / kKernelSize; const float window = static_cast<float>(kA0 - kA1 * cos(2.0 * M_PI * x) + - kA2 * cos(4.0 * M_PI * x)); + kA2 * cos(4.0 * M_PI * x)); kernel_window_storage_[idx] = window; // Compute the sinc with offset, then window the sinc() function and store // at the correct offset. - kernel_storage_[idx] = static_cast<float>(window * - ((pre_sinc == 0) ? - sinc_scale_factor : - (sin(sinc_scale_factor * pre_sinc) / pre_sinc))); + kernel_storage_[idx] = static_cast<float>( + window * ((pre_sinc == 0) + ? sinc_scale_factor + : (sin(sinc_scale_factor * pre_sinc) / pre_sinc))); } } } @@ -255,10 +255,10 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) { const float window = kernel_window_storage_[idx]; const float pre_sinc = kernel_pre_sinc_storage_[idx]; - kernel_storage_[idx] = static_cast<float>(window * - ((pre_sinc == 0) ? - sinc_scale_factor : - (sin(sinc_scale_factor * pre_sinc) / pre_sinc))); + kernel_storage_[idx] = static_cast<float>( + window * ((pre_sinc == 0) + ? sinc_scale_factor + : (sin(sinc_scale_factor * pre_sinc) / pre_sinc))); } } } @@ -312,8 +312,8 @@ void SincResampler::Resample(size_t frames, float* destination) { // Figure out how much to weight each kernel's "convolution". const double kernel_interpolation_factor = virtual_offset_idx - offset_idx; - *destination++ = CONVOLVE_FUNC( - input_ptr, k1, k2, kernel_interpolation_factor); + *destination++ = + CONVOLVE_FUNC(input_ptr, k1, k2, kernel_interpolation_factor); // Advance the virtual index. virtual_source_idx_ += current_io_ratio; @@ -352,7 +352,8 @@ void SincResampler::Flush() { UpdateRegions(false); } -float SincResampler::Convolve_C(const float* input_ptr, const float* k1, +float SincResampler::Convolve_C(const float* input_ptr, + const float* k1, const float* k2, double kernel_interpolation_factor) { float sum1 = 0; @@ -368,7 +369,7 @@ float SincResampler::Convolve_C(const float* input_ptr, const float* k1, // Linearly interpolate the two "convolutions". return static_cast<float>((1.0 - kernel_interpolation_factor) * sum1 + - kernel_interpolation_factor * sum2); + kernel_interpolation_factor * sum2); } } // namespace webrtc diff --git a/common_audio/resampler/sinc_resampler.h b/common_audio/resampler/sinc_resampler.h index deef7f63e4..6306bc9169 100644 --- a/common_audio/resampler/sinc_resampler.h +++ b/common_audio/resampler/sinc_resampler.h @@ -101,14 +101,18 @@ class SincResampler { // Compute convolution of |k1| and |k2| over |input_ptr|, resultant sums are // linearly interpolated using |kernel_interpolation_factor|. On x86 and ARM // the underlying implementation is chosen at run time. - static float Convolve_C(const float* input_ptr, const float* k1, - const float* k2, double kernel_interpolation_factor); + static float Convolve_C(const float* input_ptr, + const float* k1, + const float* k2, + double kernel_interpolation_factor); #if defined(WEBRTC_ARCH_X86_FAMILY) - static float Convolve_SSE(const float* input_ptr, const float* k1, + static float Convolve_SSE(const float* input_ptr, + const float* k1, const float* k2, double kernel_interpolation_factor); #elif defined(WEBRTC_HAS_NEON) - static float Convolve_NEON(const float* input_ptr, const float* k1, + static float Convolve_NEON(const float* input_ptr, + const float* k1, const float* k2, double kernel_interpolation_factor); #endif @@ -145,12 +149,14 @@ class SincResampler { // Data from the source is copied into this buffer for each processing pass. std::unique_ptr<float[], AlignedFreeDeleter> input_buffer_; - // Stores the runtime selection of which Convolve function to use. - // TODO(ajm): Move to using a global static which must only be initialized - // once by the user. We're not doing this initially, because we don't have - // e.g. a LazyInstance helper in webrtc. +// Stores the runtime selection of which Convolve function to use. +// TODO(ajm): Move to using a global static which must only be initialized +// once by the user. We're not doing this initially, because we don't have +// e.g. a LazyInstance helper in webrtc. #if defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__) - typedef float (*ConvolveProc)(const float*, const float*, const float*, + typedef float (*ConvolveProc)(const float*, + const float*, + const float*, double); ConvolveProc convolve_proc_; #endif diff --git a/common_audio/resampler/sinc_resampler_neon.cc b/common_audio/resampler/sinc_resampler_neon.cc index 9d77f0d12c..3649324d12 100644 --- a/common_audio/resampler/sinc_resampler_neon.cc +++ b/common_audio/resampler/sinc_resampler_neon.cc @@ -17,7 +17,8 @@ namespace webrtc { -float SincResampler::Convolve_NEON(const float* input_ptr, const float* k1, +float SincResampler::Convolve_NEON(const float* input_ptr, + const float* k1, const float* k2, double kernel_interpolation_factor) { float32x4_t m_input; @@ -25,7 +26,7 @@ float SincResampler::Convolve_NEON(const float* input_ptr, const float* k1, float32x4_t m_sums2 = vmovq_n_f32(0); const float* upper = input_ptr + kKernelSize; - for (; input_ptr < upper; ) { + for (; input_ptr < upper;) { m_input = vld1q_f32(input_ptr); input_ptr += 4; m_sums1 = vmlaq_f32(m_sums1, m_input, vld1q_f32(k1)); diff --git a/common_audio/resampler/sinc_resampler_sse.cc b/common_audio/resampler/sinc_resampler_sse.cc index 711110858f..3906a79752 100644 --- a/common_audio/resampler/sinc_resampler_sse.cc +++ b/common_audio/resampler/sinc_resampler_sse.cc @@ -17,7 +17,8 @@ namespace webrtc { -float SincResampler::Convolve_SSE(const float* input_ptr, const float* k1, +float SincResampler::Convolve_SSE(const float* input_ptr, + const float* k1, const float* k2, double kernel_interpolation_factor) { __m128 m_input; @@ -41,17 +42,18 @@ float SincResampler::Convolve_SSE(const float* input_ptr, const float* k1, } // Linearly interpolate the two "convolutions". - m_sums1 = _mm_mul_ps(m_sums1, _mm_set_ps1( - static_cast<float>(1.0 - kernel_interpolation_factor))); - m_sums2 = _mm_mul_ps(m_sums2, _mm_set_ps1( - static_cast<float>(kernel_interpolation_factor))); + m_sums1 = _mm_mul_ps( + m_sums1, + _mm_set_ps1(static_cast<float>(1.0 - kernel_interpolation_factor))); + m_sums2 = _mm_mul_ps( + m_sums2, _mm_set_ps1(static_cast<float>(kernel_interpolation_factor))); m_sums1 = _mm_add_ps(m_sums1, m_sums2); // Sum components together. float result; m_sums2 = _mm_add_ps(_mm_movehl_ps(m_sums1, m_sums1), m_sums1); - _mm_store_ss(&result, _mm_add_ss(m_sums2, _mm_shuffle_ps( - m_sums2, m_sums2, 1))); + _mm_store_ss(&result, + _mm_add_ss(m_sums2, _mm_shuffle_ps(m_sums2, m_sums2, 1))); return result; } diff --git a/common_audio/resampler/sinc_resampler_unittest.cc b/common_audio/resampler/sinc_resampler_unittest.cc index 87e991d3b6..90bdf31369 100644 --- a/common_audio/resampler/sinc_resampler_unittest.cc +++ b/common_audio/resampler/sinc_resampler_unittest.cc @@ -67,14 +67,14 @@ TEST(SincResamplerTest, ChunkedResample) { std::unique_ptr<float[]> resampled_destination(new float[max_chunk_size]); // Verify requesting ChunkSize() frames causes a single callback. - EXPECT_CALL(mock_source, Run(_, _)) - .Times(1).WillOnce(ClearBuffer()); + EXPECT_CALL(mock_source, Run(_, _)).Times(1).WillOnce(ClearBuffer()); resampler.Resample(resampler.ChunkSize(), resampled_destination.get()); // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. testing::Mock::VerifyAndClear(&mock_source); EXPECT_CALL(mock_source, Run(_, _)) - .Times(kChunks).WillRepeatedly(ClearBuffer()); + .Times(kChunks) + .WillRepeatedly(ClearBuffer()); resampler.Resample(max_chunk_size, resampled_destination.get()); } @@ -87,16 +87,14 @@ TEST(SincResamplerTest, Flush) { new float[resampler.ChunkSize()]); // Fill the resampler with junk data. - EXPECT_CALL(mock_source, Run(_, _)) - .Times(1).WillOnce(FillBuffer()); + EXPECT_CALL(mock_source, Run(_, _)).Times(1).WillOnce(FillBuffer()); resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get()); ASSERT_NE(resampled_destination[0], 0); // Flush and request more data, which should all be zeros now. resampler.Flush(); testing::Mock::VerifyAndClear(&mock_source); - EXPECT_CALL(mock_source, Run(_, _)) - .Times(1).WillOnce(ClearBuffer()); + EXPECT_CALL(mock_source, Run(_, _)).Times(1).WillOnce(ClearBuffer()); resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get()); for (size_t i = 0; i < resampler.ChunkSize() / 2; ++i) ASSERT_FLOAT_EQ(resampled_destination[i], 0); @@ -116,7 +114,6 @@ TEST(SincResamplerTest, DISABLED_SetRatioBench) { printf("SetRatio() took %.2fms.\n", total_time_c_us / 1000); } - // Define platform independent function name for Convolve* tests. #if defined(WEBRTC_ARCH_X86_FAMILY) #define CONVOLVE_FUNC Convolve_SSE @@ -232,8 +229,7 @@ TEST(SincResamplerTest, ConvolveBenchmark) { #undef CONVOLVE_FUNC typedef std::tuple<int, int, double, double> SincResamplerTestData; -class SincResamplerTest - : public testing::TestWithParam<SincResamplerTestData> { +class SincResamplerTest : public testing::TestWithParam<SincResamplerTestData> { public: SincResamplerTest() : input_rate_(std::get<0>(GetParam())), @@ -263,8 +259,8 @@ TEST_P(SincResamplerTest, Resample) { const double input_nyquist_freq = 0.5 * input_rate_; // Source for data to be resampled. - SinusoidalLinearChirpSource resampler_source( - input_rate_, input_samples, input_nyquist_freq, 0); + SinusoidalLinearChirpSource resampler_source(input_rate_, input_samples, + input_nyquist_freq, 0); const double io_ratio = input_rate_ / static_cast<double>(output_rate_); SincResampler resampler(io_ratio, SincResampler::kDefaultRequestSize, @@ -291,8 +287,8 @@ TEST_P(SincResamplerTest, Resample) { resampler.Resample(output_samples, resampled_destination.get()); // Generate pure signal. - SinusoidalLinearChirpSource pure_source( - output_rate_, output_samples, input_nyquist_freq, 0); + SinusoidalLinearChirpSource pure_source(output_rate_, output_samples, + input_nyquist_freq, 0); pure_source.Run(output_samples, pure_destination.get()); // Range of the Nyquist frequency (0.5 * min(input rate, output_rate)) which @@ -324,8 +320,8 @@ TEST_P(SincResamplerTest, Resample) { double rms_error = sqrt(sum_of_squares / output_samples); - // Convert each error to dbFS. - #define DBFS(x) 20 * log10(x) +// Convert each error to dbFS. +#define DBFS(x) 20 * log10(x) rms_error = DBFS(rms_error); low_freq_max_error = DBFS(low_freq_max_error); high_freq_max_error = DBFS(high_freq_max_error); diff --git a/common_audio/resampler/sinusoidal_linear_chirp_source.cc b/common_audio/resampler/sinusoidal_linear_chirp_source.cc index 134044e778..2afdd1be47 100644 --- a/common_audio/resampler/sinusoidal_linear_chirp_source.cc +++ b/common_audio/resampler/sinusoidal_linear_chirp_source.cc @@ -43,8 +43,7 @@ void SinusoidalLinearChirpSource::Run(size_t frames, float* destination) { } else { // Sinusoidal linear chirp. double t = (current_index_ - delay_samples_) / sample_rate_; - destination[i] = - sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t)); + destination[i] = sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t)); } } } @@ -52,7 +51,7 @@ void SinusoidalLinearChirpSource::Run(size_t frames, float* destination) { double SinusoidalLinearChirpSource::Frequency(size_t position) { return kMinFrequency + (position - delay_samples_) * - (max_frequency_ - kMinFrequency) / total_samples_; + (max_frequency_ - kMinFrequency) / total_samples_; } } // namespace webrtc diff --git a/common_audio/resampler/sinusoidal_linear_chirp_source.h b/common_audio/resampler/sinusoidal_linear_chirp_source.h index 7fcbaa0821..e9f3ca34e8 100644 --- a/common_audio/resampler/sinusoidal_linear_chirp_source.h +++ b/common_audio/resampler/sinusoidal_linear_chirp_source.h @@ -26,8 +26,10 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { public: // |delay_samples| can be used to insert a fractional sample delay into the // source. It will produce zeros until non-negative time is reached. - SinusoidalLinearChirpSource(int sample_rate, size_t samples, - double max_frequency, double delay_samples); + SinusoidalLinearChirpSource(int sample_rate, + size_t samples, + double max_frequency, + double delay_samples); virtual ~SinusoidalLinearChirpSource() {} @@ -36,9 +38,7 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { double Frequency(size_t position); private: - enum { - kMinFrequency = 5 - }; + enum { kMinFrequency = 5 }; int sample_rate_; size_t total_samples_; diff --git a/common_audio/ring_buffer.h b/common_audio/ring_buffer.h index aa2ac27375..0bbe879980 100644 --- a/common_audio/ring_buffer.h +++ b/common_audio/ring_buffer.h @@ -53,7 +53,8 @@ size_t WebRtc_ReadBuffer(RingBuffer* handle, size_t element_count); // Writes |data| to buffer and returns the number of elements written. -size_t WebRtc_WriteBuffer(RingBuffer* handle, const void* data, +size_t WebRtc_WriteBuffer(RingBuffer* handle, + const void* data, size_t element_count); // Moves the buffer read position and returns the number of elements moved. diff --git a/common_audio/ring_buffer_unittest.cc b/common_audio/ring_buffer_unittest.cc index 4bb1497b17..130e124673 100644 --- a/common_audio/ring_buffer_unittest.cc +++ b/common_audio/ring_buffer_unittest.cc @@ -21,9 +21,7 @@ namespace webrtc { struct FreeBufferDeleter { - inline void operator()(void* ptr) const { - WebRtc_FreeBuffer(ptr); - } + inline void operator()(void* ptr) const { WebRtc_FreeBuffer(ptr); } }; typedef std::unique_ptr<RingBuffer, FreeBufferDeleter> scoped_ring_buffer; @@ -31,7 +29,8 @@ static void AssertElementEq(int expected, int actual) { ASSERT_EQ(expected, actual); } -static int SetIncrementingData(int* data, int num_elements, +static int SetIncrementingData(int* data, + int num_elements, int starting_value) { for (int i = 0; i < num_elements; i++) { data[i] = starting_value++; @@ -39,7 +38,8 @@ static int SetIncrementingData(int* data, int num_elements, return starting_value; } -static int CheckIncrementingData(int* data, int num_elements, +static int CheckIncrementingData(int* data, + int num_elements, int starting_value) { for (int i = 0; i < num_elements; i++) { AssertElementEq(starting_value++, data[i]); @@ -70,35 +70,33 @@ static void RandomStressTest(int** data_ptr) { 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 int num_elements = rand() % buffer_size; // NOLINT if (write) { const int buffer_available = buffer_size - buffer_consumed; ASSERT_EQ(static_cast<size_t>(buffer_available), WebRtc_available_write(buffer.get())); const int expected_elements = std::min(num_elements, buffer_available); write_element = SetIncrementingData(write_data.get(), expected_elements, - write_element); - ASSERT_EQ(static_cast<size_t>(expected_elements), - WebRtc_WriteBuffer(buffer.get(), write_data.get(), - num_elements)); - buffer_consumed = std::min(buffer_consumed + expected_elements, - buffer_size); + write_element); + ASSERT_EQ( + static_cast<size_t>(expected_elements), + WebRtc_WriteBuffer(buffer.get(), write_data.get(), num_elements)); + buffer_consumed = + std::min(buffer_consumed + expected_elements, buffer_size); } else { - const int expected_elements = std::min(num_elements, - buffer_consumed); + const int expected_elements = std::min(num_elements, buffer_consumed); ASSERT_EQ(static_cast<size_t>(buffer_consumed), WebRtc_available_read(buffer.get())); - ASSERT_EQ(static_cast<size_t>(expected_elements), - WebRtc_ReadBuffer(buffer.get(), - reinterpret_cast<void**>(data_ptr), - read_data.get(), - num_elements)); + ASSERT_EQ( + static_cast<size_t>(expected_elements), + WebRtc_ReadBuffer(buffer.get(), reinterpret_cast<void**>(data_ptr), + read_data.get(), num_elements)); int* check_ptr = read_data.get(); if (data_ptr) { check_ptr = *data_ptr; } - read_element = CheckIncrementingData(check_ptr, expected_elements, - read_element); + read_element = + CheckIncrementingData(check_ptr, expected_elements, read_element); buffer_consumed = std::max(buffer_consumed - expected_elements, 0); } } @@ -127,8 +125,9 @@ TEST(RingBufferTest, PassingNulltoReadBufferForcesMemcpy) { SetIncrementingData(write_data, kDataSize, 0); EXPECT_EQ(kDataSize, WebRtc_WriteBuffer(buffer.get(), write_data, kDataSize)); SetIncrementingData(read_data, kDataSize, kDataSize); - EXPECT_EQ(kDataSize, WebRtc_ReadBuffer(buffer.get(), - reinterpret_cast<void**>(&data_ptr), read_data, kDataSize)); + EXPECT_EQ(kDataSize, + WebRtc_ReadBuffer(buffer.get(), reinterpret_cast<void**>(&data_ptr), + read_data, kDataSize)); // Copying was not necessary, so |read_data| has not been updated. CheckIncrementingData(data_ptr, kDataSize, 0); CheckIncrementingData(read_data, kDataSize, kDataSize); diff --git a/common_audio/signal_processing/complex_fft_tables.h b/common_audio/signal_processing/complex_fft_tables.h index 6c3fcfdbe0..5171040f5d 100644 --- a/common_audio/signal_processing/complex_fft_tables.h +++ b/common_audio/signal_processing/complex_fft_tables.h @@ -8,141 +8,125 @@ * be found in the AUTHORS file in the root of the source tree. */ - #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_COMPLEX_FFT_TABLES_H_ #define COMMON_AUDIO_SIGNAL_PROCESSING_COMPLEX_FFT_TABLES_H_ #include "typedefs.h" // NOLINT(build/include) static const int16_t kSinTable1024[] = { - 0, 201, 402, 603, 804, 1005, 1206, 1406, - 1607, 1808, 2009, 2209, 2410, 2610, 2811, 3011, - 3211, 3411, 3611, 3811, 4011, 4210, 4409, 4608, - 4807, 5006, 5205, 5403, 5601, 5799, 5997, 6195, - 6392, 6589, 6786, 6982, 7179, 7375, 7571, 7766, - 7961, 8156, 8351, 8545, 8739, 8932, 9126, 9319, - 9511, 9703, 9895, 10087, 10278, 10469, 10659, 10849, - 11038, 11227, 11416, 11604, 11792, 11980, 12166, 12353, - 12539, 12724, 12909, 13094, 13278, 13462, 13645, 13827, - 14009, 14191, 14372, 14552, 14732, 14911, 15090, 15268, - 15446, 15623, 15799, 15975, 16150, 16325, 16499, 16672, - 16845, 17017, 17189, 17360, 17530, 17699, 17868, 18036, - 18204, 18371, 18537, 18702, 18867, 19031, 19194, 19357, - 19519, 19680, 19840, 20000, 20159, 20317, 20474, 20631, - 20787, 20942, 21096, 21249, 21402, 21554, 21705, 21855, - 22004, 22153, 22301, 22448, 22594, 22739, 22883, 23027, - 23169, 23311, 23452, 23592, 23731, 23869, 24006, 24143, - 24278, 24413, 24546, 24679, 24811, 24942, 25072, 25201, - 25329, 25456, 25582, 25707, 25831, 25954, 26077, 26198, - 26318, 26437, 26556, 26673, 26789, 26905, 27019, 27132, - 27244, 27355, 27466, 27575, 27683, 27790, 27896, 28001, - 28105, 28208, 28309, 28410, 28510, 28608, 28706, 28802, - 28897, 28992, 29085, 29177, 29268, 29358, 29446, 29534, - 29621, 29706, 29790, 29873, 29955, 30036, 30116, 30195, - 30272, 30349, 30424, 30498, 30571, 30643, 30713, 30783, - 30851, 30918, 30984, 31049, 31113, 31175, 31236, 31297, - 31356, 31413, 31470, 31525, 31580, 31633, 31684, 31735, - 31785, 31833, 31880, 31926, 31970, 32014, 32056, 32097, - 32137, 32176, 32213, 32249, 32284, 32318, 32350, 32382, - 32412, 32441, 32468, 32495, 32520, 32544, 32567, 32588, - 32609, 32628, 32646, 32662, 32678, 32692, 32705, 32717, - 32727, 32736, 32744, 32751, 32757, 32761, 32764, 32766, - 32767, 32766, 32764, 32761, 32757, 32751, 32744, 32736, - 32727, 32717, 32705, 32692, 32678, 32662, 32646, 32628, - 32609, 32588, 32567, 32544, 32520, 32495, 32468, 32441, - 32412, 32382, 32350, 32318, 32284, 32249, 32213, 32176, - 32137, 32097, 32056, 32014, 31970, 31926, 31880, 31833, - 31785, 31735, 31684, 31633, 31580, 31525, 31470, 31413, - 31356, 31297, 31236, 31175, 31113, 31049, 30984, 30918, - 30851, 30783, 30713, 30643, 30571, 30498, 30424, 30349, - 30272, 30195, 30116, 30036, 29955, 29873, 29790, 29706, - 29621, 29534, 29446, 29358, 29268, 29177, 29085, 28992, - 28897, 28802, 28706, 28608, 28510, 28410, 28309, 28208, - 28105, 28001, 27896, 27790, 27683, 27575, 27466, 27355, - 27244, 27132, 27019, 26905, 26789, 26673, 26556, 26437, - 26318, 26198, 26077, 25954, 25831, 25707, 25582, 25456, - 25329, 25201, 25072, 24942, 24811, 24679, 24546, 24413, - 24278, 24143, 24006, 23869, 23731, 23592, 23452, 23311, - 23169, 23027, 22883, 22739, 22594, 22448, 22301, 22153, - 22004, 21855, 21705, 21554, 21402, 21249, 21096, 20942, - 20787, 20631, 20474, 20317, 20159, 20000, 19840, 19680, - 19519, 19357, 19194, 19031, 18867, 18702, 18537, 18371, - 18204, 18036, 17868, 17699, 17530, 17360, 17189, 17017, - 16845, 16672, 16499, 16325, 16150, 15975, 15799, 15623, - 15446, 15268, 15090, 14911, 14732, 14552, 14372, 14191, - 14009, 13827, 13645, 13462, 13278, 13094, 12909, 12724, - 12539, 12353, 12166, 11980, 11792, 11604, 11416, 11227, - 11038, 10849, 10659, 10469, 10278, 10087, 9895, 9703, - 9511, 9319, 9126, 8932, 8739, 8545, 8351, 8156, - 7961, 7766, 7571, 7375, 7179, 6982, 6786, 6589, - 6392, 6195, 5997, 5799, 5601, 5403, 5205, 5006, - 4807, 4608, 4409, 4210, 4011, 3811, 3611, 3411, - 3211, 3011, 2811, 2610, 2410, 2209, 2009, 1808, - 1607, 1406, 1206, 1005, 804, 603, 402, 201, - 0, -201, -402, -603, -804, -1005, -1206, -1406, - -1607, -1808, -2009, -2209, -2410, -2610, -2811, -3011, - -3211, -3411, -3611, -3811, -4011, -4210, -4409, -4608, - -4807, -5006, -5205, -5403, -5601, -5799, -5997, -6195, - -6392, -6589, -6786, -6982, -7179, -7375, -7571, -7766, - -7961, -8156, -8351, -8545, -8739, -8932, -9126, -9319, - -9511, -9703, -9895, -10087, -10278, -10469, -10659, -10849, - -11038, -11227, -11416, -11604, -11792, -11980, -12166, -12353, - -12539, -12724, -12909, -13094, -13278, -13462, -13645, -13827, - -14009, -14191, -14372, -14552, -14732, -14911, -15090, -15268, - -15446, -15623, -15799, -15975, -16150, -16325, -16499, -16672, - -16845, -17017, -17189, -17360, -17530, -17699, -17868, -18036, - -18204, -18371, -18537, -18702, -18867, -19031, -19194, -19357, - -19519, -19680, -19840, -20000, -20159, -20317, -20474, -20631, - -20787, -20942, -21096, -21249, -21402, -21554, -21705, -21855, - -22004, -22153, -22301, -22448, -22594, -22739, -22883, -23027, - -23169, -23311, -23452, -23592, -23731, -23869, -24006, -24143, - -24278, -24413, -24546, -24679, -24811, -24942, -25072, -25201, - -25329, -25456, -25582, -25707, -25831, -25954, -26077, -26198, - -26318, -26437, -26556, -26673, -26789, -26905, -27019, -27132, - -27244, -27355, -27466, -27575, -27683, -27790, -27896, -28001, - -28105, -28208, -28309, -28410, -28510, -28608, -28706, -28802, - -28897, -28992, -29085, -29177, -29268, -29358, -29446, -29534, - -29621, -29706, -29790, -29873, -29955, -30036, -30116, -30195, - -30272, -30349, -30424, -30498, -30571, -30643, -30713, -30783, - -30851, -30918, -30984, -31049, -31113, -31175, -31236, -31297, - -31356, -31413, -31470, -31525, -31580, -31633, -31684, -31735, - -31785, -31833, -31880, -31926, -31970, -32014, -32056, -32097, - -32137, -32176, -32213, -32249, -32284, -32318, -32350, -32382, - -32412, -32441, -32468, -32495, -32520, -32544, -32567, -32588, - -32609, -32628, -32646, -32662, -32678, -32692, -32705, -32717, - -32727, -32736, -32744, -32751, -32757, -32761, -32764, -32766, - -32767, -32766, -32764, -32761, -32757, -32751, -32744, -32736, - -32727, -32717, -32705, -32692, -32678, -32662, -32646, -32628, - -32609, -32588, -32567, -32544, -32520, -32495, -32468, -32441, - -32412, -32382, -32350, -32318, -32284, -32249, -32213, -32176, - -32137, -32097, -32056, -32014, -31970, -31926, -31880, -31833, - -31785, -31735, -31684, -31633, -31580, -31525, -31470, -31413, - -31356, -31297, -31236, -31175, -31113, -31049, -30984, -30918, - -30851, -30783, -30713, -30643, -30571, -30498, -30424, -30349, - -30272, -30195, -30116, -30036, -29955, -29873, -29790, -29706, - -29621, -29534, -29446, -29358, -29268, -29177, -29085, -28992, - -28897, -28802, -28706, -28608, -28510, -28410, -28309, -28208, - -28105, -28001, -27896, -27790, -27683, -27575, -27466, -27355, - -27244, -27132, -27019, -26905, -26789, -26673, -26556, -26437, - -26318, -26198, -26077, -25954, -25831, -25707, -25582, -25456, - -25329, -25201, -25072, -24942, -24811, -24679, -24546, -24413, - -24278, -24143, -24006, -23869, -23731, -23592, -23452, -23311, - -23169, -23027, -22883, -22739, -22594, -22448, -22301, -22153, - -22004, -21855, -21705, -21554, -21402, -21249, -21096, -20942, - -20787, -20631, -20474, -20317, -20159, -20000, -19840, -19680, - -19519, -19357, -19194, -19031, -18867, -18702, -18537, -18371, - -18204, -18036, -17868, -17699, -17530, -17360, -17189, -17017, - -16845, -16672, -16499, -16325, -16150, -15975, -15799, -15623, - -15446, -15268, -15090, -14911, -14732, -14552, -14372, -14191, - -14009, -13827, -13645, -13462, -13278, -13094, -12909, -12724, - -12539, -12353, -12166, -11980, -11792, -11604, -11416, -11227, - -11038, -10849, -10659, -10469, -10278, -10087, -9895, -9703, - -9511, -9319, -9126, -8932, -8739, -8545, -8351, -8156, - -7961, -7766, -7571, -7375, -7179, -6982, -6786, -6589, - -6392, -6195, -5997, -5799, -5601, -5403, -5205, -5006, - -4807, -4608, -4409, -4210, -4011, -3811, -3611, -3411, - -3211, -3011, -2811, -2610, -2410, -2209, -2009, -1808, - -1607, -1406, -1206, -1005, -804, -603, -402, -201 -}; + 0, 201, 402, 603, 804, 1005, 1206, 1406, 1607, + 1808, 2009, 2209, 2410, 2610, 2811, 3011, 3211, 3411, + 3611, 3811, 4011, 4210, 4409, 4608, 4807, 5006, 5205, + 5403, 5601, 5799, 5997, 6195, 6392, 6589, 6786, 6982, + 7179, 7375, 7571, 7766, 7961, 8156, 8351, 8545, 8739, + 8932, 9126, 9319, 9511, 9703, 9895, 10087, 10278, 10469, + 10659, 10849, 11038, 11227, 11416, 11604, 11792, 11980, 12166, + 12353, 12539, 12724, 12909, 13094, 13278, 13462, 13645, 13827, + 14009, 14191, 14372, 14552, 14732, 14911, 15090, 15268, 15446, + 15623, 15799, 15975, 16150, 16325, 16499, 16672, 16845, 17017, + 17189, 17360, 17530, 17699, 17868, 18036, 18204, 18371, 18537, + 18702, 18867, 19031, 19194, 19357, 19519, 19680, 19840, 20000, + 20159, 20317, 20474, 20631, 20787, 20942, 21096, 21249, 21402, + 21554, 21705, 21855, 22004, 22153, 22301, 22448, 22594, 22739, + 22883, 23027, 23169, 23311, 23452, 23592, 23731, 23869, 24006, + 24143, 24278, 24413, 24546, 24679, 24811, 24942, 25072, 25201, + 25329, 25456, 25582, 25707, 25831, 25954, 26077, 26198, 26318, + 26437, 26556, 26673, 26789, 26905, 27019, 27132, 27244, 27355, + 27466, 27575, 27683, 27790, 27896, 28001, 28105, 28208, 28309, + 28410, 28510, 28608, 28706, 28802, 28897, 28992, 29085, 29177, + 29268, 29358, 29446, 29534, 29621, 29706, 29790, 29873, 29955, + 30036, 30116, 30195, 30272, 30349, 30424, 30498, 30571, 30643, + 30713, 30783, 30851, 30918, 30984, 31049, 31113, 31175, 31236, + 31297, 31356, 31413, 31470, 31525, 31580, 31633, 31684, 31735, + 31785, 31833, 31880, 31926, 31970, 32014, 32056, 32097, 32137, + 32176, 32213, 32249, 32284, 32318, 32350, 32382, 32412, 32441, + 32468, 32495, 32520, 32544, 32567, 32588, 32609, 32628, 32646, + 32662, 32678, 32692, 32705, 32717, 32727, 32736, 32744, 32751, + 32757, 32761, 32764, 32766, 32767, 32766, 32764, 32761, 32757, + 32751, 32744, 32736, 32727, 32717, 32705, 32692, 32678, 32662, + 32646, 32628, 32609, 32588, 32567, 32544, 32520, 32495, 32468, + 32441, 32412, 32382, 32350, 32318, 32284, 32249, 32213, 32176, + 32137, 32097, 32056, 32014, 31970, 31926, 31880, 31833, 31785, + 31735, 31684, 31633, 31580, 31525, 31470, 31413, 31356, 31297, + 31236, 31175, 31113, 31049, 30984, 30918, 30851, 30783, 30713, + 30643, 30571, 30498, 30424, 30349, 30272, 30195, 30116, 30036, + 29955, 29873, 29790, 29706, 29621, 29534, 29446, 29358, 29268, + 29177, 29085, 28992, 28897, 28802, 28706, 28608, 28510, 28410, + 28309, 28208, 28105, 28001, 27896, 27790, 27683, 27575, 27466, + 27355, 27244, 27132, 27019, 26905, 26789, 26673, 26556, 26437, + 26318, 26198, 26077, 25954, 25831, 25707, 25582, 25456, 25329, + 25201, 25072, 24942, 24811, 24679, 24546, 24413, 24278, 24143, + 24006, 23869, 23731, 23592, 23452, 23311, 23169, 23027, 22883, + 22739, 22594, 22448, 22301, 22153, 22004, 21855, 21705, 21554, + 21402, 21249, 21096, 20942, 20787, 20631, 20474, 20317, 20159, + 20000, 19840, 19680, 19519, 19357, 19194, 19031, 18867, 18702, + 18537, 18371, 18204, 18036, 17868, 17699, 17530, 17360, 17189, + 17017, 16845, 16672, 16499, 16325, 16150, 15975, 15799, 15623, + 15446, 15268, 15090, 14911, 14732, 14552, 14372, 14191, 14009, + 13827, 13645, 13462, 13278, 13094, 12909, 12724, 12539, 12353, + 12166, 11980, 11792, 11604, 11416, 11227, 11038, 10849, 10659, + 10469, 10278, 10087, 9895, 9703, 9511, 9319, 9126, 8932, + 8739, 8545, 8351, 8156, 7961, 7766, 7571, 7375, 7179, + 6982, 6786, 6589, 6392, 6195, 5997, 5799, 5601, 5403, + 5205, 5006, 4807, 4608, 4409, 4210, 4011, 3811, 3611, + 3411, 3211, 3011, 2811, 2610, 2410, 2209, 2009, 1808, + 1607, 1406, 1206, 1005, 804, 603, 402, 201, 0, + -201, -402, -603, -804, -1005, -1206, -1406, -1607, -1808, + -2009, -2209, -2410, -2610, -2811, -3011, -3211, -3411, -3611, + -3811, -4011, -4210, -4409, -4608, -4807, -5006, -5205, -5403, + -5601, -5799, -5997, -6195, -6392, -6589, -6786, -6982, -7179, + -7375, -7571, -7766, -7961, -8156, -8351, -8545, -8739, -8932, + -9126, -9319, -9511, -9703, -9895, -10087, -10278, -10469, -10659, + -10849, -11038, -11227, -11416, -11604, -11792, -11980, -12166, -12353, + -12539, -12724, -12909, -13094, -13278, -13462, -13645, -13827, -14009, + -14191, -14372, -14552, -14732, -14911, -15090, -15268, -15446, -15623, + -15799, -15975, -16150, -16325, -16499, -16672, -16845, -17017, -17189, + -17360, -17530, -17699, -17868, -18036, -18204, -18371, -18537, -18702, + -18867, -19031, -19194, -19357, -19519, -19680, -19840, -20000, -20159, + -20317, -20474, -20631, -20787, -20942, -21096, -21249, -21402, -21554, + -21705, -21855, -22004, -22153, -22301, -22448, -22594, -22739, -22883, + -23027, -23169, -23311, -23452, -23592, -23731, -23869, -24006, -24143, + -24278, -24413, -24546, -24679, -24811, -24942, -25072, -25201, -25329, + -25456, -25582, -25707, -25831, -25954, -26077, -26198, -26318, -26437, + -26556, -26673, -26789, -26905, -27019, -27132, -27244, -27355, -27466, + -27575, -27683, -27790, -27896, -28001, -28105, -28208, -28309, -28410, + -28510, -28608, -28706, -28802, -28897, -28992, -29085, -29177, -29268, + -29358, -29446, -29534, -29621, -29706, -29790, -29873, -29955, -30036, + -30116, -30195, -30272, -30349, -30424, -30498, -30571, -30643, -30713, + -30783, -30851, -30918, -30984, -31049, -31113, -31175, -31236, -31297, + -31356, -31413, -31470, -31525, -31580, -31633, -31684, -31735, -31785, + -31833, -31880, -31926, -31970, -32014, -32056, -32097, -32137, -32176, + -32213, -32249, -32284, -32318, -32350, -32382, -32412, -32441, -32468, + -32495, -32520, -32544, -32567, -32588, -32609, -32628, -32646, -32662, + -32678, -32692, -32705, -32717, -32727, -32736, -32744, -32751, -32757, + -32761, -32764, -32766, -32767, -32766, -32764, -32761, -32757, -32751, + -32744, -32736, -32727, -32717, -32705, -32692, -32678, -32662, -32646, + -32628, -32609, -32588, -32567, -32544, -32520, -32495, -32468, -32441, + -32412, -32382, -32350, -32318, -32284, -32249, -32213, -32176, -32137, + -32097, -32056, -32014, -31970, -31926, -31880, -31833, -31785, -31735, + -31684, -31633, -31580, -31525, -31470, -31413, -31356, -31297, -31236, + -31175, -31113, -31049, -30984, -30918, -30851, -30783, -30713, -30643, + -30571, -30498, -30424, -30349, -30272, -30195, -30116, -30036, -29955, + -29873, -29790, -29706, -29621, -29534, -29446, -29358, -29268, -29177, + -29085, -28992, -28897, -28802, -28706, -28608, -28510, -28410, -28309, + -28208, -28105, -28001, -27896, -27790, -27683, -27575, -27466, -27355, + -27244, -27132, -27019, -26905, -26789, -26673, -26556, -26437, -26318, + -26198, -26077, -25954, -25831, -25707, -25582, -25456, -25329, -25201, + -25072, -24942, -24811, -24679, -24546, -24413, -24278, -24143, -24006, + -23869, -23731, -23592, -23452, -23311, -23169, -23027, -22883, -22739, + -22594, -22448, -22301, -22153, -22004, -21855, -21705, -21554, -21402, + -21249, -21096, -20942, -20787, -20631, -20474, -20317, -20159, -20000, + -19840, -19680, -19519, -19357, -19194, -19031, -18867, -18702, -18537, + -18371, -18204, -18036, -17868, -17699, -17530, -17360, -17189, -17017, + -16845, -16672, -16499, -16325, -16150, -15975, -15799, -15623, -15446, + -15268, -15090, -14911, -14732, -14552, -14372, -14191, -14009, -13827, + -13645, -13462, -13278, -13094, -12909, -12724, -12539, -12353, -12166, + -11980, -11792, -11604, -11416, -11227, -11038, -10849, -10659, -10469, + -10278, -10087, -9895, -9703, -9511, -9319, -9126, -8932, -8739, + -8545, -8351, -8156, -7961, -7766, -7571, -7375, -7179, -6982, + -6786, -6589, -6392, -6195, -5997, -5799, -5601, -5403, -5205, + -5006, -4807, -4608, -4409, -4210, -4011, -3811, -3611, -3411, + -3211, -3011, -2811, -2610, -2410, -2209, -2009, -1808, -1607, + -1406, -1206, -1005, -804, -603, -402, -201}; #endif // COMMON_AUDIO_SIGNAL_PROCESSING_COMPLEX_FFT_TABLES_H_ diff --git a/common_audio/signal_processing/include/real_fft.h b/common_audio/signal_processing/include/real_fft.h index 00d18caeb5..8da243da30 100644 --- a/common_audio/signal_processing/include/real_fft.h +++ b/common_audio/signal_processing/include/real_fft.h @@ -15,7 +15,7 @@ // For ComplexFFT(), the maximum fft order is 10; // WebRTC APM uses orders of only 7 and 8. -enum {kMaxFFTOrder = 10}; +enum { kMaxFFTOrder = 10 }; struct RealFFT; diff --git a/common_audio/signal_processing/include/signal_processing_library.h b/common_audio/signal_processing/include/signal_processing_library.h index 27fea6f837..4d6edbf88e 100644 --- a/common_audio/signal_processing/include/signal_processing_library.h +++ b/common_audio/signal_processing/include/signal_processing_library.h @@ -8,11 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* - * This header file includes all of the fix point signal processing library (SPL) function - * descriptions and declarations. - * For specific function calls, see bottom of file. + * This header file includes all of the fix point signal processing library + * (SPL) function descriptions and declarations. For specific function calls, + * see bottom of file. */ #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_ @@ -23,63 +22,58 @@ #include "typedefs.h" // NOLINT(build/include) // Macros specific for the fixed point implementation -#define WEBRTC_SPL_WORD16_MAX 32767 -#define WEBRTC_SPL_WORD16_MIN -32768 -#define WEBRTC_SPL_WORD32_MAX (int32_t)0x7fffffff -#define WEBRTC_SPL_WORD32_MIN (int32_t)0x80000000 -#define WEBRTC_SPL_MAX_LPC_ORDER 14 -#define WEBRTC_SPL_MIN(A, B) (A < B ? A : B) // Get min value -#define WEBRTC_SPL_MAX(A, B) (A > B ? A : B) // Get max value +#define WEBRTC_SPL_WORD16_MAX 32767 +#define WEBRTC_SPL_WORD16_MIN -32768 +#define WEBRTC_SPL_WORD32_MAX (int32_t)0x7fffffff +#define WEBRTC_SPL_WORD32_MIN (int32_t)0x80000000 +#define WEBRTC_SPL_MAX_LPC_ORDER 14 +#define WEBRTC_SPL_MIN(A, B) (A < B ? A : B) // Get min value +#define WEBRTC_SPL_MAX(A, B) (A > B ? A : B) // Get max value // TODO(kma/bjorn): For the next two macros, investigate how to correct the code // for inputs of a = WEBRTC_SPL_WORD16_MIN or WEBRTC_SPL_WORD32_MIN. -#define WEBRTC_SPL_ABS_W16(a) \ - (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a)) -#define WEBRTC_SPL_ABS_W32(a) \ - (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a)) - -#define WEBRTC_SPL_MUL(a, b) \ - ((int32_t) ((int32_t)(a) * (int32_t)(b))) -#define WEBRTC_SPL_UMUL(a, b) \ - ((uint32_t) ((uint32_t)(a) * (uint32_t)(b))) -#define WEBRTC_SPL_UMUL_32_16(a, b) \ - ((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_ABS_W16(a) (((int16_t)a >= 0) ? ((int16_t)a) : -((int16_t)a)) +#define WEBRTC_SPL_ABS_W32(a) (((int32_t)a >= 0) ? ((int32_t)a) : -((int32_t)a)) + +#define WEBRTC_SPL_MUL(a, b) ((int32_t)((int32_t)(a) * (int32_t)(b))) +#define WEBRTC_SPL_UMUL(a, b) ((uint32_t)((uint32_t)(a) * (uint32_t)(b))) +#define WEBRTC_SPL_UMUL_32_16(a, b) ((uint32_t)((uint32_t)(a) * (uint16_t)(b))) +#define WEBRTC_SPL_MUL_16_U16(a, b) ((int32_t)(int16_t)(a) * (uint16_t)(b)) +// clang-format off +// clang-format would choose some identation +// leading to presubmit error (cpplint.py) #ifndef WEBRTC_ARCH_ARM_V7 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h #ifndef MIPS32_LE // For MIPS platforms, these are inline functions in spl_inl_mips.h -#define WEBRTC_SPL_MUL_16_16(a, b) \ - ((int32_t) (((int16_t)(a)) * ((int16_t)(b)))) +#define WEBRTC_SPL_MUL_16_16(a, b) ((int32_t)(((int16_t)(a)) * ((int16_t)(b)))) #define WEBRTC_SPL_MUL_16_32_RSFT16(a, b) \ - (WEBRTC_SPL_MUL_16_16(a, b >> 16) \ - + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15)) + (WEBRTC_SPL_MUL_16_16(a, b >> 16) + \ + ((WEBRTC_SPL_MUL_16_16(a, (b & 0xffff) >> 1) + 0x4000) >> 15)) #endif #endif #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_16(a, (b) >> 16) * (1 << 5) + \ + (((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_16(a, (b) >> 16) * (1 << 2) + \ + (((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_16(a, (b) >> 16) * (1 << 1)) + \ + (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14)) +// clang-format on -#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \ - (WEBRTC_SPL_MUL_16_16(a, b) >> (c)) +#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) (WEBRTC_SPL_MUL_16_16(a, b) >> (c)) #define WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(a, b, c) \ - ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t) \ - (((int32_t)1) << ((c) - 1)))) >> (c)) + ((WEBRTC_SPL_MUL_16_16(a, b) + ((int32_t)(((int32_t)1) << ((c)-1)))) >> (c)) // 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)(B & 0x0000FFFF) * A) >> 16)) -#define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b) +#define WEBRTC_SPL_SAT(a, b, c) (b > a ? a : b < c ? c : b) // Shifting with negative numbers allowed // Positive means left shift @@ -87,12 +81,11 @@ // Shifting with negative numbers not allowed // We cannot do casting here due to signed/unsigned problem -#define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c)) +#define WEBRTC_SPL_LSHIFT_W32(x, c) ((x) << (c)) -#define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c)) +#define WEBRTC_SPL_RSHIFT_U32(x, c) ((uint32_t)(x) >> (c)) -#define WEBRTC_SPL_RAND(a) \ - ((int16_t)((((int16_t)a * 18816) >> 7) & 0x00007fff)) +#define WEBRTC_SPL_RAND(a) ((int16_t)((((int16_t)a * 18816) >> 7) & 0x00007fff)) #ifdef __cplusplus extern "C" { @@ -131,13 +124,10 @@ void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector, size_t in_vector_length, size_t samples, int16_t* out_vector); -void WebRtcSpl_ZerosArrayW16(int16_t* vector, - size_t vector_length); -void WebRtcSpl_ZerosArrayW32(int32_t* vector, - size_t vector_length); +void WebRtcSpl_ZerosArrayW16(int16_t* vector, size_t vector_length); +void WebRtcSpl_ZerosArrayW32(int32_t* vector, size_t vector_length); // End: Copy and set operations. - // Minimum and maximum operation functions and their pointers. // Implementation in min_max_operations.c. @@ -297,7 +287,6 @@ size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length); // End: Minimum and maximum operations. - // Vector scaling operations. Implementation in vector_scaling_operations.c. // Description at bottom of file. void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector, @@ -323,9 +312,11 @@ void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector, size_t vector_length, int16_t right_shifts); void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1, - int16_t gain1, int right_shifts1, + int16_t gain1, + int right_shifts1, const int16_t* in_vector2, - int16_t gain2, int right_shifts2, + int16_t gain2, + int right_shifts2, int16_t* out_vector, size_t vector_length); @@ -777,7 +768,8 @@ typedef struct { int32_t S_16_8[8]; } WebRtcSpl_State22khzTo8khz; -void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample22khzTo8khz(const int16_t* in, + int16_t* out, WebRtcSpl_State22khzTo8khz* state, int32_t* tmpmem); @@ -790,7 +782,8 @@ typedef struct { int32_t S_11_22[8]; } WebRtcSpl_State8khzTo22khz; -void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample8khzTo22khz(const int16_t* in, + int16_t* out, WebRtcSpl_State8khzTo22khz* state, int32_t* tmpmem); @@ -830,7 +823,8 @@ typedef struct { int32_t S_32_16[8]; } WebRtcSpl_State48khzTo16khz; -void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample48khzTo16khz(const int16_t* in, + int16_t* out, WebRtcSpl_State48khzTo16khz* state, int32_t* tmpmem); @@ -842,7 +836,8 @@ typedef struct { int32_t S_24_48[8]; } WebRtcSpl_State16khzTo48khz; -void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample16khzTo48khz(const int16_t* in, + int16_t* out, WebRtcSpl_State16khzTo48khz* state, int32_t* tmpmem); @@ -855,7 +850,8 @@ typedef struct { int32_t S_16_8[8]; } WebRtcSpl_State48khzTo8khz; -void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample48khzTo8khz(const int16_t* in, + int16_t* out, WebRtcSpl_State48khzTo8khz* state, int32_t* tmpmem); @@ -868,7 +864,8 @@ typedef struct { int32_t S_24_48[8]; } WebRtcSpl_State8khzTo48khz; -void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, int16_t* out, +void WebRtcSpl_Resample8khzTo48khz(const int16_t* in, + int16_t* out, WebRtcSpl_State8khzTo48khz* state, int32_t* tmpmem); @@ -881,11 +878,15 @@ void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state); * ******************************************************************/ -void WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len, - int16_t* out, int32_t* filtState); +void WebRtcSpl_DownsampleBy2(const int16_t* in, + size_t len, + int16_t* out, + int32_t* filtState); -void WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len, - int16_t* out, int32_t* filtState); +void WebRtcSpl_UpsampleBy2(const int16_t* in, + size_t len, + int16_t* out, + int32_t* filtState); /************************************************************ * END OF RESAMPLING FUNCTIONS diff --git a/common_audio/signal_processing/include/spl_inl.h b/common_audio/signal_processing/include/spl_inl.h index ba3a11376b..656a3125bb 100644 --- a/common_audio/signal_processing/include/spl_inl.h +++ b/common_audio/signal_processing/include/spl_inl.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - // This header file includes the inline functions in // the fix point signal processing library. @@ -73,7 +72,7 @@ static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) { #if !defined(MIPS_DSP_R1_LE) static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { - int16_t out16 = (int16_t) value32; + int16_t out16 = (int16_t)value32; if (value32 > 32767) out16 = 32767; @@ -112,11 +111,11 @@ static __inline int32_t WebRtcSpl_SubSatW32(int32_t a, int32_t b) { } static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { - return WebRtcSpl_SatW32ToW16((int32_t) a + (int32_t) b); + return WebRtcSpl_SatW32ToW16((int32_t)a + (int32_t)b); } static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { - return WebRtcSpl_SatW32ToW16((int32_t) var1 - (int32_t) var2); + return WebRtcSpl_SatW32ToW16((int32_t)var1 - (int32_t)var2); } #endif // #if !defined(MIPS_DSP_R1_LE) diff --git a/common_audio/signal_processing/include/spl_inl_armv7.h b/common_audio/signal_processing/include/spl_inl_armv7.h index 97179f92f2..930e91e2b3 100644 --- a/common_audio/signal_processing/include/spl_inl_armv7.h +++ b/common_audio/signal_processing/include/spl_inl_armv7.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* This header file includes the inline functions for ARM processors in * the fix point signal processing library. */ @@ -26,35 +25,37 @@ */ static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) { int32_t tmp = 0; - __asm __volatile ("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a)); + __asm __volatile("smulwb %0, %1, %2" : "=r"(tmp) : "r"(b), "r"(a)); return tmp; } static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) { int32_t tmp = 0; - __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b)); + __asm __volatile("smulbb %0, %1, %2" : "=r"(tmp) : "r"(a), "r"(b)); return tmp; } // TODO(kma): add unit test. static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { int32_t tmp = 0; - __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c)); + __asm __volatile("smlabb %0, %1, %2, %3" + : "=r"(tmp) + : "r"(a), "r"(b), "r"(c)); return tmp; } static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { int32_t s_sum = 0; - __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b)); + __asm __volatile("qadd16 %0, %1, %2" : "=r"(s_sum) : "r"(a), "r"(b)); - return (int16_t) s_sum; + return (int16_t)s_sum; } static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { int32_t l_sum = 0; - __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2)); + __asm __volatile("qadd %0, %1, %2" : "=r"(l_sum) : "r"(l_var1), "r"(l_var2)); return l_sum; } @@ -62,7 +63,7 @@ static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { int32_t l_sub = 0; - __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2)); + __asm __volatile("qsub %0, %1, %2" : "=r"(l_sub) : "r"(l_var1), "r"(l_var2)); return l_sub; } @@ -70,7 +71,7 @@ static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { int32_t s_sub = 0; - __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2)); + __asm __volatile("qsub16 %0, %1, %2" : "=r"(s_sub) : "r"(var1), "r"(var2)); return (int16_t)s_sub; } @@ -78,7 +79,7 @@ static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { int32_t tmp = 0; - __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n)); + __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(n)); return (int16_t)(32 - tmp); } @@ -92,7 +93,7 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { a ^= 0xFFFFFFFF; } - __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); + __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a)); return (int16_t)(tmp - 1); } @@ -100,9 +101,10 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { int tmp = 0; - if (a == 0) return 0; + if (a == 0) + return 0; - __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a)); + __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a)); return (int16_t)tmp; } @@ -117,7 +119,7 @@ static __inline int16_t WebRtcSpl_NormW16(int16_t a) { a_32 ^= 0xFFFFFFFF; } - __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a_32)); + __asm __volatile("clz %0, %1" : "=r"(tmp) : "r"(a_32)); return (int16_t)(tmp - 17); } @@ -126,7 +128,7 @@ static __inline int16_t WebRtcSpl_NormW16(int16_t a) { static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { int32_t out = 0; - __asm __volatile ("ssat %0, #16, %1" : "=r"(out) : "r"(value32)); + __asm __volatile("ssat %0, #16, %1" : "=r"(out) : "r"(value32)); return (int16_t)out; } diff --git a/common_audio/signal_processing/include/spl_inl_mips.h b/common_audio/signal_processing/include/spl_inl_mips.h index 5819d0f86b..1db95e8254 100644 --- a/common_audio/signal_processing/include/spl_inl_mips.h +++ b/common_audio/signal_processing/include/spl_inl_mips.h @@ -8,69 +8,65 @@ * be found in the AUTHORS file in the root of the source tree. */ - // This header file includes the inline functions in // the fix point signal processing library. #ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_ #define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_ -static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a, - int32_t b) { +static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a, int32_t b) { int32_t value32 = 0; int32_t a1 = 0, b1 = 0; __asm __volatile( #if defined(MIPS32_R2_LE) - "seh %[a1], %[a] \n\t" - "seh %[b1], %[b] \n\t" + "seh %[a1], %[a] \n\t" + "seh %[b1], %[b] \n\t" #else - "sll %[a1], %[a], 16 \n\t" - "sll %[b1], %[b], 16 \n\t" - "sra %[a1], %[a1], 16 \n\t" - "sra %[b1], %[b1], 16 \n\t" + "sll %[a1], %[a], 16 \n\t" + "sll %[b1], %[b], 16 \n\t" + "sra %[a1], %[a1], 16 \n\t" + "sra %[b1], %[b1], 16 \n\t" #endif - "mul %[value32], %[a1], %[b1] \n\t" - : [value32] "=r" (value32), [a1] "=&r" (a1), [b1] "=&r" (b1) - : [a] "r" (a), [b] "r" (b) - : "hi", "lo"); + "mul %[value32], %[a1], %[b1] \n\t" + : [value32] "=r"(value32), [a1] "=&r"(a1), [b1] "=&r"(b1) + : [a] "r"(a), [b] "r"(b) + : "hi", "lo"); return value32; } -static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, - int32_t b) { +static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) { int32_t value32 = 0, b1 = 0, b2 = 0; int32_t a1 = 0; __asm __volatile( #if defined(MIPS32_R2_LE) - "seh %[a1], %[a] \n\t" + "seh %[a1], %[a] \n\t" #else - "sll %[a1], %[a], 16 \n\t" - "sra %[a1], %[a1], 16 \n\t" + "sll %[a1], %[a], 16 \n\t" + "sra %[a1], %[a1], 16 \n\t" #endif - "andi %[b2], %[b], 0xFFFF \n\t" - "sra %[b1], %[b], 16 \n\t" - "sra %[b2], %[b2], 1 \n\t" - "mul %[value32], %[a1], %[b1] \n\t" - "mul %[b2], %[a1], %[b2] \n\t" - "addiu %[b2], %[b2], 0x4000 \n\t" - "sra %[b2], %[b2], 15 \n\t" - "addu %[value32], %[value32], %[b2] \n\t" - : [value32] "=&r" (value32), [b1] "=&r" (b1), [b2] "=&r" (b2), - [a1] "=&r" (a1) - : [a] "r" (a), [b] "r" (b) - : "hi", "lo"); + "andi %[b2], %[b], 0xFFFF \n\t" + "sra %[b1], %[b], 16 \n\t" + "sra %[b2], %[b2], 1 \n\t" + "mul %[value32], %[a1], %[b1] \n\t" + "mul %[b2], %[a1], %[b2] \n\t" + "addiu %[b2], %[b2], 0x4000 \n\t" + "sra %[b2], %[b2], 15 \n\t" + "addu %[value32], %[value32], %[b2] \n\t" + : [value32] "=&r"(value32), [b1] "=&r"(b1), [b2] "=&r"(b2), [a1] "=&r"(a1) + : [a] "r"(a), [b] "r"(b) + : "hi", "lo"); return value32; } #if defined(MIPS_DSP_R1_LE) static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { __asm __volatile( - "shll_s.w %[value32], %[value32], 16 \n\t" - "sra %[value32], %[value32], 16 \n\t" - : [value32] "+r" (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; } @@ -78,10 +74,9 @@ static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) { static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) { int32_t value32 = 0; - __asm __volatile( - "addq_s.ph %[value32], %[a], %[b] \n\t" - : [value32] "=r" (value32) - : [a] "r" (a), [b] "r" (b) ); + __asm __volatile("addq_s.ph %[value32], %[a], %[b] \n\t" + : [value32] "=r"(value32) + : [a] "r"(a), [b] "r"(b)); return (int16_t)value32; } @@ -89,9 +84,9 @@ static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { int32_t l_sum; __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) ); + "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)); return l_sum; } @@ -99,10 +94,9 @@ static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) { static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) { int32_t value32; - __asm __volatile( - "subq_s.ph %[value32], %[var1], %[var2] \n\t" - : [value32] "=r" (value32) - : [var1] "r" (var1), [var2] "r" (var2) ); + __asm __volatile("subq_s.ph %[value32], %[var1], %[var2] \n\t" + : [value32] "=r"(value32) + : [var1] "r"(var1), [var2] "r"(var2)); return (int16_t)value32; } @@ -111,9 +105,9 @@ static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) { int32_t l_diff; __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) ); + "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)); return l_diff; } @@ -124,10 +118,10 @@ static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) { int i32 = 32; __asm __volatile( - "clz %[bits], %[n] \n\t" - "subu %[bits], %[i32], %[bits] \n\t" - : [bits] "=&r" (bits) - : [n] "r" (n), [i32] "r" (i32) ); + "clz %[bits], %[n] \n\t" + "subu %[bits], %[i32], %[bits] \n\t" + : [bits] "=&r"(bits) + : [n] "r"(n), [i32] "r"(i32)); return (int16_t)bits; } @@ -136,20 +130,20 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { int zeros = 0; __asm __volatile( - ".set push \n\t" - ".set noreorder \n\t" - "bnez %[a], 1f \n\t" - " sra %[zeros], %[a], 31 \n\t" - "b 2f \n\t" - " move %[zeros], $zero \n\t" - "1: \n\t" - "xor %[zeros], %[a], %[zeros] \n\t" - "clz %[zeros], %[zeros] \n\t" - "addiu %[zeros], %[zeros], -1 \n\t" - "2: \n\t" - ".set pop \n\t" - : [zeros]"=&r"(zeros) - : [a] "r" (a) ); + ".set push \n\t" + ".set noreorder \n\t" + "bnez %[a], 1f \n\t" + " sra %[zeros], %[a], 31 \n\t" + "b 2f \n\t" + " move %[zeros], $zero \n\t" + "1: \n\t" + "xor %[zeros], %[a], %[zeros] \n\t" + "clz %[zeros], %[zeros] \n\t" + "addiu %[zeros], %[zeros], -1 \n\t" + "2: \n\t" + ".set pop \n\t" + : [zeros] "=&r"(zeros) + : [a] "r"(a)); return (int16_t)zeros; } @@ -157,10 +151,9 @@ static __inline int16_t WebRtcSpl_NormW32(int32_t a) { static __inline int16_t WebRtcSpl_NormU32(uint32_t a) { int zeros = 0; - __asm __volatile( - "clz %[zeros], %[a] \n\t" - : [zeros] "=r" (zeros) - : [a] "r" (a) ); + __asm __volatile("clz %[zeros], %[a] \n\t" + : [zeros] "=r"(zeros) + : [a] "r"(a)); return (int16_t)(zeros & 0x1f); } @@ -170,43 +163,41 @@ static __inline int16_t WebRtcSpl_NormW16(int16_t a) { int a0 = a << 16; __asm __volatile( - ".set push \n\t" - ".set noreorder \n\t" - "bnez %[a0], 1f \n\t" - " sra %[zeros], %[a0], 31 \n\t" - "b 2f \n\t" - " move %[zeros], $zero \n\t" - "1: \n\t" - "xor %[zeros], %[a0], %[zeros] \n\t" - "clz %[zeros], %[zeros] \n\t" - "addiu %[zeros], %[zeros], -1 \n\t" - "2: \n\t" - ".set pop \n\t" - : [zeros]"=&r"(zeros) - : [a0] "r" (a0) ); + ".set push \n\t" + ".set noreorder \n\t" + "bnez %[a0], 1f \n\t" + " sra %[zeros], %[a0], 31 \n\t" + "b 2f \n\t" + " move %[zeros], $zero \n\t" + "1: \n\t" + "xor %[zeros], %[a0], %[zeros] \n\t" + "clz %[zeros], %[zeros] \n\t" + "addiu %[zeros], %[zeros], -1 \n\t" + "2: \n\t" + ".set pop \n\t" + : [zeros] "=&r"(zeros) + : [a0] "r"(a0)); return (int16_t)zeros; } -static __inline int32_t WebRtc_MulAccumW16(int16_t a, - int16_t b, - int32_t c) { +static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) { int32_t res = 0, c1 = 0; __asm __volatile( #if defined(MIPS32_R2_LE) - "seh %[a], %[a] \n\t" - "seh %[b], %[b] \n\t" + "seh %[a], %[a] \n\t" + "seh %[b], %[b] \n\t" #else - "sll %[a], %[a], 16 \n\t" - "sll %[b], %[b], 16 \n\t" - "sra %[a], %[a], 16 \n\t" - "sra %[b], %[b], 16 \n\t" + "sll %[a], %[a], 16 \n\t" + "sll %[b], %[b], 16 \n\t" + "sra %[a], %[a], 16 \n\t" + "sra %[b], %[b], 16 \n\t" #endif - "mul %[res], %[a], %[b] \n\t" - "addu %[c1], %[c], %[res] \n\t" - : [c1] "=r" (c1), [res] "=&r" (res) - : [a] "r" (a), [b] "r" (b), [c] "r" (c) - : "hi", "lo"); + "mul %[res], %[a], %[b] \n\t" + "addu %[c1], %[c], %[res] \n\t" + : [c1] "=r"(c1), [res] "=&r"(res) + : [a] "r"(a), [b] "r"(b), [c] "r"(c) + : "hi", "lo"); return (c1); } diff --git a/common_audio/signal_processing/real_fft_unittest.cc b/common_audio/signal_processing/real_fft_unittest.cc index 4f5b5c72b2..2d6b7d1b86 100644 --- a/common_audio/signal_processing/real_fft_unittest.cc +++ b/common_audio/signal_processing/real_fft_unittest.cc @@ -27,17 +27,14 @@ const int kFreqDataLength = (1 << kOrder) + 2; const int kComplexFftDataLength = 2 << kOrder; // Reference data for time signal. const int16_t kRefData[kTimeDataLength] = { - 11739, 6848, -8688, 31980, -30295, 25242, 27085, 19410, - -26299, 15607, -10791, 11778, -23819, 14498, -25772, 10076, - 1173, 6848, -8688, 31980, -30295, 2522, 27085, 19410, - -2629, 5607, -3, 1178, -23819, 1498, -25772, 10076 -}; + 11739, 6848, -8688, 31980, -30295, 25242, 27085, 19410, + -26299, 15607, -10791, 11778, -23819, 14498, -25772, 10076, + 1173, 6848, -8688, 31980, -30295, 2522, 27085, 19410, + -2629, 5607, -3, 1178, -23819, 1498, -25772, 10076}; class RealFFTTest : public ::testing::Test { protected: - RealFFTTest() { - WebRtcSpl_Init(); - } + RealFFTTest() { WebRtcSpl_Init(); } }; TEST_F(RealFFTTest, CreateFailsOnBadInput) { diff --git a/common_audio/signal_processing/resample_by_2_internal.h b/common_audio/signal_processing/resample_by_2_internal.h index b0d19691c4..5483e2ebca 100644 --- a/common_audio/signal_processing/resample_by_2_internal.h +++ b/common_audio/signal_processing/resample_by_2_internal.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* * This header file contains some internal resampling functions. * @@ -23,25 +22,39 @@ * resample_by_2_fast.c * Functions for internal use in the other resample functions ******************************************************************/ -void WebRtcSpl_DownBy2IntToShort(int32_t *in, int32_t len, int16_t *out, - int32_t *state); - -void WebRtcSpl_DownBy2ShortToInt(const int16_t *in, int32_t len, - int32_t *out, int32_t *state); - -void WebRtcSpl_UpBy2ShortToInt(const int16_t *in, int32_t len, - int32_t *out, int32_t *state); - -void WebRtcSpl_UpBy2IntToInt(const int32_t *in, int32_t len, int32_t *out, - int32_t *state); +void WebRtcSpl_DownBy2IntToShort(int32_t* in, + int32_t len, + int16_t* out, + int32_t* state); + +void WebRtcSpl_DownBy2ShortToInt(const int16_t* in, + int32_t len, + int32_t* out, + int32_t* state); + +void WebRtcSpl_UpBy2ShortToInt(const int16_t* in, + int32_t len, + int32_t* out, + int32_t* state); + +void WebRtcSpl_UpBy2IntToInt(const int32_t* in, + int32_t len, + int32_t* out, + int32_t* state); -void WebRtcSpl_UpBy2IntToShort(const int32_t *in, int32_t len, - int16_t *out, int32_t *state); +void WebRtcSpl_UpBy2IntToShort(const int32_t* in, + int32_t len, + int16_t* out, + int32_t* state); -void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, int32_t len, - int32_t* out, int32_t* state); +void WebRtcSpl_LPBy2ShortToInt(const int16_t* in, + int32_t len, + int32_t* out, + int32_t* state); -void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out, +void WebRtcSpl_LPBy2IntToInt(const int32_t* in, + int32_t len, + int32_t* out, int32_t* state); #endif // COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_ diff --git a/common_audio/signal_processing/signal_processing_unittest.cc b/common_audio/signal_processing/signal_processing_unittest.cc index b9efe01fe7..4ef0c906a0 100644 --- a/common_audio/signal_processing/signal_processing_unittest.cc +++ b/common_audio/signal_processing/signal_processing_unittest.cc @@ -15,111 +15,113 @@ #include "test/gtest.h" static const size_t kVector16Size = 9; -static const int16_t vector16[kVector16Size] = {1, -15511, 4323, 1963, - WEBRTC_SPL_WORD16_MAX, 0, WEBRTC_SPL_WORD16_MIN + 5, -3333, 345}; +static const int16_t vector16[kVector16Size] = {1, + -15511, + 4323, + 1963, + WEBRTC_SPL_WORD16_MAX, + 0, + WEBRTC_SPL_WORD16_MIN + 5, + -3333, + 345}; class SplTest : public testing::Test { protected: - SplTest() { - WebRtcSpl_Init(); - } - virtual ~SplTest() { - } + SplTest() { WebRtcSpl_Init(); } + virtual ~SplTest() {} }; TEST_F(SplTest, MacroTest) { - // Macros with inputs. - int A = 10; - int B = 21; - int a = -3; - int b = WEBRTC_SPL_WORD32_MAX; - - EXPECT_EQ(10, WEBRTC_SPL_MIN(A, B)); - EXPECT_EQ(21, WEBRTC_SPL_MAX(A, B)); - - EXPECT_EQ(3, WEBRTC_SPL_ABS_W16(a)); - EXPECT_EQ(3, WEBRTC_SPL_ABS_W32(a)); - - EXPECT_EQ(-63, WEBRTC_SPL_MUL(a, B)); - EXPECT_EQ(2147483651u, WEBRTC_SPL_UMUL(a, b)); - b = WEBRTC_SPL_WORD16_MAX >> 1; - EXPECT_EQ(4294918147u, WEBRTC_SPL_UMUL_32_16(a, b)); - EXPECT_EQ(-49149, WEBRTC_SPL_MUL_16_U16(a, b)); - - a = b; - b = -3; - - EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT16(a, b)); - EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT15(a, b)); - EXPECT_EQ(-3, WEBRTC_SPL_MUL_16_32_RSFT14(a, b)); - EXPECT_EQ(-24, WEBRTC_SPL_MUL_16_32_RSFT11(a, b)); - - 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(21, WEBRTC_SPL_SAT(a, A, B)); - EXPECT_EQ(21, WEBRTC_SPL_SAT(a, B, A)); - - // Shifting with negative numbers allowed - int shift_amount = 1; // Workaround compiler warning using variable here. - // Positive means left shift - EXPECT_EQ(32766, WEBRTC_SPL_SHIFT_W32(a, shift_amount)); - - // Shifting with negative numbers not allowed - // We cannot do casting here due to signed/unsigned problem - EXPECT_EQ(32766, WEBRTC_SPL_LSHIFT_W32(a, 1)); - - EXPECT_EQ(8191u, WEBRTC_SPL_RSHIFT_U32(a, 1)); - - EXPECT_EQ(1470, WEBRTC_SPL_RAND(A)); - - EXPECT_EQ(-49149, WEBRTC_SPL_MUL_16_16(a, b)); - EXPECT_EQ(1073676289, WEBRTC_SPL_MUL_16_16(WEBRTC_SPL_WORD16_MAX, - WEBRTC_SPL_WORD16_MAX)); - EXPECT_EQ(1073709055, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MAX, - WEBRTC_SPL_WORD32_MAX)); - EXPECT_EQ(1073741824, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, - WEBRTC_SPL_WORD32_MIN)); + // Macros with inputs. + int A = 10; + int B = 21; + int a = -3; + int b = WEBRTC_SPL_WORD32_MAX; + + EXPECT_EQ(10, WEBRTC_SPL_MIN(A, B)); + EXPECT_EQ(21, WEBRTC_SPL_MAX(A, B)); + + EXPECT_EQ(3, WEBRTC_SPL_ABS_W16(a)); + EXPECT_EQ(3, WEBRTC_SPL_ABS_W32(a)); + + EXPECT_EQ(-63, WEBRTC_SPL_MUL(a, B)); + EXPECT_EQ(2147483651u, WEBRTC_SPL_UMUL(a, b)); + b = WEBRTC_SPL_WORD16_MAX >> 1; + EXPECT_EQ(4294918147u, WEBRTC_SPL_UMUL_32_16(a, b)); + EXPECT_EQ(-49149, WEBRTC_SPL_MUL_16_U16(a, b)); + + a = b; + b = -3; + + EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT16(a, b)); + EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT15(a, b)); + EXPECT_EQ(-3, WEBRTC_SPL_MUL_16_32_RSFT14(a, b)); + EXPECT_EQ(-24, WEBRTC_SPL_MUL_16_32_RSFT11(a, b)); + + 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(21, WEBRTC_SPL_SAT(a, A, B)); + EXPECT_EQ(21, WEBRTC_SPL_SAT(a, B, A)); + + // Shifting with negative numbers allowed + int shift_amount = 1; // Workaround compiler warning using variable here. + // Positive means left shift + EXPECT_EQ(32766, WEBRTC_SPL_SHIFT_W32(a, shift_amount)); + + // Shifting with negative numbers not allowed + // We cannot do casting here due to signed/unsigned problem + EXPECT_EQ(32766, WEBRTC_SPL_LSHIFT_W32(a, 1)); + + EXPECT_EQ(8191u, WEBRTC_SPL_RSHIFT_U32(a, 1)); + + EXPECT_EQ(1470, WEBRTC_SPL_RAND(A)); + + EXPECT_EQ(-49149, WEBRTC_SPL_MUL_16_16(a, b)); + EXPECT_EQ(1073676289, + WEBRTC_SPL_MUL_16_16(WEBRTC_SPL_WORD16_MAX, WEBRTC_SPL_WORD16_MAX)); + EXPECT_EQ(1073709055, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MAX, + WEBRTC_SPL_WORD32_MAX)); + EXPECT_EQ(1073741824, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, + WEBRTC_SPL_WORD32_MIN)); #ifdef WEBRTC_ARCH_ARM_V7 - EXPECT_EQ(-1073741824, - WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, - WEBRTC_SPL_WORD32_MAX)); + EXPECT_EQ(-1073741824, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, + WEBRTC_SPL_WORD32_MAX)); #else - EXPECT_EQ(-1073741823, - WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, - WEBRTC_SPL_WORD32_MAX)); + EXPECT_EQ(-1073741823, WEBRTC_SPL_MUL_16_32_RSFT16(WEBRTC_SPL_WORD16_MIN, + WEBRTC_SPL_WORD32_MAX)); #endif } TEST_F(SplTest, InlineTest) { - int16_t a16 = 121; - int16_t b16 = -17; - int32_t a32 = 111121; - int32_t b32 = -1711; - - EXPECT_EQ(17, WebRtcSpl_GetSizeInBits(a32)); - - EXPECT_EQ(0, WebRtcSpl_NormW32(0)); - EXPECT_EQ(31, WebRtcSpl_NormW32(-1)); - EXPECT_EQ(0, WebRtcSpl_NormW32(WEBRTC_SPL_WORD32_MIN)); - EXPECT_EQ(14, WebRtcSpl_NormW32(a32)); - - EXPECT_EQ(0, WebRtcSpl_NormW16(0)); - EXPECT_EQ(15, WebRtcSpl_NormW16(-1)); - EXPECT_EQ(0, WebRtcSpl_NormW16(WEBRTC_SPL_WORD16_MIN)); - EXPECT_EQ(4, WebRtcSpl_NormW16(b32)); - for (int ii = 0; ii < 15; ++ii) { - int16_t value = 1 << ii; - EXPECT_EQ(14 - ii, WebRtcSpl_NormW16(value)); - EXPECT_EQ(15 - ii, WebRtcSpl_NormW16(-value)); - } + int16_t a16 = 121; + int16_t b16 = -17; + int32_t a32 = 111121; + int32_t b32 = -1711; + + EXPECT_EQ(17, WebRtcSpl_GetSizeInBits(a32)); + + EXPECT_EQ(0, WebRtcSpl_NormW32(0)); + EXPECT_EQ(31, WebRtcSpl_NormW32(-1)); + EXPECT_EQ(0, WebRtcSpl_NormW32(WEBRTC_SPL_WORD32_MIN)); + EXPECT_EQ(14, WebRtcSpl_NormW32(a32)); + + EXPECT_EQ(0, WebRtcSpl_NormW16(0)); + EXPECT_EQ(15, WebRtcSpl_NormW16(-1)); + EXPECT_EQ(0, WebRtcSpl_NormW16(WEBRTC_SPL_WORD16_MIN)); + EXPECT_EQ(4, WebRtcSpl_NormW16(b32)); + for (int ii = 0; ii < 15; ++ii) { + int16_t value = 1 << ii; + EXPECT_EQ(14 - ii, WebRtcSpl_NormW16(value)); + EXPECT_EQ(15 - ii, WebRtcSpl_NormW16(-value)); + } - EXPECT_EQ(0, WebRtcSpl_NormU32(0u)); - EXPECT_EQ(0, WebRtcSpl_NormU32(0xffffffff)); - EXPECT_EQ(15, WebRtcSpl_NormU32(static_cast<uint32_t>(a32))); + EXPECT_EQ(0, WebRtcSpl_NormU32(0u)); + EXPECT_EQ(0, WebRtcSpl_NormU32(0xffffffff)); + EXPECT_EQ(15, WebRtcSpl_NormU32(static_cast<uint32_t>(a32))); - EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16)); - EXPECT_EQ(138, WebRtcSpl_SubSatW16(a16, b16)); + EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16)); + EXPECT_EQ(138, WebRtcSpl_SubSatW16(a16, b16)); } TEST_F(SplTest, AddSubSatW32) { @@ -168,84 +170,83 @@ TEST_F(SplTest, CountLeadingZeros64) { } TEST_F(SplTest, MathOperationsTest) { - int A = 1134567892; - int32_t num = 117; - int32_t den = -5; - uint16_t denU = 5; - EXPECT_EQ(33700, WebRtcSpl_Sqrt(A)); - EXPECT_EQ(33683, WebRtcSpl_SqrtFloor(A)); - - - EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num)); - EXPECT_EQ(-23, WebRtcSpl_DivW32W16ResW16(num, (int16_t)den)); - EXPECT_EQ(-23, WebRtcSpl_DivW32W16(num, (int16_t)den)); - EXPECT_EQ(23u, WebRtcSpl_DivU32U16(num, denU)); - EXPECT_EQ(0, WebRtcSpl_DivW32HiLow(128, 0, 256)); + int A = 1134567892; + int32_t num = 117; + int32_t den = -5; + uint16_t denU = 5; + EXPECT_EQ(33700, WebRtcSpl_Sqrt(A)); + EXPECT_EQ(33683, WebRtcSpl_SqrtFloor(A)); + + EXPECT_EQ(-91772805, WebRtcSpl_DivResultInQ31(den, num)); + EXPECT_EQ(-23, WebRtcSpl_DivW32W16ResW16(num, (int16_t)den)); + EXPECT_EQ(-23, WebRtcSpl_DivW32W16(num, (int16_t)den)); + EXPECT_EQ(23u, WebRtcSpl_DivU32U16(num, denU)); + EXPECT_EQ(0, WebRtcSpl_DivW32HiLow(128, 0, 256)); } TEST_F(SplTest, BasicArrayOperationsTest) { - const size_t kVectorSize = 4; - int B[] = {4, 12, 133, 1100}; - int16_t b16[kVectorSize]; - int32_t b32[kVectorSize]; + const size_t kVectorSize = 4; + int B[] = {4, 12, 133, 1100}; + int16_t b16[kVectorSize]; + int32_t b32[kVectorSize]; - int16_t bTmp16[kVectorSize]; - int32_t bTmp32[kVectorSize]; + int16_t bTmp16[kVectorSize]; + int32_t bTmp32[kVectorSize]; - WebRtcSpl_MemSetW16(b16, 3, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(3, b16[kk]); - } - WebRtcSpl_ZerosArrayW16(b16, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(0, b16[kk]); - } - WebRtcSpl_MemSetW32(b32, 3, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(3, b32[kk]); - } - WebRtcSpl_ZerosArrayW32(b32, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(0, b32[kk]); - } - for (size_t kk = 0; kk < kVectorSize; ++kk) { - bTmp16[kk] = (int16_t)kk; - bTmp32[kk] = (int32_t)kk; - } - WEBRTC_SPL_MEMCPY_W16(b16, bTmp16, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(b16[kk], bTmp16[kk]); - } -// WEBRTC_SPL_MEMCPY_W32(b32, bTmp32, kVectorSize); -// for (int kk = 0; kk < kVectorSize; ++kk) { -// EXPECT_EQ(b32[kk], bTmp32[kk]); -// } - WebRtcSpl_CopyFromEndW16(b16, kVectorSize, 2, bTmp16); - for (size_t kk = 0; kk < 2; ++kk) { - EXPECT_EQ(static_cast<int16_t>(kk+2), bTmp16[kk]); - } + WebRtcSpl_MemSetW16(b16, 3, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(3, b16[kk]); + } + WebRtcSpl_ZerosArrayW16(b16, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(0, b16[kk]); + } + WebRtcSpl_MemSetW32(b32, 3, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(3, b32[kk]); + } + WebRtcSpl_ZerosArrayW32(b32, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(0, b32[kk]); + } + for (size_t kk = 0; kk < kVectorSize; ++kk) { + bTmp16[kk] = (int16_t)kk; + bTmp32[kk] = (int32_t)kk; + } + WEBRTC_SPL_MEMCPY_W16(b16, bTmp16, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(b16[kk], bTmp16[kk]); + } + // WEBRTC_SPL_MEMCPY_W32(b32, bTmp32, kVectorSize); + // for (int kk = 0; kk < kVectorSize; ++kk) { + // EXPECT_EQ(b32[kk], bTmp32[kk]); + // } + WebRtcSpl_CopyFromEndW16(b16, kVectorSize, 2, bTmp16); + for (size_t kk = 0; kk < 2; ++kk) { + EXPECT_EQ(static_cast<int16_t>(kk + 2), bTmp16[kk]); + } - for (size_t kk = 0; kk < kVectorSize; ++kk) { - b32[kk] = B[kk]; - b16[kk] = (int16_t)B[kk]; - } - WebRtcSpl_VectorBitShiftW32ToW16(bTmp16, kVectorSize, b32, 1); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((B[kk]>>1), bTmp16[kk]); - } - WebRtcSpl_VectorBitShiftW16(bTmp16, kVectorSize, b16, 1); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((B[kk]>>1), bTmp16[kk]); - } - WebRtcSpl_VectorBitShiftW32(bTmp32, kVectorSize, b32, 1); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((B[kk]>>1), bTmp32[kk]); - } + for (size_t kk = 0; kk < kVectorSize; ++kk) { + b32[kk] = B[kk]; + b16[kk] = (int16_t)B[kk]; + } + WebRtcSpl_VectorBitShiftW32ToW16(bTmp16, kVectorSize, b32, 1); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((B[kk] >> 1), bTmp16[kk]); + } + WebRtcSpl_VectorBitShiftW16(bTmp16, kVectorSize, b16, 1); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((B[kk] >> 1), bTmp16[kk]); + } + WebRtcSpl_VectorBitShiftW32(bTmp32, kVectorSize, b32, 1); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((B[kk] >> 1), bTmp32[kk]); + } - WebRtcSpl_MemCpyReversedOrder(&bTmp16[3], b16, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(b16[3-kk], bTmp16[kk]); - } + WebRtcSpl_MemCpyReversedOrder(&bTmp16[3], b16, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(b16[3 - kk], bTmp16[kk]); + } } TEST_F(SplTest, MinMaxOperationsTest) { @@ -253,12 +254,40 @@ TEST_F(SplTest, MinMaxOperationsTest) { // Vectors to test the cases where minimum values have to be caught // outside of the unrolled loops in ARM-Neon. - int16_t vector16[kVectorSize] = {-1, 7485, 0, 3333, - -18283, 0, 12334, -29871, 988, -3333, - 345, -456, 222, 999, 888, 8774, WEBRTC_SPL_WORD16_MIN}; - int32_t vector32[kVectorSize] = {-1, 0, 283211, 3333, - 8712345, 0, -3333, 89345, -374585456, 222, 999, 122345334, - -12389756, -987329871, 888, -2, WEBRTC_SPL_WORD32_MIN}; + int16_t vector16[kVectorSize] = {-1, + 7485, + 0, + 3333, + -18283, + 0, + 12334, + -29871, + 988, + -3333, + 345, + -456, + 222, + 999, + 888, + 8774, + WEBRTC_SPL_WORD16_MIN}; + int32_t vector32[kVectorSize] = {-1, + 0, + 283211, + 3333, + 8712345, + 0, + -3333, + 89345, + -374585456, + 222, + 999, + 122345334, + -12389756, + -987329871, + 888, + -2, + WEBRTC_SPL_WORD32_MIN}; EXPECT_EQ(WEBRTC_SPL_WORD16_MIN, WebRtcSpl_MinValueW16(vector16, kVectorSize)); @@ -312,76 +341,75 @@ TEST_F(SplTest, MinMaxOperationsTest) { } TEST_F(SplTest, VectorOperationsTest) { - const size_t kVectorSize = 4; - int B[] = {4, 12, 133, 1100}; - int16_t a16[kVectorSize]; - int16_t b16[kVectorSize]; - int16_t bTmp16[kVectorSize]; - - for (size_t kk = 0; kk < kVectorSize; ++kk) { - a16[kk] = B[kk]; - b16[kk] = B[kk]; - } + const size_t kVectorSize = 4; + int B[] = {4, 12, 133, 1100}; + int16_t a16[kVectorSize]; + int16_t b16[kVectorSize]; + int16_t bTmp16[kVectorSize]; + + for (size_t kk = 0; kk < kVectorSize; ++kk) { + a16[kk] = B[kk]; + b16[kk] = B[kk]; + } - WebRtcSpl_AffineTransformVector(bTmp16, b16, 3, 7, 2, kVectorSize); - 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); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((B[kk]*3+B[kk]*2+2)>>2, bTmp16[kk]); - } + WebRtcSpl_AffineTransformVector(bTmp16, b16, 3, 7, 2, kVectorSize); + 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); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((B[kk] * 3 + B[kk] * 2 + 2) >> 2, bTmp16[kk]); + } - WebRtcSpl_AddAffineVectorToVector(bTmp16, b16, 3, 7, 2, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(((B[kk]*3+B[kk]*2+2)>>2)+((b16[kk]*3+7)>>2), bTmp16[kk]); - } + WebRtcSpl_AddAffineVectorToVector(bTmp16, b16, 3, 7, 2, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(((B[kk] * 3 + B[kk] * 2 + 2) >> 2) + ((b16[kk] * 3 + 7) >> 2), + bTmp16[kk]); + } - WebRtcSpl_ScaleVector(b16, bTmp16, 13, kVectorSize, 2); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((b16[kk]*13)>>2, bTmp16[kk]); - } - WebRtcSpl_ScaleVectorWithSat(b16, bTmp16, 13, kVectorSize, 2); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((b16[kk]*13)>>2, bTmp16[kk]); - } - WebRtcSpl_ScaleAndAddVectors(a16, 13, 2, b16, 7, 2, bTmp16, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(((a16[kk]*13)>>2)+((b16[kk]*7)>>2), bTmp16[kk]); - } + WebRtcSpl_ScaleVector(b16, bTmp16, 13, kVectorSize, 2); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((b16[kk] * 13) >> 2, bTmp16[kk]); + } + WebRtcSpl_ScaleVectorWithSat(b16, bTmp16, 13, kVectorSize, 2); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((b16[kk] * 13) >> 2, bTmp16[kk]); + } + WebRtcSpl_ScaleAndAddVectors(a16, 13, 2, b16, 7, 2, bTmp16, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(((a16[kk] * 13) >> 2) + ((b16[kk] * 7) >> 2), bTmp16[kk]); + } - WebRtcSpl_AddVectorsAndShift(bTmp16, a16, b16, kVectorSize, 2); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(B[kk] >> 1, bTmp16[kk]); - } - 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]); - } - WebRtcSpl_ElementwiseVectorMult(bTmp16, a16, b16, kVectorSize, 6); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ((a16[kk]*b16[kk])>>6, bTmp16[kk]); - } + WebRtcSpl_AddVectorsAndShift(bTmp16, a16, b16, kVectorSize, 2); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(B[kk] >> 1, bTmp16[kk]); + } + 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]); + } + WebRtcSpl_ElementwiseVectorMult(bTmp16, a16, b16, kVectorSize, 6); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ((a16[kk] * b16[kk]) >> 6, bTmp16[kk]); + } - WebRtcSpl_SqrtOfOneMinusXSquared(b16, kVectorSize, bTmp16); - for (size_t kk = 0; kk < kVectorSize - 1; ++kk) { - EXPECT_EQ(32767, bTmp16[kk]); - } - EXPECT_EQ(32749, bTmp16[kVectorSize - 1]); + WebRtcSpl_SqrtOfOneMinusXSquared(b16, kVectorSize, bTmp16); + for (size_t kk = 0; kk < kVectorSize - 1; ++kk) { + EXPECT_EQ(32767, bTmp16[kk]); + } + EXPECT_EQ(32749, bTmp16[kVectorSize - 1]); - EXPECT_EQ(0, WebRtcSpl_GetScalingSquare(b16, kVectorSize, 1)); + EXPECT_EQ(0, WebRtcSpl_GetScalingSquare(b16, kVectorSize, 1)); } TEST_F(SplTest, EstimatorsTest) { const size_t kOrder = 2; - const int32_t unstable_filter[] = { 4, 12, 133, 1100 }; - const int32_t stable_filter[] = { 1100, 133, 12, 4 }; - int16_t lpc[kOrder + 2] = { 0 }; - int16_t refl[kOrder + 2] = { 0 }; - int16_t lpc_result[] = { 4096, -497, 15, 0 }; - int16_t refl_result[] = { -3962, 123, 0, 0 }; + const int32_t unstable_filter[] = {4, 12, 133, 1100}; + const int32_t stable_filter[] = {1100, 133, 12, 4}; + int16_t lpc[kOrder + 2] = {0}; + int16_t refl[kOrder + 2] = {0}; + int16_t lpc_result[] = {4096, -497, 15, 0}; + int16_t refl_result[] = {-3962, 123, 0, 0}; EXPECT_EQ(0, WebRtcSpl_LevinsonDurbin(unstable_filter, lpc, refl, kOrder)); EXPECT_EQ(1, WebRtcSpl_LevinsonDurbin(stable_filter, lpc, refl, kOrder)); @@ -392,69 +420,61 @@ TEST_F(SplTest, EstimatorsTest) { } TEST_F(SplTest, FilterTest) { - const size_t kVectorSize = 4; - const size_t kFilterOrder = 3; - int16_t A[] = {1, 2, 33, 100}; - int16_t A5[] = {1, 2, 33, 100, -5}; - int16_t B[] = {4, 12, 133, 110}; - int16_t data_in[kVectorSize]; - int16_t data_out[kVectorSize]; - int16_t bTmp16Low[kVectorSize]; - int16_t bState[kVectorSize]; - int16_t bStateLow[kVectorSize]; - - WebRtcSpl_ZerosArrayW16(bState, kVectorSize); - WebRtcSpl_ZerosArrayW16(bStateLow, kVectorSize); - - for (size_t kk = 0; kk < kVectorSize; ++kk) { - data_in[kk] = A[kk]; - data_out[kk] = 0; - } + const size_t kVectorSize = 4; + const size_t kFilterOrder = 3; + int16_t A[] = {1, 2, 33, 100}; + int16_t A5[] = {1, 2, 33, 100, -5}; + int16_t B[] = {4, 12, 133, 110}; + int16_t data_in[kVectorSize]; + int16_t data_out[kVectorSize]; + int16_t bTmp16Low[kVectorSize]; + int16_t bState[kVectorSize]; + int16_t bStateLow[kVectorSize]; + + WebRtcSpl_ZerosArrayW16(bState, kVectorSize); + WebRtcSpl_ZerosArrayW16(bStateLow, kVectorSize); + + for (size_t kk = 0; kk < kVectorSize; ++kk) { + data_in[kk] = A[kk]; + data_out[kk] = 0; + } - // MA filters. - // Note that the input data has |kFilterOrder| states before the actual - // data (one sample). - WebRtcSpl_FilterMAFastQ12(&data_in[kFilterOrder], data_out, B, - kFilterOrder + 1, 1); - EXPECT_EQ(0, data_out[0]); - // AR filters. - // Note that the output data has |kFilterOrder| states before the actual - // data (one sample). - WebRtcSpl_FilterARFastQ12(data_in, &data_out[kFilterOrder], A, - kFilterOrder + 1, 1); - EXPECT_EQ(0, data_out[kFilterOrder]); - - EXPECT_EQ(kVectorSize, WebRtcSpl_FilterAR(A5, - 5, - data_in, - kVectorSize, - bState, - kVectorSize, - bStateLow, - kVectorSize, - data_out, - bTmp16Low, - kVectorSize)); + // MA filters. + // Note that the input data has |kFilterOrder| states before the actual + // data (one sample). + WebRtcSpl_FilterMAFastQ12(&data_in[kFilterOrder], data_out, B, + kFilterOrder + 1, 1); + EXPECT_EQ(0, data_out[0]); + // AR filters. + // Note that the output data has |kFilterOrder| states before the actual + // data (one sample). + WebRtcSpl_FilterARFastQ12(data_in, &data_out[kFilterOrder], A, + kFilterOrder + 1, 1); + EXPECT_EQ(0, data_out[kFilterOrder]); + + EXPECT_EQ(kVectorSize, WebRtcSpl_FilterAR(A5, 5, data_in, kVectorSize, bState, + kVectorSize, bStateLow, kVectorSize, + data_out, bTmp16Low, kVectorSize)); } TEST_F(SplTest, RandTest) { - const int kVectorSize = 4; - int16_t BU[] = {3653, 12446, 8525, 30691}; - int16_t b16[kVectorSize]; - uint32_t bSeed = 100000; - - EXPECT_EQ(7086, WebRtcSpl_RandU(&bSeed)); - EXPECT_EQ(31565, WebRtcSpl_RandU(&bSeed)); - EXPECT_EQ(-9786, WebRtcSpl_RandN(&bSeed)); - EXPECT_EQ(kVectorSize, WebRtcSpl_RandUArray(b16, kVectorSize, &bSeed)); - for (int kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(BU[kk], b16[kk]); - } + const int kVectorSize = 4; + int16_t BU[] = {3653, 12446, 8525, 30691}; + int16_t b16[kVectorSize]; + uint32_t bSeed = 100000; + + EXPECT_EQ(7086, WebRtcSpl_RandU(&bSeed)); + EXPECT_EQ(31565, WebRtcSpl_RandU(&bSeed)); + EXPECT_EQ(-9786, WebRtcSpl_RandN(&bSeed)); + EXPECT_EQ(kVectorSize, WebRtcSpl_RandUArray(b16, kVectorSize, &bSeed)); + for (int kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(BU[kk], b16[kk]); + } } TEST_F(SplTest, DotProductWithScaleTest) { - EXPECT_EQ(605362796, WebRtcSpl_DotProductWithScale(vector16, - vector16, kVector16Size, 2)); + EXPECT_EQ(605362796, WebRtcSpl_DotProductWithScale(vector16, vector16, + kVector16Size, 2)); } TEST_F(SplTest, CrossCorrelationTest) { @@ -464,8 +484,9 @@ TEST_F(SplTest, CrossCorrelationTest) { const int kStep = 1; const size_t kSeqDimension = 6; - const int16_t kVector16[kVector16Size] = {1, 4323, 1963, - WEBRTC_SPL_WORD16_MAX, WEBRTC_SPL_WORD16_MIN + 5, -3333, -876, 8483, 142}; + const int16_t kVector16[kVector16Size] = { + 1, 4323, 1963, WEBRTC_SPL_WORD16_MAX, WEBRTC_SPL_WORD16_MIN + 5, -3333, + -876, 8483, 142}; int32_t vector32[kCrossCorrelationDimension] = {0}; WebRtcSpl_CrossCorrelation(vector32, vector16, kVector16, kSeqDimension, @@ -473,12 +494,12 @@ TEST_F(SplTest, CrossCorrelationTest) { // WebRtcSpl_CrossCorrelationC() and WebRtcSpl_CrossCorrelationNeon() // are not bit-exact. - const int32_t kExpected[kCrossCorrelationDimension] = - {-266947903, -15579555, -171282001}; + const int32_t kExpected[kCrossCorrelationDimension] = {-266947903, -15579555, + -171282001}; const int32_t* expected = kExpected; #if !defined(MIPS32_LE) - const int32_t kExpectedNeon[kCrossCorrelationDimension] = - {-266947901, -15579553, -171281999}; + const int32_t kExpectedNeon[kCrossCorrelationDimension] = { + -266947901, -15579553, -171281999}; if (WebRtcSpl_CrossCorrelation != WebRtcSpl_CrossCorrelationC) { expected = kExpectedNeon; } @@ -491,8 +512,9 @@ TEST_F(SplTest, CrossCorrelationTest) { TEST_F(SplTest, AutoCorrelationTest) { int scale = 0; int32_t vector32[kVector16Size]; - const int32_t expected[kVector16Size] = {302681398, 14223410, -121705063, - -85221647, -17104971, 61806945, 6644603, -669329, 43}; + const int32_t expected[kVector16Size] = {302681398, 14223410, -121705063, + -85221647, -17104971, 61806945, + 6644603, -669329, 43}; EXPECT_EQ(kVector16Size, WebRtcSpl_AutoCorrelation(vector16, kVector16Size, @@ -504,63 +526,60 @@ TEST_F(SplTest, AutoCorrelationTest) { } TEST_F(SplTest, SignalProcessingTest) { - const size_t kVectorSize = 4; - int A[] = {1, 2, 33, 100}; - const int16_t kHanning[4] = { 2399, 8192, 13985, 16384 }; - int16_t b16[kVectorSize]; + const size_t kVectorSize = 4; + int A[] = {1, 2, 33, 100}; + const int16_t kHanning[4] = {2399, 8192, 13985, 16384}; + int16_t b16[kVectorSize]; - int16_t bTmp16[kVectorSize]; + int16_t bTmp16[kVectorSize]; - int bScale = 0; + int bScale = 0; - for (size_t kk = 0; kk < kVectorSize; ++kk) { - b16[kk] = A[kk]; - } + for (size_t kk = 0; kk < kVectorSize; ++kk) { + b16[kk] = A[kk]; + } - // TODO(bjornv): Activate the Reflection Coefficient tests when refactoring. -// WebRtcSpl_ReflCoefToLpc(b16, kVectorSize, bTmp16); -//// for (int kk = 0; kk < kVectorSize; ++kk) { -//// EXPECT_EQ(aTmp16[kk], bTmp16[kk]); -//// } -// WebRtcSpl_LpcToReflCoef(bTmp16, kVectorSize, b16); -//// for (int kk = 0; kk < kVectorSize; ++kk) { -//// EXPECT_EQ(a16[kk], b16[kk]); -//// } -// WebRtcSpl_AutoCorrToReflCoef(b32, kVectorSize, bTmp16); -//// for (int kk = 0; kk < kVectorSize; ++kk) { -//// EXPECT_EQ(aTmp16[kk], bTmp16[kk]); -//// } - - WebRtcSpl_GetHanningWindow(bTmp16, kVectorSize); - for (size_t kk = 0; kk < kVectorSize; ++kk) { - EXPECT_EQ(kHanning[kk], bTmp16[kk]); - } + // TODO(bjornv): Activate the Reflection Coefficient tests when refactoring. + // WebRtcSpl_ReflCoefToLpc(b16, kVectorSize, bTmp16); + //// for (int kk = 0; kk < kVectorSize; ++kk) { + //// EXPECT_EQ(aTmp16[kk], bTmp16[kk]); + //// } + // WebRtcSpl_LpcToReflCoef(bTmp16, kVectorSize, b16); + //// for (int kk = 0; kk < kVectorSize; ++kk) { + //// EXPECT_EQ(a16[kk], b16[kk]); + //// } + // WebRtcSpl_AutoCorrToReflCoef(b32, kVectorSize, bTmp16); + //// for (int kk = 0; kk < kVectorSize; ++kk) { + //// EXPECT_EQ(aTmp16[kk], bTmp16[kk]); + //// } + + WebRtcSpl_GetHanningWindow(bTmp16, kVectorSize); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + EXPECT_EQ(kHanning[kk], bTmp16[kk]); + } - for (size_t kk = 0; kk < kVectorSize; ++kk) { - b16[kk] = A[kk]; - } - EXPECT_EQ(11094 , WebRtcSpl_Energy(b16, kVectorSize, &bScale)); - EXPECT_EQ(0, bScale); + for (size_t kk = 0; kk < kVectorSize; ++kk) { + b16[kk] = A[kk]; + } + EXPECT_EQ(11094, WebRtcSpl_Energy(b16, kVectorSize, &bScale)); + EXPECT_EQ(0, bScale); } TEST_F(SplTest, FFTTest) { - int16_t B[] = {1, 2, 33, 100, - 2, 3, 34, 101, - 3, 4, 35, 102, - 4, 5, 36, 103}; - - EXPECT_EQ(0, WebRtcSpl_ComplexFFT(B, 3, 1)); -// for (int kk = 0; kk < 16; ++kk) { -// EXPECT_EQ(A[kk], B[kk]); -// } - EXPECT_EQ(0, WebRtcSpl_ComplexIFFT(B, 3, 1)); -// for (int kk = 0; kk < 16; ++kk) { -// EXPECT_EQ(A[kk], B[kk]); -// } - WebRtcSpl_ComplexBitReverse(B, 3); - for (int kk = 0; kk < 16; ++kk) { -// EXPECT_EQ(A[kk], B[kk]); - } + int16_t B[] = {1, 2, 33, 100, 2, 3, 34, 101, 3, 4, 35, 102, 4, 5, 36, 103}; + + EXPECT_EQ(0, WebRtcSpl_ComplexFFT(B, 3, 1)); + // for (int kk = 0; kk < 16; ++kk) { + // EXPECT_EQ(A[kk], B[kk]); + // } + EXPECT_EQ(0, WebRtcSpl_ComplexIFFT(B, 3, 1)); + // for (int kk = 0; kk < 16; ++kk) { + // EXPECT_EQ(A[kk], B[kk]); + // } + WebRtcSpl_ComplexBitReverse(B, 3); + for (int kk = 0; kk < 16; ++kk) { + // EXPECT_EQ(A[kk], B[kk]); + } } TEST_F(SplTest, Resample48WithSaturationTest) { @@ -570,14 +589,13 @@ TEST_F(SplTest, Resample48WithSaturationTest) { // Saturated input vector of 48 samples. const int32_t kVectorSaturated[3 * kBlockSize + 7] = { - -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, - -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, - -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, - 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, - 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, - 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, - 32767, 32767, 32767, 32767, 32767, 32767, 32767 - }; + -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, + -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, + -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768, + 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, + 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, + 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, + 32767, 32767, 32767, 32767, 32767, 32767, 32767}; // All values in |out_vector| should be |kRefValue32kHz|. const int32_t kRefValue32kHz1 = -1077493760; diff --git a/common_audio/sparse_fir_filter.cc b/common_audio/sparse_fir_filter.cc index ed2d79bbe1..0fc032722e 100644 --- a/common_audio/sparse_fir_filter.cc +++ b/common_audio/sparse_fir_filter.cc @@ -34,8 +34,8 @@ void SparseFIRFilter::Filter(const float* in, size_t length, float* out) { for (size_t i = 0; i < length; ++i) { out[i] = 0.f; size_t j; - for (j = 0; i >= j * sparsity_ + offset_ && - j < nonzero_coeffs_.size(); ++j) { + for (j = 0; i >= j * sparsity_ + offset_ && j < nonzero_coeffs_.size(); + ++j) { out[i] += in[i - j * sparsity_ - offset_] * nonzero_coeffs_[j]; } for (; j < nonzero_coeffs_.size(); ++j) { @@ -47,12 +47,10 @@ void SparseFIRFilter::Filter(const float* in, size_t length, float* out) { // Update current state. if (state_.size() > 0u) { if (length >= state_.size()) { - std::memcpy(&state_[0], - &in[length - state_.size()], + std::memcpy(&state_[0], &in[length - state_.size()], state_.size() * sizeof(*in)); } else { - std::memmove(&state_[0], - &state_[length], + std::memmove(&state_[0], &state_[length], (state_.size() - length) * sizeof(state_[0])); std::memcpy(&state_[state_.size() - length], in, length * sizeof(*in)); } diff --git a/common_audio/sparse_fir_filter_unittest.cc b/common_audio/sparse_fir_filter_unittest.cc index 434daaa6d9..b6cd6f9d9b 100644 --- a/common_audio/sparse_fir_filter_unittest.cc +++ b/common_audio/sparse_fir_filter_unittest.cc @@ -21,8 +21,8 @@ namespace webrtc { namespace { static const float kCoeffs[] = {0.2f, 0.3f, 0.5f, 0.7f, 0.11f}; -static const float kInput[] = - {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f}; +static const float kInput[] = {1.f, 2.f, 3.f, 4.f, 5.f, + 6.f, 7.f, 8.f, 9.f, 10.f}; template <size_t N> void VerifyOutput(const float (&expected_output)[N], const float (&output)[N]) { @@ -50,13 +50,9 @@ TEST(SparseFIRFilterTest, SameOutputForScalarCoefficientAndDifferentSparsity) { const size_t kOffset = 0; float low_sparsity_output[arraysize(kInput)]; float high_sparsity_output[arraysize(kInput)]; - SparseFIRFilter low_sparsity_filter(&kCoeff, - kNumCoeff, - kLowSparsity, + SparseFIRFilter low_sparsity_filter(&kCoeff, kNumCoeff, kLowSparsity, kOffset); - SparseFIRFilter high_sparsity_filter(&kCoeff, - kNumCoeff, - kHighSparsity, + SparseFIRFilter high_sparsity_filter(&kCoeff, kNumCoeff, kHighSparsity, kOffset); low_sparsity_filter.Filter(kInput, arraysize(kInput), low_sparsity_output); high_sparsity_filter.Filter(kInput, arraysize(kInput), high_sparsity_output); @@ -146,15 +142,10 @@ TEST(SparseFIRFilterTest, VerifySampleBasedVsBlockBasedFiltering) { const size_t kSparsity = 3; const size_t kOffset = 1; float output_block_based[arraysize(kInput)]; - SparseFIRFilter filter_block(kCoeffs, - arraysize(kCoeffs), - kSparsity, - kOffset); + SparseFIRFilter filter_block(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset); filter_block.Filter(kInput, arraysize(kInput), output_block_based); float output_sample_based[arraysize(kInput)]; - SparseFIRFilter filter_sample(kCoeffs, - arraysize(kCoeffs), - kSparsity, + SparseFIRFilter filter_sample(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset); for (size_t i = 0; i < arraysize(kInput); ++i) filter_sample.Filter(&kInput[i], 1, &output_sample_based[i]); @@ -165,8 +156,8 @@ TEST(SparseFIRFilterTest, SimpleHighPassFilter) { const size_t kSparsity = 2; const size_t kOffset = 2; const float kHPCoeffs[] = {1.f, -1.f}; - const float kConstantInput[] = - {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; + const float kConstantInput[] = {1.f, 1.f, 1.f, 1.f, 1.f, + 1.f, 1.f, 1.f, 1.f, 1.f}; float output[arraysize(kConstantInput)]; SparseFIRFilter filter(kHPCoeffs, arraysize(kHPCoeffs), kSparsity, kOffset); filter.Filter(kConstantInput, arraysize(kConstantInput), output); @@ -182,8 +173,8 @@ TEST(SparseFIRFilterTest, SimpleLowPassFilter) { const size_t kSparsity = 2; const size_t kOffset = 2; const float kLPCoeffs[] = {1.f, 1.f}; - const float kHighFrequencyInput[] = - {1.f, 1.f, -1.f, -1.f, 1.f, 1.f, -1.f, -1.f, 1.f, 1.f}; + const float kHighFrequencyInput[] = {1.f, 1.f, -1.f, -1.f, 1.f, + 1.f, -1.f, -1.f, 1.f, 1.f}; float output[arraysize(kHighFrequencyInput)]; SparseFIRFilter filter(kLPCoeffs, arraysize(kLPCoeffs), kSparsity, kOffset); filter.Filter(kHighFrequencyInput, arraysize(kHighFrequencyInput), output); @@ -203,9 +194,7 @@ TEST(SparseFIRFilterTest, SameOutputWhenSwappedCoefficientsAndInput) { SparseFIRFilter filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset); // Use arraysize(kCoeffs) for in_length to get same-length outputs. filter.Filter(kInput, arraysize(kCoeffs), output); - SparseFIRFilter filter_swapped(kInput, - arraysize(kCoeffs), - kSparsity, + SparseFIRFilter filter_swapped(kInput, arraysize(kCoeffs), kSparsity, kOffset); filter_swapped.Filter(kCoeffs, arraysize(kCoeffs), output_swapped); VerifyOutput(output, output_swapped); @@ -218,9 +207,7 @@ TEST(SparseFIRFilterTest, SameOutputAsFIRFilterWhenSparsityOneAndOffsetZero) { float sparse_output[arraysize(kInput)]; std::unique_ptr<FIRFilter> filter( CreateFirFilter(kCoeffs, arraysize(kCoeffs), arraysize(kInput))); - SparseFIRFilter sparse_filter(kCoeffs, - arraysize(kCoeffs), - kSparsity, + SparseFIRFilter sparse_filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset); filter->Filter(kInput, arraysize(kInput), output); sparse_filter.Filter(kInput, arraysize(kInput), sparse_output); diff --git a/common_audio/vad/include/webrtc_vad.h b/common_audio/vad/include/webrtc_vad.h index 353dbf0861..a6c539cf79 100644 --- a/common_audio/vad/include/webrtc_vad.h +++ b/common_audio/vad/include/webrtc_vad.h @@ -8,9 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* - * This header file includes the VAD API calls. Specific function calls are given below. + * This header file includes the VAD API calls. Specific function calls are + * given below. */ #ifndef COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT @@ -67,7 +67,9 @@ int WebRtcVad_set_mode(VadInst* handle, int mode); // returns : 1 - (Active Voice), // 0 - (Non-active Voice), // -1 - (Error) -int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame, +int WebRtcVad_Process(VadInst* handle, + int fs, + const int16_t* audio_frame, size_t frame_length); // Checks for valid combinations of |rate| and |frame_length|. We support 10, diff --git a/common_audio/vad/vad_core.h b/common_audio/vad/vad_core.h index 6541819f53..0eb8de3d1d 100644 --- a/common_audio/vad/vad_core.h +++ b/common_audio/vad/vad_core.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - /* * This header file includes the descriptions of the core VAD calls. */ @@ -19,37 +18,37 @@ #include "common_audio/signal_processing/include/signal_processing_library.h" #include "typedefs.h" // NOLINT(build/include) -enum { kNumChannels = 6 }; // Number of frequency bands (named channels). +enum { kNumChannels = 6 }; // Number of frequency bands (named channels). 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_ { - int vad; - int32_t downsampling_filter_states[4]; - WebRtcSpl_State48khzTo8khz state_48_to_8; - int16_t noise_means[kTableSize]; - int16_t speech_means[kTableSize]; - int16_t noise_stds[kTableSize]; - int16_t speech_stds[kTableSize]; - // TODO(bjornv): Change to |frame_count|. - int32_t frame_counter; - int16_t over_hang; // Over Hang - int16_t num_of_speech; - // TODO(bjornv): Change to |age_vector|. - int16_t index_vector[16 * kNumChannels]; - int16_t low_value_vector[16 * kNumChannels]; - // TODO(bjornv): Change to |median|. - int16_t mean_value[kNumChannels]; - int16_t upper_state[5]; - int16_t lower_state[5]; - int16_t hp_filter_state[4]; - int16_t over_hang_max_1[3]; - int16_t over_hang_max_2[3]; - int16_t individual[3]; - int16_t total[3]; + int vad; + int32_t downsampling_filter_states[4]; + WebRtcSpl_State48khzTo8khz state_48_to_8; + int16_t noise_means[kTableSize]; + int16_t speech_means[kTableSize]; + int16_t noise_stds[kTableSize]; + int16_t speech_stds[kTableSize]; + // TODO(bjornv): Change to |frame_count|. + int32_t frame_counter; + int16_t over_hang; // Over Hang + int16_t num_of_speech; + // TODO(bjornv): Change to |age_vector|. + int16_t index_vector[16 * kNumChannels]; + int16_t low_value_vector[16 * kNumChannels]; + // TODO(bjornv): Change to |median|. + int16_t mean_value[kNumChannels]; + int16_t upper_state[5]; + int16_t lower_state[5]; + int16_t hp_filter_state[4]; + int16_t over_hang_max_1[3]; + int16_t over_hang_max_2[3]; + int16_t individual[3]; + int16_t total[3]; - int init_flag; + int init_flag; } VadInstT; // Initializes the core VAD component. The default aggressiveness mode is @@ -100,13 +99,17 @@ int WebRtcVad_set_mode_core(VadInstT* self, int mode); * 0 - No active speech * 1-6 - Active speech */ -int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame, +int WebRtcVad_CalcVad48khz(VadInstT* inst, + const int16_t* speech_frame, size_t frame_length); -int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame, +int WebRtcVad_CalcVad32khz(VadInstT* inst, + const int16_t* speech_frame, size_t frame_length); -int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame, +int WebRtcVad_CalcVad16khz(VadInstT* inst, + const int16_t* speech_frame, size_t frame_length); -int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame, +int WebRtcVad_CalcVad8khz(VadInstT* inst, + const int16_t* speech_frame, size_t frame_length); #endif // COMMON_AUDIO_VAD_VAD_CORE_H_ diff --git a/common_audio/vad/vad_filterbank.h b/common_audio/vad/vad_filterbank.h index 620f96a699..60b785bed9 100644 --- a/common_audio/vad/vad_filterbank.h +++ b/common_audio/vad/vad_filterbank.h @@ -38,7 +38,9 @@ // - features [o] : 10 * log10(energy in each frequency band), Q4. // - returns : Total energy of the signal (NOTE! This value is not // exact. It is only used in a comparison.) -int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in, - size_t data_length, int16_t* features); +int16_t WebRtcVad_CalculateFeatures(VadInstT* self, + const int16_t* data_in, + size_t data_length, + int16_t* features); #endif // COMMON_AUDIO_VAD_VAD_FILTERBANK_H_ diff --git a/common_audio/vad/vad_filterbank_unittest.cc b/common_audio/vad/vad_filterbank_unittest.cc index 55b12793da..b80004424b 100644 --- a/common_audio/vad/vad_filterbank_unittest.cc +++ b/common_audio/vad/vad_filterbank_unittest.cc @@ -26,14 +26,12 @@ const int kNumValidFrameLengths = 3; TEST_F(VadTest, vad_filterbank) { VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT))); - static const int16_t kReference[kNumValidFrameLengths] = { 48, 11, 11 }; + static const int16_t kReference[kNumValidFrameLengths] = {48, 11, 11}; static const int16_t kFeatures[kNumValidFrameLengths * kNumChannels] = { - 1213, 759, 587, 462, 434, 272, - 1479, 1385, 1291, 1200, 1103, 1099, - 1732, 1692, 1681, 1629, 1436, 1436 - }; - static const int16_t kOffsetVector[kNumChannels] = { - 368, 368, 272, 176, 176, 176 }; + 1213, 759, 587, 462, 434, 272, 1479, 1385, 1291, + 1200, 1103, 1099, 1732, 1692, 1681, 1629, 1436, 1436}; + static const int16_t kOffsetVector[kNumChannels] = {368, 368, 272, + 176, 176, 176}; int16_t features[kNumChannels]; // Construct a speech signal that will trigger the VAD in all modes. It is diff --git a/common_audio/vad/vad_sp.h b/common_audio/vad/vad_sp.h index 21fed11b1a..8586ccd590 100644 --- a/common_audio/vad/vad_sp.h +++ b/common_audio/vad/vad_sp.h @@ -8,7 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ - // This file includes specific signal processing tools used in vad_core.c. #ifndef COMMON_AUDIO_VAD_VAD_SP_H_ diff --git a/common_audio/vad/vad_sp_unittest.cc b/common_audio/vad/vad_sp_unittest.cc index 7eb6794d21..ebe25cffce 100644 --- a/common_audio/vad/vad_sp_unittest.cc +++ b/common_audio/vad/vad_sp_unittest.cc @@ -25,19 +25,17 @@ namespace test { TEST_F(VadTest, vad_sp) { VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT))); const size_t kMaxFrameLenSp = 960; // Maximum frame length in this unittest. - int16_t zeros[kMaxFrameLenSp] = { 0 }; - int32_t state[2] = { 0 }; + int16_t zeros[kMaxFrameLenSp] = {0}; + int32_t state[2] = {0}; int16_t data_in[kMaxFrameLenSp]; int16_t data_out[kMaxFrameLenSp]; // We expect the first value to be 1600 as long as |frame_counter| is zero, // which is true for the first iteration. static const int16_t kReferenceMin[32] = { - 1600, 720, 509, 512, 532, 552, 570, 588, - 606, 624, 642, 659, 675, 691, 707, 723, - 1600, 544, 502, 522, 542, 561, 579, 597, - 615, 633, 651, 667, 683, 699, 715, 731 - }; + 1600, 720, 509, 512, 532, 552, 570, 588, 606, 624, 642, + 659, 675, 691, 707, 723, 1600, 544, 502, 522, 542, 561, + 579, 597, 615, 633, 651, 667, 683, 699, 715, 731}; // Construct a speech signal that will trigger the VAD in all modes. It is // known that (i * i) will wrap around, but that doesn't matter in this case. diff --git a/common_audio/vad/vad_unittest.cc b/common_audio/vad/vad_unittest.cc index f79678b8a0..1cef8e9949 100644 --- a/common_audio/vad/vad_unittest.cc +++ b/common_audio/vad/vad_unittest.cc @@ -60,7 +60,7 @@ TEST_F(VadTest, ApiTest) { // combinations. VadInst* handle = WebRtcVad_Create(); - int16_t zeros[kMaxFrameLength] = { 0 }; + int16_t zeros[kMaxFrameLength] = {0}; // Construct a speech signal that will trigger the VAD in all modes. It is // known that (i * i) will wrap around, but that doesn't matter in this case. @@ -87,12 +87,10 @@ TEST_F(VadTest, ApiTest) { // WebRtcVad_set_mode() invalid modes tests. Tries smallest supported value // minus one and largest supported value plus one. - EXPECT_EQ(-1, WebRtcVad_set_mode(handle, - WebRtcSpl_MinValueW32(kModes, - kModesSize) - 1)); - EXPECT_EQ(-1, WebRtcVad_set_mode(handle, - WebRtcSpl_MaxValueW32(kModes, - kModesSize) + 1)); + EXPECT_EQ(-1, WebRtcVad_set_mode( + handle, WebRtcSpl_MinValueW32(kModes, kModesSize) - 1)); + EXPECT_EQ(-1, WebRtcVad_set_mode( + handle, WebRtcSpl_MaxValueW32(kModes, kModesSize) + 1)); // WebRtcVad_Process() tests // nullptr as speech pointer @@ -109,14 +107,10 @@ TEST_F(VadTest, ApiTest) { for (size_t i = 0; i < kRatesSize; i++) { for (size_t j = 0; j < kFrameLengthsSize; j++) { if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) { - EXPECT_EQ(1, WebRtcVad_Process(handle, - kRates[i], - speech, + EXPECT_EQ(1, WebRtcVad_Process(handle, kRates[i], speech, kFrameLengths[j])); } else { - EXPECT_EQ(-1, WebRtcVad_Process(handle, - kRates[i], - speech, + EXPECT_EQ(-1, WebRtcVad_Process(handle, kRates[i], speech, kFrameLengths[j])); } } @@ -130,22 +124,20 @@ TEST_F(VadTest, ValidRatesFrameLengths) { // This test verifies valid and invalid rate/frame_length combinations. We // loop through some sampling rates and frame lengths from negative values to // values larger than possible. - const int kRates[] = { - -8000, -4000, 0, 4000, 8000, 8001, 15999, 16000, 32000, 48000, 48001, 96000 - }; + const int kRates[] = {-8000, -4000, 0, 4000, 8000, 8001, + 15999, 16000, 32000, 48000, 48001, 96000}; - const size_t kFrameLengths[] = { - 0, 80, 81, 159, 160, 240, 320, 480, 640, 960, 1440, 2000 - }; + const size_t kFrameLengths[] = {0, 80, 81, 159, 160, 240, + 320, 480, 640, 960, 1440, 2000}; for (size_t i = 0; i < arraysize(kRates); i++) { for (size_t j = 0; j < arraysize(kFrameLengths); j++) { if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) { - EXPECT_EQ(0, WebRtcVad_ValidRateAndFrameLength(kRates[i], - kFrameLengths[j])); + EXPECT_EQ( + 0, WebRtcVad_ValidRateAndFrameLength(kRates[i], kFrameLengths[j])); } else { - EXPECT_EQ(-1, WebRtcVad_ValidRateAndFrameLength(kRates[i], - kFrameLengths[j])); + EXPECT_EQ( + -1, WebRtcVad_ValidRateAndFrameLength(kRates[i], kFrameLengths[j])); } } } diff --git a/common_audio/vad/vad_unittest.h b/common_audio/vad/vad_unittest.h index f982f52eb5..ec4e8766cc 100644 --- a/common_audio/vad/vad_unittest.h +++ b/common_audio/vad/vad_unittest.h @@ -20,17 +20,17 @@ namespace webrtc { namespace test { // Modes we support -const int kModes[] = { 0, 1, 2, 3 }; +const int kModes[] = {0, 1, 2, 3}; const size_t kModesSize = sizeof(kModes) / sizeof(*kModes); // Rates we support. -const int kRates[] = { 8000, 12000, 16000, 24000, 32000, 48000 }; +const int kRates[] = {8000, 12000, 16000, 24000, 32000, 48000}; const size_t kRatesSize = sizeof(kRates) / sizeof(*kRates); // Frame lengths we support. const size_t kMaxFrameLength = 1440; -const size_t kFrameLengths[] = { 80, 120, 160, 240, 320, 480, 640, 960, - kMaxFrameLength }; +const size_t kFrameLengths[] = { + 80, 120, 160, 240, 320, 480, 640, 960, kMaxFrameLength}; const size_t kFrameLengthsSize = sizeof(kFrameLengths) / sizeof(*kFrameLengths); } // namespace test diff --git a/common_audio/wav_file.h b/common_audio/wav_file.h index 69c241aad6..cbce59d364 100644 --- a/common_audio/wav_file.h +++ b/common_audio/wav_file.h @@ -60,7 +60,7 @@ class WavWriter final : public WavFile { const int sample_rate_; const size_t num_channels_; size_t num_samples_; // Total number of samples written to file. - FILE* file_handle_; // Output file, owned by this class + FILE* file_handle_; // Output file, owned by this class RTC_DISALLOW_COPY_AND_ASSIGN(WavWriter); }; diff --git a/common_audio/wav_file_unittest.cc b/common_audio/wav_file_unittest.cc index 39e8968e93..d40229a1eb 100644 --- a/common_audio/wav_file_unittest.cc +++ b/common_audio/wav_file_unittest.cc @@ -56,6 +56,8 @@ TEST(WavWriterTest, MAYBE_CPP) { fclose(f); } static const uint8_t kExpectedContents[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 42, 0, 0, 0, // size of whole file - 8: 6 + 44 - 8 'W', 'A', 'V', 'E', @@ -73,6 +75,7 @@ TEST(WavWriterTest, MAYBE_CPP) { 10, 0, // second sample: 10.0 0xff, 0x7f, // third sample: 4e4 (saturated) kMetadata[0], kMetadata[1], + // clang-format on }; static const size_t kContentSize = kWavHeaderSize + kNumSamples * sizeof(int16_t) + sizeof(kMetadata); @@ -112,6 +115,8 @@ TEST(WavWriterTest, C) { EXPECT_EQ(kNumSamples, rtc_WavNumSamples(w)); rtc_WavClose(w); static const uint8_t kExpectedContents[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 44, 0, 0, 0, // size of whole file - 8: 8 + 44 - 8 'W', 'A', 'V', 'E', @@ -129,6 +134,7 @@ TEST(WavWriterTest, C) { 10, 0, // second sample: 10.0 0xff, 0x7f, // third sample: 4e4 (saturated) 0, 0x80, // fourth sample: -1e9 (saturated) + // clang-format on }; static const size_t kContentSize = kWavHeaderSize + kNumSamples * sizeof(int16_t); @@ -209,6 +215,7 @@ TEST(WavWriterTest, MAYBE_CPPFileDescriptor) { } static const uint8_t kExpectedContents[] = { // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 42, 0, 0, 0, // size of whole file - 8: 6 + 44 - 8 'W', 'A', 'V', 'E', diff --git a/common_audio/wav_header.cc b/common_audio/wav_header.cc index a57e917249..d093fa011c 100644 --- a/common_audio/wav_header.cc +++ b/common_audio/wav_header.cc @@ -112,17 +112,23 @@ bool CheckWavParameters(size_t num_channels, } #ifdef WEBRTC_ARCH_LITTLE_ENDIAN -static inline void WriteLE16(uint16_t* f, uint16_t x) { *f = x; } -static inline void WriteLE32(uint32_t* f, uint32_t x) { *f = x; } +static inline void WriteLE16(uint16_t* f, uint16_t x) { + *f = x; +} +static inline void WriteLE32(uint32_t* f, uint32_t x) { + *f = x; +} static inline void WriteFourCC(uint32_t* f, char a, char b, char c, char d) { - *f = static_cast<uint32_t>(a) - | static_cast<uint32_t>(b) << 8 - | static_cast<uint32_t>(c) << 16 - | static_cast<uint32_t>(d) << 24; + *f = static_cast<uint32_t>(a) | static_cast<uint32_t>(b) << 8 | + static_cast<uint32_t>(c) << 16 | static_cast<uint32_t>(d) << 24; } -static inline uint16_t ReadLE16(uint16_t x) { return x; } -static inline uint32_t ReadLE32(uint32_t x) { return x; } +static inline uint16_t ReadLE16(uint16_t x) { + return x; +} +static inline uint32_t ReadLE32(uint32_t x) { + return x; +} static inline std::string ReadFourCC(uint32_t x) { return std::string(reinterpret_cast<char*>(&x), 4); } @@ -131,11 +137,12 @@ static inline std::string ReadFourCC(uint32_t x) { #endif static inline uint32_t RiffChunkSize(size_t bytes_in_payload) { - return static_cast<uint32_t>( - bytes_in_payload + kWavHeaderSize - sizeof(ChunkHeader)); + return static_cast<uint32_t>(bytes_in_payload + kWavHeaderSize - + sizeof(ChunkHeader)); } -static inline uint32_t ByteRate(size_t num_channels, int sample_rate, +static inline uint32_t ByteRate(size_t num_channels, + int sample_rate, size_t bytes_per_sample) { return static_cast<uint32_t>(num_channels * sample_rate * bytes_per_sample); } @@ -166,8 +173,8 @@ void WriteWavHeader(uint8_t* buf, WriteLE16(&header.fmt.AudioFormat, format); WriteLE16(&header.fmt.NumChannels, static_cast<uint16_t>(num_channels)); WriteLE32(&header.fmt.SampleRate, sample_rate); - WriteLE32(&header.fmt.ByteRate, ByteRate(num_channels, sample_rate, - bytes_per_sample)); + WriteLE32(&header.fmt.ByteRate, + ByteRate(num_channels, sample_rate, bytes_per_sample)); WriteLE16(&header.fmt.BlockAlign, BlockAlign(num_channels, bytes_per_sample)); WriteLE16(&header.fmt.BitsPerSample, static_cast<uint16_t>(8 * bytes_per_sample)); @@ -239,5 +246,4 @@ bool ReadWavHeader(ReadableWav* readable, *bytes_per_sample, *num_samples); } - } // namespace webrtc diff --git a/common_audio/wav_header.h b/common_audio/wav_header.h index 2295fbe6ad..872d3abce5 100644 --- a/common_audio/wav_header.h +++ b/common_audio/wav_header.h @@ -26,8 +26,8 @@ class ReadableWav { }; enum WavFormat { - kWavFormatPcm = 1, // PCM, each sample of size bytes_per_sample - kWavFormatALaw = 6, // 8-bit ITU-T G.711 A-law + kWavFormatPcm = 1, // PCM, each sample of size bytes_per_sample + kWavFormatALaw = 6, // 8-bit ITU-T G.711 A-law kWavFormatMuLaw = 7, // 8-bit ITU-T G.711 mu-law }; diff --git a/common_audio/wav_header_unittest.cc b/common_audio/wav_header_unittest.cc index 8b30530ad9..101f3ff389 100644 --- a/common_audio/wav_header_unittest.cc +++ b/common_audio/wav_header_unittest.cc @@ -84,8 +84,8 @@ TEST(WavHeaderTest, CheckWavParameters) { // Too large values. EXPECT_FALSE(CheckWavParameters(1 << 20, 1 << 20, kWavFormatPcm, 1, 0)); - EXPECT_FALSE(CheckWavParameters( - 1, 8000, kWavFormatPcm, 1, std::numeric_limits<uint32_t>::max())); + EXPECT_FALSE(CheckWavParameters(1, 8000, kWavFormatPcm, 1, + std::numeric_limits<uint32_t>::max())); // Not the same number of samples for each channel. EXPECT_FALSE(CheckWavParameters(3, 8000, kWavFormatPcm, 1, 5)); @@ -104,6 +104,8 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { // *BAD*. { static const uint8_t kBadRiffID[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'i', 'f', 'f', // *BAD* 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -117,14 +119,16 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 8, 0, // bits per sample: 1 * 8 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; ReadableWavBuffer r(kBadRiffID, sizeof(kBadRiffID)); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kBadBitsPerSample[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -138,14 +142,16 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 1, 0, // bits per sample: *BAD* 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; ReadableWavBuffer r(kBadBitsPerSample, sizeof(kBadBitsPerSample)); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kBadByteRate[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -159,14 +165,16 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 8, 0, // bits per sample: 1 * 8 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; ReadableWavBuffer r(kBadByteRate, sizeof(kBadByteRate)); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kBadFmtHeaderSize[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -181,14 +189,16 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 0, // extra (though invalid) header byte 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; ReadableWavBuffer r(kBadFmtHeaderSize, sizeof(kBadFmtHeaderSize), false); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kNonZeroExtensionField[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -203,15 +213,17 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 1, 0, // non-zero extension field *BAD* 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; ReadableWavBuffer r(kNonZeroExtensionField, sizeof(kNonZeroExtensionField), false); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kMissingDataChunk[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', @@ -223,23 +235,25 @@ TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 0xc9, 0x33, 0x03, 0, // byte rate: 1 * 17 * 12345 17, 0, // block align: NumChannels * BytesPerSample 8, 0, // bits per sample: 1 * 8 + // clang-format on }; ReadableWavBuffer r(kMissingDataChunk, sizeof(kMissingDataChunk)); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } { static const uint8_t kMissingFmtAndDataChunks[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 'W', 'A', 'V', 'E', + // clang-format on }; ReadableWavBuffer r(kMissingFmtAndDataChunks, sizeof(kMissingFmtAndDataChunks)); - EXPECT_FALSE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_FALSE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); } } @@ -250,6 +264,8 @@ TEST(WavHeaderTest, WriteAndReadWavHeader) { memset(buf, 0xa4, sizeof(buf)); WriteWavHeader(buf + 4, 17, 12345, kWavFormatALaw, 1, 123457689); static const uint8_t kExpectedBuf[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes before header 'R', 'I', 'F', 'F', 0xbd, 0xd0, 0x5b, 0x07, // size of whole file - 8: 123457689 + 44 - 8 @@ -265,6 +281,7 @@ TEST(WavHeaderTest, WriteAndReadWavHeader) { 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes after header + // clang-format on }; static_assert(sizeof(kExpectedBuf) == kSize, "buffer size"); EXPECT_EQ(0, memcmp(kExpectedBuf, buf, kSize)); @@ -275,9 +292,8 @@ TEST(WavHeaderTest, WriteAndReadWavHeader) { size_t bytes_per_sample = 0; size_t num_samples = 0; ReadableWavBuffer r(buf + 4, sizeof(buf) - 8); - EXPECT_TRUE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_TRUE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); EXPECT_EQ(17u, num_channels); EXPECT_EQ(12345, sample_rate); EXPECT_EQ(kWavFormatALaw, format); @@ -288,6 +304,8 @@ TEST(WavHeaderTest, WriteAndReadWavHeader) { // Try reading an atypical but valid WAV header and make sure it's parsed OK. TEST(WavHeaderTest, ReadAtypicalWavHeader) { static const uint8_t kBuf[] = { + // clang-format off + // clang formatting doesn't respect inline comments. 'R', 'I', 'F', 'F', 0x3d, 0xd1, 0x5b, 0x07, // size of whole file - 8 + an extra 128 bytes of // "metadata": 123457689 + 44 - 8 + 128. (atypical) @@ -303,6 +321,7 @@ TEST(WavHeaderTest, ReadAtypicalWavHeader) { 0, 0, // zero extension size field (atypical) 'd', 'a', 't', 'a', 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 + // clang-format on }; size_t num_channels = 0; @@ -311,9 +330,8 @@ TEST(WavHeaderTest, ReadAtypicalWavHeader) { size_t bytes_per_sample = 0; size_t num_samples = 0; ReadableWavBuffer r(kBuf, sizeof(kBuf)); - EXPECT_TRUE( - ReadWavHeader(&r, &num_channels, &sample_rate, &format, - &bytes_per_sample, &num_samples)); + EXPECT_TRUE(ReadWavHeader(&r, &num_channels, &sample_rate, &format, + &bytes_per_sample, &num_samples)); EXPECT_EQ(17u, num_channels); EXPECT_EQ(12345, sample_rate); EXPECT_EQ(kWavFormatALaw, format); diff --git a/common_audio/window_generator.cc b/common_audio/window_generator.cc index 823d2b7387..da5603d9e7 100644 --- a/common_audio/window_generator.cc +++ b/common_audio/window_generator.cc @@ -25,12 +25,11 @@ namespace { complex<float> I0(complex<float> x) { complex<float> y = x / 3.75f; y *= y; - return 1.0f + y * ( - 3.5156229f + y * ( - 3.0899424f + y * ( - 1.2067492f + y * ( - 0.2659732f + y * ( - 0.360768e-1f + y * 0.45813e-2f))))); + return 1.0f + y * (3.5156229f + + y * (3.0899424f + + y * (1.2067492f + + y * (0.2659732f + + y * (0.360768e-1f + y * 0.45813e-2f))))); } } // namespace @@ -41,12 +40,13 @@ void WindowGenerator::Hanning(int length, float* window) { RTC_CHECK_GT(length, 1); RTC_CHECK(window != nullptr); for (int i = 0; i < length; ++i) { - window[i] = 0.5f * (1 - cosf(2 * static_cast<float>(M_PI) * i / - (length - 1))); + window[i] = + 0.5f * (1 - cosf(2 * static_cast<float>(M_PI) * i / (length - 1))); } } -void WindowGenerator::KaiserBesselDerived(float alpha, size_t length, +void WindowGenerator::KaiserBesselDerived(float alpha, + size_t length, float* window) { RTC_CHECK_GT(length, 1U); RTC_CHECK(window != nullptr); @@ -69,4 +69,3 @@ void WindowGenerator::KaiserBesselDerived(float alpha, size_t length, } } // namespace webrtc - diff --git a/common_audio/window_generator.h b/common_audio/window_generator.h index 5fc738eaf0..ad3b4456b9 100644 --- a/common_audio/window_generator.h +++ b/common_audio/window_generator.h @@ -30,4 +30,3 @@ class WindowGenerator { } // namespace webrtc #endif // COMMON_AUDIO_WINDOW_GENERATOR_H_ - diff --git a/common_audio/window_generator_unittest.cc b/common_audio/window_generator_unittest.cc index b2089d471a..cf339327c6 100644 --- a/common_audio/window_generator_unittest.cc +++ b/common_audio/window_generator_unittest.cc @@ -89,4 +89,3 @@ TEST(WindowGeneratorTest, Hanning) { } } // namespace webrtc - |