Reland of Enable cpplint and fix cpplint errors in webrtc/*audio (patchset #1 id:1 of https://codereview.webrtc.org/2739143002/ )
Reason for revert:
Can reland it if backwards compatible API is kept.
Original issue's description:
> Revert of Enable cpplint and fix cpplint errors in webrtc/*audio (patchset #4 id:180001 of https://codereview.webrtc.org/2683033004/ )
>
> Reason for revert:
> The API change in audio/utility/audio_frame_operations.h caused breakage. Need to keep backward-compatible API.
>
> Original issue's description:
> > Enable cpplint and fix cpplint errors in webrtc/*audio
> >
> > Change usage accordingly throughout the codebase
> >
> > BUG=webrtc:5268
> >
> > TESTED=Fixed issues reported by:
> > find webrtc/*audio -type f -name *.cc -o -name *.h | xargs cpplint.py
> >
> > Review-Url: https://codereview.webrtc.org/2683033004
> > Cr-Commit-Position: refs/heads/master@{#17133}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/aebe55ca6c2f725c81031722badb297a2fb1d331
>
> TBR=henrika@webrtc.org,henrik.lundin@webrtc.org,kwiberg@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5268
>
> Review-Url: https://codereview.webrtc.org/2739143002
> Cr-Commit-Position: refs/heads/master@{#17138}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e47c1d3ca172e5ea84e59c1e88dbe25664664e54
TBR=henrika@webrtc.org,henrik.lundin@webrtc.org,kwiberg@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
BUG=webrtc:5268
Review-Url: https://codereview.webrtc.org/2739073003
Cr-Commit-Position: refs/heads/master@{#17144}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index f7500e8..72e4326 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -18,6 +18,7 @@
'webrtc/api',
'webrtc/audio',
'webrtc/call',
+ 'webrtc/common_audio',
'webrtc/common_video',
'webrtc/examples',
'webrtc/modules/audio_mixer',
diff --git a/webrtc/audio/audio_transport_proxy.cc b/webrtc/audio/audio_transport_proxy.cc
index c201d8a..4d2f9e3 100644
--- a/webrtc/audio/audio_transport_proxy.cc
+++ b/webrtc/audio/audio_transport_proxy.cc
@@ -52,7 +52,7 @@
const int32_t clockDrift,
const uint32_t currentMicLevel,
const bool keyPressed,
- uint32_t& newMicLevel) {
+ uint32_t& newMicLevel) { // NOLINT: to avoid changing APIs
// Pass call through to original audio transport instance.
return voe_audio_transport_->RecordedDataIsAvailable(
audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec,
diff --git a/webrtc/audio/utility/audio_frame_operations.cc b/webrtc/audio/utility/audio_frame_operations.cc
index 475539f..0338b46 100644
--- a/webrtc/audio/utility/audio_frame_operations.cc
+++ b/webrtc/audio/utility/audio_frame_operations.cc
@@ -280,32 +280,32 @@
}
}
-int AudioFrameOperations::Scale(float left, float right, AudioFrame& frame) {
- if (frame.num_channels_ != 2) {
+int AudioFrameOperations::Scale(float left, float right, AudioFrame* frame) {
+ if (frame->num_channels_ != 2) {
return -1;
}
- for (size_t i = 0; i < frame.samples_per_channel_; i++) {
- frame.data_[2 * i] = static_cast<int16_t>(left * frame.data_[2 * i]);
- frame.data_[2 * i + 1] =
- static_cast<int16_t>(right * frame.data_[2 * i + 1]);
+ for (size_t i = 0; i < frame->samples_per_channel_; i++) {
+ frame->data_[2 * i] = static_cast<int16_t>(left * frame->data_[2 * i]);
+ frame->data_[2 * i + 1] =
+ static_cast<int16_t>(right * frame->data_[2 * i + 1]);
}
return 0;
}
-int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame& frame) {
+int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame* frame) {
int32_t temp_data = 0;
// Ensure that the output result is saturated [-32768, +32767].
- for (size_t i = 0; i < frame.samples_per_channel_ * frame.num_channels_;
+ for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_;
i++) {
- temp_data = static_cast<int32_t>(scale * frame.data_[i]);
+ temp_data = static_cast<int32_t>(scale * frame->data_[i]);
if (temp_data < -32768) {
- frame.data_[i] = -32768;
+ frame->data_[i] = -32768;
} else if (temp_data > 32767) {
- frame.data_[i] = 32767;
+ frame->data_[i] = 32767;
} else {
- frame.data_[i] = static_cast<int16_t>(temp_data);
+ frame->data_[i] = static_cast<int16_t>(temp_data);
}
}
return 0;
diff --git a/webrtc/audio/utility/audio_frame_operations.h b/webrtc/audio/utility/audio_frame_operations.h
index de6fdc4..56f318f 100644
--- a/webrtc/audio/utility/audio_frame_operations.h
+++ b/webrtc/audio/utility/audio_frame_operations.h
@@ -113,9 +113,19 @@
// Halve samples in |frame|.
static void ApplyHalfGain(AudioFrame* frame);
- static int Scale(float left, float right, AudioFrame& frame);
+ static int Scale(float left, float right, AudioFrame* frame);
- static int ScaleWithSat(float scale, AudioFrame& frame);
+ static int Scale(float left, float right, AudioFrame& frame) { // NOLINT
+ // TODO(oprypin): drop this method
+ return Scale(left, right, &frame);
+ }
+
+ static int ScaleWithSat(float scale, AudioFrame* frame);
+
+ static int ScaleWithSat(float scale, AudioFrame& frame) { // NOLINT
+ // TODO(oprypin): drop this method
+ return ScaleWithSat(scale, &frame);
+ }
};
} // namespace webrtc
diff --git a/webrtc/audio/utility/audio_frame_operations_unittest.cc b/webrtc/audio/utility/audio_frame_operations_unittest.cc
index af8ae24..096ea38 100644
--- a/webrtc/audio/utility/audio_frame_operations_unittest.cc
+++ b/webrtc/audio/utility/audio_frame_operations_unittest.cc
@@ -426,20 +426,20 @@
// TODO(andrew): should not allow negative scales.
TEST_F(AudioFrameOperationsTest, DISABLED_ScaleFailsWithBadParameters) {
frame_.num_channels_ = 1;
- EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, frame_));
+ EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, &frame_));
frame_.num_channels_ = 3;
- EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, frame_));
+ EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, 1.0, &frame_));
frame_.num_channels_ = 2;
- EXPECT_EQ(-1, AudioFrameOperations::Scale(-1.0, 1.0, frame_));
- EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, -1.0, frame_));
+ EXPECT_EQ(-1, AudioFrameOperations::Scale(-1.0, 1.0, &frame_));
+ EXPECT_EQ(-1, AudioFrameOperations::Scale(1.0, -1.0, &frame_));
}
// TODO(andrew): fix the wraparound bug. We should always saturate.
TEST_F(AudioFrameOperationsTest, DISABLED_ScaleDoesNotWrapAround) {
SetFrameData(4000, -4000, &frame_);
- EXPECT_EQ(0, AudioFrameOperations::Scale(10.0, 10.0, frame_));
+ EXPECT_EQ(0, AudioFrameOperations::Scale(10.0, 10.0, &frame_));
AudioFrame clipped_frame;
clipped_frame.samples_per_channel_ = 320;
@@ -450,7 +450,7 @@
TEST_F(AudioFrameOperationsTest, ScaleSucceeds) {
SetFrameData(1, -1, &frame_);
- EXPECT_EQ(0, AudioFrameOperations::Scale(2.0, 3.0, frame_));
+ EXPECT_EQ(0, AudioFrameOperations::Scale(2.0, 3.0, &frame_));
AudioFrame scaled_frame;
scaled_frame.samples_per_channel_ = 320;
@@ -461,13 +461,13 @@
// TODO(andrew): should fail with a negative scale.
TEST_F(AudioFrameOperationsTest, DISABLED_ScaleWithSatFailsWithBadParameters) {
- EXPECT_EQ(-1, AudioFrameOperations::ScaleWithSat(-1.0, frame_));
+ EXPECT_EQ(-1, AudioFrameOperations::ScaleWithSat(-1.0, &frame_));
}
TEST_F(AudioFrameOperationsTest, ScaleWithSatDoesNotWrapAround) {
frame_.num_channels_ = 1;
SetFrameData(4000, &frame_);
- EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, frame_));
+ EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, &frame_));
AudioFrame clipped_frame;
clipped_frame.samples_per_channel_ = 320;
@@ -476,7 +476,7 @@
VerifyFramesAreEqual(clipped_frame, frame_);
SetFrameData(-4000, &frame_);
- EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, frame_));
+ EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(10.0, &frame_));
SetFrameData(-32768, &clipped_frame);
VerifyFramesAreEqual(clipped_frame, frame_);
}
@@ -484,7 +484,7 @@
TEST_F(AudioFrameOperationsTest, ScaleWithSatSucceeds) {
frame_.num_channels_ = 1;
SetFrameData(1, &frame_);
- EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(2.0, frame_));
+ EXPECT_EQ(0, AudioFrameOperations::ScaleWithSat(2.0, &frame_));
AudioFrame scaled_frame;
scaled_frame.samples_per_channel_ = 320;
diff --git a/webrtc/common_audio/audio_converter.cc b/webrtc/common_audio/audio_converter.cc
index 231ba88..e859533 100644
--- a/webrtc/common_audio/audio_converter.cc
+++ b/webrtc/common_audio/audio_converter.cc
@@ -107,7 +107,8 @@
// converters must be provided.
class CompositionConverter : public AudioConverter {
public:
- CompositionConverter(std::vector<std::unique_ptr<AudioConverter>> converters)
+ explicit CompositionConverter(
+ 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.
diff --git a/webrtc/common_audio/audio_converter.h b/webrtc/common_audio/audio_converter.h
index 01dad4d..d3c65ac 100644
--- a/webrtc/common_audio/audio_converter.h
+++ b/webrtc/common_audio/audio_converter.h
@@ -31,7 +31,7 @@
size_t src_frames,
size_t dst_channels,
size_t dst_frames);
- virtual ~AudioConverter() {};
+ virtual ~AudioConverter() {}
// Convert |src|, containing |src_size| samples, to |dst|, having a sample
// capacity of |dst_capacity|. Both point to a series of buffers containing
diff --git a/webrtc/common_audio/blocker.h b/webrtc/common_audio/blocker.h
index d941c2a..3832471 100644
--- a/webrtc/common_audio/blocker.h
+++ b/webrtc/common_audio/blocker.h
@@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
-#define WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
+#ifndef WEBRTC_COMMON_AUDIO_BLOCKER_H_
+#define WEBRTC_COMMON_AUDIO_BLOCKER_H_
#include <memory>
@@ -124,4 +124,4 @@
} // namespace webrtc
-#endif // WEBRTC_INTERNAL_BEAMFORMER_BLOCKER_H_
+#endif // WEBRTC_COMMON_AUDIO_BLOCKER_H_
diff --git a/webrtc/common_audio/channel_buffer.h b/webrtc/common_audio/channel_buffer.h
index c4c85d1..930dd73 100644
--- a/webrtc/common_audio/channel_buffer.h
+++ b/webrtc/common_audio/channel_buffer.h
@@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_
-#define WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_
+#ifndef WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_
+#define WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_
#include <string.h>
@@ -183,4 +183,4 @@
} // namespace webrtc
-#endif // WEBRTC_MODULES_AUDIO_PROCESSING_CHANNEL_BUFFER_H_
+#endif // WEBRTC_COMMON_AUDIO_CHANNEL_BUFFER_H_
diff --git a/webrtc/common_audio/include/audio_util.h b/webrtc/common_audio/include/audio_util.h
index 1601c7f..9307c55 100644
--- a/webrtc/common_audio/include/audio_util.h
+++ b/webrtc/common_audio/include/audio_util.h
@@ -11,6 +11,7 @@
#ifndef WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
#define WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_
+#include <algorithm>
#include <limits>
#include <cstring>
diff --git a/webrtc/common_audio/lapped_transform.h b/webrtc/common_audio/lapped_transform.h
index 42a103a..fc03a9d 100644
--- a/webrtc/common_audio/lapped_transform.h
+++ b/webrtc/common_audio/lapped_transform.h
@@ -99,11 +99,11 @@
public:
explicit BlockThunk(LappedTransform* parent) : parent_(parent) {}
- void ProcessBlock(const float* const* input,
- size_t num_frames,
- size_t num_input_channels,
- size_t num_output_channels,
- float* const* output) override;
+ void ProcessBlock(const float* const* input,
+ size_t num_frames,
+ size_t num_input_channels,
+ size_t num_output_channels,
+ float* const* output) override;
private:
LappedTransform* const parent_;
diff --git a/webrtc/common_audio/real_fourier.h b/webrtc/common_audio/real_fourier.h
index 5e83e37..1b851e9 100644
--- a/webrtc/common_audio/real_fourier.h
+++ b/webrtc/common_audio/real_fourier.h
@@ -35,7 +35,7 @@
// Construct a wrapper instance for the given input order, which must be
// between 1 and kMaxFftOrder, inclusively.
static std::unique_ptr<RealFourier> Create(int fft_order);
- virtual ~RealFourier() {};
+ virtual ~RealFourier() {}
// Helper to compute the smallest FFT order (a power of 2) which will contain
// the given input length.
diff --git a/webrtc/common_audio/resampler/include/resampler.h b/webrtc/common_audio/resampler/include/resampler.h
index e26ac90..259349b 100644
--- a/webrtc/common_audio/resampler/include/resampler.h
+++ b/webrtc/common_audio/resampler/include/resampler.h
@@ -13,8 +13,8 @@
* A wrapper for resampling a numerous amount of sampling combinations.
*/
-#ifndef WEBRTC_RESAMPLER_RESAMPLER_H_
-#define WEBRTC_RESAMPLER_RESAMPLER_H_
+#ifndef WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
+#define WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
#include <stddef.h>
@@ -23,73 +23,70 @@
namespace webrtc {
// All methods return 0 on success and -1 on failure.
-class Resampler
-{
+class Resampler {
+ public:
+ Resampler();
+ Resampler(int inFreq, int outFreq, size_t num_channels);
+ ~Resampler();
-public:
- Resampler();
- Resampler(int inFreq, int outFreq, size_t num_channels);
- ~Resampler();
+ // Reset all states
+ int Reset(int inFreq, int outFreq, size_t num_channels);
- // Reset all states
- int Reset(int inFreq, int outFreq, size_t num_channels);
+ // Reset all states if any parameter has changed
+ int ResetIfNeeded(int inFreq, int outFreq, size_t num_channels);
- // Reset all states if any parameter has changed
- 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
- // Resample samplesIn to samplesOut.
- int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut,
- size_t maxLen, size_t &outLen);
+ private:
+ enum ResamplerMode {
+ kResamplerMode1To1,
+ kResamplerMode1To2,
+ kResamplerMode1To3,
+ kResamplerMode1To4,
+ kResamplerMode1To6,
+ kResamplerMode1To12,
+ kResamplerMode2To3,
+ kResamplerMode2To11,
+ kResamplerMode4To11,
+ kResamplerMode8To11,
+ kResamplerMode11To16,
+ kResamplerMode11To32,
+ kResamplerMode2To1,
+ kResamplerMode3To1,
+ kResamplerMode4To1,
+ kResamplerMode6To1,
+ kResamplerMode12To1,
+ kResamplerMode3To2,
+ kResamplerMode11To2,
+ kResamplerMode11To4,
+ kResamplerMode11To8
+ };
-private:
- enum ResamplerMode
- {
- kResamplerMode1To1,
- kResamplerMode1To2,
- kResamplerMode1To3,
- kResamplerMode1To4,
- kResamplerMode1To6,
- kResamplerMode1To12,
- kResamplerMode2To3,
- kResamplerMode2To11,
- kResamplerMode4To11,
- kResamplerMode8To11,
- kResamplerMode11To16,
- kResamplerMode11To32,
- kResamplerMode2To1,
- kResamplerMode3To1,
- kResamplerMode4To1,
- kResamplerMode6To1,
- kResamplerMode12To1,
- kResamplerMode3To2,
- kResamplerMode11To2,
- kResamplerMode11To4,
- kResamplerMode11To8
- };
+ // Generic pointers since we don't know what states we'll need
+ void* state1_;
+ void* state2_;
+ void* state3_;
- // Generic pointers since we don't know what states we'll need
- void* state1_;
- void* state2_;
- void* state3_;
+ // Storage if needed
+ int16_t* in_buffer_;
+ int16_t* out_buffer_;
+ size_t in_buffer_size_;
+ size_t out_buffer_size_;
+ size_t in_buffer_size_max_;
+ size_t out_buffer_size_max_;
- // Storage if needed
- int16_t* in_buffer_;
- int16_t* out_buffer_;
- size_t in_buffer_size_;
- size_t out_buffer_size_;
- size_t in_buffer_size_max_;
- size_t out_buffer_size_max_;
+ int my_in_frequency_khz_;
+ int my_out_frequency_khz_;
+ ResamplerMode my_mode_;
+ size_t num_channels_;
- int my_in_frequency_khz_;
- int my_out_frequency_khz_;
- ResamplerMode my_mode_;
- size_t num_channels_;
-
- // Extra instance for stereo
- Resampler* slave_left_;
- Resampler* slave_right_;
+ // Extra instance for stereo
+ Resampler* slave_left_;
+ Resampler* slave_right_;
};
} // namespace webrtc
-#endif // WEBRTC_RESAMPLER_RESAMPLER_H_
+#endif // WEBRTC_COMMON_AUDIO_RESAMPLER_INCLUDE_RESAMPLER_H_
diff --git a/webrtc/common_audio/resampler/push_resampler.cc b/webrtc/common_audio/resampler/push_resampler.cc
index 788223d..ec904b8 100644
--- a/webrtc/common_audio/resampler/push_resampler.cc
+++ b/webrtc/common_audio/resampler/push_resampler.cc
@@ -53,7 +53,7 @@
RTC_DCHECK_GE(dst_capacity, dst_size_10ms);
#endif
}
-}
+} // namespace
template <typename T>
PushResampler<T>::PushResampler()
diff --git a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc
index ab7f141..eab46ef 100644
--- a/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc
+++ b/webrtc/common_audio/resampler/push_sinc_resampler_unittest.cc
@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <algorithm>
#include <cmath>
#include <cstring>
#include <memory>
diff --git a/webrtc/common_audio/resampler/resampler.cc b/webrtc/common_audio/resampler/resampler.cc
index c91a5de..8efb16c 100644
--- a/webrtc/common_audio/resampler/resampler.cc
+++ b/webrtc/common_audio/resampler/resampler.cc
@@ -44,916 +44,860 @@
Reset(inFreq, outFreq, num_channels);
}
-Resampler::~Resampler()
-{
- if (state1_)
- {
- free(state1_);
- }
- if (state2_)
- {
- free(state2_);
- }
- if (state3_)
- {
- free(state3_);
- }
- if (in_buffer_)
- {
- free(in_buffer_);
- }
- if (out_buffer_)
- {
- free(out_buffer_);
- }
- if (slave_left_)
- {
- delete slave_left_;
- }
- if (slave_right_)
- {
- delete slave_right_;
- }
+Resampler::~Resampler() {
+ if (state1_) {
+ free(state1_);
+ }
+ if (state2_) {
+ free(state2_);
+ }
+ if (state3_) {
+ free(state3_);
+ }
+ if (in_buffer_) {
+ free(in_buffer_);
+ }
+ if (out_buffer_) {
+ free(out_buffer_);
+ }
+ if (slave_left_) {
+ delete slave_left_;
+ }
+ if (slave_right_) {
+ delete slave_right_;
+ }
}
-int Resampler::ResetIfNeeded(int inFreq, int outFreq, size_t num_channels)
-{
- int tmpInFreq_kHz = inFreq / 1000;
- int tmpOutFreq_kHz = outFreq / 1000;
+int Resampler::ResetIfNeeded(int inFreq, int outFreq, size_t num_channels) {
+ int tmpInFreq_kHz = inFreq / 1000;
+ int tmpOutFreq_kHz = outFreq / 1000;
- if ((tmpInFreq_kHz != my_in_frequency_khz_) || (tmpOutFreq_kHz != my_out_frequency_khz_)
- || (num_channels != num_channels_))
- {
- return Reset(inFreq, outFreq, num_channels);
- } else
- {
- return 0;
- }
+ if ((tmpInFreq_kHz != my_in_frequency_khz_)
+ || (tmpOutFreq_kHz != my_out_frequency_khz_)
+ || (num_channels != num_channels_)) {
+ return Reset(inFreq, outFreq, num_channels);
+ } else {
+ return 0;
+ }
}
-int Resampler::Reset(int inFreq, int outFreq, size_t num_channels)
-{
- if (num_channels != 1 && num_channels != 2) {
+int Resampler::Reset(int inFreq, int outFreq, size_t num_channels) {
+ if (num_channels != 1 && num_channels != 2) {
return -1;
- }
- num_channels_ = num_channels;
+ }
+ num_channels_ = num_channels;
- if (state1_)
- {
- free(state1_);
- state1_ = nullptr;
- }
- if (state2_)
- {
- free(state2_);
- state2_ = nullptr;
- }
- if (state3_)
- {
- free(state3_);
- state3_ = nullptr;
- }
- if (in_buffer_)
- {
- free(in_buffer_);
- in_buffer_ = nullptr;
- }
- if (out_buffer_)
- {
- free(out_buffer_);
- out_buffer_ = nullptr;
- }
- if (slave_left_)
- {
- delete slave_left_;
- slave_left_ = nullptr;
- }
- if (slave_right_)
- {
- delete slave_right_;
- slave_right_ = nullptr;
- }
+ if (state1_) {
+ free(state1_);
+ state1_ = nullptr;
+ }
+ if (state2_) {
+ free(state2_);
+ state2_ = nullptr;
+ }
+ if (state3_) {
+ free(state3_);
+ state3_ = nullptr;
+ }
+ if (in_buffer_) {
+ free(in_buffer_);
+ in_buffer_ = nullptr;
+ }
+ if (out_buffer_) {
+ free(out_buffer_);
+ out_buffer_ = nullptr;
+ }
+ if (slave_left_) {
+ delete slave_left_;
+ slave_left_ = nullptr;
+ }
+ if (slave_right_) {
+ delete slave_right_;
+ slave_right_ = nullptr;
+ }
- in_buffer_size_ = 0;
- out_buffer_size_ = 0;
- in_buffer_size_max_ = 0;
- out_buffer_size_max_ = 0;
+ in_buffer_size_ = 0;
+ out_buffer_size_ = 0;
+ in_buffer_size_max_ = 0;
+ out_buffer_size_max_ = 0;
- // Start with a math exercise, Euclid's algorithm to find the gcd:
- int a = inFreq;
- int b = outFreq;
- int c = a % b;
- while (c != 0)
- {
- a = b;
- b = c;
- c = a % b;
- }
- // b is now the gcd;
+ // Start with a math exercise, Euclid's algorithm to find the gcd:
+ int a = inFreq;
+ int b = outFreq;
+ int c = a % b;
+ while (c != 0) {
+ a = b;
+ b = c;
+ c = a % b;
+ }
+ // b is now the gcd;
- // We need to track what domain we're in.
- my_in_frequency_khz_ = inFreq / 1000;
- my_out_frequency_khz_ = outFreq / 1000;
+ // We need to track what domain we're in.
+ my_in_frequency_khz_ = inFreq / 1000;
+ my_out_frequency_khz_ = outFreq / 1000;
- // Scale with GCD
- inFreq = inFreq / b;
- outFreq = outFreq / b;
+ // Scale with GCD
+ inFreq = inFreq / b;
+ outFreq = outFreq / b;
- if (num_channels_ == 2)
- {
- // Create two mono resamplers.
- slave_left_ = new Resampler(inFreq, outFreq, 1);
- slave_right_ = new Resampler(inFreq, outFreq, 1);
- }
+ if (num_channels_ == 2) {
+ // Create two mono resamplers.
+ slave_left_ = new Resampler(inFreq, outFreq, 1);
+ slave_right_ = new Resampler(inFreq, outFreq, 1);
+ }
- if (inFreq == outFreq)
- {
- my_mode_ = kResamplerMode1To1;
- } else if (inFreq == 1)
- {
- switch (outFreq)
- {
- case 2:
- my_mode_ = kResamplerMode1To2;
- break;
- case 3:
- my_mode_ = kResamplerMode1To3;
- break;
- case 4:
- my_mode_ = kResamplerMode1To4;
- break;
- case 6:
- my_mode_ = kResamplerMode1To6;
- break;
- case 12:
- my_mode_ = kResamplerMode1To12;
- break;
- default:
- return -1;
- }
- } else if (outFreq == 1)
- {
- switch (inFreq)
- {
- case 2:
- my_mode_ = kResamplerMode2To1;
- break;
- case 3:
- my_mode_ = kResamplerMode3To1;
- break;
- case 4:
- my_mode_ = kResamplerMode4To1;
- break;
- case 6:
- my_mode_ = kResamplerMode6To1;
- break;
- case 12:
- my_mode_ = kResamplerMode12To1;
- break;
- default:
- return -1;
- }
- } else if ((inFreq == 2) && (outFreq == 3))
- {
- my_mode_ = kResamplerMode2To3;
- } else if ((inFreq == 2) && (outFreq == 11))
- {
- my_mode_ = kResamplerMode2To11;
- } else if ((inFreq == 4) && (outFreq == 11))
- {
- my_mode_ = kResamplerMode4To11;
- } else if ((inFreq == 8) && (outFreq == 11))
- {
- my_mode_ = kResamplerMode8To11;
- } else if ((inFreq == 3) && (outFreq == 2))
- {
- my_mode_ = kResamplerMode3To2;
- } else if ((inFreq == 11) && (outFreq == 2))
- {
- my_mode_ = kResamplerMode11To2;
- } else if ((inFreq == 11) && (outFreq == 4))
- {
- my_mode_ = kResamplerMode11To4;
- } else if ((inFreq == 11) && (outFreq == 16))
- {
- my_mode_ = kResamplerMode11To16;
- } else if ((inFreq == 11) && (outFreq == 32))
- {
- my_mode_ = kResamplerMode11To32;
- } else if ((inFreq == 11) && (outFreq == 8))
- {
- my_mode_ = kResamplerMode11To8;
- } else
- {
+ if (inFreq == outFreq) {
+ my_mode_ = kResamplerMode1To1;
+ } else if (inFreq == 1) {
+ switch (outFreq) {
+ case 2:
+ my_mode_ = kResamplerMode1To2;
+ break;
+ case 3:
+ my_mode_ = kResamplerMode1To3;
+ break;
+ case 4:
+ my_mode_ = kResamplerMode1To4;
+ break;
+ case 6:
+ my_mode_ = kResamplerMode1To6;
+ break;
+ case 12:
+ my_mode_ = kResamplerMode1To12;
+ break;
+ default:
return -1;
}
-
- // Now create the states we need
- switch (my_mode_)
- {
- case kResamplerMode1To1:
- // No state needed;
- break;
- case kResamplerMode1To2:
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode1To3:
- state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
- WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state1_);
- break;
- case kResamplerMode1To4:
- // 1:2
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- // 2:4
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode1To6:
- // 1:2
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- // 2:6
- state2_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
- WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state2_);
- break;
- case kResamplerMode1To12:
- // 1:2
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- // 2:4
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- // 4:12
- state3_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
- WebRtcSpl_ResetResample16khzTo48khz(
- (WebRtcSpl_State16khzTo48khz*) state3_);
- break;
- case kResamplerMode2To3:
- // 2:6
- state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
- WebRtcSpl_ResetResample16khzTo48khz((WebRtcSpl_State16khzTo48khz *)state1_);
- // 6:3
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode2To11:
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
-
- state2_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz));
- WebRtcSpl_ResetResample8khzTo22khz((WebRtcSpl_State8khzTo22khz *)state2_);
- break;
- case kResamplerMode4To11:
- state1_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz));
- WebRtcSpl_ResetResample8khzTo22khz((WebRtcSpl_State8khzTo22khz *)state1_);
- break;
- case kResamplerMode8To11:
- state1_ = malloc(sizeof(WebRtcSpl_State16khzTo22khz));
- WebRtcSpl_ResetResample16khzTo22khz((WebRtcSpl_State16khzTo22khz *)state1_);
- break;
- case kResamplerMode11To16:
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
-
- state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
- WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state2_);
- break;
- case kResamplerMode11To32:
- // 11 -> 22
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
-
- // 22 -> 16
- state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
- WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state2_);
-
- // 16 -> 32
- state3_ = malloc(8 * sizeof(int32_t));
- memset(state3_, 0, 8 * sizeof(int32_t));
-
- break;
- case kResamplerMode2To1:
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode3To1:
- state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
- WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state1_);
- break;
- case kResamplerMode4To1:
- // 4:2
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- // 2:1
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode6To1:
- // 6:2
- state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
- WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state1_);
- // 2:1
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode12To1:
- // 12:4
- state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
- WebRtcSpl_ResetResample48khzTo16khz(
- (WebRtcSpl_State48khzTo16khz*) state1_);
- // 4:2
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
- // 2:1
- state3_ = malloc(8 * sizeof(int32_t));
- memset(state3_, 0, 8 * sizeof(int32_t));
- break;
- case kResamplerMode3To2:
- // 3:6
- state1_ = malloc(8 * sizeof(int32_t));
- memset(state1_, 0, 8 * sizeof(int32_t));
- // 6:2
- state2_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
- WebRtcSpl_ResetResample48khzTo16khz((WebRtcSpl_State48khzTo16khz *)state2_);
- break;
- case kResamplerMode11To2:
- state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz));
- WebRtcSpl_ResetResample22khzTo8khz((WebRtcSpl_State22khzTo8khz *)state1_);
-
- state2_ = malloc(8 * sizeof(int32_t));
- memset(state2_, 0, 8 * sizeof(int32_t));
-
- break;
- case kResamplerMode11To4:
- state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz));
- WebRtcSpl_ResetResample22khzTo8khz((WebRtcSpl_State22khzTo8khz *)state1_);
- break;
- case kResamplerMode11To8:
- state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
- WebRtcSpl_ResetResample22khzTo16khz((WebRtcSpl_State22khzTo16khz *)state1_);
- break;
-
+ } else if (outFreq == 1) {
+ switch (inFreq) {
+ case 2:
+ my_mode_ = kResamplerMode2To1;
+ break;
+ case 3:
+ my_mode_ = kResamplerMode3To1;
+ break;
+ case 4:
+ my_mode_ = kResamplerMode4To1;
+ break;
+ case 6:
+ my_mode_ = kResamplerMode6To1;
+ break;
+ case 12:
+ my_mode_ = kResamplerMode12To1;
+ break;
+ default:
+ return -1;
}
+ } else if ((inFreq == 2) && (outFreq == 3)) {
+ my_mode_ = kResamplerMode2To3;
+ } else if ((inFreq == 2) && (outFreq == 11)) {
+ my_mode_ = kResamplerMode2To11;
+ } else if ((inFreq == 4) && (outFreq == 11)) {
+ my_mode_ = kResamplerMode4To11;
+ } else if ((inFreq == 8) && (outFreq == 11)) {
+ my_mode_ = kResamplerMode8To11;
+ } else if ((inFreq == 3) && (outFreq == 2)) {
+ my_mode_ = kResamplerMode3To2;
+ } else if ((inFreq == 11) && (outFreq == 2)) {
+ my_mode_ = kResamplerMode11To2;
+ } else if ((inFreq == 11) && (outFreq == 4)) {
+ my_mode_ = kResamplerMode11To4;
+ } else if ((inFreq == 11) && (outFreq == 16)) {
+ my_mode_ = kResamplerMode11To16;
+ } else if ((inFreq == 11) && (outFreq == 32)) {
+ my_mode_ = kResamplerMode11To32;
+ } else if ((inFreq == 11) && (outFreq == 8)) {
+ my_mode_ = kResamplerMode11To8;
+ } else {
+ return -1;
+ }
- return 0;
+ // Now create the states we need
+ switch (my_mode_) {
+ case kResamplerMode1To1:
+ // No state needed;
+ break;
+ case kResamplerMode1To2:
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode1To3:
+ state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
+ WebRtcSpl_ResetResample16khzTo48khz(
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state1_));
+ break;
+ case kResamplerMode1To4:
+ // 1:2
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ // 2:4
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode1To6:
+ // 1:2
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ // 2:6
+ state2_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
+ WebRtcSpl_ResetResample16khzTo48khz(
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state2_));
+ break;
+ case kResamplerMode1To12:
+ // 1:2
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ // 2:4
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ // 4:12
+ state3_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
+ WebRtcSpl_ResetResample16khzTo48khz(
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state3_));
+ break;
+ case kResamplerMode2To3:
+ // 2:6
+ state1_ = malloc(sizeof(WebRtcSpl_State16khzTo48khz));
+ WebRtcSpl_ResetResample16khzTo48khz(
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state1_));
+ // 6:3
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode2To11:
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+
+ state2_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz));
+ WebRtcSpl_ResetResample8khzTo22khz(
+ static_cast<WebRtcSpl_State8khzTo22khz*>(state2_));
+ break;
+ case kResamplerMode4To11:
+ state1_ = malloc(sizeof(WebRtcSpl_State8khzTo22khz));
+ WebRtcSpl_ResetResample8khzTo22khz(
+ static_cast<WebRtcSpl_State8khzTo22khz*>(state1_));
+ break;
+ case kResamplerMode8To11:
+ state1_ = malloc(sizeof(WebRtcSpl_State16khzTo22khz));
+ WebRtcSpl_ResetResample16khzTo22khz(
+ static_cast<WebRtcSpl_State16khzTo22khz*>(state1_));
+ break;
+ case kResamplerMode11To16:
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+
+ state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
+ WebRtcSpl_ResetResample22khzTo16khz(
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state2_));
+ break;
+ case kResamplerMode11To32:
+ // 11 -> 22
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+
+ // 22 -> 16
+ state2_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
+ WebRtcSpl_ResetResample22khzTo16khz(
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state2_));
+
+ // 16 -> 32
+ state3_ = malloc(8 * sizeof(int32_t));
+ memset(state3_, 0, 8 * sizeof(int32_t));
+
+ break;
+ case kResamplerMode2To1:
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode3To1:
+ state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
+ WebRtcSpl_ResetResample48khzTo16khz(
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_));
+ break;
+ case kResamplerMode4To1:
+ // 4:2
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ // 2:1
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode6To1:
+ // 6:2
+ state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
+ WebRtcSpl_ResetResample48khzTo16khz(
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_));
+ // 2:1
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode12To1:
+ // 12:4
+ state1_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
+ WebRtcSpl_ResetResample48khzTo16khz(
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_));
+ // 4:2
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+ // 2:1
+ state3_ = malloc(8 * sizeof(int32_t));
+ memset(state3_, 0, 8 * sizeof(int32_t));
+ break;
+ case kResamplerMode3To2:
+ // 3:6
+ state1_ = malloc(8 * sizeof(int32_t));
+ memset(state1_, 0, 8 * sizeof(int32_t));
+ // 6:2
+ state2_ = malloc(sizeof(WebRtcSpl_State48khzTo16khz));
+ WebRtcSpl_ResetResample48khzTo16khz(
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state2_));
+ break;
+ case kResamplerMode11To2:
+ state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz));
+ WebRtcSpl_ResetResample22khzTo8khz(
+ static_cast<WebRtcSpl_State22khzTo8khz*>(state1_));
+
+ state2_ = malloc(8 * sizeof(int32_t));
+ memset(state2_, 0, 8 * sizeof(int32_t));
+
+ break;
+ case kResamplerMode11To4:
+ state1_ = malloc(sizeof(WebRtcSpl_State22khzTo8khz));
+ WebRtcSpl_ResetResample22khzTo8khz(
+ static_cast<WebRtcSpl_State22khzTo8khz*>(state1_));
+ break;
+ case kResamplerMode11To8:
+ state1_ = malloc(sizeof(WebRtcSpl_State22khzTo16khz));
+ WebRtcSpl_ResetResample22khzTo16khz(
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state1_));
+ break;
+ }
+
+ return 0;
}
// Synchronous resampling, all output samples are written to samplesOut
int Resampler::Push(const int16_t * samplesIn, size_t lengthIn,
- int16_t* samplesOut, size_t maxLen, size_t &outLen)
-{
- if (num_channels_ == 2)
- {
- // Split up the signal and call the slave object for each channel
- int16_t* left = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2);
- int16_t* right = (int16_t*)malloc(lengthIn * sizeof(int16_t) / 2);
- int16_t* out_left = (int16_t*)malloc(maxLen / 2 * sizeof(int16_t));
- int16_t* out_right =
- (int16_t*)malloc(maxLen / 2 * sizeof(int16_t));
- int res = 0;
- for (size_t i = 0; i < lengthIn; i += 2)
- {
- left[i >> 1] = samplesIn[i];
- right[i >> 1] = samplesIn[i + 1];
- }
-
- // It's OK to overwrite the local parameter, since it's just a copy
- lengthIn = lengthIn / 2;
-
- size_t actualOutLen_left = 0;
- size_t actualOutLen_right = 0;
- // Do resampling for right channel
- res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2, actualOutLen_left);
- res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2, actualOutLen_right);
- if (res || (actualOutLen_left != actualOutLen_right))
- {
- free(left);
- free(right);
- free(out_left);
- free(out_right);
- return -1;
- }
-
- // Reassemble the signal
- for (size_t i = 0; i < actualOutLen_left; i++)
- {
- samplesOut[i * 2] = out_left[i];
- samplesOut[i * 2 + 1] = out_right[i];
- }
- outLen = 2 * actualOutLen_left;
-
- free(left);
- free(right);
- free(out_left);
- free(out_right);
-
- return 0;
+ int16_t* samplesOut, size_t maxLen, size_t& outLen) {
+ if (num_channels_ == 2) {
+ // Split up the signal and call the slave object for each channel
+ int16_t* left =
+ static_cast<int16_t*>(malloc(lengthIn * sizeof(int16_t) / 2));
+ int16_t* right =
+ static_cast<int16_t*>(malloc(lengthIn * sizeof(int16_t) / 2));
+ int16_t* out_left =
+ static_cast<int16_t*>(malloc(maxLen / 2 * sizeof(int16_t)));
+ int16_t* out_right =
+ static_cast<int16_t*>(malloc(maxLen / 2 * sizeof(int16_t)));
+ int res = 0;
+ for (size_t i = 0; i < lengthIn; i += 2) {
+ left[i >> 1] = samplesIn[i];
+ right[i >> 1] = samplesIn[i + 1];
}
- // Containers for temp samples
- int16_t* tmp;
- int16_t* tmp_2;
- // tmp data for resampling routines
- int32_t* tmp_mem;
+ // It's OK to overwrite the local parameter, since it's just a copy
+ lengthIn = lengthIn / 2;
- switch (my_mode_)
- {
- case kResamplerMode1To1:
- memcpy(samplesOut, samplesIn, lengthIn * sizeof(int16_t));
- outLen = lengthIn;
- break;
- case kResamplerMode1To2:
- if (maxLen < (lengthIn * 2))
- {
- return -1;
- }
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_);
- outLen = lengthIn * 2;
- return 0;
- case kResamplerMode1To3:
-
- // We can only handle blocks of 160 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 160) != 0)
- {
- return -1;
- }
- if (maxLen < (lengthIn * 3))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 160)
- {
- WebRtcSpl_Resample16khzTo48khz(samplesIn + i, samplesOut + i * 3,
- (WebRtcSpl_State16khzTo48khz *)state1_,
- tmp_mem);
- }
- outLen = lengthIn * 3;
- free(tmp_mem);
- return 0;
- case kResamplerMode1To4:
- if (maxLen < (lengthIn * 4))
- {
- return -1;
- }
-
- tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn);
- // 1:2
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
- // 2:4
- WebRtcSpl_UpsampleBy2(tmp, lengthIn * 2, samplesOut, (int32_t*)state2_);
- outLen = lengthIn * 4;
- free(tmp);
- return 0;
- case kResamplerMode1To6:
- // We can only handle blocks of 80 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 80) != 0)
- {
- return -1;
- }
- if (maxLen < (lengthIn * 6))
- {
- return -1;
- }
-
- //1:2
-
- tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t));
- tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn);
-
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
- outLen = lengthIn * 2;
-
- for (size_t i = 0; i < outLen; i += 160)
- {
- WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3,
- (WebRtcSpl_State16khzTo48khz *)state2_,
- tmp_mem);
- }
- outLen = outLen * 3;
- free(tmp_mem);
- free(tmp);
-
- return 0;
- case kResamplerMode1To12:
- // We can only handle blocks of 40 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 40) != 0) {
- return -1;
- }
- if (maxLen < (lengthIn * 12)) {
- return -1;
- }
-
- tmp_mem = (int32_t*) malloc(336 * sizeof(int32_t));
- tmp = (int16_t*) malloc(sizeof(int16_t) * 4 * lengthIn);
- //1:2
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut,
- (int32_t*) state1_);
- outLen = lengthIn * 2;
- //2:4
- WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, (int32_t*) state2_);
- outLen = outLen * 2;
- // 4:12
- for (size_t i = 0; i < outLen; i += 160) {
- // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples
- // as input and outputs a resampled block of 480 samples. The
- // data is now actually in 32 kHz sampling rate, despite the
- // function name, and with a resampling factor of three becomes
- // 96 kHz.
- WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3,
- (WebRtcSpl_State16khzTo48khz*) state3_,
- tmp_mem);
- }
- outLen = outLen * 3;
- free(tmp_mem);
- free(tmp);
-
- return 0;
- case kResamplerMode2To3:
- if (maxLen < (lengthIn * 3 / 2))
- {
- return -1;
- }
- // 2:6
- // We can only handle blocks of 160 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 160) != 0)
- {
- return -1;
- }
- tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 3));
- tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t));
- for (size_t i = 0; i < lengthIn; i += 160)
- {
- WebRtcSpl_Resample16khzTo48khz(samplesIn + i, tmp + i * 3,
- (WebRtcSpl_State16khzTo48khz *)state1_,
- tmp_mem);
- }
- lengthIn = lengthIn * 3;
- // 6:3
- WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut, (int32_t*)state2_);
- outLen = lengthIn / 2;
- free(tmp);
- free(tmp_mem);
- return 0;
- case kResamplerMode2To11:
-
- // We can only handle blocks of 80 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 80) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 11) / 2))
- {
- return -1;
- }
- tmp = (int16_t*)malloc(sizeof(int16_t) * 2 * lengthIn);
- // 1:2
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
- lengthIn *= 2;
-
- tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 80)
- {
- WebRtcSpl_Resample8khzTo22khz(tmp + i, samplesOut + (i * 11) / 4,
- (WebRtcSpl_State8khzTo22khz *)state2_,
- tmp_mem);
- }
- outLen = (lengthIn * 11) / 4;
- free(tmp_mem);
- free(tmp);
- return 0;
- case kResamplerMode4To11:
-
- // We can only handle blocks of 80 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 80) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 11) / 4))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 80)
- {
- WebRtcSpl_Resample8khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 4,
- (WebRtcSpl_State8khzTo22khz *)state1_,
- tmp_mem);
- }
- outLen = (lengthIn * 11) / 4;
- free(tmp_mem);
- return 0;
- case kResamplerMode8To11:
- // We can only handle blocks of 160 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 160) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 11) / 8))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(88 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 160)
- {
- WebRtcSpl_Resample16khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 8,
- (WebRtcSpl_State16khzTo22khz *)state1_,
- tmp_mem);
- }
- outLen = (lengthIn * 11) / 8;
- free(tmp_mem);
- return 0;
-
- case kResamplerMode11To16:
- // We can only handle blocks of 110 samples
- if ((lengthIn % 110) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 16) / 11))
- {
- return -1;
- }
-
- tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t));
- tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2));
-
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
-
- for (size_t i = 0; i < (lengthIn * 2); i += 220)
- {
- WebRtcSpl_Resample22khzTo16khz(tmp + i, samplesOut + (i / 220) * 160,
- (WebRtcSpl_State22khzTo16khz *)state2_,
- tmp_mem);
- }
-
- outLen = (lengthIn * 16) / 11;
-
- free(tmp_mem);
- free(tmp);
- return 0;
-
- case kResamplerMode11To32:
-
- // We can only handle blocks of 110 samples
- if ((lengthIn % 110) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 32) / 11))
- {
- return -1;
- }
-
- tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t));
- tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn * 2));
-
- // 11 -> 22 kHz in samplesOut
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_);
-
- // 22 -> 16 in tmp
- for (size_t i = 0; i < (lengthIn * 2); i += 220)
- {
- WebRtcSpl_Resample22khzTo16khz(samplesOut + i, tmp + (i / 220) * 160,
- (WebRtcSpl_State22khzTo16khz *)state2_,
- tmp_mem);
- }
-
- // 16 -> 32 in samplesOut
- WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut,
- (int32_t*)state3_);
-
- outLen = (lengthIn * 32) / 11;
-
- free(tmp_mem);
- free(tmp);
- return 0;
-
- case kResamplerMode2To1:
- if (maxLen < (lengthIn / 2))
- {
- return -1;
- }
- WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_);
- outLen = lengthIn / 2;
- return 0;
- case kResamplerMode3To1:
- // We can only handle blocks of 480 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 480) != 0)
- {
- return -1;
- }
- if (maxLen < (lengthIn / 3))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 480)
- {
- WebRtcSpl_Resample48khzTo16khz(samplesIn + i, samplesOut + i / 3,
- (WebRtcSpl_State48khzTo16khz *)state1_,
- tmp_mem);
- }
- outLen = lengthIn / 3;
- free(tmp_mem);
- return 0;
- case kResamplerMode4To1:
- if (maxLen < (lengthIn / 4))
- {
- return -1;
- }
- tmp = (int16_t*)malloc(sizeof(int16_t) * lengthIn / 2);
- // 4:2
- WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
- // 2:1
- WebRtcSpl_DownsampleBy2(tmp, lengthIn / 2, samplesOut, (int32_t*)state2_);
- outLen = lengthIn / 4;
- free(tmp);
- return 0;
-
- case kResamplerMode6To1:
- // We can only handle blocks of 480 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 480) != 0)
- {
- return -1;
- }
- if (maxLen < (lengthIn / 6))
- {
- return -1;
- }
-
- tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
- tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn) / 3);
-
- for (size_t i = 0; i < lengthIn; i += 480)
- {
- WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3,
- (WebRtcSpl_State48khzTo16khz *)state1_,
- tmp_mem);
- }
- outLen = lengthIn / 3;
- free(tmp_mem);
- WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut, (int32_t*)state2_);
- free(tmp);
- outLen = outLen / 2;
- return 0;
- case kResamplerMode12To1:
- // We can only handle blocks of 480 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 480) != 0) {
- return -1;
- }
- if (maxLen < (lengthIn / 12)) {
- return -1;
- }
-
- tmp_mem = (int32_t*) malloc(496 * sizeof(int32_t));
- tmp = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 3);
- tmp_2 = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 6);
- // 12:4
- for (size_t i = 0; i < lengthIn; i += 480) {
- // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples
- // as input and outputs a resampled block of 160 samples. The
- // data is now actually in 96 kHz sampling rate, despite the
- // function name, and with a resampling factor of 1/3 becomes
- // 32 kHz.
- WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3,
- (WebRtcSpl_State48khzTo16khz*) state1_,
- tmp_mem);
- }
- outLen = lengthIn / 3;
- free(tmp_mem);
- // 4:2
- WebRtcSpl_DownsampleBy2(tmp, outLen, tmp_2, (int32_t*) state2_);
- outLen = outLen / 2;
- free(tmp);
- // 2:1
- WebRtcSpl_DownsampleBy2(tmp_2, outLen, samplesOut,
- (int32_t*) state3_);
- free(tmp_2);
- outLen = outLen / 2;
- return 0;
- case kResamplerMode3To2:
- if (maxLen < (lengthIn * 2 / 3))
- {
- return -1;
- }
- // 3:6
- tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 2));
- WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
- lengthIn *= 2;
- // 6:2
- // We can only handle blocks of 480 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 480) != 0)
- {
- free(tmp);
- return -1;
- }
- tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
- for (size_t i = 0; i < lengthIn; i += 480)
- {
- WebRtcSpl_Resample48khzTo16khz(tmp + i, samplesOut + i / 3,
- (WebRtcSpl_State48khzTo16khz *)state2_,
- tmp_mem);
- }
- outLen = lengthIn / 3;
- free(tmp);
- free(tmp_mem);
- return 0;
- case kResamplerMode11To2:
- // We can only handle blocks of 220 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 220) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 2) / 11))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t));
- tmp = (int16_t*)malloc((lengthIn * 4) / 11 * sizeof(int16_t));
-
- for (size_t i = 0; i < lengthIn; i += 220)
- {
- WebRtcSpl_Resample22khzTo8khz(samplesIn + i, tmp + (i * 4) / 11,
- (WebRtcSpl_State22khzTo8khz *)state1_,
- tmp_mem);
- }
- lengthIn = (lengthIn * 4) / 11;
-
- WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut,
- (int32_t*)state2_);
- outLen = lengthIn / 2;
-
- free(tmp_mem);
- free(tmp);
- return 0;
- case kResamplerMode11To4:
- // We can only handle blocks of 220 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 220) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 4) / 11))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 220)
- {
- WebRtcSpl_Resample22khzTo8khz(samplesIn + i, samplesOut + (i * 4) / 11,
- (WebRtcSpl_State22khzTo8khz *)state1_,
- tmp_mem);
- }
- outLen = (lengthIn * 4) / 11;
- free(tmp_mem);
- return 0;
- case kResamplerMode11To8:
- // We can only handle blocks of 160 samples
- // Can be fixed, but I don't think it's needed
- if ((lengthIn % 220) != 0)
- {
- return -1;
- }
- if (maxLen < ((lengthIn * 8) / 11))
- {
- return -1;
- }
- tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t));
-
- for (size_t i = 0; i < lengthIn; i += 220)
- {
- WebRtcSpl_Resample22khzTo16khz(samplesIn + i, samplesOut + (i * 8) / 11,
- (WebRtcSpl_State22khzTo16khz *)state1_,
- tmp_mem);
- }
- outLen = (lengthIn * 8) / 11;
- free(tmp_mem);
- return 0;
- break;
-
+ size_t actualOutLen_left = 0;
+ size_t actualOutLen_right = 0;
+ // Do resampling for right channel
+ res |= slave_left_->Push(left, lengthIn, out_left, maxLen / 2,
+ actualOutLen_left);
+ res |= slave_right_->Push(right, lengthIn, out_right, maxLen / 2,
+ actualOutLen_right);
+ if (res || (actualOutLen_left != actualOutLen_right)) {
+ free(left);
+ free(right);
+ free(out_left);
+ free(out_right);
+ return -1;
}
+
+ // Reassemble the signal
+ for (size_t i = 0; i < actualOutLen_left; i++) {
+ samplesOut[i * 2] = out_left[i];
+ samplesOut[i * 2 + 1] = out_right[i];
+ }
+ outLen = 2 * actualOutLen_left;
+
+ free(left);
+ free(right);
+ free(out_left);
+ free(out_right);
+
return 0;
+ }
+
+ // Containers for temp samples
+ int16_t* tmp;
+ int16_t* tmp_2;
+ // tmp data for resampling routines
+ int32_t* tmp_mem;
+
+ switch (my_mode_) {
+ case kResamplerMode1To1:
+ memcpy(samplesOut, samplesIn, lengthIn * sizeof(int16_t));
+ outLen = lengthIn;
+ break;
+ case kResamplerMode1To2:
+ if (maxLen < (lengthIn * 2)) {
+ return -1;
+ }
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut,
+ static_cast<int32_t*>(state1_));
+ outLen = lengthIn * 2;
+ return 0;
+ case kResamplerMode1To3:
+
+ // We can only handle blocks of 160 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 160) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn * 3)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(336 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 160) {
+ WebRtcSpl_Resample16khzTo48khz(
+ samplesIn + i, samplesOut + i * 3,
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state1_), tmp_mem);
+ }
+ outLen = lengthIn * 3;
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode1To4:
+ if (maxLen < (lengthIn * 4)) {
+ return -1;
+ }
+
+ tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * 2 * lengthIn));
+ // 1:2
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+ // 2:4
+ WebRtcSpl_UpsampleBy2(tmp, lengthIn * 2, samplesOut,
+ static_cast<int32_t*>(state2_));
+ outLen = lengthIn * 4;
+ free(tmp);
+ return 0;
+ case kResamplerMode1To6:
+ // We can only handle blocks of 80 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 80) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn * 6)) {
+ return -1;
+ }
+
+ // 1:2
+
+ tmp_mem = static_cast<int32_t*>(malloc(336 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * 2 * lengthIn));
+
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+ outLen = lengthIn * 2;
+
+ for (size_t i = 0; i < outLen; i += 160) {
+ WebRtcSpl_Resample16khzTo48khz(
+ tmp + i, samplesOut + i * 3,
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state2_), tmp_mem);
+ }
+ outLen = outLen * 3;
+ free(tmp_mem);
+ free(tmp);
+
+ return 0;
+ case kResamplerMode1To12:
+ // We can only handle blocks of 40 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 40) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn * 12)) {
+ return -1;
+ }
+
+ tmp_mem = static_cast<int32_t*>(malloc(336 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * 4 * lengthIn));
+ // 1:2
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut,
+ static_cast<int32_t*>(state1_));
+ outLen = lengthIn * 2;
+ // 2:4
+ WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp,
+ static_cast<int32_t*>(state2_));
+ outLen = outLen * 2;
+ // 4:12
+ for (size_t i = 0; i < outLen; i += 160) {
+ // WebRtcSpl_Resample16khzTo48khz() takes a block of 160 samples
+ // as input and outputs a resampled block of 480 samples. The
+ // data is now actually in 32 kHz sampling rate, despite the
+ // function name, and with a resampling factor of three becomes
+ // 96 kHz.
+ WebRtcSpl_Resample16khzTo48khz(
+ tmp + i, samplesOut + i * 3,
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state3_), tmp_mem);
+ }
+ outLen = outLen * 3;
+ free(tmp_mem);
+ free(tmp);
+
+ return 0;
+ case kResamplerMode2To3:
+ if (maxLen < (lengthIn * 3 / 2)) {
+ return -1;
+ }
+ // 2:6
+ // We can only handle blocks of 160 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 160) != 0) {
+ return -1;
+ }
+ tmp = static_cast<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(
+ samplesIn + i, tmp + i * 3,
+ static_cast<WebRtcSpl_State16khzTo48khz*>(state1_), tmp_mem);
+ }
+ lengthIn = lengthIn * 3;
+ // 6:3
+ WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut,
+ static_cast<int32_t*>(state2_));
+ outLen = lengthIn / 2;
+ free(tmp);
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode2To11:
+
+ // We can only handle blocks of 80 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 80) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 11) / 2)) {
+ return -1;
+ }
+ tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * 2 * lengthIn));
+ // 1:2
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+ lengthIn *= 2;
+
+ tmp_mem = static_cast<int32_t*>(malloc(98 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 80) {
+ WebRtcSpl_Resample8khzTo22khz(
+ tmp + i, samplesOut + (i * 11) / 4,
+ static_cast<WebRtcSpl_State8khzTo22khz*>(state2_), tmp_mem);
+ }
+ outLen = (lengthIn * 11) / 4;
+ free(tmp_mem);
+ free(tmp);
+ return 0;
+ case kResamplerMode4To11:
+
+ // We can only handle blocks of 80 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 80) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 11) / 4)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(98 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 80) {
+ WebRtcSpl_Resample8khzTo22khz(
+ samplesIn + i, samplesOut + (i * 11) / 4,
+ static_cast<WebRtcSpl_State8khzTo22khz*>(state1_), tmp_mem);
+ }
+ outLen = (lengthIn * 11) / 4;
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode8To11:
+ // We can only handle blocks of 160 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 160) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 11) / 8)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(88 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 160) {
+ WebRtcSpl_Resample16khzTo22khz(
+ samplesIn + i, samplesOut + (i * 11) / 8,
+ static_cast<WebRtcSpl_State16khzTo22khz*>(state1_), tmp_mem);
+ }
+ outLen = (lengthIn * 11) / 8;
+ free(tmp_mem);
+ return 0;
+
+ case kResamplerMode11To16:
+ // We can only handle blocks of 110 samples
+ if ((lengthIn % 110) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 16) / 11)) {
+ return -1;
+ }
+
+ tmp_mem = static_cast<int32_t*>(malloc(104 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc((sizeof(int16_t) * lengthIn * 2)));
+
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+
+ for (size_t i = 0; i < (lengthIn * 2); i += 220) {
+ WebRtcSpl_Resample22khzTo16khz(
+ tmp + i, samplesOut + (i / 220) * 160,
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state2_), tmp_mem);
+ }
+
+ outLen = (lengthIn * 16) / 11;
+
+ free(tmp_mem);
+ free(tmp);
+ return 0;
+
+ case kResamplerMode11To32:
+
+ // We can only handle blocks of 110 samples
+ if ((lengthIn % 110) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 32) / 11)) {
+ return -1;
+ }
+
+ tmp_mem = static_cast<int32_t*>(malloc(104 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc((sizeof(int16_t) * lengthIn * 2)));
+
+ // 11 -> 22 kHz in samplesOut
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut,
+ static_cast<int32_t*>(state1_));
+
+ // 22 -> 16 in tmp
+ for (size_t i = 0; i < (lengthIn * 2); i += 220) {
+ WebRtcSpl_Resample22khzTo16khz(
+ samplesOut + i, tmp + (i / 220) * 160,
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state2_), tmp_mem);
+ }
+
+ // 16 -> 32 in samplesOut
+ WebRtcSpl_UpsampleBy2(tmp, (lengthIn * 16) / 11, samplesOut,
+ static_cast<int32_t*>(state3_));
+
+ outLen = (lengthIn * 32) / 11;
+
+ free(tmp_mem);
+ free(tmp);
+ return 0;
+
+ case kResamplerMode2To1:
+ if (maxLen < (lengthIn / 2)) {
+ return -1;
+ }
+ WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, samplesOut,
+ static_cast<int32_t*>(state1_));
+ outLen = lengthIn / 2;
+ return 0;
+ case kResamplerMode3To1:
+ // We can only handle blocks of 480 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 480) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn / 3)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(496 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 480) {
+ WebRtcSpl_Resample48khzTo16khz(
+ samplesIn + i, samplesOut + i / 3,
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_), tmp_mem);
+ }
+ outLen = lengthIn / 3;
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode4To1:
+ if (maxLen < (lengthIn / 4)) {
+ return -1;
+ }
+ tmp = static_cast<int16_t*>(malloc(sizeof(int16_t) * lengthIn / 2));
+ // 4:2
+ WebRtcSpl_DownsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+ // 2:1
+ WebRtcSpl_DownsampleBy2(tmp, lengthIn / 2, samplesOut,
+ static_cast<int32_t*>(state2_));
+ outLen = lengthIn / 4;
+ free(tmp);
+ return 0;
+
+ case kResamplerMode6To1:
+ // We can only handle blocks of 480 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 480) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn / 6)) {
+ return -1;
+ }
+
+ tmp_mem = static_cast<int32_t*>(malloc(496 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc((sizeof(int16_t) * lengthIn) / 3));
+
+ for (size_t i = 0; i < lengthIn; i += 480) {
+ WebRtcSpl_Resample48khzTo16khz(
+ samplesIn + i, tmp + i / 3,
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_), tmp_mem);
+ }
+ outLen = lengthIn / 3;
+ free(tmp_mem);
+ WebRtcSpl_DownsampleBy2(tmp, outLen, samplesOut,
+ static_cast<int32_t*>(state2_));
+ free(tmp);
+ outLen = outLen / 2;
+ return 0;
+ case kResamplerMode12To1:
+ // We can only handle blocks of 480 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 480) != 0) {
+ return -1;
+ }
+ if (maxLen < (lengthIn / 12)) {
+ return -1;
+ }
+
+ tmp_mem = static_cast<int32_t*>(malloc(496 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(malloc((sizeof(int16_t) * lengthIn) / 3));
+ tmp_2 = static_cast<int16_t*>(malloc((sizeof(int16_t) * lengthIn) / 6));
+ // 12:4
+ for (size_t i = 0; i < lengthIn; i += 480) {
+ // WebRtcSpl_Resample48khzTo16khz() takes a block of 480 samples
+ // as input and outputs a resampled block of 160 samples. The
+ // data is now actually in 96 kHz sampling rate, despite the
+ // function name, and with a resampling factor of 1/3 becomes
+ // 32 kHz.
+ WebRtcSpl_Resample48khzTo16khz(
+ samplesIn + i, tmp + i / 3,
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state1_), tmp_mem);
+ }
+ outLen = lengthIn / 3;
+ free(tmp_mem);
+ // 4:2
+ WebRtcSpl_DownsampleBy2(tmp, outLen, tmp_2,
+ static_cast<int32_t*>(state2_));
+ outLen = outLen / 2;
+ free(tmp);
+ // 2:1
+ WebRtcSpl_DownsampleBy2(tmp_2, outLen, samplesOut,
+ static_cast<int32_t*>(state3_));
+ free(tmp_2);
+ outLen = outLen / 2;
+ return 0;
+ case kResamplerMode3To2:
+ if (maxLen < (lengthIn * 2 / 3)) {
+ return -1;
+ }
+ // 3:6
+ tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 2));
+ WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp,
+ static_cast<int32_t*>(state1_));
+ lengthIn *= 2;
+ // 6:2
+ // We can only handle blocks of 480 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 480) != 0) {
+ free(tmp);
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(496 * sizeof(int32_t)));
+ for (size_t i = 0; i < lengthIn; i += 480) {
+ WebRtcSpl_Resample48khzTo16khz(
+ tmp + i, samplesOut + i / 3,
+ static_cast<WebRtcSpl_State48khzTo16khz*>(state2_), tmp_mem);
+ }
+ outLen = lengthIn / 3;
+ free(tmp);
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode11To2:
+ // We can only handle blocks of 220 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 220) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 2) / 11)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(126 * sizeof(int32_t)));
+ tmp = static_cast<int16_t*>(
+ malloc((lengthIn * 4) / 11 * sizeof(int16_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 220) {
+ WebRtcSpl_Resample22khzTo8khz(
+ samplesIn + i, tmp + (i * 4) / 11,
+ static_cast<WebRtcSpl_State22khzTo8khz*>(state1_), tmp_mem);
+ }
+ lengthIn = (lengthIn * 4) / 11;
+
+ WebRtcSpl_DownsampleBy2(tmp, lengthIn, samplesOut,
+ static_cast<int32_t*>(state2_));
+ outLen = lengthIn / 2;
+
+ free(tmp_mem);
+ free(tmp);
+ return 0;
+ case kResamplerMode11To4:
+ // We can only handle blocks of 220 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 220) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 4) / 11)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(126 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 220) {
+ WebRtcSpl_Resample22khzTo8khz(
+ samplesIn + i, samplesOut + (i * 4) / 11,
+ static_cast<WebRtcSpl_State22khzTo8khz*>(state1_), tmp_mem);
+ }
+ outLen = (lengthIn * 4) / 11;
+ free(tmp_mem);
+ return 0;
+ case kResamplerMode11To8:
+ // We can only handle blocks of 160 samples
+ // Can be fixed, but I don't think it's needed
+ if ((lengthIn % 220) != 0) {
+ return -1;
+ }
+ if (maxLen < ((lengthIn * 8) / 11)) {
+ return -1;
+ }
+ tmp_mem = static_cast<int32_t*>(malloc(104 * sizeof(int32_t)));
+
+ for (size_t i = 0; i < lengthIn; i += 220) {
+ WebRtcSpl_Resample22khzTo16khz(
+ samplesIn + i, samplesOut + (i * 8) / 11,
+ static_cast<WebRtcSpl_State22khzTo16khz*>(state1_), tmp_mem);
+ }
+ outLen = (lengthIn * 8) / 11;
+ free(tmp_mem);
+ return 0;
+ break;
+ }
+ return 0;
}
} // namespace webrtc
diff --git a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc
index 35c5d22..82546d0 100644
--- a/webrtc/common_audio/resampler/sinc_resampler_unittest.cc
+++ b/webrtc/common_audio/resampler/sinc_resampler_unittest.cc
@@ -16,6 +16,7 @@
#include <math.h>
+#include <algorithm>
#include <memory>
#include "webrtc/base/timeutils.h"
diff --git a/webrtc/common_audio/ring_buffer_unittest.cc b/webrtc/common_audio/ring_buffer_unittest.cc
index a5b53b0..20fc014 100644
--- a/webrtc/common_audio/ring_buffer_unittest.cc
+++ b/webrtc/common_audio/ring_buffer_unittest.cc
@@ -58,7 +58,8 @@
printf("seed=%u\n", seed);
srand(seed);
for (int i = 0; i < kNumTests; i++) {
- const int buffer_size = std::max(rand() % kMaxBufferSize, 1);
+ // rand_r is not supported on many platforms, so rand is used.
+ const int buffer_size = std::max(rand() % kMaxBufferSize, 1); // NOLINT
std::unique_ptr<int[]> write_data(new int[buffer_size]);
std::unique_ptr<int[]> read_data(new int[buffer_size]);
scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int)));
@@ -68,8 +69,8 @@
int write_element = 0;
int read_element = 0;
for (int j = 0; j < kNumOps; j++) {
- const bool write = rand() % 2 == 0 ? true : false;
- const int num_elements = rand() % buffer_size;
+ const bool write = rand() % 2 == 0 ? true : false; // 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),
diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
index f1d605b..f4fe8e8 100644
--- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h
+++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
@@ -15,8 +15,8 @@
* For specific function calls, see bottom of file.
*/
-#ifndef WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
-#define WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
+#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_
+#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_
#include <string.h>
#include "webrtc/common_audio/signal_processing/dot_product_with_scale.h"
@@ -60,13 +60,13 @@
#define WEBRTC_SPL_MUL_16_32_RSFT11(a, b) \
(WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 5) + \
- (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
+ (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x0200) >> 10))
#define WEBRTC_SPL_MUL_16_32_RSFT14(a, b) \
(WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 2) + \
- (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
+ (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x1000) >> 13))
#define WEBRTC_SPL_MUL_16_32_RSFT15(a, b) \
((WEBRTC_SPL_MUL_16_16(a, (b) >> 16) * (1 << 1)) + \
- (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
+ (((WEBRTC_SPL_MUL_16_U16(a, (uint16_t)(b)) >> 1) + 0x2000) >> 14))
#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
(WEBRTC_SPL_MUL_16_16(a, b) >> (c))
@@ -77,7 +77,7 @@
// C + the 32 most significant bits of A * B
#define WEBRTC_SPL_SCALEDIFF32(A, B, C) \
- (C + (B >> 16) * A + (((uint32_t)(0x0000FFFF & B) * 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)
@@ -906,7 +906,7 @@
#ifdef __cplusplus
}
#endif // __cplusplus
-#endif // WEBRTC_SPL_SIGNAL_PROCESSING_LIBRARY_H_
+#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SIGNAL_PROCESSING_LIBRARY_H_
//
// WebRtcSpl_AddSatW16(...)
diff --git a/webrtc/common_audio/signal_processing/include/spl_inl.h b/webrtc/common_audio/signal_processing/include/spl_inl.h
index 90098ca..370834e 100644
--- a/webrtc/common_audio/signal_processing/include/spl_inl.h
+++ b/webrtc/common_audio/signal_processing/include/spl_inl.h
@@ -12,8 +12,8 @@
// This header file includes the inline functions in
// the fix point signal processing library.
-#ifndef WEBRTC_SPL_SPL_INL_H_
-#define WEBRTC_SPL_SPL_INL_H_
+#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_
+#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_
#include "webrtc/system_wrappers/include/compile_assert_c.h"
@@ -56,7 +56,7 @@
// Returns the number of leading zero bits in the argument.
static __inline int WebRtcSpl_CountLeadingZeros64(uint64_t n) {
#ifdef __GNUC__
- COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t));
+ COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t)); // NOLINT
return n == 0 ? 64 : __builtin_clzll(n);
#else
return WebRtcSpl_CountLeadingZeros64_NotBuiltin(n);
@@ -151,4 +151,4 @@
#endif // WEBRTC_ARCH_ARM_V7
-#endif // WEBRTC_SPL_SPL_INL_H_
+#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_H_
diff --git a/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h b/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h
index 2718801..634be48 100644
--- a/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h
+++ b/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h
@@ -13,8 +13,8 @@
* the fix point signal processing library.
*/
-#ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_
-#define WEBRTC_SPL_SPL_INL_ARMV7_H_
+#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_
+#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_
/* TODO(kma): Replace some assembly code with GCC intrinsics
* (e.g. __builtin_clz).
@@ -88,8 +88,7 @@
if (a == 0) {
return 0;
- }
- else if (a < 0) {
+ } else if (a < 0) {
a ^= 0xFFFFFFFF;
}
@@ -114,8 +113,7 @@
if (a_32 == 0) {
return 0;
- }
- else if (a_32 < 0) {
+ } else if (a_32 < 0) {
a_32 ^= 0xFFFFFFFF;
}
@@ -133,4 +131,4 @@
return (int16_t)out;
}
-#endif // WEBRTC_SPL_SPL_INL_ARMV7_H_
+#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_ARMV7_H_
diff --git a/webrtc/common_audio/signal_processing/include/spl_inl_mips.h b/webrtc/common_audio/signal_processing/include/spl_inl_mips.h
index cd04bdd..90fa07a 100644
--- a/webrtc/common_audio/signal_processing/include/spl_inl_mips.h
+++ b/webrtc/common_audio/signal_processing/include/spl_inl_mips.h
@@ -12,8 +12,8 @@
// This header file includes the inline functions in
// the fix point signal processing library.
-#ifndef WEBRTC_SPL_SPL_INL_MIPS_H_
-#define WEBRTC_SPL_SPL_INL_MIPS_H_
+#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_
+#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_
static __inline int32_t WEBRTC_SPL_MUL_16_16(int32_t a,
int32_t b) {
@@ -33,8 +33,7 @@
"mul %[value32], %[a1], %[b1] \n\t"
: [value32] "=r" (value32), [a1] "=&r" (a1), [b1] "=&r" (b1)
: [a] "r" (a), [b] "r" (b)
- : "hi", "lo"
- );
+ : "hi", "lo");
return value32;
}
@@ -61,8 +60,7 @@
: [value32] "=&r" (value32), [b1] "=&r" (b1), [b2] "=&r" (b2),
[a1] "=&r" (a1)
: [a] "r" (a), [b] "r" (b)
- : "hi", "lo"
- );
+ : "hi", "lo");
return value32;
}
@@ -72,8 +70,7 @@
"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;
}
@@ -84,8 +81,7 @@
__asm __volatile(
"addq_s.ph %[value32], %[a], %[b] \n\t"
: [value32] "=r" (value32)
- : [a] "r" (a), [b] "r" (b)
- );
+ : [a] "r" (a), [b] "r" (b) );
return (int16_t)value32;
}
@@ -95,8 +91,7 @@
__asm __volatile(
"addq_s.w %[l_sum], %[l_var1], %[l_var2] \n\t"
: [l_sum] "=r" (l_sum)
- : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2)
- );
+ : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) );
return l_sum;
}
@@ -107,8 +102,7 @@
__asm __volatile(
"subq_s.ph %[value32], %[var1], %[var2] \n\t"
: [value32] "=r" (value32)
- : [var1] "r" (var1), [var2] "r" (var2)
- );
+ : [var1] "r" (var1), [var2] "r" (var2) );
return (int16_t)value32;
}
@@ -119,8 +113,7 @@
__asm __volatile(
"subq_s.w %[l_diff], %[l_var1], %[l_var2] \n\t"
: [l_diff] "=r" (l_diff)
- : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2)
- );
+ : [l_var1] "r" (l_var1), [l_var2] "r" (l_var2) );
return l_diff;
}
@@ -134,8 +127,7 @@
"clz %[bits], %[n] \n\t"
"subu %[bits], %[i32], %[bits] \n\t"
: [bits] "=&r" (bits)
- : [n] "r" (n), [i32] "r" (i32)
- );
+ : [n] "r" (n), [i32] "r" (i32) );
return (int16_t)bits;
}
@@ -157,8 +149,7 @@
"2: \n\t"
".set pop \n\t"
: [zeros]"=&r"(zeros)
- : [a] "r" (a)
- );
+ : [a] "r" (a) );
return (int16_t)zeros;
}
@@ -169,8 +160,7 @@
__asm __volatile(
"clz %[zeros], %[a] \n\t"
: [zeros] "=r" (zeros)
- : [a] "r" (a)
- );
+ : [a] "r" (a) );
return (int16_t)(zeros & 0x1f);
}
@@ -193,8 +183,7 @@
"2: \n\t"
".set pop \n\t"
: [zeros]"=&r"(zeros)
- : [a0] "r" (a0)
- );
+ : [a0] "r" (a0) );
return (int16_t)zeros;
}
@@ -217,9 +206,8 @@
"addu %[c1], %[c], %[res] \n\t"
: [c1] "=r" (c1), [res] "=&r" (res)
: [a] "r" (a), [b] "r" (b), [c] "r" (c)
- : "hi", "lo"
- );
+ : "hi", "lo");
return (c1);
}
-#endif // WEBRTC_SPL_SPL_INL_MIPS_H_
+#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_SPL_INL_MIPS_H_
diff --git a/webrtc/common_audio/signal_processing/real_fft_unittest.cc b/webrtc/common_audio/signal_processing/real_fft_unittest.cc
index 2823422..fcf11d7 100644
--- a/webrtc/common_audio/signal_processing/real_fft_unittest.cc
+++ b/webrtc/common_audio/signal_processing/real_fft_unittest.cc
@@ -35,9 +35,9 @@
class RealFFTTest : public ::testing::Test {
protected:
- RealFFTTest() {
- WebRtcSpl_Init();
- }
+ RealFFTTest() {
+ WebRtcSpl_Init();
+ }
};
TEST_F(RealFFTTest, CreateFailsOnBadInput) {
@@ -60,7 +60,7 @@
for (i = 0, j = 0; i < kTimeDataLength; i += 1, j += 2) {
complex_fft_buff[j] = kRefData[i];
complex_fft_buff[j + 1] = 0; // Insert zero's to imaginary parts.
- };
+ }
// Create and run real forward FFT.
RealFFT* fft = WebRtcSpl_CreateRealFFT(kOrder);
diff --git a/webrtc/common_audio/signal_processing/resample_by_2_internal.h b/webrtc/common_audio/signal_processing/resample_by_2_internal.h
index 5c9533e..d0954e5 100644
--- a/webrtc/common_audio/signal_processing/resample_by_2_internal.h
+++ b/webrtc/common_audio/signal_processing/resample_by_2_internal.h
@@ -14,8 +14,8 @@
*
*/
-#ifndef WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_
-#define WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_
+#ifndef WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_
+#define WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_
#include "webrtc/typedefs.h"
@@ -44,4 +44,4 @@
void WebRtcSpl_LPBy2IntToInt(const int32_t* in, int32_t len, int32_t* out,
int32_t* state);
-#endif // WEBRTC_SPL_RESAMPLE_BY_2_INTERNAL_H_
+#endif // WEBRTC_COMMON_AUDIO_SIGNAL_PROCESSING_RESAMPLE_BY_2_INTERNAL_H_
diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
index 9bf22fe..da6197e 100644
--- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
+++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
@@ -20,11 +20,11 @@
class SplTest : public testing::Test {
protected:
- SplTest() {
- WebRtcSpl_Init();
- }
- virtual ~SplTest() {
- }
+ SplTest() {
+ WebRtcSpl_Init();
+ }
+ virtual ~SplTest() {
+ }
};
TEST_F(SplTest, MacroTest) {
@@ -328,7 +328,8 @@
for (size_t kk = 0; kk < kVectorSize; ++kk) {
EXPECT_EQ((B[kk]*3+7)>>2, bTmp16[kk]);
}
- WebRtcSpl_ScaleAndAddVectorsWithRound(b16, 3, b16, 2, 2, bTmp16, kVectorSize);
+ WebRtcSpl_ScaleAndAddVectorsWithRound(b16, 3, b16, 2, 2, bTmp16,
+ kVectorSize);
for (size_t kk = 0; kk < kVectorSize; ++kk) {
EXPECT_EQ((B[kk]*3+B[kk]*2+2)>>2, bTmp16[kk]);
}
@@ -355,7 +356,8 @@
for (size_t kk = 0; kk < kVectorSize; ++kk) {
EXPECT_EQ(B[kk] >> 1, bTmp16[kk]);
}
- WebRtcSpl_ReverseOrderMultArrayElements(bTmp16, a16, &b16[3], kVectorSize, 2);
+ WebRtcSpl_ReverseOrderMultArrayElements(bTmp16, a16, &b16[3],
+ kVectorSize, 2);
for (size_t kk = 0; kk < kVectorSize; ++kk) {
EXPECT_EQ((a16[kk]*b16[3-kk])>>2, bTmp16[kk]);
}
@@ -558,7 +560,7 @@
// }
WebRtcSpl_ComplexBitReverse(B, 3);
for (int kk = 0; kk < 16; ++kk) {
- //EXPECT_EQ(A[kk], B[kk]);
+// EXPECT_EQ(A[kk], B[kk]);
}
}
diff --git a/webrtc/common_audio/vad/vad_core.h b/webrtc/common_audio/vad/vad_core.h
index 0a76d96..47e2d88 100644
--- a/webrtc/common_audio/vad/vad_core.h
+++ b/webrtc/common_audio/vad/vad_core.h
@@ -24,9 +24,7 @@
enum { kTableSize = kNumChannels * kNumGaussians };
enum { kMinEnergy = 10 }; // Minimum energy required to trigger audio signal.
-typedef struct VadInstT_
-{
-
+typedef struct VadInstT_ {
int vad;
int32_t downsampling_filter_states[4];
WebRtcSpl_State48khzTo8khz state_48_to_8;
@@ -36,7 +34,7 @@
int16_t speech_stds[kTableSize];
// TODO(bjornv): Change to |frame_count|.
int32_t frame_counter;
- int16_t over_hang; // Over Hang
+ int16_t over_hang; // Over Hang
int16_t num_of_speech;
// TODO(bjornv): Change to |age_vector|.
int16_t index_vector[16 * kNumChannels];
@@ -52,7 +50,6 @@
int16_t total[3];
int init_flag;
-
} VadInstT;
// Initializes the core VAD component. The default aggressiveness mode is
diff --git a/webrtc/common_audio/vad/vad_core_unittest.cc b/webrtc/common_audio/vad/vad_core_unittest.cc
index ba53c56..d922010 100644
--- a/webrtc/common_audio/vad/vad_core_unittest.cc
+++ b/webrtc/common_audio/vad/vad_core_unittest.cc
@@ -18,7 +18,8 @@
#include "webrtc/common_audio/vad/vad_core.h"
}
-namespace {
+namespace webrtc {
+namespace test {
TEST_F(VadTest, InitCore) {
// Test WebRtcVad_InitCore().
@@ -102,4 +103,5 @@
free(self);
}
-} // namespace
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/common_audio/vad/vad_filterbank_unittest.cc b/webrtc/common_audio/vad/vad_filterbank_unittest.cc
index 5b27801..d15fc1b 100644
--- a/webrtc/common_audio/vad/vad_filterbank_unittest.cc
+++ b/webrtc/common_audio/vad/vad_filterbank_unittest.cc
@@ -19,7 +19,8 @@
#include "webrtc/common_audio/vad/vad_filterbank.h"
}
-namespace {
+namespace webrtc {
+namespace test {
const int kNumValidFrameLengths = 3;
@@ -89,4 +90,5 @@
free(self);
}
-} // namespace
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/common_audio/vad/vad_gmm_unittest.cc b/webrtc/common_audio/vad/vad_gmm_unittest.cc
index 9de93f6..7d95111 100644
--- a/webrtc/common_audio/vad/vad_gmm_unittest.cc
+++ b/webrtc/common_audio/vad/vad_gmm_unittest.cc
@@ -16,7 +16,8 @@
#include "webrtc/common_audio/vad/vad_gmm.h"
}
-namespace {
+namespace webrtc {
+namespace test {
TEST_F(VadTest, vad_gmm) {
int16_t delta = 0;
@@ -40,4 +41,5 @@
EXPECT_EQ(0, WebRtcVad_GaussianProbability(105, 0, 128, &delta));
EXPECT_EQ(13440, delta);
}
-} // namespace
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/common_audio/vad/vad_sp_unittest.cc b/webrtc/common_audio/vad/vad_sp_unittest.cc
index 1e335e3..e841308 100644
--- a/webrtc/common_audio/vad/vad_sp_unittest.cc
+++ b/webrtc/common_audio/vad/vad_sp_unittest.cc
@@ -19,7 +19,8 @@
#include "webrtc/common_audio/vad/vad_sp.h"
}
-namespace {
+namespace webrtc {
+namespace test {
TEST_F(VadTest, vad_sp) {
VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));
@@ -71,4 +72,5 @@
free(self);
}
-} // namespace
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/common_audio/vad/vad_unittest.cc b/webrtc/common_audio/vad/vad_unittest.cc
index a03f667..f2210d9 100644
--- a/webrtc/common_audio/vad/vad_unittest.cc
+++ b/webrtc/common_audio/vad/vad_unittest.cc
@@ -52,7 +52,8 @@
return false;
}
-namespace {
+namespace webrtc {
+namespace test {
TEST_F(VadTest, ApiTest) {
// This API test runs through the APIs for all possible valid and invalid
@@ -152,4 +153,5 @@
// TODO(bjornv): Add a process test, run on file.
-} // namespace
+} // namespace test
+} // namespace webrtc
diff --git a/webrtc/common_audio/vad/vad_unittest.h b/webrtc/common_audio/vad/vad_unittest.h
index 55ba527..7edf585 100644
--- a/webrtc/common_audio/vad/vad_unittest.h
+++ b/webrtc/common_audio/vad/vad_unittest.h
@@ -8,15 +8,16 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H
-#define WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H
+#ifndef WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_
+#define WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_
#include <stddef.h> // size_t
#include "webrtc/test/gtest.h"
#include "webrtc/typedefs.h"
-namespace {
+namespace webrtc {
+namespace test {
// Modes we support
const int kModes[] = { 0, 1, 2, 3 };
@@ -32,7 +33,8 @@
kMaxFrameLength };
const size_t kFrameLengthsSize = sizeof(kFrameLengths) / sizeof(*kFrameLengths);
-} // namespace
+} // namespace test
+} // namespace webrtc
class VadTest : public ::testing::Test {
protected:
@@ -44,4 +46,4 @@
bool ValidRatesAndFrameLengths(int rate, size_t frame_length);
};
-#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H
+#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H_
diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc
index 66d66e6..a9fe6fd 100644
--- a/webrtc/voice_engine/channel.cc
+++ b/webrtc/voice_engine/channel.cc
@@ -675,7 +675,7 @@
// Output volume scaling
if (output_gain < 0.99f || output_gain > 1.01f) {
// TODO(solenberg): Combine with mute state - this can cause clicks!
- AudioFrameOperations::ScaleWithSat(output_gain, *audioFrame);
+ AudioFrameOperations::ScaleWithSat(output_gain, audioFrame);
}
// Mix decoded PCM output with file if file mixing is enabled