Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t. This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects. This was be reviewed and approved in pieces: https://codereview.webrtc.org/1224093003 https://codereview.webrtc.org/1224123002 https://codereview.webrtc.org/1224163002 https://codereview.webrtc.org/1225133003 https://codereview.webrtc.org/1225173002 https://codereview.webrtc.org/1227163003 https://codereview.webrtc.org/1227203003 https://codereview.webrtc.org/1227213002 https://codereview.webrtc.org/1227893002 https://codereview.webrtc.org/1228793004 https://codereview.webrtc.org/1228803003 https://codereview.webrtc.org/1228823002 https://codereview.webrtc.org/1228823003 https://codereview.webrtc.org/1228843002 https://codereview.webrtc.org/1230693002 https://codereview.webrtc.org/1231713002 The change is being landed as TBR to all the folks who reviewed the above. BUG=chromium:81439 TEST=none R=andrew@webrtc.org, pbos@webrtc.org TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher Review URL: https://codereview.webrtc.org/1230503003 . Cr-Commit-Position: refs/heads/master@{#9768}
This commit is contained in:
parent
b594041ec8
commit
dce40cf804
@ -68,7 +68,7 @@ void LocalAudioSinkAdapter::OnData(const void* audio_data,
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) {
|
||||
size_t number_of_frames) {
|
||||
rtc::CritScope lock(&lock_);
|
||||
if (sink_) {
|
||||
sink_->OnData(audio_data, bits_per_sample, sample_rate,
|
||||
|
||||
@ -82,7 +82,7 @@ class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) override;
|
||||
size_t number_of_frames) override;
|
||||
|
||||
// cricket::AudioRenderer implementation.
|
||||
void SetSink(cricket::AudioRenderer::Sink* sink) override;
|
||||
|
||||
@ -187,7 +187,7 @@ class AudioTrackSinkInterface {
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) = 0;
|
||||
size_t number_of_frames) = 0;
|
||||
protected:
|
||||
virtual ~AudioTrackSinkInterface() {}
|
||||
};
|
||||
|
||||
@ -615,9 +615,9 @@ bool FakeAudioCaptureModule::Initialize() {
|
||||
|
||||
void FakeAudioCaptureModule::SetSendBuffer(int value) {
|
||||
Sample* buffer_ptr = reinterpret_cast<Sample*>(send_buffer_);
|
||||
const int buffer_size_in_samples =
|
||||
const size_t buffer_size_in_samples =
|
||||
sizeof(send_buffer_) / kNumberBytesPerSample;
|
||||
for (int i = 0; i < buffer_size_in_samples; ++i) {
|
||||
for (size_t i = 0; i < buffer_size_in_samples; ++i) {
|
||||
buffer_ptr[i] = value;
|
||||
}
|
||||
}
|
||||
@ -628,9 +628,9 @@ void FakeAudioCaptureModule::ResetRecBuffer() {
|
||||
|
||||
bool FakeAudioCaptureModule::CheckRecBuffer(int value) {
|
||||
const Sample* buffer_ptr = reinterpret_cast<const Sample*>(rec_buffer_);
|
||||
const int buffer_size_in_samples =
|
||||
const size_t buffer_size_in_samples =
|
||||
sizeof(rec_buffer_) / kNumberBytesPerSample;
|
||||
for (int i = 0; i < buffer_size_in_samples; ++i) {
|
||||
for (size_t i = 0; i < buffer_size_in_samples; ++i) {
|
||||
if (buffer_ptr[i] >= value) return true;
|
||||
}
|
||||
return false;
|
||||
@ -698,7 +698,7 @@ void FakeAudioCaptureModule::ReceiveFrameP() {
|
||||
return;
|
||||
}
|
||||
ResetRecBuffer();
|
||||
uint32_t nSamplesOut = 0;
|
||||
size_t nSamplesOut = 0;
|
||||
int64_t elapsed_time_ms = 0;
|
||||
int64_t ntp_time_ms = 0;
|
||||
if (audio_callback_->NeedMorePlayData(kNumberSamples, kNumberBytesPerSample,
|
||||
|
||||
@ -57,8 +57,8 @@ class FakeAudioCaptureModule
|
||||
|
||||
// The value for the following constants have been derived by running VoE
|
||||
// using a real ADM. The constants correspond to 10ms of mono audio at 44kHz.
|
||||
static const int kNumberSamples = 440;
|
||||
static const int kNumberBytesPerSample = sizeof(Sample);
|
||||
static const size_t kNumberSamples = 440;
|
||||
static const size_t kNumberBytesPerSample = sizeof(Sample);
|
||||
|
||||
// Creates a FakeAudioCaptureModule or returns NULL on failure.
|
||||
static rtc::scoped_refptr<FakeAudioCaptureModule> Create();
|
||||
|
||||
@ -56,8 +56,8 @@ class FakeAdmTest : public testing::Test,
|
||||
// Callbacks inherited from webrtc::AudioTransport.
|
||||
// ADM is pushing data.
|
||||
int32_t RecordedDataIsAvailable(const void* audioSamples,
|
||||
const uint32_t nSamples,
|
||||
const uint8_t nBytesPerSample,
|
||||
const size_t nSamples,
|
||||
const size_t nBytesPerSample,
|
||||
const uint8_t nChannels,
|
||||
const uint32_t samplesPerSec,
|
||||
const uint32_t totalDelayMS,
|
||||
@ -80,18 +80,18 @@ class FakeAdmTest : public testing::Test,
|
||||
}
|
||||
|
||||
// ADM is pulling data.
|
||||
int32_t NeedMorePlayData(const uint32_t nSamples,
|
||||
const uint8_t nBytesPerSample,
|
||||
int32_t NeedMorePlayData(const size_t nSamples,
|
||||
const size_t nBytesPerSample,
|
||||
const uint8_t nChannels,
|
||||
const uint32_t samplesPerSec,
|
||||
void* audioSamples,
|
||||
uint32_t& nSamplesOut,
|
||||
size_t& nSamplesOut,
|
||||
int64_t* elapsed_time_ms,
|
||||
int64_t* ntp_time_ms) override {
|
||||
rtc::CritScope cs(&crit_);
|
||||
++pull_iterations_;
|
||||
const uint32_t audio_buffer_size = nSamples * nBytesPerSample;
|
||||
const uint32_t bytes_out = RecordedDataReceived() ?
|
||||
const size_t audio_buffer_size = nSamples * nBytesPerSample;
|
||||
const size_t bytes_out = RecordedDataReceived() ?
|
||||
CopyFromRecBuffer(audioSamples, audio_buffer_size):
|
||||
GenerateZeroBuffer(audioSamples, audio_buffer_size);
|
||||
nSamplesOut = bytes_out / nBytesPerSample;
|
||||
@ -115,13 +115,13 @@ class FakeAdmTest : public testing::Test,
|
||||
bool RecordedDataReceived() const {
|
||||
return rec_buffer_bytes_ != 0;
|
||||
}
|
||||
int32_t GenerateZeroBuffer(void* audio_buffer, uint32_t audio_buffer_size) {
|
||||
size_t GenerateZeroBuffer(void* audio_buffer, size_t audio_buffer_size) {
|
||||
memset(audio_buffer, 0, audio_buffer_size);
|
||||
return audio_buffer_size;
|
||||
}
|
||||
int32_t CopyFromRecBuffer(void* audio_buffer, uint32_t audio_buffer_size) {
|
||||
size_t CopyFromRecBuffer(void* audio_buffer, size_t audio_buffer_size) {
|
||||
EXPECT_EQ(audio_buffer_size, rec_buffer_bytes_);
|
||||
const uint32_t min_buffer_size = min(audio_buffer_size, rec_buffer_bytes_);
|
||||
const size_t min_buffer_size = min(audio_buffer_size, rec_buffer_bytes_);
|
||||
memcpy(audio_buffer, rec_buffer_, min_buffer_size);
|
||||
return min_buffer_size;
|
||||
}
|
||||
@ -133,7 +133,7 @@ class FakeAdmTest : public testing::Test,
|
||||
|
||||
char rec_buffer_[FakeAudioCaptureModule::kNumberSamples *
|
||||
FakeAudioCaptureModule::kNumberBytesPerSample];
|
||||
uint32_t rec_buffer_bytes_;
|
||||
size_t rec_buffer_bytes_;
|
||||
};
|
||||
|
||||
TEST_F(FakeAdmTest, TestProccess) {
|
||||
|
||||
@ -28,6 +28,8 @@
|
||||
#ifndef TALK_MEDIA_BASE_AUDIORENDERER_H_
|
||||
#define TALK_MEDIA_BASE_AUDIORENDERER_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace cricket {
|
||||
|
||||
// Abstract interface for rendering the audio data.
|
||||
@ -40,7 +42,7 @@ class AudioRenderer {
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) = 0;
|
||||
size_t number_of_frames) = 0;
|
||||
|
||||
// Called when the AudioRenderer is going away.
|
||||
virtual void OnClose() = 0;
|
||||
|
||||
@ -438,7 +438,7 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) override {}
|
||||
size_t number_of_frames) override {}
|
||||
void OnClose() override { renderer_ = NULL; }
|
||||
AudioRenderer* renderer() const { return renderer_; }
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ class FakeAudioProcessing : public webrtc::AudioProcessing {
|
||||
WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
|
||||
WEBRTC_STUB(ProcessStream, (
|
||||
const float* const* src,
|
||||
int samples_per_channel,
|
||||
size_t samples_per_channel,
|
||||
int input_sample_rate_hz,
|
||||
webrtc::AudioProcessing::ChannelLayout input_layout,
|
||||
int output_sample_rate_hz,
|
||||
@ -147,7 +147,7 @@ class FakeAudioProcessing : public webrtc::AudioProcessing {
|
||||
WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
|
||||
WEBRTC_STUB(AnalyzeReverseStream, (
|
||||
const float* const* data,
|
||||
int samples_per_channel,
|
||||
size_t samples_per_channel,
|
||||
int sample_rate_hz,
|
||||
webrtc::AudioProcessing::ChannelLayout layout));
|
||||
WEBRTC_STUB(ProcessReverseStream,
|
||||
|
||||
@ -1569,7 +1569,7 @@ bool WebRtcVoiceEngine::UnregisterProcessor(
|
||||
void WebRtcVoiceEngine::Process(int channel,
|
||||
webrtc::ProcessingTypes type,
|
||||
int16_t audio10ms[],
|
||||
int length,
|
||||
size_t length,
|
||||
int sampling_freq,
|
||||
bool is_stereo) {
|
||||
rtc::CritScope cs(&signal_media_critical_);
|
||||
@ -1665,7 +1665,7 @@ class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer
|
||||
int bits_per_sample,
|
||||
int sample_rate,
|
||||
int number_of_channels,
|
||||
int number_of_frames) override {
|
||||
size_t number_of_frames) override {
|
||||
voe_audio_transport_->OnData(channel_,
|
||||
audio_data,
|
||||
bits_per_sample,
|
||||
|
||||
@ -130,7 +130,7 @@ class WebRtcVoiceEngine
|
||||
void Process(int channel,
|
||||
webrtc::ProcessingTypes type,
|
||||
int16_t audio10ms[],
|
||||
int length,
|
||||
size_t length,
|
||||
int sampling_freq,
|
||||
bool is_stereo) override;
|
||||
|
||||
|
||||
@ -24,8 +24,8 @@ namespace webrtc {
|
||||
|
||||
class CopyConverter : public AudioConverter {
|
||||
public:
|
||||
CopyConverter(int src_channels, int src_frames, int dst_channels,
|
||||
int dst_frames)
|
||||
CopyConverter(int src_channels, size_t src_frames, int dst_channels,
|
||||
size_t dst_frames)
|
||||
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {}
|
||||
~CopyConverter() override {};
|
||||
|
||||
@ -41,15 +41,15 @@ class CopyConverter : public AudioConverter {
|
||||
|
||||
class UpmixConverter : public AudioConverter {
|
||||
public:
|
||||
UpmixConverter(int src_channels, int src_frames, int dst_channels,
|
||||
int dst_frames)
|
||||
UpmixConverter(int src_channels, size_t src_frames, int dst_channels,
|
||||
size_t dst_frames)
|
||||
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {}
|
||||
~UpmixConverter() override {};
|
||||
|
||||
void Convert(const float* const* src, size_t src_size, float* const* dst,
|
||||
size_t dst_capacity) override {
|
||||
CheckSizes(src_size, dst_capacity);
|
||||
for (int i = 0; i < dst_frames(); ++i) {
|
||||
for (size_t i = 0; i < dst_frames(); ++i) {
|
||||
const float value = src[0][i];
|
||||
for (int j = 0; j < dst_channels(); ++j)
|
||||
dst[j][i] = value;
|
||||
@ -59,8 +59,8 @@ class UpmixConverter : public AudioConverter {
|
||||
|
||||
class DownmixConverter : public AudioConverter {
|
||||
public:
|
||||
DownmixConverter(int src_channels, int src_frames, int dst_channels,
|
||||
int dst_frames)
|
||||
DownmixConverter(int src_channels, size_t src_frames, int dst_channels,
|
||||
size_t dst_frames)
|
||||
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {
|
||||
}
|
||||
~DownmixConverter() override {};
|
||||
@ -69,7 +69,7 @@ class DownmixConverter : public AudioConverter {
|
||||
size_t dst_capacity) override {
|
||||
CheckSizes(src_size, dst_capacity);
|
||||
float* dst_mono = dst[0];
|
||||
for (int i = 0; i < src_frames(); ++i) {
|
||||
for (size_t i = 0; i < src_frames(); ++i) {
|
||||
float sum = 0;
|
||||
for (int j = 0; j < src_channels(); ++j)
|
||||
sum += src[j][i];
|
||||
@ -80,8 +80,8 @@ class DownmixConverter : public AudioConverter {
|
||||
|
||||
class ResampleConverter : public AudioConverter {
|
||||
public:
|
||||
ResampleConverter(int src_channels, int src_frames, int dst_channels,
|
||||
int dst_frames)
|
||||
ResampleConverter(int src_channels, size_t src_frames, int dst_channels,
|
||||
size_t dst_frames)
|
||||
: AudioConverter(src_channels, src_frames, dst_channels, dst_frames) {
|
||||
resamplers_.reserve(src_channels);
|
||||
for (int i = 0; i < src_channels; ++i)
|
||||
@ -136,9 +136,9 @@ class CompositionConverter : public AudioConverter {
|
||||
};
|
||||
|
||||
rtc::scoped_ptr<AudioConverter> AudioConverter::Create(int src_channels,
|
||||
int src_frames,
|
||||
size_t src_frames,
|
||||
int dst_channels,
|
||||
int dst_frames) {
|
||||
size_t dst_frames) {
|
||||
rtc::scoped_ptr<AudioConverter> sp;
|
||||
if (src_channels > dst_channels) {
|
||||
if (src_frames != dst_frames) {
|
||||
@ -182,8 +182,8 @@ AudioConverter::AudioConverter()
|
||||
dst_channels_(0),
|
||||
dst_frames_(0) {}
|
||||
|
||||
AudioConverter::AudioConverter(int src_channels, int src_frames,
|
||||
int dst_channels, int dst_frames)
|
||||
AudioConverter::AudioConverter(int src_channels, size_t src_frames,
|
||||
int dst_channels, size_t dst_frames)
|
||||
: src_channels_(src_channels),
|
||||
src_frames_(src_frames),
|
||||
dst_channels_(dst_channels),
|
||||
@ -192,8 +192,8 @@ AudioConverter::AudioConverter(int src_channels, int src_frames,
|
||||
}
|
||||
|
||||
void AudioConverter::CheckSizes(size_t src_size, size_t dst_capacity) const {
|
||||
CHECK_EQ(src_size, checked_cast<size_t>(src_channels() * src_frames()));
|
||||
CHECK_GE(dst_capacity, checked_cast<size_t>(dst_channels() * dst_frames()));
|
||||
CHECK_EQ(src_size, src_channels() * src_frames());
|
||||
CHECK_GE(dst_capacity, dst_channels() * dst_frames());
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -27,9 +27,9 @@ class AudioConverter {
|
||||
// Returns a new AudioConverter, which will use the supplied format for its
|
||||
// lifetime. Caller is responsible for the memory.
|
||||
static rtc::scoped_ptr<AudioConverter> Create(int src_channels,
|
||||
int src_frames,
|
||||
size_t src_frames,
|
||||
int dst_channels,
|
||||
int dst_frames);
|
||||
size_t dst_frames);
|
||||
virtual ~AudioConverter() {};
|
||||
|
||||
// Convert |src|, containing |src_size| samples, to |dst|, having a sample
|
||||
@ -40,23 +40,23 @@ class AudioConverter {
|
||||
float* const* dst, size_t dst_capacity) = 0;
|
||||
|
||||
int src_channels() const { return src_channels_; }
|
||||
int src_frames() const { return src_frames_; }
|
||||
size_t src_frames() const { return src_frames_; }
|
||||
int dst_channels() const { return dst_channels_; }
|
||||
int dst_frames() const { return dst_frames_; }
|
||||
size_t dst_frames() const { return dst_frames_; }
|
||||
|
||||
protected:
|
||||
AudioConverter();
|
||||
AudioConverter(int src_channels, int src_frames, int dst_channels,
|
||||
int dst_frames);
|
||||
AudioConverter(int src_channels, size_t src_frames, int dst_channels,
|
||||
size_t dst_frames);
|
||||
|
||||
// Helper to CHECK that inputs are correctly sized.
|
||||
void CheckSizes(size_t src_size, size_t dst_capacity) const;
|
||||
|
||||
private:
|
||||
const int src_channels_;
|
||||
const int src_frames_;
|
||||
const size_t src_frames_;
|
||||
const int dst_channels_;
|
||||
const int dst_frames_;
|
||||
const size_t dst_frames_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AudioConverter);
|
||||
};
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/base/format_macros.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/common_audio/audio_converter.h"
|
||||
#include "webrtc/common_audio/channel_buffer.h"
|
||||
@ -43,20 +44,20 @@ void VerifyParams(const ChannelBuffer<float>& ref,
|
||||
// signals to compensate for the resampling delay.
|
||||
float ComputeSNR(const ChannelBuffer<float>& ref,
|
||||
const ChannelBuffer<float>& test,
|
||||
int expected_delay) {
|
||||
size_t expected_delay) {
|
||||
VerifyParams(ref, test);
|
||||
float best_snr = 0;
|
||||
int best_delay = 0;
|
||||
size_t best_delay = 0;
|
||||
|
||||
// Search within one sample of the expected delay.
|
||||
for (int delay = std::max(expected_delay, 1) - 1;
|
||||
for (size_t delay = std::max(expected_delay, static_cast<size_t>(1)) - 1;
|
||||
delay <= std::min(expected_delay + 1, ref.num_frames());
|
||||
++delay) {
|
||||
float mse = 0;
|
||||
float variance = 0;
|
||||
float mean = 0;
|
||||
for (int i = 0; i < ref.num_channels(); ++i) {
|
||||
for (int j = 0; j < ref.num_frames() - delay; ++j) {
|
||||
for (size_t j = 0; j < ref.num_frames() - delay; ++j) {
|
||||
float error = ref.channels()[i][j] - test.channels()[i][j + delay];
|
||||
mse += error * error;
|
||||
variance += ref.channels()[i][j] * ref.channels()[i][j];
|
||||
@ -64,7 +65,7 @@ float ComputeSNR(const ChannelBuffer<float>& ref,
|
||||
}
|
||||
}
|
||||
|
||||
const int length = ref.num_channels() * (ref.num_frames() - delay);
|
||||
const size_t length = ref.num_channels() * (ref.num_frames() - delay);
|
||||
mse /= length;
|
||||
variance /= length;
|
||||
mean /= length;
|
||||
@ -77,7 +78,7 @@ float ComputeSNR(const ChannelBuffer<float>& ref,
|
||||
best_delay = delay;
|
||||
}
|
||||
}
|
||||
printf("SNR=%.1f dB at delay=%d\n", best_snr, best_delay);
|
||||
printf("SNR=%.1f dB at delay=%" PRIuS "\n", best_snr, best_delay);
|
||||
return best_snr;
|
||||
}
|
||||
|
||||
@ -122,9 +123,10 @@ void RunAudioConverterTest(int src_channels,
|
||||
ScopedBuffer ref_buffer = CreateBuffer(ref_data, dst_frames);
|
||||
|
||||
// The sinc resampler has a known delay, which we compute here.
|
||||
const int delay_frames = src_sample_rate_hz == dst_sample_rate_hz ? 0 :
|
||||
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);
|
||||
printf("(%d, %d Hz) -> (%d, %d Hz) ", // SNR reported on the same line later.
|
||||
src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz);
|
||||
|
||||
|
||||
@ -34,27 +34,27 @@ void ReadAndWriteTest(const ChannelBuffer<float>& input,
|
||||
while (input_pos + buf.WriteFramesAvailable() < total_frames) {
|
||||
// Write until the buffer is as full as possible.
|
||||
while (buf.WriteFramesAvailable() >= num_write_chunk_frames) {
|
||||
buf.Write(input.Slice(slice.get(), static_cast<int>(input_pos)),
|
||||
num_channels, num_write_chunk_frames);
|
||||
buf.Write(input.Slice(slice.get(), input_pos), num_channels,
|
||||
num_write_chunk_frames);
|
||||
input_pos += num_write_chunk_frames;
|
||||
}
|
||||
// Read until the buffer is as empty as possible.
|
||||
while (buf.ReadFramesAvailable() >= num_read_chunk_frames) {
|
||||
EXPECT_LT(output_pos, total_frames);
|
||||
buf.Read(output->Slice(slice.get(), static_cast<int>(output_pos)),
|
||||
num_channels, num_read_chunk_frames);
|
||||
buf.Read(output->Slice(slice.get(), output_pos), num_channels,
|
||||
num_read_chunk_frames);
|
||||
output_pos += num_read_chunk_frames;
|
||||
}
|
||||
}
|
||||
|
||||
// Write and read the last bit.
|
||||
if (input_pos < total_frames) {
|
||||
buf.Write(input.Slice(slice.get(), static_cast<int>(input_pos)),
|
||||
num_channels, total_frames - input_pos);
|
||||
buf.Write(input.Slice(slice.get(), input_pos), num_channels,
|
||||
total_frames - input_pos);
|
||||
}
|
||||
if (buf.ReadFramesAvailable()) {
|
||||
buf.Read(output->Slice(slice.get(), static_cast<int>(output_pos)),
|
||||
num_channels, buf.ReadFramesAvailable());
|
||||
buf.Read(output->Slice(slice.get(), output_pos), num_channels,
|
||||
buf.ReadFramesAvailable());
|
||||
}
|
||||
EXPECT_EQ(0u, buf.ReadFramesAvailable());
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ void FloatS16ToFloat(const float* src, size_t size, float* dest) {
|
||||
|
||||
template <>
|
||||
void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
int16_t* deinterleaved) {
|
||||
DownmixInterleavedToMonoImpl<int16_t, int32_t>(interleaved, num_frames,
|
||||
|
||||
@ -18,20 +18,20 @@ namespace {
|
||||
|
||||
using ::testing::ElementsAreArray;
|
||||
|
||||
void ExpectArraysEq(const int16_t* ref, const int16_t* test, int length) {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
void ExpectArraysEq(const int16_t* ref, const int16_t* test, size_t length) {
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
EXPECT_EQ(ref[i], test[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpectArraysEq(const float* ref, const float* test, int length) {
|
||||
for (int i = 0; i < length; ++i) {
|
||||
void ExpectArraysEq(const float* ref, const float* test, size_t length) {
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
EXPECT_FLOAT_EQ(ref[i], test[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AudioUtilTest, FloatToS16) {
|
||||
const int kSize = 9;
|
||||
const size_t kSize = 9;
|
||||
const float kInput[kSize] = {0.f,
|
||||
0.4f / 32767.f,
|
||||
0.6f / 32767.f,
|
||||
@ -49,7 +49,7 @@ TEST(AudioUtilTest, FloatToS16) {
|
||||
}
|
||||
|
||||
TEST(AudioUtilTest, S16ToFloat) {
|
||||
const int kSize = 7;
|
||||
const size_t kSize = 7;
|
||||
const int16_t kInput[kSize] = {0, 1, -1, 16384, -16384, 32767, -32768};
|
||||
const float kReference[kSize] = {
|
||||
0.f, 1.f / 32767.f, -1.f / 32768.f, 16384.f / 32767.f, -0.5f, 1.f, -1.f};
|
||||
@ -59,7 +59,7 @@ TEST(AudioUtilTest, S16ToFloat) {
|
||||
}
|
||||
|
||||
TEST(AudioUtilTest, FloatS16ToS16) {
|
||||
const int kSize = 7;
|
||||
const size_t kSize = 7;
|
||||
const float kInput[kSize] = {0.f, 0.4f, 0.5f, -0.4f,
|
||||
-0.5f, 32768.f, -32769.f};
|
||||
const int16_t kReference[kSize] = {0, 0, 1, 0, -1, 32767, -32768};
|
||||
@ -69,7 +69,7 @@ TEST(AudioUtilTest, FloatS16ToS16) {
|
||||
}
|
||||
|
||||
TEST(AudioUtilTest, FloatToFloatS16) {
|
||||
const int kSize = 9;
|
||||
const size_t kSize = 9;
|
||||
const float kInput[kSize] = {0.f,
|
||||
0.4f / 32767.f,
|
||||
0.6f / 32767.f,
|
||||
@ -87,7 +87,7 @@ TEST(AudioUtilTest, FloatToFloatS16) {
|
||||
}
|
||||
|
||||
TEST(AudioUtilTest, FloatS16ToFloat) {
|
||||
const int kSize = 9;
|
||||
const size_t kSize = 9;
|
||||
const float kInput[kSize] = {0.f, 0.4f, 0.6f, -0.4f, -0.6f,
|
||||
32767.f, -32768.f, 36043.7f, -36044.8f};
|
||||
const float kReference[kSize] = {0.f,
|
||||
@ -106,9 +106,9 @@ TEST(AudioUtilTest, FloatS16ToFloat) {
|
||||
|
||||
TEST(AudioUtilTest, InterleavingStereo) {
|
||||
const int16_t kInterleaved[] = {2, 3, 4, 9, 8, 27, 16, 81};
|
||||
const int kSamplesPerChannel = 4;
|
||||
const size_t kSamplesPerChannel = 4;
|
||||
const int kNumChannels = 2;
|
||||
const int kLength = kSamplesPerChannel * kNumChannels;
|
||||
const size_t kLength = kSamplesPerChannel * kNumChannels;
|
||||
int16_t left[kSamplesPerChannel], right[kSamplesPerChannel];
|
||||
int16_t* deinterleaved[] = {left, right};
|
||||
Deinterleave(kInterleaved, kSamplesPerChannel, kNumChannels, deinterleaved);
|
||||
@ -124,7 +124,7 @@ TEST(AudioUtilTest, InterleavingStereo) {
|
||||
|
||||
TEST(AudioUtilTest, InterleavingMonoIsIdentical) {
|
||||
const int16_t kInterleaved[] = {1, 2, 3, 4, 5};
|
||||
const int kSamplesPerChannel = 5;
|
||||
const size_t kSamplesPerChannel = 5;
|
||||
const int kNumChannels = 1;
|
||||
int16_t mono[kSamplesPerChannel];
|
||||
int16_t* deinterleaved[] = {mono};
|
||||
@ -138,7 +138,7 @@ TEST(AudioUtilTest, InterleavingMonoIsIdentical) {
|
||||
|
||||
TEST(AudioUtilTest, DownmixInterleavedToMono) {
|
||||
{
|
||||
const int kNumFrames = 4;
|
||||
const size_t kNumFrames = 4;
|
||||
const int kNumChannels = 1;
|
||||
const int16_t interleaved[kNumChannels * kNumFrames] = {1, 2, -1, -3};
|
||||
int16_t deinterleaved[kNumFrames];
|
||||
@ -149,7 +149,7 @@ TEST(AudioUtilTest, DownmixInterleavedToMono) {
|
||||
EXPECT_THAT(deinterleaved, ElementsAreArray(interleaved));
|
||||
}
|
||||
{
|
||||
const int kNumFrames = 2;
|
||||
const size_t kNumFrames = 2;
|
||||
const int kNumChannels = 2;
|
||||
const int16_t interleaved[kNumChannels * kNumFrames] = {10, 20, -10, -30};
|
||||
int16_t deinterleaved[kNumFrames];
|
||||
@ -161,7 +161,7 @@ TEST(AudioUtilTest, DownmixInterleavedToMono) {
|
||||
EXPECT_THAT(deinterleaved, ElementsAreArray(expected));
|
||||
}
|
||||
{
|
||||
const int kNumFrames = 3;
|
||||
const size_t kNumFrames = 3;
|
||||
const int kNumChannels = 3;
|
||||
const int16_t interleaved[kNumChannels * kNumFrames] = {
|
||||
30000, 30000, 24001, -5, -10, -20, -30000, -30999, -30000};
|
||||
@ -177,7 +177,7 @@ TEST(AudioUtilTest, DownmixInterleavedToMono) {
|
||||
|
||||
TEST(AudioUtilTest, DownmixToMonoTest) {
|
||||
{
|
||||
const int kNumFrames = 4;
|
||||
const size_t kNumFrames = 4;
|
||||
const int kNumChannels = 1;
|
||||
const float input_data[kNumChannels][kNumFrames] = {{1.f, 2.f, -1.f, -3.f}};
|
||||
const float* input[kNumChannels];
|
||||
@ -192,7 +192,7 @@ TEST(AudioUtilTest, DownmixToMonoTest) {
|
||||
EXPECT_THAT(downmixed, ElementsAreArray(input_data[0]));
|
||||
}
|
||||
{
|
||||
const int kNumFrames = 3;
|
||||
const size_t kNumFrames = 3;
|
||||
const int kNumChannels = 2;
|
||||
const float input_data[kNumChannels][kNumFrames] = {{1.f, 2.f, -1.f},
|
||||
{3.f, 0.f, 1.f}};
|
||||
@ -209,7 +209,7 @@ TEST(AudioUtilTest, DownmixToMonoTest) {
|
||||
EXPECT_THAT(downmixed, ElementsAreArray(expected));
|
||||
}
|
||||
{
|
||||
const int kNumFrames = 3;
|
||||
const size_t kNumFrames = 3;
|
||||
const int kNumChannels = 3;
|
||||
const int16_t input_data[kNumChannels][kNumFrames] = {
|
||||
{30000, -5, -30000}, {30000, -10, -30999}, {24001, -20, -30000}};
|
||||
|
||||
@ -18,15 +18,15 @@ namespace {
|
||||
|
||||
// Adds |a| and |b| frame by frame into |result| (basically matrix addition).
|
||||
void AddFrames(const float* const* a,
|
||||
int a_start_index,
|
||||
size_t a_start_index,
|
||||
const float* const* b,
|
||||
int b_start_index,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
float* const* result,
|
||||
int result_start_index) {
|
||||
size_t result_start_index) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
for (int j = 0; j < num_frames; ++j) {
|
||||
for (size_t j = 0; j < num_frames; ++j) {
|
||||
result[i][j + result_start_index] =
|
||||
a[i][j + a_start_index] + b[i][j + b_start_index];
|
||||
}
|
||||
@ -35,11 +35,11 @@ void AddFrames(const float* const* a,
|
||||
|
||||
// Copies |src| into |dst| channel by channel.
|
||||
void CopyFrames(const float* const* src,
|
||||
int src_start_index,
|
||||
int num_frames,
|
||||
size_t src_start_index,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
float* const* dst,
|
||||
int dst_start_index) {
|
||||
size_t dst_start_index) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
memcpy(&dst[i][dst_start_index],
|
||||
&src[i][src_start_index],
|
||||
@ -49,11 +49,11 @@ void CopyFrames(const float* const* src,
|
||||
|
||||
// Moves |src| into |dst| channel by channel.
|
||||
void MoveFrames(const float* const* src,
|
||||
int src_start_index,
|
||||
int num_frames,
|
||||
size_t src_start_index,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
float* const* dst,
|
||||
int dst_start_index) {
|
||||
size_t dst_start_index) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
memmove(&dst[i][dst_start_index],
|
||||
&src[i][src_start_index],
|
||||
@ -62,8 +62,8 @@ void MoveFrames(const float* const* src,
|
||||
}
|
||||
|
||||
void ZeroOut(float* const* buffer,
|
||||
int starting_idx,
|
||||
int num_frames,
|
||||
size_t starting_idx,
|
||||
size_t num_frames,
|
||||
int num_channels) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
memset(&buffer[i][starting_idx], 0,
|
||||
@ -74,18 +74,18 @@ void ZeroOut(float* const* buffer,
|
||||
// Pointwise multiplies each channel of |frames| with |window|. Results are
|
||||
// stored in |frames|.
|
||||
void ApplyWindow(const float* window,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
float* const* frames) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
for (int j = 0; j < num_frames; ++j) {
|
||||
for (size_t j = 0; j < num_frames; ++j) {
|
||||
frames[i][j] = frames[i][j] * window[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int gcd(int a, int b) {
|
||||
int tmp;
|
||||
size_t gcd(size_t a, size_t b) {
|
||||
size_t tmp;
|
||||
while (b) {
|
||||
tmp = a;
|
||||
a = b;
|
||||
@ -98,12 +98,12 @@ int gcd(int a, int b) {
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
Blocker::Blocker(int chunk_size,
|
||||
int block_size,
|
||||
Blocker::Blocker(size_t chunk_size,
|
||||
size_t block_size,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
const float* window,
|
||||
int shift_amount,
|
||||
size_t shift_amount,
|
||||
BlockerCallback* callback)
|
||||
: chunk_size_(chunk_size),
|
||||
block_size_(block_size),
|
||||
@ -165,7 +165,7 @@ Blocker::Blocker(int chunk_size,
|
||||
//
|
||||
// TODO(claguna): Look at using ring buffers to eliminate some copies.
|
||||
void Blocker::ProcessChunk(const float* const* input,
|
||||
int chunk_size,
|
||||
size_t chunk_size,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) {
|
||||
@ -174,7 +174,7 @@ void Blocker::ProcessChunk(const float* const* input,
|
||||
CHECK_EQ(num_output_channels, num_output_channels_);
|
||||
|
||||
input_buffer_.Write(input, num_input_channels, chunk_size_);
|
||||
int first_frame_in_block = frame_offset_;
|
||||
size_t first_frame_in_block = frame_offset_;
|
||||
|
||||
// Loop through blocks.
|
||||
while (first_frame_in_block < chunk_size_) {
|
||||
|
||||
@ -25,7 +25,7 @@ class BlockerCallback {
|
||||
virtual ~BlockerCallback() {}
|
||||
|
||||
virtual void ProcessBlock(const float* const* input,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) = 0;
|
||||
@ -63,34 +63,34 @@ class BlockerCallback {
|
||||
// copy of window and does not attempt to delete it.
|
||||
class Blocker {
|
||||
public:
|
||||
Blocker(int chunk_size,
|
||||
int block_size,
|
||||
Blocker(size_t chunk_size,
|
||||
size_t block_size,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
const float* window,
|
||||
int shift_amount,
|
||||
size_t shift_amount,
|
||||
BlockerCallback* callback);
|
||||
|
||||
void ProcessChunk(const float* const* input,
|
||||
int chunk_size,
|
||||
size_t chunk_size,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output);
|
||||
|
||||
private:
|
||||
const int chunk_size_;
|
||||
const int block_size_;
|
||||
const size_t chunk_size_;
|
||||
const size_t block_size_;
|
||||
const int num_input_channels_;
|
||||
const int num_output_channels_;
|
||||
|
||||
// The number of frames of delay to add at the beginning of the first chunk.
|
||||
const int initial_delay_;
|
||||
const size_t initial_delay_;
|
||||
|
||||
// The frame index into the input buffer where the first block should be read
|
||||
// from. This is necessary because shift_amount_ is not necessarily a
|
||||
// multiple of chunk_size_, so blocks won't line up at the start of the
|
||||
// buffer.
|
||||
int frame_offset_;
|
||||
size_t frame_offset_;
|
||||
|
||||
// Since blocks nearly always overlap, there are certain blocks that require
|
||||
// frames from the end of one chunk and the beginning of the next chunk. The
|
||||
@ -113,7 +113,7 @@ class Blocker {
|
||||
|
||||
// The amount of frames between the start of contiguous blocks. For example,
|
||||
// |shift_amount_| = |block_size_| / 2 for a Hann window.
|
||||
int shift_amount_;
|
||||
size_t shift_amount_;
|
||||
|
||||
BlockerCallback* callback_;
|
||||
};
|
||||
|
||||
@ -18,12 +18,12 @@ namespace {
|
||||
class PlusThreeBlockerCallback : public webrtc::BlockerCallback {
|
||||
public:
|
||||
void ProcessBlock(const float* const* input,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) override {
|
||||
for (int i = 0; i < num_output_channels; ++i) {
|
||||
for (int j = 0; j < num_frames; ++j) {
|
||||
for (size_t j = 0; j < num_frames; ++j) {
|
||||
output[i][j] = input[i][j] + 3;
|
||||
}
|
||||
}
|
||||
@ -34,12 +34,12 @@ class PlusThreeBlockerCallback : public webrtc::BlockerCallback {
|
||||
class CopyBlockerCallback : public webrtc::BlockerCallback {
|
||||
public:
|
||||
void ProcessBlock(const float* const* input,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) override {
|
||||
for (int i = 0; i < num_output_channels; ++i) {
|
||||
for (int j = 0; j < num_frames; ++j) {
|
||||
for (size_t j = 0; j < num_frames; ++j) {
|
||||
output[i][j] = input[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,9 +12,9 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
IFChannelBuffer::IFChannelBuffer(int num_frames,
|
||||
IFChannelBuffer::IFChannelBuffer(size_t num_frames,
|
||||
int num_channels,
|
||||
int num_bands)
|
||||
size_t num_bands)
|
||||
: ivalid_(true),
|
||||
ibuf_(num_frames, num_channels, num_bands),
|
||||
fvalid_(true),
|
||||
@ -48,7 +48,7 @@ void IFChannelBuffer::RefreshF() const {
|
||||
const int16_t* const* int_channels = ibuf_.channels();
|
||||
float* const* float_channels = fbuf_.channels();
|
||||
for (int i = 0; i < ibuf_.num_channels(); ++i) {
|
||||
for (int j = 0; j < ibuf_.num_frames(); ++j) {
|
||||
for (size_t j = 0; j < ibuf_.num_frames(); ++j) {
|
||||
float_channels[i][j] = int_channels[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,9 +39,9 @@ namespace webrtc {
|
||||
template <typename T>
|
||||
class ChannelBuffer {
|
||||
public:
|
||||
ChannelBuffer(int num_frames,
|
||||
ChannelBuffer(size_t num_frames,
|
||||
int num_channels,
|
||||
int num_bands = 1)
|
||||
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]),
|
||||
@ -50,7 +50,7 @@ class ChannelBuffer {
|
||||
num_channels_(num_channels),
|
||||
num_bands_(num_bands) {
|
||||
for (int i = 0; i < num_channels_; ++i) {
|
||||
for (int j = 0; j < num_bands_; ++j) {
|
||||
for (size_t j = 0; j < num_bands_; ++j) {
|
||||
channels_[j * num_channels_ + i] =
|
||||
&data_[i * num_frames_ + j * num_frames_per_band_];
|
||||
bands_[i * num_bands_ + j] = channels_[j * num_channels_ + i];
|
||||
@ -74,12 +74,11 @@ class ChannelBuffer {
|
||||
// 0 <= band < |num_bands_|
|
||||
// 0 <= channel < |num_channels_|
|
||||
// 0 <= sample < |num_frames_per_band_|
|
||||
const T* const* channels(int band) const {
|
||||
const T* const* channels(size_t band) const {
|
||||
DCHECK_LT(band, num_bands_);
|
||||
DCHECK_GE(band, 0);
|
||||
return &channels_[band * num_channels_];
|
||||
}
|
||||
T* const* channels(int band) {
|
||||
T* const* channels(size_t band) {
|
||||
const ChannelBuffer<T>* t = this;
|
||||
return const_cast<T* const*>(t->channels(band));
|
||||
}
|
||||
@ -103,21 +102,21 @@ class ChannelBuffer {
|
||||
|
||||
// Sets the |slice| pointers to the |start_frame| position for each channel.
|
||||
// Returns |slice| for convenience.
|
||||
const T* const* Slice(T** slice, int start_frame) const {
|
||||
const T* const* Slice(T** slice, size_t start_frame) const {
|
||||
DCHECK_LT(start_frame, num_frames_);
|
||||
for (int i = 0; i < num_channels_; ++i)
|
||||
slice[i] = &channels_[i][start_frame];
|
||||
return slice;
|
||||
}
|
||||
T** Slice(T** slice, int start_frame) {
|
||||
T** Slice(T** slice, size_t start_frame) {
|
||||
const ChannelBuffer<T>* t = this;
|
||||
return const_cast<T**>(t->Slice(slice, start_frame));
|
||||
}
|
||||
|
||||
int num_frames() const { return num_frames_; }
|
||||
int num_frames_per_band() const { return num_frames_per_band_; }
|
||||
size_t num_frames() const { return num_frames_; }
|
||||
size_t num_frames_per_band() const { return num_frames_per_band_; }
|
||||
int num_channels() const { return num_channels_; }
|
||||
int num_bands() const { return num_bands_; }
|
||||
size_t num_bands() const { return num_bands_; }
|
||||
size_t size() const {return num_frames_ * num_channels_; }
|
||||
|
||||
void SetDataForTesting(const T* data, size_t size) {
|
||||
@ -129,10 +128,10 @@ class ChannelBuffer {
|
||||
rtc::scoped_ptr<T[]> data_;
|
||||
rtc::scoped_ptr<T* []> channels_;
|
||||
rtc::scoped_ptr<T* []> bands_;
|
||||
const int num_frames_;
|
||||
const int num_frames_per_band_;
|
||||
const size_t num_frames_;
|
||||
const size_t num_frames_per_band_;
|
||||
const int num_channels_;
|
||||
const int num_bands_;
|
||||
const size_t num_bands_;
|
||||
};
|
||||
|
||||
// One int16_t and one float ChannelBuffer that are kept in sync. The sync is
|
||||
@ -143,17 +142,17 @@ class ChannelBuffer {
|
||||
// fbuf() until the next call to any of the other functions.
|
||||
class IFChannelBuffer {
|
||||
public:
|
||||
IFChannelBuffer(int num_frames, int num_channels, int num_bands = 1);
|
||||
IFChannelBuffer(size_t num_frames, int num_channels, size_t num_bands = 1);
|
||||
|
||||
ChannelBuffer<int16_t>* ibuf();
|
||||
ChannelBuffer<float>* fbuf();
|
||||
const ChannelBuffer<int16_t>* ibuf_const() const;
|
||||
const ChannelBuffer<float>* fbuf_const() const;
|
||||
|
||||
int num_frames() const { return ibuf_.num_frames(); }
|
||||
int num_frames_per_band() const { return ibuf_.num_frames_per_band(); }
|
||||
size_t num_frames() const { return ibuf_.num_frames(); }
|
||||
size_t num_frames_per_band() const { return ibuf_.num_frames_per_band(); }
|
||||
int num_channels() const { return ibuf_.num_channels(); }
|
||||
int num_bands() const { return ibuf_.num_bands(); }
|
||||
size_t num_bands() const { return ibuf_.num_bands(); }
|
||||
|
||||
private:
|
||||
void RefreshF() const;
|
||||
|
||||
@ -27,7 +27,7 @@ functions
|
||||
dfst: Sine Transform of RDFT (Real Anti-symmetric DFT)
|
||||
function prototypes
|
||||
void cdft(int, int, float *, int *, float *);
|
||||
void rdft(int, int, float *, int *, float *);
|
||||
void rdft(size_t, int, float *, size_t *, float *);
|
||||
void ddct(int, int, float *, int *, float *);
|
||||
void ddst(int, int, float *, int *, float *);
|
||||
void dfct(int, float *, float *, int *, float *);
|
||||
@ -94,7 +94,7 @@ function prototypes
|
||||
ip[0] = 0; // first time only
|
||||
rdft(n, -1, a, ip, w);
|
||||
[parameters]
|
||||
n :data length (int)
|
||||
n :data length (size_t)
|
||||
n >= 2, n = power of 2
|
||||
a[0...n-1] :input/output data (float *)
|
||||
<case1>
|
||||
@ -107,7 +107,7 @@ function prototypes
|
||||
a[2*j] = R[j], 0<=j<n/2
|
||||
a[2*j+1] = I[j], 0<j<n/2
|
||||
a[1] = R[n/2]
|
||||
ip[0...*] :work area for bit reversal (int *)
|
||||
ip[0...*] :work area for bit reversal (size_t *)
|
||||
length of ip >= 2+sqrt(n/2)
|
||||
strictly,
|
||||
length of ip >=
|
||||
@ -286,18 +286,20 @@ Appendix :
|
||||
w[] and ip[] are compatible with all routines.
|
||||
*/
|
||||
|
||||
static void makewt(int nw, int *ip, float *w);
|
||||
static void makect(int nc, int *ip, float *c);
|
||||
static void bitrv2(int n, int *ip, float *a);
|
||||
#include <stddef.h>
|
||||
|
||||
static void makewt(size_t nw, size_t *ip, float *w);
|
||||
static void makect(size_t nc, size_t *ip, float *c);
|
||||
static void bitrv2(size_t n, size_t *ip, float *a);
|
||||
#if 0 // Not used.
|
||||
static void bitrv2conj(int n, int *ip, float *a);
|
||||
#endif
|
||||
static void cftfsub(int n, float *a, float *w);
|
||||
static void cftbsub(int n, float *a, float *w);
|
||||
static void cft1st(int n, float *a, float *w);
|
||||
static void cftmdl(int n, int l, float *a, float *w);
|
||||
static void rftfsub(int n, float *a, int nc, float *c);
|
||||
static void rftbsub(int n, float *a, int nc, float *c);
|
||||
static void cftfsub(size_t n, float *a, float *w);
|
||||
static void cftbsub(size_t n, float *a, float *w);
|
||||
static void cft1st(size_t n, float *a, float *w);
|
||||
static void cftmdl(size_t n, size_t l, float *a, float *w);
|
||||
static void rftfsub(size_t n, float *a, size_t nc, float *c);
|
||||
static void rftbsub(size_t n, float *a, size_t nc, float *c);
|
||||
#if 0 // Not used.
|
||||
static void dctsub(int n, float *a, int nc, float *c)
|
||||
static void dstsub(int n, float *a, int nc, float *c)
|
||||
@ -325,9 +327,9 @@ void WebRtc_cdft(int n, int isgn, float *a, int *ip, float *w)
|
||||
#endif
|
||||
|
||||
|
||||
void WebRtc_rdft(int n, int isgn, float *a, int *ip, float *w)
|
||||
void WebRtc_rdft(size_t n, int isgn, float *a, size_t *ip, float *w)
|
||||
{
|
||||
int nw, nc;
|
||||
size_t nw, nc;
|
||||
float xi;
|
||||
|
||||
nw = ip[0];
|
||||
@ -643,9 +645,9 @@ static void dfst(int n, float *a, float *t, int *ip, float *w)
|
||||
|
||||
#include <math.h>
|
||||
|
||||
static void makewt(int nw, int *ip, float *w)
|
||||
static void makewt(size_t nw, size_t *ip, float *w)
|
||||
{
|
||||
int j, nwh;
|
||||
size_t j, nwh;
|
||||
float delta, x, y;
|
||||
|
||||
ip[0] = nw;
|
||||
@ -672,9 +674,9 @@ static void makewt(int nw, int *ip, float *w)
|
||||
}
|
||||
|
||||
|
||||
static void makect(int nc, int *ip, float *c)
|
||||
static void makect(size_t nc, size_t *ip, float *c)
|
||||
{
|
||||
int j, nch;
|
||||
size_t j, nch;
|
||||
float delta;
|
||||
|
||||
ip[1] = nc;
|
||||
@ -694,9 +696,9 @@ static void makect(int nc, int *ip, float *c)
|
||||
/* -------- child routines -------- */
|
||||
|
||||
|
||||
static void bitrv2(int n, int *ip, float *a)
|
||||
static void bitrv2(size_t n, size_t *ip, float *a)
|
||||
{
|
||||
int j, j1, k, k1, l, m, m2;
|
||||
size_t j, j1, k, k1, l, m, m2;
|
||||
float xr, xi, yr, yi;
|
||||
|
||||
ip[0] = 0;
|
||||
@ -903,9 +905,9 @@ static void bitrv2conj(int n, int *ip, float *a)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void cftfsub(int n, float *a, float *w)
|
||||
static void cftfsub(size_t n, float *a, float *w)
|
||||
{
|
||||
int j, j1, j2, j3, l;
|
||||
size_t j, j1, j2, j3, l;
|
||||
float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||
|
||||
l = 2;
|
||||
@ -953,9 +955,9 @@ static void cftfsub(int n, float *a, float *w)
|
||||
}
|
||||
|
||||
|
||||
static void cftbsub(int n, float *a, float *w)
|
||||
static void cftbsub(size_t n, float *a, float *w)
|
||||
{
|
||||
int j, j1, j2, j3, l;
|
||||
size_t j, j1, j2, j3, l;
|
||||
float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||
|
||||
l = 2;
|
||||
@ -1003,9 +1005,9 @@ static void cftbsub(int n, float *a, float *w)
|
||||
}
|
||||
|
||||
|
||||
static void cft1st(int n, float *a, float *w)
|
||||
static void cft1st(size_t n, float *a, float *w)
|
||||
{
|
||||
int j, k1, k2;
|
||||
size_t j, k1, k2;
|
||||
float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
||||
float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||
|
||||
@ -1108,9 +1110,9 @@ static void cft1st(int n, float *a, float *w)
|
||||
}
|
||||
|
||||
|
||||
static void cftmdl(int n, int l, float *a, float *w)
|
||||
static void cftmdl(size_t n, size_t l, float *a, float *w)
|
||||
{
|
||||
int j, j1, j2, j3, k, k1, k2, m, m2;
|
||||
size_t j, j1, j2, j3, k, k1, k2, m, m2;
|
||||
float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
|
||||
float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
|
||||
|
||||
@ -1235,9 +1237,9 @@ static void cftmdl(int n, int l, float *a, float *w)
|
||||
}
|
||||
|
||||
|
||||
static void rftfsub(int n, float *a, int nc, float *c)
|
||||
static void rftfsub(size_t n, float *a, size_t nc, float *c)
|
||||
{
|
||||
int j, k, kk, ks, m;
|
||||
size_t j, k, kk, ks, m;
|
||||
float wkr, wki, xr, xi, yr, yi;
|
||||
|
||||
m = n >> 1;
|
||||
@ -1260,9 +1262,9 @@ static void rftfsub(int n, float *a, int nc, float *c)
|
||||
}
|
||||
|
||||
|
||||
static void rftbsub(int n, float *a, int nc, float *c)
|
||||
static void rftbsub(size_t n, float *a, size_t nc, float *c)
|
||||
{
|
||||
int j, k, kk, ks, m;
|
||||
size_t j, k, kk, ks, m;
|
||||
float wkr, wki, xr, xi, yr, yi;
|
||||
|
||||
a[1] = -a[1];
|
||||
|
||||
@ -16,7 +16,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Refer to fft4g.c for documentation.
|
||||
void WebRtc_rdft(int n, int isgn, float *a, int *ip, float *w);
|
||||
void WebRtc_rdft(size_t n, int isgn, float *a, size_t *ip, float *w);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@ -86,13 +86,13 @@ void CopyAudioIfNeeded(const T* const* src,
|
||||
// per buffer).
|
||||
template <typename T>
|
||||
void Deinterleave(const T* interleaved,
|
||||
int samples_per_channel,
|
||||
size_t samples_per_channel,
|
||||
int num_channels,
|
||||
T* const* deinterleaved) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
T* channel = deinterleaved[i];
|
||||
int interleaved_idx = i;
|
||||
for (int j = 0; j < samples_per_channel; ++j) {
|
||||
for (size_t j = 0; j < samples_per_channel; ++j) {
|
||||
channel[j] = interleaved[interleaved_idx];
|
||||
interleaved_idx += num_channels;
|
||||
}
|
||||
@ -104,13 +104,13 @@ void Deinterleave(const T* interleaved,
|
||||
// (|samples_per_channel| * |num_channels|).
|
||||
template <typename T>
|
||||
void Interleave(const T* const* deinterleaved,
|
||||
int samples_per_channel,
|
||||
size_t samples_per_channel,
|
||||
int num_channels,
|
||||
T* interleaved) {
|
||||
for (int i = 0; i < num_channels; ++i) {
|
||||
const T* channel = deinterleaved[i];
|
||||
int interleaved_idx = i;
|
||||
for (int j = 0; j < samples_per_channel; ++j) {
|
||||
for (size_t j = 0; j < samples_per_channel; ++j) {
|
||||
interleaved[interleaved_idx] = channel[j];
|
||||
interleaved_idx += num_channels;
|
||||
}
|
||||
@ -135,10 +135,10 @@ void UpmixMonoToInterleaved(const T* mono,
|
||||
|
||||
template <typename T, typename Intermediate>
|
||||
void DownmixToMono(const T* const* input_channels,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
T* out) {
|
||||
for (int i = 0; i < num_frames; ++i) {
|
||||
for (size_t i = 0; i < num_frames; ++i) {
|
||||
Intermediate value = input_channels[0][i];
|
||||
for (int j = 1; j < num_channels; ++j) {
|
||||
value += input_channels[j][i];
|
||||
@ -151,11 +151,11 @@ void DownmixToMono(const T* const* input_channels,
|
||||
// all channels.
|
||||
template <typename T, typename Intermediate>
|
||||
void DownmixInterleavedToMonoImpl(const T* interleaved,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
T* deinterleaved) {
|
||||
DCHECK_GT(num_channels, 0);
|
||||
DCHECK_GT(num_frames, 0);
|
||||
DCHECK_GT(num_frames, 0u);
|
||||
|
||||
const T* const end = interleaved + num_frames * num_channels;
|
||||
|
||||
@ -173,13 +173,13 @@ void DownmixInterleavedToMonoImpl(const T* interleaved,
|
||||
|
||||
template <typename T>
|
||||
void DownmixInterleavedToMono(const T* interleaved,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
T* deinterleaved);
|
||||
|
||||
template <>
|
||||
void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_channels,
|
||||
int16_t* deinterleaved);
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
namespace webrtc {
|
||||
|
||||
void LappedTransform::BlockThunk::ProcessBlock(const float* const* input,
|
||||
int num_frames,
|
||||
size_t num_frames,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) {
|
||||
@ -35,7 +35,7 @@ void LappedTransform::BlockThunk::ProcessBlock(const float* const* input,
|
||||
parent_->cplx_pre_.Row(i));
|
||||
}
|
||||
|
||||
int block_length = RealFourier::ComplexLength(
|
||||
size_t block_length = RealFourier::ComplexLength(
|
||||
RealFourier::FftOrder(num_frames));
|
||||
CHECK_EQ(parent_->cplx_length_, block_length);
|
||||
parent_->block_processor_->ProcessAudioBlock(parent_->cplx_pre_.Array(),
|
||||
@ -54,10 +54,10 @@ void LappedTransform::BlockThunk::ProcessBlock(const float* const* input,
|
||||
|
||||
LappedTransform::LappedTransform(int num_in_channels,
|
||||
int num_out_channels,
|
||||
int chunk_length,
|
||||
size_t chunk_length,
|
||||
const float* window,
|
||||
int block_length,
|
||||
int shift_amount,
|
||||
size_t block_length,
|
||||
size_t shift_amount,
|
||||
Callback* callback)
|
||||
: blocker_callback_(this),
|
||||
num_in_channels_(num_in_channels),
|
||||
@ -84,12 +84,12 @@ LappedTransform::LappedTransform(int num_in_channels,
|
||||
cplx_length_,
|
||||
RealFourier::kFftBufferAlignment) {
|
||||
CHECK(num_in_channels_ > 0 && num_out_channels_ > 0);
|
||||
CHECK_GT(block_length_, 0);
|
||||
CHECK_GT(chunk_length_, 0);
|
||||
CHECK_GT(block_length_, 0u);
|
||||
CHECK_GT(chunk_length_, 0u);
|
||||
CHECK(block_processor_);
|
||||
|
||||
// block_length_ power of 2?
|
||||
CHECK_EQ(0, block_length_ & (block_length_ - 1));
|
||||
CHECK_EQ(0u, block_length_ & (block_length_ - 1));
|
||||
}
|
||||
|
||||
void LappedTransform::ProcessChunk(const float* const* in_chunk,
|
||||
|
||||
@ -35,7 +35,7 @@ class LappedTransform {
|
||||
virtual ~Callback() {}
|
||||
|
||||
virtual void ProcessAudioBlock(const std::complex<float>* const* in_block,
|
||||
int num_in_channels, int frames,
|
||||
int num_in_channels, size_t frames,
|
||||
int num_out_channels,
|
||||
std::complex<float>* const* out_block) = 0;
|
||||
};
|
||||
@ -46,8 +46,12 @@ class LappedTransform {
|
||||
// |block_length| defines the length of a block, in samples.
|
||||
// |shift_amount| is in samples. |callback| is the caller-owned audio
|
||||
// processing function called for each block of the input chunk.
|
||||
LappedTransform(int num_in_channels, int num_out_channels, int chunk_length,
|
||||
const float* window, int block_length, int shift_amount,
|
||||
LappedTransform(int num_in_channels,
|
||||
int num_out_channels,
|
||||
size_t chunk_length,
|
||||
const float* window,
|
||||
size_t block_length,
|
||||
size_t shift_amount,
|
||||
Callback* callback);
|
||||
~LappedTransform() {}
|
||||
|
||||
@ -63,7 +67,7 @@ class LappedTransform {
|
||||
// to ProcessChunk via the parameter in_chunk.
|
||||
//
|
||||
// Returns the same chunk_length passed to the LappedTransform constructor.
|
||||
int chunk_length() const { return chunk_length_; }
|
||||
size_t chunk_length() const { return chunk_length_; }
|
||||
|
||||
// Get the number of input channels.
|
||||
//
|
||||
@ -89,7 +93,7 @@ class LappedTransform {
|
||||
public:
|
||||
explicit BlockThunk(LappedTransform* parent) : parent_(parent) {}
|
||||
|
||||
virtual void ProcessBlock(const float* const* input, int num_frames,
|
||||
virtual void ProcessBlock(const float* const* input, size_t num_frames,
|
||||
int num_input_channels, int num_output_channels,
|
||||
float* const* output);
|
||||
|
||||
@ -100,14 +104,14 @@ class LappedTransform {
|
||||
const int num_in_channels_;
|
||||
const int num_out_channels_;
|
||||
|
||||
const int block_length_;
|
||||
const int chunk_length_;
|
||||
const size_t block_length_;
|
||||
const size_t chunk_length_;
|
||||
|
||||
Callback* const block_processor_;
|
||||
Blocker blocker_;
|
||||
|
||||
rtc::scoped_ptr<RealFourier> fft_;
|
||||
const int cplx_length_;
|
||||
const size_t cplx_length_;
|
||||
AlignedArray<float> real_buf_;
|
||||
AlignedArray<std::complex<float> > cplx_pre_;
|
||||
AlignedArray<std::complex<float> > cplx_post_;
|
||||
|
||||
@ -26,7 +26,7 @@ class NoopCallback : public webrtc::LappedTransform::Callback {
|
||||
|
||||
virtual void ProcessAudioBlock(const complex<float>* const* in_block,
|
||||
int in_channels,
|
||||
int frames,
|
||||
size_t frames,
|
||||
int out_channels,
|
||||
complex<float>* const* out_block) {
|
||||
CHECK_EQ(in_channels, out_channels);
|
||||
@ -50,19 +50,19 @@ class FftCheckerCallback : public webrtc::LappedTransform::Callback {
|
||||
|
||||
virtual void ProcessAudioBlock(const complex<float>* const* in_block,
|
||||
int in_channels,
|
||||
int frames,
|
||||
size_t frames,
|
||||
int out_channels,
|
||||
complex<float>* const* out_block) {
|
||||
CHECK_EQ(in_channels, out_channels);
|
||||
|
||||
int full_length = (frames - 1) * 2;
|
||||
size_t full_length = (frames - 1) * 2;
|
||||
++block_num_;
|
||||
|
||||
if (block_num_ > 0) {
|
||||
ASSERT_NEAR(in_block[0][0].real(), static_cast<float>(full_length),
|
||||
1e-5f);
|
||||
ASSERT_NEAR(in_block[0][0].imag(), 0.0f, 1e-5f);
|
||||
for (int i = 1; i < frames; ++i) {
|
||||
for (size_t i = 1; i < frames; ++i) {
|
||||
ASSERT_NEAR(in_block[0][i].real(), 0.0f, 1e-5f);
|
||||
ASSERT_NEAR(in_block[0][i].imag(), 0.0f, 1e-5f);
|
||||
}
|
||||
@ -190,14 +190,14 @@ TEST(LappedTransformTest, chunk_length) {
|
||||
// Make sure that chunk_length returns the same value passed to the
|
||||
// LappedTransform constructor.
|
||||
{
|
||||
const int kExpectedChunkLength = 512;
|
||||
const size_t kExpectedChunkLength = 512;
|
||||
const LappedTransform trans(1, 1, kExpectedChunkLength, window,
|
||||
kBlockLength, kBlockLength, &call);
|
||||
|
||||
EXPECT_EQ(kExpectedChunkLength, trans.chunk_length());
|
||||
}
|
||||
{
|
||||
const int kExpectedChunkLength = 160;
|
||||
const size_t kExpectedChunkLength = 160;
|
||||
const LappedTransform trans(1, 1, kExpectedChunkLength, window,
|
||||
kBlockLength, kBlockLength, &call);
|
||||
|
||||
|
||||
@ -29,17 +29,17 @@ rtc::scoped_ptr<RealFourier> RealFourier::Create(int fft_order) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int RealFourier::FftOrder(int length) {
|
||||
CHECK_GT(length, 0);
|
||||
int RealFourier::FftOrder(size_t length) {
|
||||
CHECK_GT(length, 0U);
|
||||
return WebRtcSpl_GetSizeInBits(static_cast<uint32_t>(length - 1));
|
||||
}
|
||||
|
||||
int RealFourier::FftLength(int order) {
|
||||
size_t RealFourier::FftLength(int order) {
|
||||
CHECK_GE(order, 0);
|
||||
return 1 << order;
|
||||
return static_cast<size_t>(1 << order);
|
||||
}
|
||||
|
||||
int RealFourier::ComplexLength(int order) {
|
||||
size_t RealFourier::ComplexLength(int order) {
|
||||
return FftLength(order) / 2 + 1;
|
||||
}
|
||||
|
||||
|
||||
@ -39,14 +39,14 @@ class RealFourier {
|
||||
|
||||
// Helper to compute the smallest FFT order (a power of 2) which will contain
|
||||
// the given input length.
|
||||
static int FftOrder(int length);
|
||||
static int FftOrder(size_t length);
|
||||
|
||||
// Helper to compute the input length from the FFT order.
|
||||
static int FftLength(int order);
|
||||
static size_t FftLength(int order);
|
||||
|
||||
// Helper to compute the exact length, in complex floats, of the transform
|
||||
// output (i.e. |2^order / 2 + 1|).
|
||||
static int ComplexLength(int order);
|
||||
static size_t ComplexLength(int order);
|
||||
|
||||
// Buffer allocation helpers. The buffers are large enough to hold |count|
|
||||
// floats/complexes and suitably aligned for use by the implementation.
|
||||
|
||||
@ -22,12 +22,12 @@ using std::complex;
|
||||
|
||||
namespace {
|
||||
|
||||
void Conjugate(complex<float>* array, int complex_length) {
|
||||
void Conjugate(complex<float>* array, size_t complex_length) {
|
||||
std::for_each(array, array + complex_length,
|
||||
[=](complex<float>& v) { v = std::conj(v); });
|
||||
}
|
||||
|
||||
size_t ComputeWorkIpSize(int fft_length) {
|
||||
size_t ComputeWorkIpSize(size_t fft_length) {
|
||||
return static_cast<size_t>(2 + std::ceil(std::sqrt(
|
||||
static_cast<float>(fft_length))));
|
||||
}
|
||||
@ -40,7 +40,7 @@ RealFourierOoura::RealFourierOoura(int fft_order)
|
||||
complex_length_(ComplexLength(order_)),
|
||||
// Zero-initializing work_ip_ will cause rdft to initialize these work
|
||||
// arrays on the first call.
|
||||
work_ip_(new int[ComputeWorkIpSize(length_)]()),
|
||||
work_ip_(new size_t[ComputeWorkIpSize(length_)]()),
|
||||
work_w_(new float[complex_length_]()) {
|
||||
CHECK_GE(fft_order, 1);
|
||||
}
|
||||
@ -66,7 +66,7 @@ void RealFourierOoura::Inverse(const complex<float>* src, float* dest) const {
|
||||
auto dest_complex = reinterpret_cast<complex<float>*>(dest);
|
||||
// The real output array is shorter than the input complex array by one
|
||||
// complex element.
|
||||
const int dest_complex_length = complex_length_ - 1;
|
||||
const size_t dest_complex_length = complex_length_ - 1;
|
||||
std::copy(src, src + dest_complex_length, dest_complex);
|
||||
// Restore Ooura's conjugate definition.
|
||||
Conjugate(dest_complex, dest_complex_length);
|
||||
|
||||
@ -31,11 +31,11 @@ class RealFourierOoura : public RealFourier {
|
||||
|
||||
private:
|
||||
const int order_;
|
||||
const int length_;
|
||||
const int complex_length_;
|
||||
const size_t length_;
|
||||
const size_t complex_length_;
|
||||
// These are work arrays for Ooura. The names are based on the comments in
|
||||
// fft4g.c.
|
||||
const rtc::scoped_ptr<int[]> work_ip_;
|
||||
const rtc::scoped_ptr<size_t[]> work_ip_;
|
||||
const rtc::scoped_ptr<float[]> work_w_;
|
||||
};
|
||||
|
||||
|
||||
@ -46,12 +46,12 @@ TEST(RealFourierStaticsTest, OrderComputation) {
|
||||
}
|
||||
|
||||
TEST(RealFourierStaticsTest, ComplexLengthComputation) {
|
||||
EXPECT_EQ(2, RealFourier::ComplexLength(1));
|
||||
EXPECT_EQ(3, RealFourier::ComplexLength(2));
|
||||
EXPECT_EQ(5, RealFourier::ComplexLength(3));
|
||||
EXPECT_EQ(9, RealFourier::ComplexLength(4));
|
||||
EXPECT_EQ(17, RealFourier::ComplexLength(5));
|
||||
EXPECT_EQ(65, RealFourier::ComplexLength(7));
|
||||
EXPECT_EQ(2U, RealFourier::ComplexLength(1));
|
||||
EXPECT_EQ(3U, RealFourier::ComplexLength(2));
|
||||
EXPECT_EQ(5U, RealFourier::ComplexLength(3));
|
||||
EXPECT_EQ(9U, RealFourier::ComplexLength(4));
|
||||
EXPECT_EQ(17U, RealFourier::ComplexLength(5));
|
||||
EXPECT_EQ(65U, RealFourier::ComplexLength(7));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@ -33,7 +33,7 @@ class PushResampler {
|
||||
|
||||
// Returns the total number of samples provided in destination (e.g. 32 kHz,
|
||||
// 2 channel audio gives 640 samples).
|
||||
int Resample(const T* src, int src_length, T* dst, int dst_capacity);
|
||||
int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity);
|
||||
|
||||
private:
|
||||
rtc::scoped_ptr<PushSincResampler> sinc_resampler_;
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
#ifndef WEBRTC_RESAMPLER_RESAMPLER_H_
|
||||
#define WEBRTC_RESAMPLER_RESAMPLER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -36,8 +38,8 @@ public:
|
||||
int ResetIfNeeded(int inFreq, int outFreq, int num_channels);
|
||||
|
||||
// Resample samplesIn to samplesOut.
|
||||
int Push(const int16_t* samplesIn, int lengthIn, int16_t* samplesOut,
|
||||
int maxLen, int &outLen);
|
||||
int Push(const int16_t* samplesIn, size_t lengthIn, int16_t* samplesOut,
|
||||
size_t maxLen, size_t &outLen);
|
||||
|
||||
private:
|
||||
enum ResamplerMode
|
||||
@ -73,10 +75,10 @@ private:
|
||||
// Storage if needed
|
||||
int16_t* in_buffer_;
|
||||
int16_t* out_buffer_;
|
||||
int in_buffer_size_;
|
||||
int out_buffer_size_;
|
||||
int in_buffer_size_max_;
|
||||
int out_buffer_size_max_;
|
||||
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_;
|
||||
|
||||
@ -47,8 +47,10 @@ int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz,
|
||||
dst_sample_rate_hz_ = dst_sample_rate_hz;
|
||||
num_channels_ = num_channels;
|
||||
|
||||
const int src_size_10ms_mono = src_sample_rate_hz / 100;
|
||||
const int dst_size_10ms_mono = dst_sample_rate_hz / 100;
|
||||
const size_t src_size_10ms_mono =
|
||||
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));
|
||||
if (num_channels_ == 2) {
|
||||
@ -64,10 +66,12 @@ int PushResampler<T>::InitializeIfNeeded(int src_sample_rate_hz,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int PushResampler<T>::Resample(const T* src, int src_length, T* dst,
|
||||
int dst_capacity) {
|
||||
const int src_size_10ms = src_sample_rate_hz_ * num_channels_ / 100;
|
||||
const int dst_size_10ms = dst_sample_rate_hz_ * num_channels_ / 100;
|
||||
int PushResampler<T>::Resample(const T* src, size_t src_length, T* dst,
|
||||
size_t dst_capacity) {
|
||||
const size_t src_size_10ms =
|
||||
static_cast<size_t>(src_sample_rate_hz_ * num_channels_ / 100);
|
||||
const size_t dst_size_10ms =
|
||||
static_cast<size_t>(dst_sample_rate_hz_ * num_channels_ / 100);
|
||||
if (src_length != src_size_10ms || dst_capacity < dst_size_10ms)
|
||||
return -1;
|
||||
|
||||
@ -75,15 +79,15 @@ int PushResampler<T>::Resample(const T* src, int src_length, T* dst,
|
||||
// The old resampler provides this memcpy facility in the case of matching
|
||||
// sample rates, so reproduce it here for the sinc resampler.
|
||||
memcpy(dst, src, src_length * sizeof(T));
|
||||
return src_length;
|
||||
return static_cast<int>(src_length);
|
||||
}
|
||||
if (num_channels_ == 2) {
|
||||
const int src_length_mono = src_length / num_channels_;
|
||||
const int dst_capacity_mono = dst_capacity / num_channels_;
|
||||
const size_t src_length_mono = src_length / num_channels_;
|
||||
const size_t dst_capacity_mono = dst_capacity / num_channels_;
|
||||
T* deinterleaved[] = {src_left_.get(), src_right_.get()};
|
||||
Deinterleave(src, src_length_mono, num_channels_, deinterleaved);
|
||||
|
||||
int dst_length_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,
|
||||
@ -92,9 +96,10 @@ int PushResampler<T>::Resample(const T* src, int src_length, T* dst,
|
||||
deinterleaved[0] = dst_left_.get();
|
||||
deinterleaved[1] = dst_right_.get();
|
||||
Interleave(deinterleaved, dst_length_mono, num_channels_, dst);
|
||||
return dst_length_mono * num_channels_;
|
||||
return static_cast<int>(dst_length_mono * num_channels_);
|
||||
} else {
|
||||
return sinc_resampler_->Resample(src, src_length, dst, dst_capacity);
|
||||
return static_cast<int>(
|
||||
sinc_resampler_->Resample(src, src_length, dst, dst_capacity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
PushSincResampler::PushSincResampler(int source_frames, int destination_frames)
|
||||
PushSincResampler::PushSincResampler(size_t source_frames,
|
||||
size_t destination_frames)
|
||||
: resampler_(new SincResampler(source_frames * 1.0 / destination_frames,
|
||||
source_frames,
|
||||
this)),
|
||||
@ -30,10 +31,10 @@ PushSincResampler::PushSincResampler(int source_frames, int destination_frames)
|
||||
PushSincResampler::~PushSincResampler() {
|
||||
}
|
||||
|
||||
int PushSincResampler::Resample(const int16_t* source,
|
||||
int source_length,
|
||||
int16_t* destination,
|
||||
int destination_capacity) {
|
||||
size_t PushSincResampler::Resample(const int16_t* source,
|
||||
size_t source_length,
|
||||
int16_t* destination,
|
||||
size_t destination_capacity) {
|
||||
if (!float_buffer_.get())
|
||||
float_buffer_.reset(new float[destination_frames_]);
|
||||
|
||||
@ -45,10 +46,10 @@ int PushSincResampler::Resample(const int16_t* source,
|
||||
return destination_frames_;
|
||||
}
|
||||
|
||||
int PushSincResampler::Resample(const float* source,
|
||||
int source_length,
|
||||
float* destination,
|
||||
int destination_capacity) {
|
||||
size_t PushSincResampler::Resample(const float* source,
|
||||
size_t source_length,
|
||||
float* destination,
|
||||
size_t destination_capacity) {
|
||||
CHECK_EQ(source_length, resampler_->request_frames());
|
||||
CHECK_GE(destination_capacity, destination_frames_);
|
||||
// Cache the source pointer. Calling Resample() will immediately trigger
|
||||
@ -77,7 +78,7 @@ int PushSincResampler::Resample(const float* source,
|
||||
return destination_frames_;
|
||||
}
|
||||
|
||||
void PushSincResampler::Run(int frames, float* destination) {
|
||||
void PushSincResampler::Run(size_t frames, float* destination) {
|
||||
// Ensure we are only asked for the available samples. This would fail if
|
||||
// Run() was triggered more than once per Resample() call.
|
||||
CHECK_EQ(source_available_, frames);
|
||||
@ -93,7 +94,7 @@ void PushSincResampler::Run(int frames, float* destination) {
|
||||
if (source_ptr_) {
|
||||
std::memcpy(destination, source_ptr_, frames * sizeof(*destination));
|
||||
} else {
|
||||
for (int i = 0; i < frames; ++i)
|
||||
for (size_t i = 0; i < frames; ++i)
|
||||
destination[i] = static_cast<float>(source_ptr_int_[i]);
|
||||
}
|
||||
source_available_ -= frames;
|
||||
|
||||
@ -27,7 +27,7 @@ class PushSincResampler : public SincResamplerCallback {
|
||||
// Provide the size of the source and destination blocks in samples. These
|
||||
// must correspond to the same time duration (typically 10 ms) as the sample
|
||||
// ratio is inferred from them.
|
||||
PushSincResampler(int source_frames, int destination_frames);
|
||||
PushSincResampler(size_t source_frames, size_t destination_frames);
|
||||
~PushSincResampler() override;
|
||||
|
||||
// Perform the resampling. |source_frames| must always equal the
|
||||
@ -35,12 +35,12 @@ 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|).
|
||||
int Resample(const int16_t* source, int source_frames,
|
||||
int16_t* destination, int destination_capacity);
|
||||
int Resample(const float* source,
|
||||
int source_frames,
|
||||
float* destination,
|
||||
int 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,
|
||||
size_t destination_capacity);
|
||||
|
||||
// Delay due to the filter kernel. Essentially, the time after which an input
|
||||
// sample will appear in the resampled output.
|
||||
@ -50,7 +50,7 @@ class PushSincResampler : public SincResamplerCallback {
|
||||
|
||||
protected:
|
||||
// Implements SincResamplerCallback.
|
||||
void Run(int frames, float* destination) override;
|
||||
void Run(size_t frames, float* destination) override;
|
||||
|
||||
private:
|
||||
friend class PushSincResamplerTest;
|
||||
@ -60,13 +60,13 @@ class PushSincResampler : public SincResamplerCallback {
|
||||
rtc::scoped_ptr<float[]> float_buffer_;
|
||||
const float* source_ptr_;
|
||||
const int16_t* source_ptr_int_;
|
||||
const int destination_frames_;
|
||||
const size_t destination_frames_;
|
||||
|
||||
// True on the first call to Resample(), to prime the SincResampler buffer.
|
||||
bool first_pass_;
|
||||
|
||||
// Used to assert we are only requested for as much data as is available.
|
||||
int source_available_;
|
||||
size_t source_available_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PushSincResampler);
|
||||
};
|
||||
|
||||
@ -58,14 +58,14 @@ class PushSincResamplerTest : public ::testing::TestWithParam<
|
||||
|
||||
class ZeroSource : public SincResamplerCallback {
|
||||
public:
|
||||
void Run(int frames, float* destination) {
|
||||
void Run(size_t frames, float* destination) {
|
||||
std::memset(destination, 0, sizeof(float) * frames);
|
||||
}
|
||||
};
|
||||
|
||||
void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) {
|
||||
const int input_samples = input_rate_ / 100;
|
||||
const int output_samples = output_rate_ / 100;
|
||||
const size_t input_samples = static_cast<size_t>(input_rate_ / 100);
|
||||
const size_t output_samples = static_cast<size_t>(output_rate_ / 100);
|
||||
const int kResampleIterations = 500000;
|
||||
|
||||
// Source for data to be resampled.
|
||||
@ -77,7 +77,7 @@ void PushSincResamplerTest::ResampleBenchmarkTest(bool int_format) {
|
||||
rtc::scoped_ptr<int16_t[]> destination_int(new int16_t[output_samples]);
|
||||
|
||||
resampler_source.Run(input_samples, source.get());
|
||||
for (int i = 0; i < input_samples; ++i) {
|
||||
for (size_t i = 0; i < input_samples; ++i) {
|
||||
source_int[i] = static_cast<int16_t>(floor(32767 * source[i] + 0.5));
|
||||
}
|
||||
|
||||
@ -134,11 +134,13 @@ void PushSincResamplerTest::ResampleTest(bool int_format) {
|
||||
// Make comparisons using one second of data.
|
||||
static const double kTestDurationSecs = 1;
|
||||
// 10 ms blocks.
|
||||
const int kNumBlocks = kTestDurationSecs * 100;
|
||||
const int input_block_size = input_rate_ / 100;
|
||||
const int output_block_size = output_rate_ / 100;
|
||||
const int input_samples = kTestDurationSecs * input_rate_;
|
||||
const int output_samples = kTestDurationSecs * output_rate_;
|
||||
const size_t kNumBlocks = static_cast<size_t>(kTestDurationSecs * 100);
|
||||
const size_t input_block_size = static_cast<size_t>(input_rate_ / 100);
|
||||
const size_t output_block_size = static_cast<size_t>(output_rate_ / 100);
|
||||
const size_t input_samples =
|
||||
static_cast<size_t>(kTestDurationSecs * input_rate_);
|
||||
const size_t output_samples =
|
||||
static_cast<size_t>(kTestDurationSecs * output_rate_);
|
||||
|
||||
// Nyquist frequency for the input sampling rate.
|
||||
const double input_nyquist_freq = 0.5 * input_rate_;
|
||||
@ -163,7 +165,7 @@ 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 int output_delay_samples = output_block_size -
|
||||
const size_t output_delay_samples = output_block_size -
|
||||
resampler.get_resampler_for_testing()->ChunkSize();
|
||||
|
||||
// Generate resampled signal.
|
||||
@ -171,7 +173,7 @@ void PushSincResamplerTest::ResampleTest(bool int_format) {
|
||||
// rather than in a single pass, to exercise how it will be used in WebRTC.
|
||||
resampler_source.Run(input_samples, source.get());
|
||||
if (int_format) {
|
||||
for (int i = 0; i < kNumBlocks; ++i) {
|
||||
for (size_t i = 0; i < kNumBlocks; ++i) {
|
||||
FloatToS16(&source[i * input_block_size], input_block_size,
|
||||
source_int.get());
|
||||
EXPECT_EQ(output_block_size,
|
||||
@ -183,7 +185,7 @@ void PushSincResamplerTest::ResampleTest(bool int_format) {
|
||||
&resampled_destination[i * output_block_size]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < kNumBlocks; ++i) {
|
||||
for (size_t i = 0; i < kNumBlocks; ++i) {
|
||||
EXPECT_EQ(
|
||||
output_block_size,
|
||||
resampler.Resample(&source[i * input_block_size],
|
||||
@ -211,7 +213,7 @@ void PushSincResamplerTest::ResampleTest(bool int_format) {
|
||||
double low_frequency_range = kLowFrequencyNyquistRange * 0.5 * minimum_rate;
|
||||
double high_frequency_range = kHighFrequencyNyquistRange * 0.5 * minimum_rate;
|
||||
|
||||
for (int i = 0; i < output_samples; ++i) {
|
||||
for (size_t i = 0; i < output_samples; ++i) {
|
||||
double error = fabs(resampled_destination[i] - pure_destination[i]);
|
||||
|
||||
if (pure_source.Frequency(i) < low_frequency_range) {
|
||||
|
||||
@ -401,8 +401,8 @@ int Resampler::Reset(int inFreq, int outFreq, int num_channels)
|
||||
}
|
||||
|
||||
// Synchronous resampling, all output samples are written to samplesOut
|
||||
int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
int16_t* samplesOut, int maxLen, int &outLen)
|
||||
int Resampler::Push(const int16_t * samplesIn, size_t lengthIn,
|
||||
int16_t* samplesOut, size_t maxLen, size_t &outLen)
|
||||
{
|
||||
if (num_channels_ == 2)
|
||||
{
|
||||
@ -413,7 +413,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
int16_t* out_right =
|
||||
(int16_t*)malloc(maxLen / 2 * sizeof(int16_t));
|
||||
int res = 0;
|
||||
for (int i = 0; i < lengthIn; i += 2)
|
||||
for (size_t i = 0; i < lengthIn; i += 2)
|
||||
{
|
||||
left[i >> 1] = samplesIn[i];
|
||||
right[i >> 1] = samplesIn[i + 1];
|
||||
@ -422,8 +422,8 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
// It's OK to overwrite the local parameter, since it's just a copy
|
||||
lengthIn = lengthIn / 2;
|
||||
|
||||
int actualOutLen_left = 0;
|
||||
int actualOutLen_right = 0;
|
||||
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);
|
||||
@ -437,7 +437,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
|
||||
// Reassemble the signal
|
||||
for (int i = 0; i < actualOutLen_left; i++)
|
||||
for (size_t i = 0; i < actualOutLen_left; i++)
|
||||
{
|
||||
samplesOut[i * 2] = out_left[i];
|
||||
samplesOut[i * 2 + 1] = out_right[i];
|
||||
@ -486,7 +486,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 160)
|
||||
for (size_t i = 0; i < lengthIn; i += 160)
|
||||
{
|
||||
WebRtcSpl_Resample16khzTo48khz(samplesIn + i, samplesOut + i * 3,
|
||||
(WebRtcSpl_State16khzTo48khz *)state1_,
|
||||
@ -529,7 +529,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
|
||||
outLen = lengthIn * 2;
|
||||
|
||||
for (int i = 0; i < outLen; i += 160)
|
||||
for (size_t i = 0; i < outLen; i += 160)
|
||||
{
|
||||
WebRtcSpl_Resample16khzTo48khz(tmp + i, samplesOut + i * 3,
|
||||
(WebRtcSpl_State16khzTo48khz *)state2_,
|
||||
@ -560,7 +560,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
WebRtcSpl_UpsampleBy2(samplesOut, outLen, tmp, (int32_t*) state2_);
|
||||
outLen = outLen * 2;
|
||||
// 4:12
|
||||
for (int i = 0; i < outLen; i += 160) {
|
||||
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
|
||||
@ -589,7 +589,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp = static_cast<int16_t*> (malloc(sizeof(int16_t) * lengthIn * 3));
|
||||
tmp_mem = (int32_t*)malloc(336 * sizeof(int32_t));
|
||||
for (int i = 0; i < lengthIn; i += 160)
|
||||
for (size_t i = 0; i < lengthIn; i += 160)
|
||||
{
|
||||
WebRtcSpl_Resample16khzTo48khz(samplesIn + i, tmp + i * 3,
|
||||
(WebRtcSpl_State16khzTo48khz *)state1_,
|
||||
@ -621,7 +621,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
|
||||
tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 80)
|
||||
for (size_t i = 0; i < lengthIn; i += 80)
|
||||
{
|
||||
WebRtcSpl_Resample8khzTo22khz(tmp + i, samplesOut + (i * 11) / 4,
|
||||
(WebRtcSpl_State8khzTo22khz *)state2_,
|
||||
@ -645,7 +645,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(98 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 80)
|
||||
for (size_t i = 0; i < lengthIn; i += 80)
|
||||
{
|
||||
WebRtcSpl_Resample8khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 4,
|
||||
(WebRtcSpl_State8khzTo22khz *)state1_,
|
||||
@ -667,7 +667,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(88 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 160)
|
||||
for (size_t i = 0; i < lengthIn; i += 160)
|
||||
{
|
||||
WebRtcSpl_Resample16khzTo22khz(samplesIn + i, samplesOut + (i * 11) / 8,
|
||||
(WebRtcSpl_State16khzTo22khz *)state1_,
|
||||
@ -693,7 +693,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
|
||||
WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, tmp, (int32_t*)state1_);
|
||||
|
||||
for (int i = 0; i < (lengthIn * 2); i += 220)
|
||||
for (size_t i = 0; i < (lengthIn * 2); i += 220)
|
||||
{
|
||||
WebRtcSpl_Resample22khzTo16khz(tmp + i, samplesOut + (i / 220) * 160,
|
||||
(WebRtcSpl_State22khzTo16khz *)state2_,
|
||||
@ -725,7 +725,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
WebRtcSpl_UpsampleBy2(samplesIn, lengthIn, samplesOut, (int32_t*)state1_);
|
||||
|
||||
// 22 -> 16 in tmp
|
||||
for (int i = 0; i < (lengthIn * 2); i += 220)
|
||||
for (size_t i = 0; i < (lengthIn * 2); i += 220)
|
||||
{
|
||||
WebRtcSpl_Resample22khzTo16khz(samplesOut + i, tmp + (i / 220) * 160,
|
||||
(WebRtcSpl_State22khzTo16khz *)state2_,
|
||||
@ -763,7 +763,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 480)
|
||||
for (size_t i = 0; i < lengthIn; i += 480)
|
||||
{
|
||||
WebRtcSpl_Resample48khzTo16khz(samplesIn + i, samplesOut + i / 3,
|
||||
(WebRtcSpl_State48khzTo16khz *)state1_,
|
||||
@ -801,7 +801,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
|
||||
tmp = (int16_t*)malloc((sizeof(int16_t) * lengthIn) / 3);
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 480)
|
||||
for (size_t i = 0; i < lengthIn; i += 480)
|
||||
{
|
||||
WebRtcSpl_Resample48khzTo16khz(samplesIn + i, tmp + i / 3,
|
||||
(WebRtcSpl_State48khzTo16khz *)state1_,
|
||||
@ -827,7 +827,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
tmp = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 3);
|
||||
tmp_2 = (int16_t*) malloc((sizeof(int16_t) * lengthIn) / 6);
|
||||
// 12:4
|
||||
for (int i = 0; i < lengthIn; i += 480) {
|
||||
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
|
||||
@ -867,7 +867,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
return -1;
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(496 * sizeof(int32_t));
|
||||
for (int i = 0; i < lengthIn; i += 480)
|
||||
for (size_t i = 0; i < lengthIn; i += 480)
|
||||
{
|
||||
WebRtcSpl_Resample48khzTo16khz(tmp + i, samplesOut + i / 3,
|
||||
(WebRtcSpl_State48khzTo16khz *)state2_,
|
||||
@ -891,7 +891,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t));
|
||||
tmp = (int16_t*)malloc((lengthIn * 4) / 11 * sizeof(int16_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 220)
|
||||
for (size_t i = 0; i < lengthIn; i += 220)
|
||||
{
|
||||
WebRtcSpl_Resample22khzTo8khz(samplesIn + i, tmp + (i * 4) / 11,
|
||||
(WebRtcSpl_State22khzTo8khz *)state1_,
|
||||
@ -919,7 +919,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(126 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 220)
|
||||
for (size_t i = 0; i < lengthIn; i += 220)
|
||||
{
|
||||
WebRtcSpl_Resample22khzTo8khz(samplesIn + i, samplesOut + (i * 4) / 11,
|
||||
(WebRtcSpl_State22khzTo8khz *)state1_,
|
||||
@ -941,7 +941,7 @@ int Resampler::Push(const int16_t * samplesIn, int lengthIn,
|
||||
}
|
||||
tmp_mem = (int32_t*)malloc(104 * sizeof(int32_t));
|
||||
|
||||
for (int i = 0; i < lengthIn; i += 220)
|
||||
for (size_t i = 0; i < lengthIn; i += 220)
|
||||
{
|
||||
WebRtcSpl_Resample22khzTo16khz(samplesIn + i, samplesOut + (i * 8) / 11,
|
||||
(WebRtcSpl_State22khzTo16khz *)state1_,
|
||||
|
||||
@ -98,12 +98,12 @@ TEST_F(ResamplerTest, Mono) {
|
||||
SCOPED_TRACE(ss.str());
|
||||
|
||||
if (ValidRates(kRates[i], kRates[j])) {
|
||||
int in_length = kRates[i] / 100;
|
||||
int out_length = 0;
|
||||
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(kRates[j] / 100, out_length);
|
||||
EXPECT_EQ(static_cast<size_t>(kRates[j] / 100), out_length);
|
||||
} else {
|
||||
EXPECT_EQ(-1, rs_.Reset(kRates[i], kRates[j], kChannels));
|
||||
}
|
||||
@ -120,13 +120,13 @@ TEST_F(ResamplerTest, Stereo) {
|
||||
SCOPED_TRACE(ss.str());
|
||||
|
||||
if (ValidRates(kRates[i], kRates[j])) {
|
||||
int in_length = kChannels * kRates[i] / 100;
|
||||
int out_length = 0;
|
||||
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(kChannels * kRates[j] / 100, 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));
|
||||
|
||||
@ -149,7 +149,7 @@ void SincResampler::InitializeCPUSpecificFeatures() {}
|
||||
#endif
|
||||
|
||||
SincResampler::SincResampler(double io_sample_rate_ratio,
|
||||
int request_frames,
|
||||
size_t request_frames,
|
||||
SincResamplerCallback* read_cb)
|
||||
: io_sample_rate_ratio_(io_sample_rate_ratio),
|
||||
read_cb_(read_cb),
|
||||
@ -215,14 +215,15 @@ void SincResampler::InitializeKernel() {
|
||||
// Generates a set of windowed sinc() kernels.
|
||||
// We generate a range of sub-sample offsets from 0.0 to 1.0.
|
||||
const double sinc_scale_factor = SincScaleFactor(io_sample_rate_ratio_);
|
||||
for (int offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
|
||||
for (size_t offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
|
||||
const float subsample_offset =
|
||||
static_cast<float>(offset_idx) / kKernelOffsetCount;
|
||||
|
||||
for (int i = 0; i < kKernelSize; ++i) {
|
||||
const int idx = i + offset_idx * kKernelSize;
|
||||
const float pre_sinc =
|
||||
static_cast<float>(M_PI * (i - kKernelSize / 2 - subsample_offset));
|
||||
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));
|
||||
kernel_pre_sinc_storage_[idx] = pre_sinc;
|
||||
|
||||
// Compute Blackman window, matching the offset of the sinc().
|
||||
@ -252,9 +253,9 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) {
|
||||
// Optimize reinitialization by reusing values which are independent of
|
||||
// |sinc_scale_factor|. Provides a 3x speedup.
|
||||
const double sinc_scale_factor = SincScaleFactor(io_sample_rate_ratio_);
|
||||
for (int offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
|
||||
for (int i = 0; i < kKernelSize; ++i) {
|
||||
const int idx = i + offset_idx * kKernelSize;
|
||||
for (size_t offset_idx = 0; offset_idx <= kKernelOffsetCount; ++offset_idx) {
|
||||
for (size_t i = 0; i < kKernelSize; ++i) {
|
||||
const size_t idx = i + offset_idx * kKernelSize;
|
||||
const float window = kernel_window_storage_[idx];
|
||||
const float pre_sinc = kernel_pre_sinc_storage_[idx];
|
||||
|
||||
@ -266,8 +267,8 @@ void SincResampler::SetRatio(double io_sample_rate_ratio) {
|
||||
}
|
||||
}
|
||||
|
||||
void SincResampler::Resample(int frames, float* destination) {
|
||||
int remaining_frames = frames;
|
||||
void SincResampler::Resample(size_t frames, float* destination) {
|
||||
size_t remaining_frames = frames;
|
||||
|
||||
// Step (1) -- Prime the input buffer at the start of the input stream.
|
||||
if (!buffer_primed_ && remaining_frames) {
|
||||
@ -343,8 +344,8 @@ void SincResampler::Resample(int frames, float* destination) {
|
||||
|
||||
#undef CONVOLVE_FUNC
|
||||
|
||||
int SincResampler::ChunkSize() const {
|
||||
return static_cast<int>(block_size_ / io_sample_rate_ratio_);
|
||||
size_t SincResampler::ChunkSize() const {
|
||||
return static_cast<size_t>(block_size_ / io_sample_rate_ratio_);
|
||||
}
|
||||
|
||||
void SincResampler::Flush() {
|
||||
@ -363,7 +364,7 @@ float SincResampler::Convolve_C(const float* input_ptr, const float* k1,
|
||||
|
||||
// Generate a single output sample. Unrolling this loop hurt performance in
|
||||
// local testing.
|
||||
int n = kKernelSize;
|
||||
size_t n = kKernelSize;
|
||||
while (n--) {
|
||||
sum1 += *input_ptr * *k1++;
|
||||
sum2 += *input_ptr++ * *k2++;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace webrtc {
|
||||
class SincResamplerCallback {
|
||||
public:
|
||||
virtual ~SincResamplerCallback() {}
|
||||
virtual void Run(int frames, float* destination) = 0;
|
||||
virtual void Run(size_t frames, float* destination) = 0;
|
||||
};
|
||||
|
||||
// SincResampler is a high-quality single-channel sample-rate converter.
|
||||
@ -37,17 +37,18 @@ class SincResampler {
|
||||
// The kernel size can be adjusted for quality (higher is better) at the
|
||||
// expense of performance. Must be a multiple of 32.
|
||||
// TODO(dalecurtis): Test performance to see if we can jack this up to 64+.
|
||||
static const int kKernelSize = 32;
|
||||
static const size_t kKernelSize = 32;
|
||||
|
||||
// Default request size. Affects how often and for how much SincResampler
|
||||
// calls back for input. Must be greater than kKernelSize.
|
||||
static const int kDefaultRequestSize = 512;
|
||||
static const size_t kDefaultRequestSize = 512;
|
||||
|
||||
// The kernel offset count is used for interpolation and is the number of
|
||||
// sub-sample kernel shifts. Can be adjusted for quality (higher is better)
|
||||
// at the expense of allocating more memory.
|
||||
static const int kKernelOffsetCount = 32;
|
||||
static const int kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1);
|
||||
static const size_t kKernelOffsetCount = 32;
|
||||
static const size_t kKernelStorageSize =
|
||||
kKernelSize * (kKernelOffsetCount + 1);
|
||||
|
||||
// Constructs a SincResampler with the specified |read_cb|, which is used to
|
||||
// acquire audio data for resampling. |io_sample_rate_ratio| is the ratio
|
||||
@ -56,18 +57,18 @@ class SincResampler {
|
||||
// greater than kKernelSize. Specify kDefaultRequestSize if there are no
|
||||
// request size constraints.
|
||||
SincResampler(double io_sample_rate_ratio,
|
||||
int request_frames,
|
||||
size_t request_frames,
|
||||
SincResamplerCallback* read_cb);
|
||||
virtual ~SincResampler();
|
||||
|
||||
// Resample |frames| of data from |read_cb_| into |destination|.
|
||||
void Resample(int frames, float* destination);
|
||||
void Resample(size_t frames, float* destination);
|
||||
|
||||
// The maximum size in frames that guarantees Resample() will only make a
|
||||
// single call to |read_cb_| for more data.
|
||||
int ChunkSize() const;
|
||||
size_t ChunkSize() const;
|
||||
|
||||
int request_frames() const { return request_frames_; }
|
||||
size_t request_frames() const { return request_frames_; }
|
||||
|
||||
// Flush all buffered data and reset internal indices. Not thread safe, do
|
||||
// not call while Resample() is in progress.
|
||||
@ -125,13 +126,13 @@ class SincResampler {
|
||||
SincResamplerCallback* read_cb_;
|
||||
|
||||
// The size (in samples) to request from each |read_cb_| execution.
|
||||
const int request_frames_;
|
||||
const size_t request_frames_;
|
||||
|
||||
// The number of source frames processed per pass.
|
||||
int block_size_;
|
||||
size_t block_size_;
|
||||
|
||||
// The size (in samples) of the internal buffer used by the resampler.
|
||||
const int input_buffer_size_;
|
||||
const size_t input_buffer_size_;
|
||||
|
||||
// Contains kKernelOffsetCount kernels back-to-back, each of size kKernelSize.
|
||||
// The kernel offsets are sub-sample shifts of a windowed sinc shifted from
|
||||
|
||||
@ -27,13 +27,13 @@ float SincResampler::Convolve_SSE(const float* input_ptr, const float* k1,
|
||||
// Based on |input_ptr| alignment, we need to use loadu or load. Unrolling
|
||||
// these loops hurt performance in local testing.
|
||||
if (reinterpret_cast<uintptr_t>(input_ptr) & 0x0F) {
|
||||
for (int i = 0; i < kKernelSize; i += 4) {
|
||||
for (size_t i = 0; i < kKernelSize; i += 4) {
|
||||
m_input = _mm_loadu_ps(input_ptr + i);
|
||||
m_sums1 = _mm_add_ps(m_sums1, _mm_mul_ps(m_input, _mm_load_ps(k1 + i)));
|
||||
m_sums2 = _mm_add_ps(m_sums2, _mm_mul_ps(m_input, _mm_load_ps(k2 + i)));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < kKernelSize; i += 4) {
|
||||
for (size_t i = 0; i < kKernelSize; i += 4) {
|
||||
m_input = _mm_load_ps(input_ptr + i);
|
||||
m_sums1 = _mm_add_ps(m_sums1, _mm_mul_ps(m_input, _mm_load_ps(k1 + i)));
|
||||
m_sums2 = _mm_add_ps(m_sums2, _mm_mul_ps(m_input, _mm_load_ps(k2 + i)));
|
||||
|
||||
@ -36,7 +36,7 @@ static const double kKernelInterpolationFactor = 0.5;
|
||||
// Helper class to ensure ChunkedResample() functions properly.
|
||||
class MockSource : public SincResamplerCallback {
|
||||
public:
|
||||
MOCK_METHOD2(Run, void(int frames, float* destination));
|
||||
MOCK_METHOD2(Run, void(size_t frames, float* destination));
|
||||
};
|
||||
|
||||
ACTION(ClearBuffer) {
|
||||
@ -61,7 +61,7 @@ TEST(SincResamplerTest, ChunkedResample) {
|
||||
&mock_source);
|
||||
|
||||
static const int kChunks = 2;
|
||||
int max_chunk_size = resampler.ChunkSize() * kChunks;
|
||||
size_t max_chunk_size = resampler.ChunkSize() * kChunks;
|
||||
rtc::scoped_ptr<float[]> resampled_destination(new float[max_chunk_size]);
|
||||
|
||||
// Verify requesting ChunkSize() frames causes a single callback.
|
||||
@ -96,7 +96,7 @@ TEST(SincResamplerTest, Flush) {
|
||||
EXPECT_CALL(mock_source, Run(_, _))
|
||||
.Times(1).WillOnce(ClearBuffer());
|
||||
resampler.Resample(resampler.ChunkSize() / 2, resampled_destination.get());
|
||||
for (int i = 0; i < resampler.ChunkSize() / 2; ++i)
|
||||
for (size_t i = 0; i < resampler.ChunkSize() / 2; ++i)
|
||||
ASSERT_FLOAT_EQ(resampled_destination[i], 0);
|
||||
}
|
||||
|
||||
@ -251,8 +251,10 @@ class SincResamplerTest
|
||||
TEST_P(SincResamplerTest, Resample) {
|
||||
// Make comparisons using one second of data.
|
||||
static const double kTestDurationSecs = 1;
|
||||
const int input_samples = kTestDurationSecs * input_rate_;
|
||||
const int output_samples = kTestDurationSecs * output_rate_;
|
||||
const size_t input_samples =
|
||||
static_cast<size_t>(kTestDurationSecs * input_rate_);
|
||||
const size_t output_samples =
|
||||
static_cast<size_t>(kTestDurationSecs * output_rate_);
|
||||
|
||||
// Nyquist frequency for the input sampling rate.
|
||||
const double input_nyquist_freq = 0.5 * input_rate_;
|
||||
@ -302,7 +304,7 @@ TEST_P(SincResamplerTest, Resample) {
|
||||
int minimum_rate = std::min(input_rate_, output_rate_);
|
||||
double low_frequency_range = kLowFrequencyNyquistRange * 0.5 * minimum_rate;
|
||||
double high_frequency_range = kHighFrequencyNyquistRange * 0.5 * minimum_rate;
|
||||
for (int i = 0; i < output_samples; ++i) {
|
||||
for (size_t i = 0; i < output_samples; ++i) {
|
||||
double error = fabs(resampled_destination[i] - pure_destination[i]);
|
||||
|
||||
if (pure_source.Frequency(i) < low_frequency_range) {
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
namespace webrtc {
|
||||
|
||||
SinusoidalLinearChirpSource::SinusoidalLinearChirpSource(int sample_rate,
|
||||
int samples, double max_frequency, double delay_samples)
|
||||
size_t samples,
|
||||
double max_frequency,
|
||||
double delay_samples)
|
||||
: sample_rate_(sample_rate),
|
||||
total_samples_(samples),
|
||||
max_frequency_(max_frequency),
|
||||
@ -29,8 +31,8 @@ SinusoidalLinearChirpSource::SinusoidalLinearChirpSource(int sample_rate,
|
||||
k_ = (max_frequency_ - kMinFrequency) / duration;
|
||||
}
|
||||
|
||||
void SinusoidalLinearChirpSource::Run(int frames, float* destination) {
|
||||
for (int i = 0; i < frames; ++i, ++current_index_) {
|
||||
void SinusoidalLinearChirpSource::Run(size_t frames, float* destination) {
|
||||
for (size_t i = 0; i < frames; ++i, ++current_index_) {
|
||||
// Filter out frequencies higher than Nyquist.
|
||||
if (Frequency(current_index_) > 0.5 * sample_rate_) {
|
||||
destination[i] = 0;
|
||||
@ -48,7 +50,7 @@ void SinusoidalLinearChirpSource::Run(int frames, float* destination) {
|
||||
}
|
||||
}
|
||||
|
||||
double SinusoidalLinearChirpSource::Frequency(int position) {
|
||||
double SinusoidalLinearChirpSource::Frequency(size_t position) {
|
||||
return kMinFrequency + (position - delay_samples_) *
|
||||
(max_frequency_ - kMinFrequency) / total_samples_;
|
||||
}
|
||||
|
||||
@ -26,14 +26,14 @@ 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, int samples,
|
||||
SinusoidalLinearChirpSource(int sample_rate, size_t samples,
|
||||
double max_frequency, double delay_samples);
|
||||
|
||||
virtual ~SinusoidalLinearChirpSource() {}
|
||||
|
||||
void Run(int frames, float* destination) override;
|
||||
void Run(size_t frames, float* destination) override;
|
||||
|
||||
double Frequency(int position);
|
||||
double Frequency(size_t position);
|
||||
|
||||
private:
|
||||
enum {
|
||||
@ -41,10 +41,10 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback {
|
||||
};
|
||||
|
||||
int sample_rate_;
|
||||
int total_samples_;
|
||||
size_t total_samples_;
|
||||
double max_frequency_;
|
||||
double k_;
|
||||
int current_index_;
|
||||
size_t current_index_;
|
||||
double delay_samples_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SinusoidalLinearChirpSource);
|
||||
|
||||
@ -11,20 +11,18 @@
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int order,
|
||||
size_t in_vector_length,
|
||||
size_t order,
|
||||
int32_t* result,
|
||||
int* scale) {
|
||||
int32_t sum = 0;
|
||||
int i = 0, j = 0;
|
||||
size_t i = 0, j = 0;
|
||||
int16_t smax = 0;
|
||||
int scaling = 0;
|
||||
|
||||
if (order > in_vector_length) {
|
||||
/* Undefined */
|
||||
return -1;
|
||||
} else if (order < 0) {
|
||||
order = in_vector_length;
|
||||
}
|
||||
|
||||
// Find the maximum absolute value of the samples.
|
||||
@ -64,5 +62,5 @@ int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
|
||||
}
|
||||
|
||||
*scale = scaling;
|
||||
return order + 1;
|
||||
return (int)(order + 1);
|
||||
}
|
||||
|
||||
@ -157,7 +157,8 @@ int WebRtcSpl_ComplexFFT(int16_t frfi[], int stages, int mode)
|
||||
|
||||
int WebRtcSpl_ComplexIFFT(int16_t frfi[], int stages, int mode)
|
||||
{
|
||||
int i, j, l, k, istep, n, m, scale, shift;
|
||||
size_t i, j, l, istep, n, m;
|
||||
int k, scale, shift;
|
||||
int16_t wr, wi;
|
||||
int32_t tr32, ti32, qr32, qi32;
|
||||
int32_t tmp32, round2;
|
||||
|
||||
@ -26,9 +26,9 @@
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
|
||||
void WebRtcSpl_MemSetW16(int16_t *ptr, int16_t set_value, int length)
|
||||
void WebRtcSpl_MemSetW16(int16_t *ptr, int16_t set_value, size_t length)
|
||||
{
|
||||
int j;
|
||||
size_t j;
|
||||
int16_t *arrptr = ptr;
|
||||
|
||||
for (j = length; j > 0; j--)
|
||||
@ -37,9 +37,9 @@ void WebRtcSpl_MemSetW16(int16_t *ptr, int16_t set_value, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcSpl_MemSetW32(int32_t *ptr, int32_t set_value, int length)
|
||||
void WebRtcSpl_MemSetW32(int32_t *ptr, int32_t set_value, size_t length)
|
||||
{
|
||||
int j;
|
||||
size_t j;
|
||||
int32_t *arrptr = ptr;
|
||||
|
||||
for (j = length; j > 0; j--)
|
||||
@ -48,9 +48,11 @@ void WebRtcSpl_MemSetW32(int32_t *ptr, int32_t set_value, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcSpl_MemCpyReversedOrder(int16_t* dest, int16_t* source, int length)
|
||||
void WebRtcSpl_MemCpyReversedOrder(int16_t* dest,
|
||||
int16_t* source,
|
||||
size_t length)
|
||||
{
|
||||
int j;
|
||||
size_t j;
|
||||
int16_t* destPtr = dest;
|
||||
int16_t* sourcePtr = source;
|
||||
|
||||
@ -61,20 +63,20 @@ void WebRtcSpl_MemCpyReversedOrder(int16_t* dest, int16_t* source, int length)
|
||||
}
|
||||
|
||||
void WebRtcSpl_CopyFromEndW16(const int16_t *vector_in,
|
||||
int length,
|
||||
int samples,
|
||||
size_t length,
|
||||
size_t samples,
|
||||
int16_t *vector_out)
|
||||
{
|
||||
// Copy the last <samples> of the input vector to vector_out
|
||||
WEBRTC_SPL_MEMCPY_W16(vector_out, &vector_in[length - samples], samples);
|
||||
}
|
||||
|
||||
void WebRtcSpl_ZerosArrayW16(int16_t *vector, int length)
|
||||
void WebRtcSpl_ZerosArrayW16(int16_t *vector, size_t length)
|
||||
{
|
||||
WebRtcSpl_MemSetW16(vector, 0, length);
|
||||
}
|
||||
|
||||
void WebRtcSpl_ZerosArrayW32(int32_t *vector, int length)
|
||||
void WebRtcSpl_ZerosArrayW32(int32_t *vector, size_t length)
|
||||
{
|
||||
WebRtcSpl_MemSetW32(vector, 0, length);
|
||||
}
|
||||
|
||||
@ -14,11 +14,11 @@
|
||||
void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2) {
|
||||
int i = 0, j = 0;
|
||||
size_t i = 0, j = 0;
|
||||
|
||||
for (i = 0; i < dim_cross_correlation; i++) {
|
||||
int32_t corr = 0;
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2) {
|
||||
|
||||
|
||||
@ -15,19 +15,14 @@
|
||||
static inline void DotProductWithScaleNeon(int32_t* cross_correlation,
|
||||
const int16_t* vector1,
|
||||
const int16_t* vector2,
|
||||
int length,
|
||||
size_t length,
|
||||
int scaling) {
|
||||
int i = 0;
|
||||
int len1 = length >> 3;
|
||||
int len2 = length & 7;
|
||||
size_t i = 0;
|
||||
size_t len1 = length >> 3;
|
||||
size_t len2 = length & 7;
|
||||
int64x2_t sum0 = vdupq_n_s64(0);
|
||||
int64x2_t sum1 = vdupq_n_s64(0);
|
||||
|
||||
if (length < 0) {
|
||||
*cross_correlation = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = len1; i > 0; i -= 1) {
|
||||
int16x8_t seq1_16x8 = vld1q_s16(vector1);
|
||||
int16x8_t seq2_16x8 = vld1q_s16(vector2);
|
||||
@ -72,11 +67,11 @@ static inline void DotProductWithScaleNeon(int32_t* cross_correlation,
|
||||
void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2) {
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < dim_cross_correlation; i++) {
|
||||
const int16_t* seq1_ptr = seq1;
|
||||
|
||||
@ -12,10 +12,10 @@
|
||||
|
||||
int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
|
||||
const int16_t* vector2,
|
||||
int length,
|
||||
size_t length,
|
||||
int scaling) {
|
||||
int32_t sum = 0;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
/* Unroll the loop to improve performance. */
|
||||
for (i = 0; i + 3 < length; i += 4) {
|
||||
|
||||
@ -13,20 +13,20 @@
|
||||
// TODO(Bjornv): Change the function parameter order to WebRTC code style.
|
||||
// C version of WebRtcSpl_DownsampleFast() for generic platforms.
|
||||
int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
size_t delay) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
int32_t out_s32 = 0;
|
||||
int endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
size_t endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
|
||||
// Return error if any of the running conditions doesn't meet.
|
||||
if (data_out_length <= 0 || coefficients_length <= 0
|
||||
if (data_out_length == 0 || coefficients_length == 0
|
||||
|| data_in_length < endpos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -12,18 +12,18 @@
|
||||
|
||||
// Version of WebRtcSpl_DownsampleFast() for MIPS platforms.
|
||||
int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay) {
|
||||
size_t delay) {
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int32_t out_s32 = 0;
|
||||
int endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
size_t endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
|
||||
int32_t tmp1, tmp2, tmp3, tmp4, factor_2;
|
||||
int16_t* p_coefficients;
|
||||
@ -36,7 +36,7 @@ int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
|
||||
#endif // #if !defined(MIPS_DSP_R1_LE)
|
||||
|
||||
// Return error if any of the running conditions doesn't meet.
|
||||
if (data_out_length <= 0 || coefficients_length <= 0
|
||||
if (data_out_length == 0 || coefficients_length == 0
|
||||
|| data_in_length < endpos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -15,22 +15,22 @@
|
||||
// NEON intrinsics version of WebRtcSpl_DownsampleFast()
|
||||
// for ARM 32-bit/64-bit platforms.
|
||||
int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
size_t delay) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
int32_t out_s32 = 0;
|
||||
int endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
int res = data_out_length & 0x7;
|
||||
int endpos1 = endpos - factor * res;
|
||||
size_t endpos = delay + factor * (data_out_length - 1) + 1;
|
||||
size_t res = data_out_length & 0x7;
|
||||
size_t endpos1 = endpos - factor * res;
|
||||
|
||||
// Return error if any of the running conditions doesn't meet.
|
||||
if (data_out_length <= 0 || coefficients_length <= 0
|
||||
if (data_out_length == 0 || coefficients_length == 0
|
||||
|| data_in_length < endpos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -17,13 +17,15 @@
|
||||
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor)
|
||||
int32_t WebRtcSpl_Energy(int16_t* vector,
|
||||
size_t vector_length,
|
||||
int* scale_factor)
|
||||
{
|
||||
int32_t en = 0;
|
||||
int i;
|
||||
size_t i;
|
||||
int scaling =
|
||||
WebRtcSpl_GetScalingSquare(vector, vector_length, vector_length);
|
||||
int looptimes = vector_length;
|
||||
size_t looptimes = vector_length;
|
||||
int16_t *vectorptr = vector;
|
||||
|
||||
for (i = 0; i < looptimes; i++)
|
||||
|
||||
@ -17,21 +17,21 @@
|
||||
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
int WebRtcSpl_FilterAR(const int16_t* a,
|
||||
int a_length,
|
||||
const int16_t* x,
|
||||
int x_length,
|
||||
int16_t* state,
|
||||
int state_length,
|
||||
int16_t* state_low,
|
||||
int state_low_length,
|
||||
int16_t* filtered,
|
||||
int16_t* filtered_low,
|
||||
int filtered_low_length)
|
||||
size_t WebRtcSpl_FilterAR(const int16_t* a,
|
||||
size_t a_length,
|
||||
const int16_t* x,
|
||||
size_t x_length,
|
||||
int16_t* state,
|
||||
size_t state_length,
|
||||
int16_t* state_low,
|
||||
size_t state_low_length,
|
||||
int16_t* filtered,
|
||||
int16_t* filtered_low,
|
||||
size_t filtered_low_length)
|
||||
{
|
||||
int32_t o;
|
||||
int32_t oLOW;
|
||||
int i, j, stop;
|
||||
size_t i, j, stop;
|
||||
const int16_t* x_ptr = &x[0];
|
||||
int16_t* filteredFINAL_ptr = filtered;
|
||||
int16_t* filteredFINAL_LOW_ptr = filtered_low;
|
||||
|
||||
@ -16,10 +16,10 @@
|
||||
void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
|
||||
int16_t* data_out,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
int data_length) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
size_t coefficients_length,
|
||||
size_t data_length) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
|
||||
assert(data_length > 0);
|
||||
assert(coefficients_length > 1);
|
||||
|
||||
@ -155,10 +155,10 @@ END:
|
||||
@void WebRtcSpl_FilterARFastQ12(int16_t* data_in,
|
||||
@ int16_t* data_out,
|
||||
@ int16_t* __restrict coefficients,
|
||||
@ int coefficients_length,
|
||||
@ int data_length) {
|
||||
@ int i = 0;
|
||||
@ int j = 0;
|
||||
@ size_t coefficients_length,
|
||||
@ size_t data_length) {
|
||||
@ size_t i = 0;
|
||||
@ size_t j = 0;
|
||||
@
|
||||
@ assert(data_length > 0);
|
||||
@ assert(coefficients_length > 1);
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
|
||||
int16_t* data_out,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
int data_length) {
|
||||
size_t coefficients_length,
|
||||
size_t data_length) {
|
||||
int r0, r1, r2, r3;
|
||||
int coef0, offset;
|
||||
int i, j, k;
|
||||
|
||||
@ -20,10 +20,10 @@
|
||||
void WebRtcSpl_FilterMAFastQ12(const int16_t* in_ptr,
|
||||
int16_t* out_ptr,
|
||||
const int16_t* B,
|
||||
int16_t B_length,
|
||||
int16_t length)
|
||||
size_t B_length,
|
||||
size_t length)
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
int32_t o = 0;
|
||||
|
||||
@ -53,15 +53,15 @@ static const int16_t kHanningTable[] = {
|
||||
16354, 16362, 16369, 16374, 16378, 16382, 16383, 16384
|
||||
};
|
||||
|
||||
void WebRtcSpl_GetHanningWindow(int16_t *v, int16_t size)
|
||||
void WebRtcSpl_GetHanningWindow(int16_t *v, size_t size)
|
||||
{
|
||||
int jj;
|
||||
size_t jj;
|
||||
int16_t *vptr1;
|
||||
|
||||
int32_t index;
|
||||
int32_t factor = ((int32_t)0x40000000);
|
||||
|
||||
factor = WebRtcSpl_DivW32W16(factor, size);
|
||||
factor = WebRtcSpl_DivW32W16(factor, (int16_t)size);
|
||||
if (size < 513)
|
||||
index = (int32_t)-0x200000;
|
||||
else
|
||||
|
||||
@ -18,16 +18,16 @@
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int times)
|
||||
size_t in_vector_length,
|
||||
size_t times)
|
||||
{
|
||||
int16_t nbits = WebRtcSpl_GetSizeInBits((uint32_t)times);
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t smax = -1;
|
||||
int16_t sabs;
|
||||
int16_t *sptr = in_vector;
|
||||
int16_t t;
|
||||
int looptimes = in_vector_length;
|
||||
size_t looptimes = in_vector_length;
|
||||
|
||||
for (i = looptimes; i > 0; i--)
|
||||
{
|
||||
|
||||
@ -23,10 +23,10 @@
|
||||
|
||||
void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in,
|
||||
const int16_t *win,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t *outptr = out;
|
||||
const int16_t *inptr = in;
|
||||
const int16_t *winptr = win;
|
||||
@ -37,10 +37,10 @@ void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in,
|
||||
}
|
||||
|
||||
void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in,
|
||||
const int16_t *win, int16_t vector_length,
|
||||
const int16_t *win, size_t vector_length,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t *outptr = out;
|
||||
const int16_t *inptr = in;
|
||||
const int16_t *winptr = win;
|
||||
@ -51,10 +51,10 @@ void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in,
|
||||
}
|
||||
|
||||
void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1,
|
||||
const int16_t *in2, int16_t vector_length,
|
||||
const int16_t *in2, size_t vector_length,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t *outptr = out;
|
||||
const int16_t *in1ptr = in1;
|
||||
const int16_t *in2ptr = in2;
|
||||
@ -66,9 +66,10 @@ void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1,
|
||||
|
||||
void WebRtcSpl_AddAffineVectorToVector(int16_t *out, int16_t *in,
|
||||
int16_t gain, int32_t add_constant,
|
||||
int16_t right_shifts, int vector_length)
|
||||
int16_t right_shifts,
|
||||
size_t vector_length)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < vector_length; i++)
|
||||
{
|
||||
@ -78,9 +79,9 @@ void WebRtcSpl_AddAffineVectorToVector(int16_t *out, int16_t *in,
|
||||
|
||||
void WebRtcSpl_AffineTransformVector(int16_t *out, int16_t *in,
|
||||
int16_t gain, int32_t add_constant,
|
||||
int16_t right_shifts, int vector_length)
|
||||
int16_t right_shifts, size_t vector_length)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < vector_length; i++)
|
||||
{
|
||||
|
||||
@ -115,28 +115,28 @@ extern "C" {
|
||||
void WebRtcSpl_Init();
|
||||
|
||||
int16_t WebRtcSpl_GetScalingSquare(int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int times);
|
||||
size_t in_vector_length,
|
||||
size_t times);
|
||||
|
||||
// Copy and set operations. Implementation in copy_set_operations.c.
|
||||
// Descriptions at bottom of file.
|
||||
void WebRtcSpl_MemSetW16(int16_t* vector,
|
||||
int16_t set_value,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
void WebRtcSpl_MemSetW32(int32_t* vector,
|
||||
int32_t set_value,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
void WebRtcSpl_MemCpyReversedOrder(int16_t* out_vector,
|
||||
int16_t* in_vector,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
void WebRtcSpl_CopyFromEndW16(const int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int samples,
|
||||
size_t in_vector_length,
|
||||
size_t samples,
|
||||
int16_t* out_vector);
|
||||
void WebRtcSpl_ZerosArrayW16(int16_t* vector,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
void WebRtcSpl_ZerosArrayW32(int32_t* vector,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
// End: Copy and set operations.
|
||||
|
||||
|
||||
@ -150,15 +150,15 @@ void WebRtcSpl_ZerosArrayW32(int32_t* vector,
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Maximum absolute value in vector;
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
typedef int16_t (*MaxAbsValueW16)(const int16_t* vector, size_t length);
|
||||
extern MaxAbsValueW16 WebRtcSpl_MaxAbsValueW16;
|
||||
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the largest absolute value in a signed 32-bit vector.
|
||||
@ -168,15 +168,15 @@ int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Maximum absolute value in vector;
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
typedef int32_t (*MaxAbsValueW32)(const int32_t* vector, size_t length);
|
||||
extern MaxAbsValueW32 WebRtcSpl_MaxAbsValueW32;
|
||||
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS_DSP_R1_LE)
|
||||
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the maximum value of a 16-bit vector.
|
||||
@ -186,17 +186,17 @@ int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Maximum sample value in |vector|.
|
||||
// If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MIN
|
||||
// If (vector == NULL || length == 0) WEBRTC_SPL_WORD16_MIN
|
||||
// is returned. Note that WEBRTC_SPL_WORD16_MIN is a feasible
|
||||
// value and we can't catch errors purely based on it.
|
||||
typedef int16_t (*MaxValueW16)(const int16_t* vector, int length);
|
||||
typedef int16_t (*MaxValueW16)(const int16_t* vector, size_t length);
|
||||
extern MaxValueW16 WebRtcSpl_MaxValueW16;
|
||||
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the maximum value of a 32-bit vector.
|
||||
@ -206,17 +206,17 @@ int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Maximum sample value in |vector|.
|
||||
// If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MIN
|
||||
// If (vector == NULL || length == 0) WEBRTC_SPL_WORD32_MIN
|
||||
// is returned. Note that WEBRTC_SPL_WORD32_MIN is a feasible
|
||||
// value and we can't catch errors purely based on it.
|
||||
typedef int32_t (*MaxValueW32)(const int32_t* vector, int length);
|
||||
typedef int32_t (*MaxValueW32)(const int32_t* vector, size_t length);
|
||||
extern MaxValueW32 WebRtcSpl_MaxValueW32;
|
||||
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the minimum value of a 16-bit vector.
|
||||
@ -226,17 +226,17 @@ int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Minimum sample value in |vector|.
|
||||
// If (vector == NULL || length <= 0) WEBRTC_SPL_WORD16_MAX
|
||||
// If (vector == NULL || length == 0) WEBRTC_SPL_WORD16_MAX
|
||||
// is returned. Note that WEBRTC_SPL_WORD16_MAX is a feasible
|
||||
// value and we can't catch errors purely based on it.
|
||||
typedef int16_t (*MinValueW16)(const int16_t* vector, int length);
|
||||
typedef int16_t (*MinValueW16)(const int16_t* vector, size_t length);
|
||||
extern MinValueW16 WebRtcSpl_MinValueW16;
|
||||
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
|
||||
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the minimum value of a 32-bit vector.
|
||||
@ -246,17 +246,17 @@ int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Minimum sample value in |vector|.
|
||||
// If (vector == NULL || length <= 0) WEBRTC_SPL_WORD32_MAX
|
||||
// If (vector == NULL || length == 0) WEBRTC_SPL_WORD32_MAX
|
||||
// is returned. Note that WEBRTC_SPL_WORD32_MAX is a feasible
|
||||
// value and we can't catch errors purely based on it.
|
||||
typedef int32_t (*MinValueW32)(const int32_t* vector, int length);
|
||||
typedef int32_t (*MinValueW32)(const int32_t* vector, size_t length);
|
||||
extern MinValueW32 WebRtcSpl_MinValueW32;
|
||||
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
|
||||
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length);
|
||||
#endif
|
||||
|
||||
// Returns the vector index to the largest absolute value of a 16-bit vector.
|
||||
@ -266,11 +266,11 @@ int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length);
|
||||
// - length : Number of samples in vector.
|
||||
//
|
||||
// Return value : Index to the maximum absolute value in vector, or -1,
|
||||
// if (vector == NULL || length <= 0).
|
||||
// if (vector == NULL || length == 0).
|
||||
// If there are multiple equal maxima, return the index of the
|
||||
// first. -32768 will always have precedence over 32767 (despite
|
||||
// -32768 presenting an int16 absolute value of 32767);
|
||||
int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
|
||||
int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length);
|
||||
|
||||
// Returns the vector index to the maximum sample value of a 16-bit vector.
|
||||
//
|
||||
@ -280,8 +280,8 @@ int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length);
|
||||
//
|
||||
// Return value : Index to the maximum value in vector (if multiple
|
||||
// indexes have the maximum, return the first);
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length);
|
||||
|
||||
// Returns the vector index to the maximum sample value of a 32-bit vector.
|
||||
//
|
||||
@ -291,8 +291,8 @@ int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length);
|
||||
//
|
||||
// Return value : Index to the maximum value in vector (if multiple
|
||||
// indexes have the maximum, return the first);
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length);
|
||||
|
||||
// Returns the vector index to the minimum sample value of a 16-bit vector.
|
||||
//
|
||||
@ -302,8 +302,8 @@ int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length);
|
||||
//
|
||||
// Return value : Index to the mimimum value in vector (if multiple
|
||||
// indexes have the minimum, return the first);
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length);
|
||||
|
||||
// Returns the vector index to the minimum sample value of a 32-bit vector.
|
||||
//
|
||||
@ -313,8 +313,8 @@ int WebRtcSpl_MinIndexW16(const int16_t* vector, int length);
|
||||
//
|
||||
// Return value : Index to the mimimum value in vector (if multiple
|
||||
// indexes have the minimum, return the first);
|
||||
// or -1, if (vector == NULL || length <= 0).
|
||||
int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
|
||||
// or -1, if (vector == NULL || length == 0).
|
||||
int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length);
|
||||
|
||||
// End: Minimum and maximum operations.
|
||||
|
||||
@ -322,33 +322,33 @@ int WebRtcSpl_MinIndexW32(const int32_t* vector, int length);
|
||||
// Vector scaling operations. Implementation in vector_scaling_operations.c.
|
||||
// Description at bottom of file.
|
||||
void WebRtcSpl_VectorBitShiftW16(int16_t* out_vector,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
const int16_t* in_vector,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_VectorBitShiftW32(int32_t* out_vector,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
const int32_t* in_vector,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out_vector,
|
||||
int vector_length,
|
||||
size_t vector_length,
|
||||
const int32_t* in_vector,
|
||||
int right_shifts);
|
||||
void WebRtcSpl_ScaleVector(const int16_t* in_vector,
|
||||
int16_t* out_vector,
|
||||
int16_t gain,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_ScaleVectorWithSat(const int16_t* in_vector,
|
||||
int16_t* out_vector,
|
||||
int16_t gain,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_ScaleAndAddVectors(const int16_t* in_vector1,
|
||||
int16_t gain1, int right_shifts1,
|
||||
const int16_t* in_vector2,
|
||||
int16_t gain2, int right_shifts2,
|
||||
int16_t* out_vector,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
|
||||
// The functions (with related pointer) perform the vector operation:
|
||||
// out_vector[k] = ((scale1 * in_vector1[k]) + (scale2 * in_vector2[k])
|
||||
@ -374,7 +374,7 @@ typedef int (*ScaleAndAddVectorsWithRound)(const int16_t* in_vector1,
|
||||
int16_t in_vector2_scale,
|
||||
int right_shifts,
|
||||
int16_t* out_vector,
|
||||
int length);
|
||||
size_t length);
|
||||
extern ScaleAndAddVectorsWithRound WebRtcSpl_ScaleAndAddVectorsWithRound;
|
||||
int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
|
||||
int16_t in_vector1_scale,
|
||||
@ -382,7 +382,7 @@ int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
|
||||
int16_t in_vector2_scale,
|
||||
int right_shifts,
|
||||
int16_t* out_vector,
|
||||
int length);
|
||||
size_t length);
|
||||
#if defined(MIPS_DSP_R1_LE)
|
||||
int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
|
||||
int16_t in_vector1_scale,
|
||||
@ -390,7 +390,7 @@ int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
|
||||
int16_t in_vector2_scale,
|
||||
int right_shifts,
|
||||
int16_t* out_vector,
|
||||
int length);
|
||||
size_t length);
|
||||
#endif
|
||||
// End: Vector scaling operations.
|
||||
|
||||
@ -399,30 +399,30 @@ int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
|
||||
void WebRtcSpl_ReverseOrderMultArrayElements(int16_t* out_vector,
|
||||
const int16_t* in_vector,
|
||||
const int16_t* window,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_ElementwiseVectorMult(int16_t* out_vector,
|
||||
const int16_t* in_vector,
|
||||
const int16_t* window,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_AddVectorsAndShift(int16_t* out_vector,
|
||||
const int16_t* in_vector1,
|
||||
const int16_t* in_vector2,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
int16_t right_shifts);
|
||||
void WebRtcSpl_AddAffineVectorToVector(int16_t* out_vector,
|
||||
int16_t* in_vector,
|
||||
int16_t gain,
|
||||
int32_t add_constant,
|
||||
int16_t right_shifts,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
|
||||
int16_t* in_vector,
|
||||
int16_t gain,
|
||||
int32_t add_constant,
|
||||
int16_t right_shifts,
|
||||
int vector_length);
|
||||
size_t vector_length);
|
||||
// End: iLBC specific functions.
|
||||
|
||||
// Signal processing operations.
|
||||
@ -447,8 +447,8 @@ void WebRtcSpl_AffineTransformVector(int16_t* out_vector,
|
||||
// - -1, if |order| > |in_vector_length|;
|
||||
// - Number of samples in |result|, i.e. (order+1), otherwise.
|
||||
int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int order,
|
||||
size_t in_vector_length,
|
||||
size_t order,
|
||||
int32_t* result,
|
||||
int* scale);
|
||||
|
||||
@ -467,7 +467,7 @@ int WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
|
||||
int16_t WebRtcSpl_LevinsonDurbin(const int32_t* auto_corr,
|
||||
int16_t* lpc_coef,
|
||||
int16_t* refl_coef,
|
||||
int16_t order);
|
||||
size_t order);
|
||||
|
||||
// Converts reflection coefficients |refl_coef| to LPC coefficients |lpc_coef|.
|
||||
// This version is a 16 bit operation.
|
||||
@ -540,24 +540,24 @@ void WebRtcSpl_AutoCorrToReflCoef(const int32_t* auto_corr,
|
||||
typedef void (*CrossCorrelation)(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2);
|
||||
extern CrossCorrelation WebRtcSpl_CrossCorrelation;
|
||||
void WebRtcSpl_CrossCorrelationC(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2);
|
||||
#endif
|
||||
@ -565,8 +565,8 @@ void WebRtcSpl_CrossCorrelationNeon(int32_t* cross_correlation,
|
||||
void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
|
||||
const int16_t* seq1,
|
||||
const int16_t* seq2,
|
||||
int16_t dim_seq,
|
||||
int16_t dim_cross_correlation,
|
||||
size_t dim_seq,
|
||||
size_t dim_cross_correlation,
|
||||
int right_shifts,
|
||||
int step_seq2);
|
||||
#endif
|
||||
@ -579,7 +579,7 @@ void WebRtcSpl_CrossCorrelation_mips(int32_t* cross_correlation,
|
||||
//
|
||||
// Output:
|
||||
// - window : Hanning vector in Q14.
|
||||
void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
|
||||
void WebRtcSpl_GetHanningWindow(int16_t* window, size_t size);
|
||||
|
||||
// Calculates y[k] = sqrt(1 - x[k]^2) for each element of the input vector
|
||||
// |in_vector|. Input and output values are in Q15.
|
||||
@ -591,7 +591,7 @@ void WebRtcSpl_GetHanningWindow(int16_t* window, int16_t size);
|
||||
// Output:
|
||||
// - out_vector : Output values in Q15
|
||||
void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t* in_vector,
|
||||
int vector_length,
|
||||
size_t vector_length,
|
||||
int16_t* out_vector);
|
||||
// End: Signal processing operations.
|
||||
|
||||
@ -617,7 +617,9 @@ int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den);
|
||||
int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low);
|
||||
// End: Divisions.
|
||||
|
||||
int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
|
||||
int32_t WebRtcSpl_Energy(int16_t* vector,
|
||||
size_t vector_length,
|
||||
int* scale_factor);
|
||||
|
||||
// Calculates the dot product between two (int16_t) vectors.
|
||||
//
|
||||
@ -632,21 +634,21 @@ int32_t WebRtcSpl_Energy(int16_t* vector, int vector_length, int* scale_factor);
|
||||
// Return value : The dot product in Q(-scaling)
|
||||
int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
|
||||
const int16_t* vector2,
|
||||
int length,
|
||||
size_t length,
|
||||
int scaling);
|
||||
|
||||
// Filter operations.
|
||||
int WebRtcSpl_FilterAR(const int16_t* ar_coef,
|
||||
int ar_coef_length,
|
||||
const int16_t* in_vector,
|
||||
int in_vector_length,
|
||||
int16_t* filter_state,
|
||||
int filter_state_length,
|
||||
int16_t* filter_state_low,
|
||||
int filter_state_low_length,
|
||||
int16_t* out_vector,
|
||||
int16_t* out_vector_low,
|
||||
int out_vector_low_length);
|
||||
size_t WebRtcSpl_FilterAR(const int16_t* ar_coef,
|
||||
size_t ar_coef_length,
|
||||
const int16_t* in_vector,
|
||||
size_t in_vector_length,
|
||||
int16_t* filter_state,
|
||||
size_t filter_state_length,
|
||||
int16_t* filter_state_low,
|
||||
size_t filter_state_low_length,
|
||||
int16_t* out_vector,
|
||||
int16_t* out_vector_low,
|
||||
size_t out_vector_low_length);
|
||||
|
||||
// WebRtcSpl_FilterMAFastQ12(...)
|
||||
//
|
||||
@ -665,8 +667,8 @@ int WebRtcSpl_FilterAR(const int16_t* ar_coef,
|
||||
void WebRtcSpl_FilterMAFastQ12(const int16_t* in_vector,
|
||||
int16_t* out_vector,
|
||||
const int16_t* ma_coef,
|
||||
int16_t ma_coef_length,
|
||||
int16_t vector_length);
|
||||
size_t ma_coef_length,
|
||||
size_t vector_length);
|
||||
|
||||
// Performs a AR filtering on a vector in Q12
|
||||
// Input:
|
||||
@ -681,8 +683,8 @@ void WebRtcSpl_FilterMAFastQ12(const int16_t* in_vector,
|
||||
void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
|
||||
int16_t* data_out,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
int data_length);
|
||||
size_t coefficients_length,
|
||||
size_t data_length);
|
||||
|
||||
// The functions (with related pointer) perform a MA down sampling filter
|
||||
// on a vector.
|
||||
@ -701,41 +703,41 @@ void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
|
||||
// - data_out : Filtered samples
|
||||
// Return value : 0 if OK, -1 if |in_vector| is too short
|
||||
typedef int (*DownsampleFast)(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay);
|
||||
size_t delay);
|
||||
extern DownsampleFast WebRtcSpl_DownsampleFast;
|
||||
int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay);
|
||||
size_t delay);
|
||||
#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
|
||||
int WebRtcSpl_DownsampleFastNeon(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay);
|
||||
size_t delay);
|
||||
#endif
|
||||
#if defined(MIPS32_LE)
|
||||
int WebRtcSpl_DownsampleFast_mips(const int16_t* data_in,
|
||||
int data_in_length,
|
||||
size_t data_in_length,
|
||||
int16_t* data_out,
|
||||
int data_out_length,
|
||||
size_t data_out_length,
|
||||
const int16_t* __restrict coefficients,
|
||||
int coefficients_length,
|
||||
size_t coefficients_length,
|
||||
int factor,
|
||||
int delay);
|
||||
size_t delay);
|
||||
#endif
|
||||
|
||||
// End: Filter operations.
|
||||
@ -844,11 +846,11 @@ void WebRtcSpl_ResetResample8khzTo22khz(WebRtcSpl_State8khzTo22khz* state);
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out, int32_t K);
|
||||
void WebRtcSpl_Resample48khzTo32khz(const int32_t* In, int32_t* Out, size_t K);
|
||||
|
||||
void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out, int32_t K);
|
||||
void WebRtcSpl_Resample32khzTo24khz(const int32_t* In, int32_t* Out, size_t K);
|
||||
|
||||
void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out, int32_t K);
|
||||
void WebRtcSpl_Resample44khzTo32khz(const int32_t* In, int32_t* Out, size_t K);
|
||||
|
||||
/*******************************************************************
|
||||
* resample_48khz.c
|
||||
@ -918,24 +920,24 @@ void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state);
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
void WebRtcSpl_DownsampleBy2(const int16_t* in, int len,
|
||||
void WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len,
|
||||
int16_t* out, int32_t* filtState);
|
||||
|
||||
void WebRtcSpl_UpsampleBy2(const int16_t* in, int len,
|
||||
void WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len,
|
||||
int16_t* out, int32_t* filtState);
|
||||
|
||||
/************************************************************
|
||||
* END OF RESAMPLING FUNCTIONS
|
||||
************************************************************/
|
||||
void WebRtcSpl_AnalysisQMF(const int16_t* in_data,
|
||||
int in_data_length,
|
||||
size_t in_data_length,
|
||||
int16_t* low_band,
|
||||
int16_t* high_band,
|
||||
int32_t* filter_state1,
|
||||
int32_t* filter_state2);
|
||||
void WebRtcSpl_SynthesisQMF(const int16_t* low_band,
|
||||
const int16_t* high_band,
|
||||
int band_length,
|
||||
size_t band_length,
|
||||
int16_t* out_data,
|
||||
int32_t* filter_state1,
|
||||
int32_t* filter_state2);
|
||||
|
||||
@ -20,9 +20,9 @@
|
||||
#define SPL_LEVINSON_MAXORDER 20
|
||||
|
||||
int16_t WebRtcSpl_LevinsonDurbin(const int32_t* R, int16_t* A, int16_t* K,
|
||||
int16_t order)
|
||||
size_t order)
|
||||
{
|
||||
int16_t i, j;
|
||||
size_t i, j;
|
||||
// Auto-correlation coefficients in high precision
|
||||
int16_t R_hi[SPL_LEVINSON_MAXORDER + 1], R_low[SPL_LEVINSON_MAXORDER + 1];
|
||||
// LPC coefficients in high precision
|
||||
|
||||
@ -33,10 +33,11 @@
|
||||
// TODO(kma): Move the next six functions into min_max_operations_c.c.
|
||||
|
||||
// Maximum absolute value of word16 vector. C version for generic platforms.
|
||||
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length) {
|
||||
int i = 0, absolute = 0, maximum = 0;
|
||||
int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
|
||||
size_t i = 0;
|
||||
int absolute = 0, maximum = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -57,14 +58,14 @@ int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Maximum absolute value of word32 vector. C version for generic platforms.
|
||||
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
|
||||
// Use uint32_t for the local variables, to accommodate the return value
|
||||
// of abs(0x80000000), which is 0x80000000.
|
||||
|
||||
uint32_t absolute = 0, maximum = 0;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -81,11 +82,11 @@ int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Maximum value of word16 vector. C version for generic platforms.
|
||||
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
|
||||
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -97,11 +98,11 @@ int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Maximum value of word32 vector. C version for generic platforms.
|
||||
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
|
||||
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -113,11 +114,11 @@ int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Minimum value of word16 vector. C version for generic platforms.
|
||||
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
|
||||
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
@ -129,11 +130,11 @@ int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Minimum value of word32 vector. C version for generic platforms.
|
||||
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
|
||||
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
@ -145,12 +146,13 @@ int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Index of maximum absolute value in a word16 vector.
|
||||
int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length) {
|
||||
int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
|
||||
// Use type int for local variables, to accomodate the value of abs(-32768).
|
||||
|
||||
int i = 0, absolute = 0, maximum = 0, index = 0;
|
||||
size_t i = 0, index = 0;
|
||||
int absolute = 0, maximum = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -163,15 +165,15 @@ int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
// Index of maximum value in a word16 vector.
|
||||
int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length) {
|
||||
int i = 0, index = 0;
|
||||
int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
|
||||
size_t i = 0, index = 0;
|
||||
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -182,15 +184,15 @@ int WebRtcSpl_MaxIndexW16(const int16_t* vector, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
// Index of maximum value in a word32 vector.
|
||||
int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length) {
|
||||
int i = 0, index = 0;
|
||||
int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
|
||||
size_t i = 0, index = 0;
|
||||
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -201,15 +203,15 @@ int WebRtcSpl_MaxIndexW32(const int32_t* vector, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
// Index of minimum value in a word16 vector.
|
||||
int WebRtcSpl_MinIndexW16(const int16_t* vector, int length) {
|
||||
int i = 0, index = 0;
|
||||
int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
|
||||
size_t i = 0, index = 0;
|
||||
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -220,15 +222,15 @@ int WebRtcSpl_MinIndexW16(const int16_t* vector, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
// Index of minimum value in a word32 vector.
|
||||
int WebRtcSpl_MinIndexW32(const int32_t* vector, int length) {
|
||||
int i = 0, index = 0;
|
||||
int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
|
||||
size_t i = 0, index = 0;
|
||||
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -239,5 +241,5 @@ int WebRtcSpl_MinIndexW32(const int32_t* vector, int length) {
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
// Maximum absolute value of word16 vector.
|
||||
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, size_t length) {
|
||||
int32_t totMax = 0;
|
||||
int32_t tmp32_0, tmp32_1, tmp32_2, tmp32_3;
|
||||
int i, loop_size;
|
||||
size_t i, loop_size;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
#if defined(MIPS_DSP_R1)
|
||||
@ -222,14 +222,14 @@ int16_t WebRtcSpl_MaxAbsValueW16_mips(const int16_t* vector, int length) {
|
||||
|
||||
#if defined(MIPS_DSP_R1_LE)
|
||||
// Maximum absolute value of word32 vector. Version for MIPS platform.
|
||||
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, size_t length) {
|
||||
// Use uint32_t for the local variables, to accommodate the return value
|
||||
// of abs(0x80000000), which is 0x80000000.
|
||||
|
||||
uint32_t absolute = 0, maximum = 0;
|
||||
int tmp1 = 0, max_value = 0x7fffffff;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -260,12 +260,12 @@ int32_t WebRtcSpl_MaxAbsValueW32_mips(const int32_t* vector, int length) {
|
||||
#endif // #if defined(MIPS_DSP_R1_LE)
|
||||
|
||||
// Maximum value of word16 vector. Version for MIPS platform.
|
||||
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, size_t length) {
|
||||
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
|
||||
int tmp1;
|
||||
int16_t value;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -291,11 +291,11 @@ int16_t WebRtcSpl_MaxValueW16_mips(const int16_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Maximum value of word32 vector. Version for MIPS platform.
|
||||
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, size_t length) {
|
||||
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
|
||||
int tmp1, value;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -322,12 +322,12 @@ int32_t WebRtcSpl_MaxValueW32_mips(const int32_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Minimum value of word16 vector. Version for MIPS platform.
|
||||
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, size_t length) {
|
||||
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
|
||||
int tmp1;
|
||||
int16_t value;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
@ -354,11 +354,11 @@ int16_t WebRtcSpl_MinValueW16_mips(const int16_t* vector, int length) {
|
||||
}
|
||||
|
||||
// Minimum value of word32 vector. Version for MIPS platform.
|
||||
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MinValueW32_mips(const int32_t* vector, size_t length) {
|
||||
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
|
||||
int tmp1, value;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
|
||||
@ -14,15 +14,15 @@
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
// Maximum absolute value of word16 vector. C version for generic platforms.
|
||||
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length) {
|
||||
int absolute = 0, maximum = 0;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int16_t* p_start = vector;
|
||||
int rest = length & 7;
|
||||
size_t rest = length & 7;
|
||||
const int16_t* p_end = vector + length - rest;
|
||||
|
||||
int16x8_t v;
|
||||
@ -69,15 +69,15 @@ int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, int length) {
|
||||
|
||||
// Maximum absolute value of word32 vector. NEON intrinsics version for
|
||||
// ARM 32-bit/64-bit platforms.
|
||||
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, size_t length) {
|
||||
// Use uint32_t for the local variables, to accommodate the return value
|
||||
// of abs(0x80000000), which is 0x80000000.
|
||||
|
||||
uint32_t absolute = 0, maximum = 0;
|
||||
int i = 0;
|
||||
int residual = length & 0x7;
|
||||
size_t i = 0;
|
||||
size_t residual = length & 0x7;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -126,12 +126,12 @@ int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length) {
|
||||
|
||||
// Maximum value of word16 vector. NEON intrinsics version for
|
||||
// ARM 32-bit/64-bit platforms.
|
||||
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, size_t length) {
|
||||
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
|
||||
int i = 0;
|
||||
int residual = length & 0x7;
|
||||
size_t i = 0;
|
||||
size_t residual = length & 0x7;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -166,12 +166,12 @@ int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length) {
|
||||
|
||||
// Maximum value of word32 vector. NEON intrinsics version for
|
||||
// ARM 32-bit/64-bit platforms.
|
||||
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, size_t length) {
|
||||
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
|
||||
int i = 0;
|
||||
int residual = length & 0x7;
|
||||
size_t i = 0;
|
||||
size_t residual = length & 0x7;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
@ -210,12 +210,12 @@ int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length) {
|
||||
|
||||
// Minimum value of word16 vector. NEON intrinsics version for
|
||||
// ARM 32-bit/64-bit platforms.
|
||||
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length) {
|
||||
int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, size_t length) {
|
||||
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
|
||||
int i = 0;
|
||||
int residual = length & 0x7;
|
||||
size_t i = 0;
|
||||
size_t residual = length & 0x7;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
@ -250,12 +250,12 @@ int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length) {
|
||||
|
||||
// Minimum value of word32 vector. NEON intrinsics version for
|
||||
// ARM 32-bit/64-bit platforms.
|
||||
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length) {
|
||||
int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, size_t length) {
|
||||
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
|
||||
int i = 0;
|
||||
int residual = length & 0x7;
|
||||
size_t i = 0;
|
||||
size_t residual = length & 0x7;
|
||||
|
||||
if (vector == NULL || length <= 0) {
|
||||
if (vector == NULL || length == 0) {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
|
||||
@ -67,10 +67,10 @@ static const uint16_t kResampleAllpass2[3] = {12199, 37471, 60255};
|
||||
|
||||
// decimator
|
||||
#if !defined(MIPS32_LE)
|
||||
void WebRtcSpl_DownsampleBy2(const int16_t* in, int len,
|
||||
void WebRtcSpl_DownsampleBy2(const int16_t* in, size_t len,
|
||||
int16_t* out, int32_t* filtState) {
|
||||
int32_t tmp1, tmp2, diff, in32, out32;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
register int32_t state0 = filtState[0];
|
||||
register int32_t state1 = filtState[1];
|
||||
@ -125,10 +125,10 @@ void WebRtcSpl_DownsampleBy2(const int16_t* in, int len,
|
||||
#endif // #if defined(MIPS32_LE)
|
||||
|
||||
|
||||
void WebRtcSpl_UpsampleBy2(const int16_t* in, int len,
|
||||
void WebRtcSpl_UpsampleBy2(const int16_t* in, size_t len,
|
||||
int16_t* out, int32_t* filtState) {
|
||||
int32_t tmp1, tmp2, diff, in32, out32;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
register int32_t state0 = filtState[0];
|
||||
register int32_t state1 = filtState[1];
|
||||
|
||||
@ -29,11 +29,11 @@ static const uint16_t kResampleAllpass2[3] = {12199, 37471, 60255};
|
||||
|
||||
// decimator
|
||||
void WebRtcSpl_DownsampleBy2(const int16_t* in,
|
||||
int len,
|
||||
size_t len,
|
||||
int16_t* out,
|
||||
int32_t* filtState) {
|
||||
int32_t out32;
|
||||
int i, len1;
|
||||
size_t i, len1;
|
||||
|
||||
register int32_t state0 = filtState[0];
|
||||
register int32_t state1 = filtState[1];
|
||||
|
||||
@ -41,7 +41,7 @@ static const int16_t kCoefficients44To32[4][9] = {
|
||||
// output: int32_t (shifted 15 positions to the left, + offset 16384) :: size 2 * K
|
||||
// K: number of blocks
|
||||
|
||||
void WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
void WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, size_t K)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Filter operation:
|
||||
@ -49,7 +49,7 @@ void WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
// Perform resampling (3 input samples -> 2 output samples);
|
||||
// process in sub blocks of size 3 samples.
|
||||
int32_t tmp;
|
||||
int32_t m;
|
||||
size_t m;
|
||||
|
||||
for (m = 0; m < K; m++)
|
||||
{
|
||||
@ -86,14 +86,14 @@ void WebRtcSpl_Resample48khzTo32khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
// output: int32_t (shifted 15 positions to the left, + offset 16384) :: size 3 * K
|
||||
// K: number of blocks
|
||||
|
||||
void WebRtcSpl_Resample32khzTo24khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
void WebRtcSpl_Resample32khzTo24khz(const int32_t *In, int32_t *Out, size_t K)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Filter operation:
|
||||
//
|
||||
// Perform resampling (4 input samples -> 3 output samples);
|
||||
// process in sub blocks of size 4 samples.
|
||||
int32_t m;
|
||||
size_t m;
|
||||
int32_t tmp;
|
||||
|
||||
for (m = 0; m < K; m++)
|
||||
@ -194,7 +194,7 @@ static void WebRtcSpl_ResampDotProduct(const int32_t *in1, const int32_t *in2,
|
||||
// output: int32_t (shifted 15 positions to the left, + offset 16384) :: size 8 * K
|
||||
// K: number of blocks
|
||||
|
||||
void WebRtcSpl_Resample44khzTo32khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
void WebRtcSpl_Resample44khzTo32khz(const int32_t *In, int32_t *Out, size_t K)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Filter operation:
|
||||
@ -202,7 +202,7 @@ void WebRtcSpl_Resample44khzTo32khz(const int32_t *In, int32_t *Out, int32_t K)
|
||||
// Perform resampling (11 input samples -> 8 output samples);
|
||||
// process in sub blocks of size 11 samples.
|
||||
int32_t tmp;
|
||||
int32_t m;
|
||||
size_t m;
|
||||
|
||||
for (m = 0; m < K; m++)
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
static const int kVector16Size = 9;
|
||||
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};
|
||||
|
||||
@ -157,7 +157,7 @@ TEST_F(SplTest, MathOperationsTest) {
|
||||
}
|
||||
|
||||
TEST_F(SplTest, BasicArrayOperationsTest) {
|
||||
const int kVectorSize = 4;
|
||||
const size_t kVectorSize = 4;
|
||||
int B[] = {4, 12, 133, 1100};
|
||||
int16_t b16[kVectorSize];
|
||||
int32_t b32[kVectorSize];
|
||||
@ -166,27 +166,27 @@ TEST_F(SplTest, BasicArrayOperationsTest) {
|
||||
int32_t bTmp32[kVectorSize];
|
||||
|
||||
WebRtcSpl_MemSetW16(b16, 3, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(3, b16[kk]);
|
||||
}
|
||||
WebRtcSpl_ZerosArrayW16(b16, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(0, b16[kk]);
|
||||
}
|
||||
WebRtcSpl_MemSetW32(b32, 3, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(3, b32[kk]);
|
||||
}
|
||||
WebRtcSpl_ZerosArrayW32(b32, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(0, b32[kk]);
|
||||
}
|
||||
for (int kk = 0; kk < kVectorSize; ++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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(b16[kk], bTmp16[kk]);
|
||||
}
|
||||
// WEBRTC_SPL_MEMCPY_W32(b32, bTmp32, kVectorSize);
|
||||
@ -194,36 +194,36 @@ TEST_F(SplTest, BasicArrayOperationsTest) {
|
||||
// EXPECT_EQ(b32[kk], bTmp32[kk]);
|
||||
// }
|
||||
WebRtcSpl_CopyFromEndW16(b16, kVectorSize, 2, bTmp16);
|
||||
for (int kk = 0; kk < 2; ++kk) {
|
||||
EXPECT_EQ(kk+2, bTmp16[kk]);
|
||||
for (size_t kk = 0; kk < 2; ++kk) {
|
||||
EXPECT_EQ(static_cast<int16_t>(kk+2), bTmp16[kk]);
|
||||
}
|
||||
|
||||
for (int kk = 0; kk < kVectorSize; ++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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ((B[kk]>>1), bTmp16[kk]);
|
||||
}
|
||||
WebRtcSpl_VectorBitShiftW16(bTmp16, kVectorSize, b16, 1);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ((B[kk]>>1), bTmp16[kk]);
|
||||
}
|
||||
WebRtcSpl_VectorBitShiftW32(bTmp32, kVectorSize, b32, 1);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ((B[kk]>>1), bTmp32[kk]);
|
||||
}
|
||||
|
||||
WebRtcSpl_MemCpyReversedOrder(&bTmp16[3], b16, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(b16[3-kk], bTmp16[kk]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SplTest, ExeptionsHandlingMinMaxOperationsTest) {
|
||||
// Test how the functions handle exceptional cases.
|
||||
const int kVectorSize = 2;
|
||||
const size_t kVectorSize = 2;
|
||||
int16_t vector16[kVectorSize] = {0};
|
||||
int32_t vector32[kVectorSize] = {0};
|
||||
|
||||
@ -252,7 +252,7 @@ TEST_F(SplTest, ExeptionsHandlingMinMaxOperationsTest) {
|
||||
}
|
||||
|
||||
TEST_F(SplTest, MinMaxOperationsTest) {
|
||||
const int kVectorSize = 17;
|
||||
const size_t kVectorSize = 17;
|
||||
|
||||
// Vectors to test the cases where minimum values have to be caught
|
||||
// outside of the unrolled loops in ARM-Neon.
|
||||
@ -267,8 +267,10 @@ TEST_F(SplTest, MinMaxOperationsTest) {
|
||||
WebRtcSpl_MinValueW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(WEBRTC_SPL_WORD32_MIN,
|
||||
WebRtcSpl_MinValueW32(vector32, kVectorSize));
|
||||
EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MinIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MinIndexW32(vector32, kVectorSize));
|
||||
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
|
||||
WebRtcSpl_MinIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
|
||||
WebRtcSpl_MinIndexW32(vector32, kVectorSize));
|
||||
|
||||
// Test the cases where maximum values have to be caught
|
||||
// outside of the unrolled loops in ARM-Neon.
|
||||
@ -283,9 +285,12 @@ TEST_F(SplTest, MinMaxOperationsTest) {
|
||||
WebRtcSpl_MaxAbsValueW32(vector32, kVectorSize));
|
||||
EXPECT_EQ(WEBRTC_SPL_WORD32_MAX,
|
||||
WebRtcSpl_MaxValueW32(vector32, kVectorSize));
|
||||
EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(kVectorSize - 1, WebRtcSpl_MaxIndexW32(vector32, kVectorSize));
|
||||
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
|
||||
WebRtcSpl_MaxAbsIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
|
||||
WebRtcSpl_MaxIndexW16(vector16, kVectorSize));
|
||||
EXPECT_EQ(static_cast<int>(kVectorSize - 1),
|
||||
WebRtcSpl_MaxIndexW32(vector32, kVectorSize));
|
||||
|
||||
// Test the cases where multiple maximum and minimum values are present.
|
||||
vector16[1] = WEBRTC_SPL_WORD16_MAX;
|
||||
@ -315,59 +320,59 @@ TEST_F(SplTest, MinMaxOperationsTest) {
|
||||
}
|
||||
|
||||
TEST_F(SplTest, VectorOperationsTest) {
|
||||
const int kVectorSize = 4;
|
||||
const size_t kVectorSize = 4;
|
||||
int B[] = {4, 12, 133, 1100};
|
||||
int16_t a16[kVectorSize];
|
||||
int16_t b16[kVectorSize];
|
||||
int16_t bTmp16[kVectorSize];
|
||||
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ((b16[kk]*13)>>2, bTmp16[kk]);
|
||||
}
|
||||
WebRtcSpl_ScaleVectorWithSat(b16, bTmp16, 13, kVectorSize, 2);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(B[kk] >> 1, bTmp16[kk]);
|
||||
}
|
||||
WebRtcSpl_ReverseOrderMultArrayElements(bTmp16, a16, &b16[3], kVectorSize, 2);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
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 (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ((a16[kk]*b16[kk])>>6, bTmp16[kk]);
|
||||
}
|
||||
|
||||
WebRtcSpl_SqrtOfOneMinusXSquared(b16, kVectorSize, bTmp16);
|
||||
for (int kk = 0; kk < kVectorSize - 1; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize - 1; ++kk) {
|
||||
EXPECT_EQ(32767, bTmp16[kk]);
|
||||
}
|
||||
EXPECT_EQ(32749, bTmp16[kVectorSize - 1]);
|
||||
@ -376,7 +381,7 @@ TEST_F(SplTest, VectorOperationsTest) {
|
||||
}
|
||||
|
||||
TEST_F(SplTest, EstimatorsTest) {
|
||||
const int16_t kOrder = 2;
|
||||
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 };
|
||||
@ -386,15 +391,15 @@ TEST_F(SplTest, EstimatorsTest) {
|
||||
|
||||
EXPECT_EQ(0, WebRtcSpl_LevinsonDurbin(unstable_filter, lpc, refl, kOrder));
|
||||
EXPECT_EQ(1, WebRtcSpl_LevinsonDurbin(stable_filter, lpc, refl, kOrder));
|
||||
for (int i = 0; i < kOrder + 2; ++i) {
|
||||
for (size_t i = 0; i < kOrder + 2; ++i) {
|
||||
EXPECT_EQ(lpc_result[i], lpc[i]);
|
||||
EXPECT_EQ(refl_result[i], refl[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SplTest, FilterTest) {
|
||||
const int kVectorSize = 4;
|
||||
const int kFilterOrder = 3;
|
||||
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};
|
||||
@ -407,7 +412,7 @@ TEST_F(SplTest, FilterTest) {
|
||||
WebRtcSpl_ZerosArrayW16(bState, kVectorSize);
|
||||
WebRtcSpl_ZerosArrayW16(bStateLow, kVectorSize);
|
||||
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
data_in[kk] = A[kk];
|
||||
data_out[kk] = 0;
|
||||
}
|
||||
@ -460,10 +465,10 @@ TEST_F(SplTest, DotProductWithScaleTest) {
|
||||
|
||||
TEST_F(SplTest, CrossCorrelationTest) {
|
||||
// Note the function arguments relation specificed by API.
|
||||
const int kCrossCorrelationDimension = 3;
|
||||
const size_t kCrossCorrelationDimension = 3;
|
||||
const int kShift = 2;
|
||||
const int kStep = 1;
|
||||
const int kSeqDimension = 6;
|
||||
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};
|
||||
@ -484,7 +489,7 @@ TEST_F(SplTest, CrossCorrelationTest) {
|
||||
expected = kExpectedNeon;
|
||||
}
|
||||
#endif
|
||||
for (int i = 0; i < kCrossCorrelationDimension; ++i) {
|
||||
for (size_t i = 0; i < kCrossCorrelationDimension; ++i) {
|
||||
EXPECT_EQ(expected[i], vector32[i]);
|
||||
}
|
||||
}
|
||||
@ -497,17 +502,17 @@ TEST_F(SplTest, AutoCorrelationTest) {
|
||||
|
||||
EXPECT_EQ(-1, WebRtcSpl_AutoCorrelation(vector16, kVector16Size,
|
||||
kVector16Size + 1, vector32, &scale));
|
||||
EXPECT_EQ(kVector16Size,
|
||||
EXPECT_EQ(static_cast<int>(kVector16Size),
|
||||
WebRtcSpl_AutoCorrelation(vector16, kVector16Size,
|
||||
kVector16Size - 1, vector32, &scale));
|
||||
EXPECT_EQ(3, scale);
|
||||
for (int i = 0; i < kVector16Size; ++i) {
|
||||
for (size_t i = 0; i < kVector16Size; ++i) {
|
||||
EXPECT_EQ(expected[i], vector32[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SplTest, SignalProcessingTest) {
|
||||
const int kVectorSize = 4;
|
||||
const size_t kVectorSize = 4;
|
||||
int A[] = {1, 2, 33, 100};
|
||||
const int16_t kHanning[4] = { 2399, 8192, 13985, 16384 };
|
||||
int16_t b16[kVectorSize];
|
||||
@ -516,7 +521,7 @@ TEST_F(SplTest, SignalProcessingTest) {
|
||||
|
||||
int bScale = 0;
|
||||
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
b16[kk] = A[kk];
|
||||
}
|
||||
|
||||
@ -535,11 +540,11 @@ TEST_F(SplTest, SignalProcessingTest) {
|
||||
//// }
|
||||
|
||||
WebRtcSpl_GetHanningWindow(bTmp16, kVectorSize);
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
EXPECT_EQ(kHanning[kk], bTmp16[kk]);
|
||||
}
|
||||
|
||||
for (int kk = 0; kk < kVectorSize; ++kk) {
|
||||
for (size_t kk = 0; kk < kVectorSize; ++kk) {
|
||||
b16[kk] = A[kk];
|
||||
}
|
||||
EXPECT_EQ(11094 , WebRtcSpl_Energy(b16, kVectorSize, &bScale));
|
||||
@ -569,7 +574,7 @@ TEST_F(SplTest, FFTTest) {
|
||||
TEST_F(SplTest, Resample48WithSaturationTest) {
|
||||
// The test resamples 3*kBlockSize number of samples to 2*kBlockSize number
|
||||
// of samples.
|
||||
const int kBlockSize = 16;
|
||||
const size_t kBlockSize = 16;
|
||||
|
||||
// Saturated input vector of 48 samples.
|
||||
const int32_t kVectorSaturated[3 * kBlockSize + 7] = {
|
||||
@ -600,11 +605,11 @@ TEST_F(SplTest, Resample48WithSaturationTest) {
|
||||
|
||||
// Comparing output values against references. The values at position
|
||||
// 12-15 are skipped to account for the filter lag.
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
for (size_t i = 0; i < 12; ++i) {
|
||||
EXPECT_EQ(kRefValue32kHz1, out_vector[i]);
|
||||
EXPECT_EQ(kRefValue16kHz1, out_vector_w16[i]);
|
||||
}
|
||||
for (int i = 16; i < 2 * kBlockSize; ++i) {
|
||||
for (size_t i = 16; i < 2 * kBlockSize; ++i) {
|
||||
EXPECT_EQ(kRefValue32kHz2, out_vector[i]);
|
||||
EXPECT_EQ(kRefValue16kHz2, out_vector_w16[i]);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ static const uint16_t WebRtcSpl_kAllPassFilter2[3] = {21333, 49062, 63010};
|
||||
// |data_length|
|
||||
//
|
||||
|
||||
void WebRtcSpl_AllPassQMF(int32_t* in_data, int data_length,
|
||||
void WebRtcSpl_AllPassQMF(int32_t* in_data, size_t data_length,
|
||||
int32_t* out_data, const uint16_t* filter_coefficients,
|
||||
int32_t* filter_state)
|
||||
{
|
||||
@ -65,7 +65,7 @@ void WebRtcSpl_AllPassQMF(int32_t* in_data, int data_length,
|
||||
// filter operation takes the |in_data| (which is the output from the previous cascade
|
||||
// filter) and store the output in |out_data|.
|
||||
// Note that the input vector values are changed during the process.
|
||||
int k;
|
||||
size_t k;
|
||||
int32_t diff;
|
||||
// First all-pass cascade; filter from in_data to out_data.
|
||||
|
||||
@ -124,18 +124,18 @@ void WebRtcSpl_AllPassQMF(int32_t* in_data, int data_length,
|
||||
filter_state[5] = out_data[data_length - 1]; // y[N-1], becomes y[-1] next time
|
||||
}
|
||||
|
||||
void WebRtcSpl_AnalysisQMF(const int16_t* in_data, int in_data_length,
|
||||
void WebRtcSpl_AnalysisQMF(const int16_t* in_data, size_t in_data_length,
|
||||
int16_t* low_band, int16_t* high_band,
|
||||
int32_t* filter_state1, int32_t* filter_state2)
|
||||
{
|
||||
int16_t i;
|
||||
size_t i;
|
||||
int16_t k;
|
||||
int32_t tmp;
|
||||
int32_t half_in1[kMaxBandFrameLength];
|
||||
int32_t half_in2[kMaxBandFrameLength];
|
||||
int32_t filter1[kMaxBandFrameLength];
|
||||
int32_t filter2[kMaxBandFrameLength];
|
||||
const int band_length = in_data_length / 2;
|
||||
const size_t band_length = in_data_length / 2;
|
||||
assert(in_data_length % 2 == 0);
|
||||
assert(band_length <= kMaxBandFrameLength);
|
||||
|
||||
@ -165,7 +165,7 @@ void WebRtcSpl_AnalysisQMF(const int16_t* in_data, int in_data_length,
|
||||
}
|
||||
|
||||
void WebRtcSpl_SynthesisQMF(const int16_t* low_band, const int16_t* high_band,
|
||||
int band_length, int16_t* out_data,
|
||||
size_t band_length, int16_t* out_data,
|
||||
int32_t* filter_state1, int32_t* filter_state2)
|
||||
{
|
||||
int32_t tmp;
|
||||
@ -173,7 +173,7 @@ void WebRtcSpl_SynthesisQMF(const int16_t* low_band, const int16_t* high_band,
|
||||
int32_t half_in2[kMaxBandFrameLength];
|
||||
int32_t filter1[kMaxBandFrameLength];
|
||||
int32_t filter2[kMaxBandFrameLength];
|
||||
int16_t i;
|
||||
size_t i;
|
||||
int16_t k;
|
||||
assert(band_length <= kMaxBandFrameLength);
|
||||
|
||||
|
||||
@ -17,11 +17,11 @@
|
||||
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t *xQ15, int vector_length,
|
||||
void WebRtcSpl_SqrtOfOneMinusXSquared(int16_t *xQ15, size_t vector_length,
|
||||
int16_t *yQ15)
|
||||
{
|
||||
int32_t sq;
|
||||
int m;
|
||||
size_t m;
|
||||
int16_t tmp;
|
||||
|
||||
for (m = 0; m < vector_length; m++)
|
||||
|
||||
@ -22,10 +22,10 @@
|
||||
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
|
||||
void WebRtcSpl_VectorBitShiftW16(int16_t *res, int16_t length,
|
||||
void WebRtcSpl_VectorBitShiftW16(int16_t *res, size_t length,
|
||||
const int16_t *in, int16_t right_shifts)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (right_shifts > 0)
|
||||
{
|
||||
@ -43,11 +43,11 @@ void WebRtcSpl_VectorBitShiftW16(int16_t *res, int16_t length,
|
||||
}
|
||||
|
||||
void WebRtcSpl_VectorBitShiftW32(int32_t *out_vector,
|
||||
int16_t vector_length,
|
||||
size_t vector_length,
|
||||
const int32_t *in_vector,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (right_shifts > 0)
|
||||
{
|
||||
@ -64,9 +64,9 @@ void WebRtcSpl_VectorBitShiftW32(int32_t *out_vector,
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, int length,
|
||||
void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, size_t length,
|
||||
const int32_t* in, int right_shifts) {
|
||||
int i;
|
||||
size_t i;
|
||||
int32_t tmp_w32;
|
||||
|
||||
if (right_shifts >= 0) {
|
||||
@ -84,11 +84,11 @@ void WebRtcSpl_VectorBitShiftW32ToW16(int16_t* out, int length,
|
||||
}
|
||||
|
||||
void WebRtcSpl_ScaleVector(const int16_t *in_vector, int16_t *out_vector,
|
||||
int16_t gain, int16_t in_vector_length,
|
||||
int16_t gain, size_t in_vector_length,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
// Performs vector operation: out_vector = (gain*in_vector)>>right_shifts
|
||||
int i;
|
||||
size_t i;
|
||||
const int16_t *inptr;
|
||||
int16_t *outptr;
|
||||
|
||||
@ -102,11 +102,11 @@ void WebRtcSpl_ScaleVector(const int16_t *in_vector, int16_t *out_vector,
|
||||
}
|
||||
|
||||
void WebRtcSpl_ScaleVectorWithSat(const int16_t *in_vector, int16_t *out_vector,
|
||||
int16_t gain, int16_t in_vector_length,
|
||||
int16_t gain, size_t in_vector_length,
|
||||
int16_t right_shifts)
|
||||
{
|
||||
// Performs vector operation: out_vector = (gain*in_vector)>>right_shifts
|
||||
int i;
|
||||
size_t i;
|
||||
const int16_t *inptr;
|
||||
int16_t *outptr;
|
||||
|
||||
@ -120,10 +120,10 @@ void WebRtcSpl_ScaleVectorWithSat(const int16_t *in_vector, int16_t *out_vector,
|
||||
|
||||
void WebRtcSpl_ScaleAndAddVectors(const int16_t *in1, int16_t gain1, int shift1,
|
||||
const int16_t *in2, int16_t gain2, int shift2,
|
||||
int16_t *out, int vector_length)
|
||||
int16_t *out, size_t vector_length)
|
||||
{
|
||||
// Performs vector operation: out = (gain1*in1)>>shift1 + (gain2*in2)>>shift2
|
||||
int i;
|
||||
size_t i;
|
||||
const int16_t *in1ptr;
|
||||
const int16_t *in2ptr;
|
||||
int16_t *outptr;
|
||||
@ -146,12 +146,12 @@ int WebRtcSpl_ScaleAndAddVectorsWithRoundC(const int16_t* in_vector1,
|
||||
int16_t in_vector2_scale,
|
||||
int right_shifts,
|
||||
int16_t* out_vector,
|
||||
int length) {
|
||||
int i = 0;
|
||||
size_t length) {
|
||||
size_t i = 0;
|
||||
int round_value = (1 << right_shifts) >> 1;
|
||||
|
||||
if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL ||
|
||||
length <= 0 || right_shifts < 0) {
|
||||
length == 0 || right_shifts < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -22,15 +22,16 @@ int WebRtcSpl_ScaleAndAddVectorsWithRound_mips(const int16_t* in_vector1,
|
||||
int16_t in_vector2_scale,
|
||||
int right_shifts,
|
||||
int16_t* out_vector,
|
||||
int length) {
|
||||
size_t length) {
|
||||
int16_t r0 = 0, r1 = 0;
|
||||
int16_t *in1 = (int16_t*)in_vector1;
|
||||
int16_t *in2 = (int16_t*)in_vector2;
|
||||
int16_t *out = out_vector;
|
||||
int i = 0, value32 = 0;
|
||||
size_t i = 0;
|
||||
int value32 = 0;
|
||||
|
||||
if (in_vector1 == NULL || in_vector2 == NULL || out_vector == NULL ||
|
||||
length <= 0 || right_shifts < 0) {
|
||||
length == 0 || right_shifts < 0) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
|
||||
@ -15,24 +15,24 @@
|
||||
namespace webrtc {
|
||||
|
||||
SparseFIRFilter::SparseFIRFilter(const float* nonzero_coeffs,
|
||||
int num_nonzero_coeffs,
|
||||
int sparsity,
|
||||
int offset)
|
||||
size_t num_nonzero_coeffs,
|
||||
size_t sparsity,
|
||||
size_t offset)
|
||||
: sparsity_(sparsity),
|
||||
offset_(offset),
|
||||
nonzero_coeffs_(nonzero_coeffs, nonzero_coeffs + num_nonzero_coeffs),
|
||||
state_(sparsity_ * (num_nonzero_coeffs - 1) + offset_, 0.f) {
|
||||
CHECK_GE(num_nonzero_coeffs, 1);
|
||||
CHECK_GE(sparsity, 1);
|
||||
CHECK_GE(num_nonzero_coeffs, 1u);
|
||||
CHECK_GE(sparsity, 1u);
|
||||
}
|
||||
|
||||
void SparseFIRFilter::Filter(const float* in, int length, float* out) {
|
||||
void SparseFIRFilter::Filter(const float* in, size_t length, float* out) {
|
||||
// Convolves the input signal |in| with the filter kernel |nonzero_coeffs_|
|
||||
// taking into account the previous state.
|
||||
for (int i = 0; i < length; ++i) {
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
out[i] = 0.f;
|
||||
size_t j;
|
||||
for (j = 0; i >= static_cast<int>(j) * sparsity_ + offset_ &&
|
||||
for (j = 0; i >= j * sparsity_ + offset_ &&
|
||||
j < nonzero_coeffs_.size(); ++j) {
|
||||
out[i] += in[i - j * sparsity_ - offset_] * nonzero_coeffs_[j];
|
||||
}
|
||||
@ -44,7 +44,7 @@ void SparseFIRFilter::Filter(const float* in, int length, float* out) {
|
||||
|
||||
// Update current state.
|
||||
if (state_.size() > 0u) {
|
||||
if (length >= static_cast<int>(state_.size())) {
|
||||
if (length >= state_.size()) {
|
||||
std::memcpy(&state_[0],
|
||||
&in[length - state_.size()],
|
||||
state_.size() * sizeof(*in));
|
||||
|
||||
@ -30,17 +30,17 @@ class SparseFIRFilter final {
|
||||
// B = [0 coeffs[0] 0 0 coeffs[1] 0 0 coeffs[2] ... ]
|
||||
// All initial state values will be zeros.
|
||||
SparseFIRFilter(const float* nonzero_coeffs,
|
||||
int num_nonzero_coeffs,
|
||||
int sparsity,
|
||||
int offset);
|
||||
size_t num_nonzero_coeffs,
|
||||
size_t sparsity,
|
||||
size_t offset);
|
||||
|
||||
// Filters the |in| data supplied.
|
||||
// |out| must be previously allocated and it must be at least of |length|.
|
||||
void Filter(const float* in, int length, float* out);
|
||||
void Filter(const float* in, size_t length, float* out);
|
||||
|
||||
private:
|
||||
const int sparsity_;
|
||||
const int offset_;
|
||||
const size_t sparsity_;
|
||||
const size_t offset_;
|
||||
const std::vector<float> nonzero_coeffs_;
|
||||
std::vector<float> state_;
|
||||
|
||||
|
||||
@ -31,9 +31,9 @@ void VerifyOutput(const float (&expected_output)[N], const float (&output)[N]) {
|
||||
|
||||
TEST(SparseFIRFilterTest, FilterAsIdentity) {
|
||||
const float kCoeff = 1.f;
|
||||
const int kNumCoeff = 1;
|
||||
const int kSparsity = 3;
|
||||
const int kOffset = 0;
|
||||
const size_t kNumCoeff = 1;
|
||||
const size_t kSparsity = 3;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(&kCoeff, kNumCoeff, kSparsity, kOffset);
|
||||
filter.Filter(kInput, arraysize(kInput), output);
|
||||
@ -42,10 +42,10 @@ TEST(SparseFIRFilterTest, FilterAsIdentity) {
|
||||
|
||||
TEST(SparseFIRFilterTest, SameOutputForScalarCoefficientAndDifferentSparsity) {
|
||||
const float kCoeff = 2.f;
|
||||
const int kNumCoeff = 1;
|
||||
const int kLowSparsity = 1;
|
||||
const int kHighSparsity = 7;
|
||||
const int kOffset = 0;
|
||||
const size_t kNumCoeff = 1;
|
||||
const size_t kLowSparsity = 1;
|
||||
const size_t kHighSparsity = 7;
|
||||
const size_t kOffset = 0;
|
||||
float low_sparsity_output[arraysize(kInput)];
|
||||
float high_sparsity_output[arraysize(kInput)];
|
||||
SparseFIRFilter low_sparsity_filter(&kCoeff,
|
||||
@ -63,9 +63,9 @@ TEST(SparseFIRFilterTest, SameOutputForScalarCoefficientAndDifferentSparsity) {
|
||||
|
||||
TEST(SparseFIRFilterTest, FilterUsedAsScalarMultiplication) {
|
||||
const float kCoeff = 5.f;
|
||||
const int kNumCoeff = 1;
|
||||
const int kSparsity = 5;
|
||||
const int kOffset = 0;
|
||||
const size_t kNumCoeff = 1;
|
||||
const size_t kSparsity = 5;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(&kCoeff, kNumCoeff, kSparsity, kOffset);
|
||||
filter.Filter(kInput, arraysize(kInput), output);
|
||||
@ -77,9 +77,9 @@ TEST(SparseFIRFilterTest, FilterUsedAsScalarMultiplication) {
|
||||
|
||||
TEST(SparseFIRFilterTest, FilterUsedAsInputShifting) {
|
||||
const float kCoeff = 1.f;
|
||||
const int kNumCoeff = 1;
|
||||
const int kSparsity = 1;
|
||||
const int kOffset = 4;
|
||||
const size_t kNumCoeff = 1;
|
||||
const size_t kSparsity = 1;
|
||||
const size_t kOffset = 4;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(&kCoeff, kNumCoeff, kSparsity, kOffset);
|
||||
filter.Filter(kInput, arraysize(kInput), output);
|
||||
@ -91,8 +91,8 @@ TEST(SparseFIRFilterTest, FilterUsedAsInputShifting) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, FilterUsedAsArbitraryWeighting) {
|
||||
const int kSparsity = 2;
|
||||
const int kOffset = 1;
|
||||
const size_t kSparsity = 2;
|
||||
const size_t kOffset = 1;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset);
|
||||
filter.Filter(kInput, arraysize(kInput), output);
|
||||
@ -104,8 +104,8 @@ TEST(SparseFIRFilterTest, FilterUsedAsArbitraryWeighting) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, FilterInLengthLesserOrEqualToCoefficientsLength) {
|
||||
const int kSparsity = 1;
|
||||
const int kOffset = 0;
|
||||
const size_t kSparsity = 1;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset);
|
||||
filter.Filter(kInput, 2, output);
|
||||
@ -114,8 +114,8 @@ TEST(SparseFIRFilterTest, FilterInLengthLesserOrEqualToCoefficientsLength) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, MultipleFilterCalls) {
|
||||
const int kSparsity = 1;
|
||||
const int kOffset = 0;
|
||||
const size_t kSparsity = 1;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kInput)];
|
||||
SparseFIRFilter filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset);
|
||||
filter.Filter(kInput, 2, output);
|
||||
@ -141,8 +141,8 @@ TEST(SparseFIRFilterTest, MultipleFilterCalls) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, VerifySampleBasedVsBlockBasedFiltering) {
|
||||
const int kSparsity = 3;
|
||||
const int kOffset = 1;
|
||||
const size_t kSparsity = 3;
|
||||
const size_t kOffset = 1;
|
||||
float output_block_based[arraysize(kInput)];
|
||||
SparseFIRFilter filter_block(kCoeffs,
|
||||
arraysize(kCoeffs),
|
||||
@ -160,8 +160,8 @@ TEST(SparseFIRFilterTest, VerifySampleBasedVsBlockBasedFiltering) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, SimpleHighPassFilter) {
|
||||
const int kSparsity = 2;
|
||||
const int kOffset = 2;
|
||||
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};
|
||||
@ -177,8 +177,8 @@ TEST(SparseFIRFilterTest, SimpleHighPassFilter) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, SimpleLowPassFilter) {
|
||||
const int kSparsity = 2;
|
||||
const int kOffset = 2;
|
||||
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};
|
||||
@ -194,8 +194,8 @@ TEST(SparseFIRFilterTest, SimpleLowPassFilter) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, SameOutputWhenSwappedCoefficientsAndInput) {
|
||||
const int kSparsity = 1;
|
||||
const int kOffset = 0;
|
||||
const size_t kSparsity = 1;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kCoeffs)];
|
||||
float output_swapped[arraysize(kCoeffs)];
|
||||
SparseFIRFilter filter(kCoeffs, arraysize(kCoeffs), kSparsity, kOffset);
|
||||
@ -210,8 +210,8 @@ TEST(SparseFIRFilterTest, SameOutputWhenSwappedCoefficientsAndInput) {
|
||||
}
|
||||
|
||||
TEST(SparseFIRFilterTest, SameOutputAsFIRFilterWhenSparsityOneAndOffsetZero) {
|
||||
const int kSparsity = 1;
|
||||
const int kOffset = 0;
|
||||
const size_t kSparsity = 1;
|
||||
const size_t kOffset = 0;
|
||||
float output[arraysize(kInput)];
|
||||
float sparse_output[arraysize(kInput)];
|
||||
rtc::scoped_ptr<FIRFilter> filter(FIRFilter::Create(kCoeffs,
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
#ifndef WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_ // NOLINT
|
||||
#define WEBRTC_COMMON_AUDIO_VAD_INCLUDE_WEBRTC_VAD_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
typedef struct WebRtcVadInst VadInst;
|
||||
@ -66,7 +68,7 @@ int WebRtcVad_set_mode(VadInst* handle, int mode);
|
||||
// 0 - (Non-active Voice),
|
||||
// -1 - (Error)
|
||||
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||
int frame_length);
|
||||
size_t frame_length);
|
||||
|
||||
// Checks for valid combinations of |rate| and |frame_length|. We support 10,
|
||||
// 20 and 30 ms frames and the rates 8000, 16000 and 32000 Hz.
|
||||
@ -75,7 +77,7 @@ int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||
// - frame_length [i] : Speech frame buffer length in number of samples.
|
||||
//
|
||||
// returns : 0 - (valid combination), -1 - (invalid combination)
|
||||
int WebRtcVad_ValidRateAndFrameLength(int rate, int frame_length);
|
||||
int WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -28,8 +28,7 @@ Vad::~Vad() {
|
||||
enum Vad::Activity Vad::VoiceActivity(const int16_t* audio,
|
||||
size_t num_samples,
|
||||
int sample_rate_hz) {
|
||||
int ret = WebRtcVad_Process(
|
||||
handle_, sample_rate_hz, audio, static_cast<int>(num_samples));
|
||||
int ret = WebRtcVad_Process(handle_, sample_rate_hz, audio, num_samples);
|
||||
switch (ret) {
|
||||
case 0:
|
||||
return kPassive;
|
||||
|
||||
@ -122,7 +122,7 @@ static int32_t WeightedAverage(int16_t* data, int16_t offset,
|
||||
//
|
||||
// - returns : the VAD decision (0 - noise, 1 - speech).
|
||||
static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
||||
int16_t total_power, int frame_length) {
|
||||
int16_t total_power, size_t frame_length) {
|
||||
int channel, k;
|
||||
int16_t feature_minimum;
|
||||
int16_t h0, h1;
|
||||
@ -596,16 +596,16 @@ int WebRtcVad_set_mode_core(VadInstT* self, int mode) {
|
||||
// probability for both speech and background noise.
|
||||
|
||||
int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length) {
|
||||
size_t frame_length) {
|
||||
int vad;
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t speech_nb[240]; // 30 ms in 8 kHz.
|
||||
// |tmp_mem| is a temporary memory used by resample function, length is
|
||||
// frame length in 10 ms (480 samples) + 256 extra.
|
||||
int32_t tmp_mem[480 + 256] = { 0 };
|
||||
const int kFrameLen10ms48khz = 480;
|
||||
const int kFrameLen10ms8khz = 80;
|
||||
int num_10ms_frames = frame_length / kFrameLen10ms48khz;
|
||||
const size_t kFrameLen10ms48khz = 480;
|
||||
const size_t kFrameLen10ms8khz = 80;
|
||||
size_t num_10ms_frames = frame_length / kFrameLen10ms48khz;
|
||||
|
||||
for (i = 0; i < num_10ms_frames; i++) {
|
||||
WebRtcSpl_Resample48khzTo8khz(speech_frame,
|
||||
@ -621,9 +621,10 @@ int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
}
|
||||
|
||||
int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length)
|
||||
size_t frame_length)
|
||||
{
|
||||
int len, vad;
|
||||
size_t len;
|
||||
int vad;
|
||||
int16_t speechWB[480]; // Downsampled speech frame: 960 samples (30ms in SWB)
|
||||
int16_t speechNB[240]; // Downsampled speech frame: 480 samples (30ms in WB)
|
||||
|
||||
@ -643,9 +644,10 @@ int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
}
|
||||
|
||||
int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length)
|
||||
size_t frame_length)
|
||||
{
|
||||
int len, vad;
|
||||
size_t len;
|
||||
int vad;
|
||||
int16_t speechNB[240]; // Downsampled speech frame: 480 samples (30ms in WB)
|
||||
|
||||
// Wideband: Downsample signal before doing VAD
|
||||
@ -659,7 +661,7 @@ int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
}
|
||||
|
||||
int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length)
|
||||
size_t frame_length)
|
||||
{
|
||||
int16_t feature_vector[kNumChannels], total_power;
|
||||
|
||||
|
||||
@ -104,12 +104,12 @@ int WebRtcVad_set_mode_core(VadInstT* self, int mode);
|
||||
* 1-6 - Active speech
|
||||
*/
|
||||
int WebRtcVad_CalcVad48khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length);
|
||||
size_t frame_length);
|
||||
int WebRtcVad_CalcVad32khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length);
|
||||
size_t frame_length);
|
||||
int WebRtcVad_CalcVad16khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length);
|
||||
size_t frame_length);
|
||||
int WebRtcVad_CalcVad8khz(VadInstT* inst, const int16_t* speech_frame,
|
||||
int frame_length);
|
||||
size_t frame_length);
|
||||
|
||||
#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_CORE_H_
|
||||
|
||||
@ -82,7 +82,7 @@ TEST_F(VadTest, CalcVad) {
|
||||
|
||||
// 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.
|
||||
for (int16_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
for (size_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
speech[i] = static_cast<int16_t>(i * i);
|
||||
}
|
||||
for (size_t j = 0; j < kFrameLengthsSize; ++j) {
|
||||
|
||||
@ -38,9 +38,9 @@ static const int16_t kOffsetVector[6] = { 368, 368, 272, 176, 176, 176 };
|
||||
// - filter_state [i/o] : State of the filter.
|
||||
// - data_out [o] : Output audio data in the frequency interval
|
||||
// 80 - 250 Hz.
|
||||
static void HighPassFilter(const int16_t* data_in, int data_length,
|
||||
static void HighPassFilter(const int16_t* data_in, size_t data_length,
|
||||
int16_t* filter_state, int16_t* data_out) {
|
||||
int i;
|
||||
size_t i;
|
||||
const int16_t* in_ptr = data_in;
|
||||
int16_t* out_ptr = data_out;
|
||||
int32_t tmp32 = 0;
|
||||
@ -80,7 +80,7 @@ static void HighPassFilter(const int16_t* data_in, int data_length,
|
||||
// - filter_coefficient [i] : Given in Q15.
|
||||
// - filter_state [i/o] : State of the filter given in Q(-1).
|
||||
// - data_out [o] : Output audio signal given in Q(-1).
|
||||
static void AllPassFilter(const int16_t* data_in, int data_length,
|
||||
static void AllPassFilter(const int16_t* data_in, size_t data_length,
|
||||
int16_t filter_coefficient, int16_t* filter_state,
|
||||
int16_t* data_out) {
|
||||
// The filter can only cause overflow (in the w16 output variable)
|
||||
@ -89,7 +89,7 @@ static void AllPassFilter(const int16_t* data_in, int data_length,
|
||||
// First 6 taps of the impulse response:
|
||||
// 0.6399 0.5905 -0.3779 0.2418 -0.1547 0.0990
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
int16_t tmp16 = 0;
|
||||
int32_t tmp32 = 0;
|
||||
int32_t state32 = ((int32_t) (*filter_state) << 16); // Q15
|
||||
@ -117,11 +117,11 @@ static void AllPassFilter(const int16_t* data_in, int data_length,
|
||||
// The length is |data_length| / 2.
|
||||
// - lp_data_out [o] : Output audio data of the lower half of the spectrum.
|
||||
// The length is |data_length| / 2.
|
||||
static void SplitFilter(const int16_t* data_in, int data_length,
|
||||
static void SplitFilter(const int16_t* data_in, size_t data_length,
|
||||
int16_t* upper_state, int16_t* lower_state,
|
||||
int16_t* hp_data_out, int16_t* lp_data_out) {
|
||||
int i;
|
||||
int half_length = data_length >> 1; // Downsampling by 2.
|
||||
size_t i;
|
||||
size_t half_length = data_length >> 1; // Downsampling by 2.
|
||||
int16_t tmp_out;
|
||||
|
||||
// All-pass filtering upper branch.
|
||||
@ -151,7 +151,7 @@ static void SplitFilter(const int16_t* data_in, int data_length,
|
||||
// NOTE: |total_energy| is only updated if
|
||||
// |total_energy| <= |kMinEnergy|.
|
||||
// - log_energy [o] : 10 * log10("energy of |data_in|") given in Q4.
|
||||
static void LogOfEnergy(const int16_t* data_in, int data_length,
|
||||
static void LogOfEnergy(const int16_t* data_in, size_t data_length,
|
||||
int16_t offset, int16_t* total_energy,
|
||||
int16_t* log_energy) {
|
||||
// |tot_rshifts| accumulates the number of right shifts performed on |energy|.
|
||||
@ -243,7 +243,7 @@ static void LogOfEnergy(const int16_t* data_in, int data_length,
|
||||
}
|
||||
|
||||
int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,
|
||||
int data_length, int16_t* features) {
|
||||
size_t data_length, int16_t* features) {
|
||||
int16_t total_energy = 0;
|
||||
// We expect |data_length| to be 80, 160 or 240 samples, which corresponds to
|
||||
// 10, 20 or 30 ms in 8 kHz. Therefore, the intermediate downsampled data will
|
||||
@ -251,9 +251,9 @@ int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,
|
||||
// the second split.
|
||||
int16_t hp_120[120], lp_120[120];
|
||||
int16_t hp_60[60], lp_60[60];
|
||||
const int half_data_length = data_length >> 1;
|
||||
int length = half_data_length; // |data_length| / 2, corresponds to
|
||||
// bandwidth = 2000 Hz after downsampling.
|
||||
const size_t half_data_length = data_length >> 1;
|
||||
size_t length = half_data_length; // |data_length| / 2, corresponds to
|
||||
// bandwidth = 2000 Hz after downsampling.
|
||||
|
||||
// Initialize variables for the first SplitFilter().
|
||||
int frequency_band = 0;
|
||||
@ -261,7 +261,6 @@ int16_t WebRtcVad_CalculateFeatures(VadInstT* self, const int16_t* data_in,
|
||||
int16_t* hp_out_ptr = hp_120; // [2000 - 4000] Hz.
|
||||
int16_t* lp_out_ptr = lp_120; // [0 - 2000] Hz.
|
||||
|
||||
assert(data_length >= 0);
|
||||
assert(data_length <= 240);
|
||||
assert(4 < kNumChannels - 1); // Checking maximum |frequency_band|.
|
||||
|
||||
|
||||
@ -39,6 +39,6 @@
|
||||
// - 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,
|
||||
int data_length, int16_t* features);
|
||||
size_t data_length, int16_t* features);
|
||||
|
||||
#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_FILTERBANK_H_
|
||||
|
||||
@ -38,7 +38,7 @@ TEST_F(VadTest, vad_filterbank) {
|
||||
// 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.
|
||||
int16_t speech[kMaxFrameLength];
|
||||
for (int16_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
for (size_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
speech[i] = static_cast<int16_t>(i * i);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ TEST_F(VadTest, vad_filterbank) {
|
||||
|
||||
// Verify that all ones in gives kOffsetVector out. Any other constant input
|
||||
// will have a small impact in the sub bands.
|
||||
for (int16_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
for (size_t i = 0; i < kMaxFrameLength; ++i) {
|
||||
speech[i] = 1;
|
||||
}
|
||||
for (size_t j = 0; j < kFrameLengthsSize; ++j) {
|
||||
|
||||
@ -27,12 +27,13 @@ static const int16_t kSmoothingUp = 32439; // 0.99 in Q15.
|
||||
void WebRtcVad_Downsampling(const int16_t* signal_in,
|
||||
int16_t* signal_out,
|
||||
int32_t* filter_state,
|
||||
int in_length) {
|
||||
size_t in_length) {
|
||||
int16_t tmp16_1 = 0, tmp16_2 = 0;
|
||||
int32_t tmp32_1 = filter_state[0];
|
||||
int32_t tmp32_2 = filter_state[1];
|
||||
int n = 0;
|
||||
int half_length = (in_length >> 1); // Downsampling by 2 gives half length.
|
||||
size_t n = 0;
|
||||
// Downsampling by 2 gives half length.
|
||||
size_t half_length = (in_length >> 1);
|
||||
|
||||
// Filter coefficients in Q13, filter state in Q0.
|
||||
for (n = 0; n < half_length; n++) {
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
void WebRtcVad_Downsampling(const int16_t* signal_in,
|
||||
int16_t* signal_out,
|
||||
int32_t* filter_state,
|
||||
int in_length);
|
||||
size_t in_length);
|
||||
|
||||
// Updates and returns the smoothed feature minimum. As minimum we use the
|
||||
// median of the five smallest feature values in a 100 frames long window.
|
||||
|
||||
@ -23,7 +23,7 @@ namespace {
|
||||
|
||||
TEST_F(VadTest, vad_sp) {
|
||||
VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));
|
||||
const int kMaxFrameLenSp = 960; // Maximum frame length in this unittest.
|
||||
const size_t kMaxFrameLenSp = 960; // Maximum frame length in this unittest.
|
||||
int16_t zeros[kMaxFrameLenSp] = { 0 };
|
||||
int32_t state[2] = { 0 };
|
||||
int16_t data_in[kMaxFrameLenSp];
|
||||
@ -40,14 +40,14 @@ TEST_F(VadTest, vad_sp) {
|
||||
|
||||
// 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.
|
||||
for (int16_t i = 0; i < kMaxFrameLenSp; ++i) {
|
||||
for (size_t i = 0; i < kMaxFrameLenSp; ++i) {
|
||||
data_in[i] = static_cast<int16_t>(i * i);
|
||||
}
|
||||
// Input values all zeros, expect all zeros out.
|
||||
WebRtcVad_Downsampling(zeros, data_out, state, kMaxFrameLenSp);
|
||||
EXPECT_EQ(0, state[0]);
|
||||
EXPECT_EQ(0, state[1]);
|
||||
for (int16_t i = 0; i < kMaxFrameLenSp / 2; ++i) {
|
||||
for (size_t i = 0; i < kMaxFrameLenSp / 2; ++i) {
|
||||
EXPECT_EQ(0, data_out[i]);
|
||||
}
|
||||
// Make a simple non-zero data test.
|
||||
|
||||
@ -27,7 +27,7 @@ void VadTest::SetUp() {}
|
||||
void VadTest::TearDown() {}
|
||||
|
||||
// Returns true if the rate and frame length combination is valid.
|
||||
bool VadTest::ValidRatesAndFrameLengths(int rate, int frame_length) {
|
||||
bool VadTest::ValidRatesAndFrameLengths(int rate, size_t frame_length) {
|
||||
if (rate == 8000) {
|
||||
if (frame_length == 80 || frame_length == 160 || frame_length == 240) {
|
||||
return true;
|
||||
@ -65,7 +65,7 @@ TEST_F(VadTest, ApiTest) {
|
||||
// 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.
|
||||
int16_t speech[kMaxFrameLength];
|
||||
for (int16_t i = 0; i < kMaxFrameLength; i++) {
|
||||
for (size_t i = 0; i < kMaxFrameLength; i++) {
|
||||
speech[i] = static_cast<int16_t>(i * i);
|
||||
}
|
||||
|
||||
@ -134,8 +134,8 @@ TEST_F(VadTest, ValidRatesFrameLengths) {
|
||||
-8000, -4000, 0, 4000, 8000, 8001, 15999, 16000, 32000, 48000, 48001, 96000
|
||||
};
|
||||
|
||||
const int kFrameLengths[] = {
|
||||
-10, 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++) {
|
||||
|
||||
@ -28,8 +28,8 @@ const int kRates[] = { 8000, 12000, 16000, 24000, 32000, 48000 };
|
||||
const size_t kRatesSize = sizeof(kRates) / sizeof(*kRates);
|
||||
|
||||
// Frame lengths we support.
|
||||
const int kMaxFrameLength = 1440;
|
||||
const int kFrameLengths[] = { 80, 120, 160, 240, 320, 480, 640, 960,
|
||||
const size_t kMaxFrameLength = 1440;
|
||||
const size_t kFrameLengths[] = { 80, 120, 160, 240, 320, 480, 640, 960,
|
||||
kMaxFrameLength };
|
||||
const size_t kFrameLengthsSize = sizeof(kFrameLengths) / sizeof(*kFrameLengths);
|
||||
|
||||
@ -42,7 +42,7 @@ class VadTest : public ::testing::Test {
|
||||
virtual void TearDown();
|
||||
|
||||
// Returns true if the rate and frame length combination is valid.
|
||||
bool ValidRatesAndFrameLengths(int rate, int frame_length);
|
||||
bool ValidRatesAndFrameLengths(int rate, size_t frame_length);
|
||||
};
|
||||
|
||||
#endif // WEBRTC_COMMON_AUDIO_VAD_VAD_UNITTEST_H
|
||||
|
||||
@ -56,7 +56,7 @@ int WebRtcVad_set_mode(VadInst* handle, int mode) {
|
||||
}
|
||||
|
||||
int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||
int frame_length) {
|
||||
size_t frame_length) {
|
||||
int vad = -1;
|
||||
VadInstT* self = (VadInstT*) handle;
|
||||
|
||||
@ -90,11 +90,11 @@ int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
|
||||
return vad;
|
||||
}
|
||||
|
||||
int WebRtcVad_ValidRateAndFrameLength(int rate, int frame_length) {
|
||||
int WebRtcVad_ValidRateAndFrameLength(int rate, size_t frame_length) {
|
||||
int return_value = -1;
|
||||
size_t i;
|
||||
int valid_length_ms;
|
||||
int valid_length;
|
||||
size_t valid_length;
|
||||
|
||||
// We only allow 10, 20 or 30 ms frames. Loop through valid frame rates and
|
||||
// see if we have a matching pair.
|
||||
@ -102,7 +102,7 @@ int WebRtcVad_ValidRateAndFrameLength(int rate, int frame_length) {
|
||||
if (kValidRates[i] == rate) {
|
||||
for (valid_length_ms = 10; valid_length_ms <= kMaxFrameLengthMs;
|
||||
valid_length_ms += 10) {
|
||||
valid_length = (kValidRates[i] / 1000 * valid_length_ms);
|
||||
valid_length = (size_t)(kValidRates[i] / 1000 * valid_length_ms);
|
||||
if (frame_length == valid_length) {
|
||||
return_value = 0;
|
||||
break;
|
||||
|
||||
@ -46,20 +46,20 @@ void WindowGenerator::Hanning(int length, float* window) {
|
||||
}
|
||||
}
|
||||
|
||||
void WindowGenerator::KaiserBesselDerived(float alpha, int length,
|
||||
void WindowGenerator::KaiserBesselDerived(float alpha, size_t length,
|
||||
float* window) {
|
||||
CHECK_GT(length, 1);
|
||||
CHECK_GT(length, 1U);
|
||||
CHECK(window != nullptr);
|
||||
|
||||
const int half = (length + 1) / 2;
|
||||
const size_t half = (length + 1) / 2;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (int i = 0; i <= half; ++i) {
|
||||
for (size_t i = 0; i <= half; ++i) {
|
||||
complex<float> r = (4.0f * i) / length - 1.0f;
|
||||
sum += I0(static_cast<float>(M_PI) * alpha * sqrt(1.0f - r * r)).real();
|
||||
window[i] = sum;
|
||||
}
|
||||
for (int i = length - 1; i >= half; --i) {
|
||||
for (size_t i = length - 1; i >= half; --i) {
|
||||
window[length - i - 1] = sqrtf(window[length - i - 1] / sum);
|
||||
window[i] = window[length - i - 1];
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#ifndef WEBRTC_COMMON_AUDIO_WINDOW_GENERATOR_H_
|
||||
#define WEBRTC_COMMON_AUDIO_WINDOW_GENERATOR_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -19,7 +21,7 @@ namespace webrtc {
|
||||
class WindowGenerator {
|
||||
public:
|
||||
static void Hanning(int length, float* window);
|
||||
static void KaiserBesselDerived(float alpha, int length, float* window);
|
||||
static void KaiserBesselDerived(float alpha, size_t length, float* window);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(WindowGenerator);
|
||||
|
||||
@ -381,7 +381,7 @@ struct NetworkStatistics // NETEQ statistics
|
||||
// max packet waiting time in the jitter buffer (ms)
|
||||
int maxWaitingTimeMs;
|
||||
// added samples in off mode due to packet loss
|
||||
int addedSamples;
|
||||
size_t addedSamples;
|
||||
};
|
||||
|
||||
// Statistics for calls to AudioCodingModule::PlayoutData10Ms().
|
||||
|
||||
@ -56,7 +56,9 @@ int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
|
||||
|
||||
bool AudioDecoder::HasDecodePlc() const { return false; }
|
||||
|
||||
int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return 0; }
|
||||
size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AudioDecoder::IncomingPacket(const uint8_t* payload,
|
||||
size_t payload_len,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user