Move ring_buffer to common_audio.
In preparation for adding a C++ wrapper in common_audio. Also, change the return type of Init to void and call it from Create. R=aluebs@webrtc.org Review URL: https://webrtc-codereview.appspot.com/37619004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8068 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -37,6 +37,8 @@ source_set("common_audio") {
|
||||
"resampler/resampler.cc",
|
||||
"resampler/sinc_resampler.cc",
|
||||
"resampler/sinc_resampler.h",
|
||||
"ring_buffer.c",
|
||||
"ring_buffer.h",
|
||||
"signal_processing/include/real_fft.h",
|
||||
"signal_processing/include/signal_processing_library.h",
|
||||
"signal_processing/include/spl_inl.h",
|
||||
|
@ -32,6 +32,7 @@
|
||||
'audio_converter.cc',
|
||||
'audio_converter.h',
|
||||
'audio_util.cc',
|
||||
'audio_util.h',
|
||||
'blocker.cc',
|
||||
'blocker.h',
|
||||
'fir_filter.cc',
|
||||
@ -47,6 +48,8 @@
|
||||
'resampler/resampler.cc',
|
||||
'resampler/sinc_resampler.cc',
|
||||
'resampler/sinc_resampler.h',
|
||||
'ring_buffer.c',
|
||||
'ring_buffer.h',
|
||||
'signal_processing/include/real_fft.h',
|
||||
'signal_processing/include/signal_processing_library.h',
|
||||
'signal_processing/include/spl_inl.h',
|
||||
@ -235,6 +238,7 @@
|
||||
'resampler/sinc_resampler_unittest.cc',
|
||||
'resampler/sinusoidal_linear_chirp_source.cc',
|
||||
'resampler/sinusoidal_linear_chirp_source.h',
|
||||
'ring_buffer_unittest.cc',
|
||||
'signal_processing/real_fft_unittest.cc',
|
||||
'signal_processing/signal_processing_unittest.cc',
|
||||
'vad/vad_core_unittest.cc',
|
||||
|
@ -11,7 +11,7 @@
|
||||
// A ring buffer to hold arbitrary data. Provides no thread safety. Unless
|
||||
// otherwise specified, functions return 0 on success and -1 on error.
|
||||
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
|
||||
#include <stddef.h> // size_t
|
||||
#include <stdlib.h>
|
||||
@ -85,23 +85,18 @@ RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size) {
|
||||
|
||||
self->element_count = element_count;
|
||||
self->element_size = element_size;
|
||||
WebRtc_InitBuffer(self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
int WebRtc_InitBuffer(RingBuffer* self) {
|
||||
if (!self) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void WebRtc_InitBuffer(RingBuffer* self) {
|
||||
self->read_pos = 0;
|
||||
self->write_pos = 0;
|
||||
self->rw_wrap = SAME_WRAP;
|
||||
|
||||
// Initialize buffer to zeros
|
||||
memset(self->data, 0, self->element_count * self->element_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WebRtc_FreeBuffer(void* handle) {
|
@ -11,8 +11,12 @@
|
||||
// A ring buffer to hold arbitrary data. Provides no thread safety. Unless
|
||||
// otherwise specified, functions return 0 on success and -1 on error.
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
|
||||
#ifndef WEBRTC_COMMON_AUDIO_RING_BUFFER_H_
|
||||
#define WEBRTC_COMMON_AUDIO_RING_BUFFER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h> // size_t
|
||||
|
||||
@ -20,7 +24,7 @@ typedef struct RingBuffer RingBuffer;
|
||||
|
||||
// Returns NULL on failure.
|
||||
RingBuffer* WebRtc_CreateBuffer(size_t element_count, size_t element_size);
|
||||
int WebRtc_InitBuffer(RingBuffer* handle);
|
||||
void WebRtc_InitBuffer(RingBuffer* handle);
|
||||
void WebRtc_FreeBuffer(void* handle);
|
||||
|
||||
// Reads data from the buffer. The |data_ptr| will point to the address where
|
||||
@ -55,4 +59,8 @@ size_t WebRtc_available_read(const RingBuffer* handle);
|
||||
// Returns number of available elements for write.
|
||||
size_t WebRtc_available_write(const RingBuffer* handle);
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_RING_BUFFER_H_
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WEBRTC_COMMON_AUDIO_RING_BUFFER_H_
|
@ -8,14 +8,11 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// TODO(ajm): Make this a comprehensive test.
|
||||
|
||||
extern "C" {
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
}
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
@ -65,7 +62,7 @@ static void RandomStressTest(int** data_ptr) {
|
||||
scoped_ptr<int[]> read_data(new int[buffer_size]);
|
||||
scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int)));
|
||||
ASSERT_TRUE(buffer.get() != NULL);
|
||||
ASSERT_EQ(0, WebRtc_InitBuffer(buffer.get()));
|
||||
WebRtc_InitBuffer(buffer.get());
|
||||
int buffer_consumed = 0;
|
||||
int write_element = 0;
|
||||
int read_element = 0;
|
||||
@ -123,7 +120,7 @@ TEST(RingBufferTest, PassingNulltoReadBufferForcesMemcpy) {
|
||||
|
||||
scoped_ring_buffer buffer(WebRtc_CreateBuffer(kDataSize, sizeof(int)));
|
||||
ASSERT_TRUE(buffer.get() != NULL);
|
||||
ASSERT_EQ(0, WebRtc_InitBuffer(buffer.get()));
|
||||
WebRtc_InitBuffer(buffer.get());
|
||||
|
||||
SetIncrementingData(write_data, kDataSize, 0);
|
||||
EXPECT_EQ(kDataSize, WebRtc_WriteBuffer(buffer.get(), write_data, kDataSize));
|
@ -120,8 +120,6 @@ source_set("audio_processing") {
|
||||
"utility/delay_estimator_wrapper.h",
|
||||
"utility/fft4g.c",
|
||||
"utility/fft4g.h",
|
||||
"utility/ring_buffer.c",
|
||||
"utility/ring_buffer.h",
|
||||
"voice_detection_impl.cc",
|
||||
"voice_detection_impl.h",
|
||||
]
|
||||
|
@ -24,12 +24,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_common.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_core_internal.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_rdft.h"
|
||||
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
@ -1452,33 +1452,16 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) {
|
||||
aec->normal_error_threshold = 1.5e-6f;
|
||||
}
|
||||
|
||||
if (WebRtc_InitBuffer(aec->nearFrBuf) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtc_InitBuffer(aec->outFrBuf) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtc_InitBuffer(aec->nearFrBufH) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtc_InitBuffer(aec->outFrBufH) == -1) {
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aec->nearFrBuf);
|
||||
WebRtc_InitBuffer(aec->outFrBuf);
|
||||
WebRtc_InitBuffer(aec->nearFrBufH);
|
||||
WebRtc_InitBuffer(aec->outFrBufH);
|
||||
|
||||
// Initialize far-end buffers.
|
||||
if (WebRtc_InitBuffer(aec->far_buf) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (WebRtc_InitBuffer(aec->far_buf_windowed) == -1) {
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aec->far_buf);
|
||||
WebRtc_InitBuffer(aec->far_buf_windowed);
|
||||
#ifdef WEBRTC_AEC_DEBUG_DUMP
|
||||
if (WebRtc_InitBuffer(aec->far_time_buf) == -1) {
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aec->far_time_buf);
|
||||
{
|
||||
int process_rate = sampFreq > 16000 ? 16000 : sampFreq;
|
||||
ReopenWav(&aec->farFile, "aec_far",
|
||||
|
@ -11,10 +11,10 @@
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_INTERNAL_H_
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/wav_file.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_common.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_core.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
// Number of partitions for the extended filter mode. The first one is an enum
|
||||
|
@ -20,11 +20,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_core.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_resampler.h"
|
||||
#include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
// Measured delays [ms]
|
||||
@ -222,10 +222,7 @@ int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WebRtc_InitBuffer(aecpc->far_pre_buf) == -1) {
|
||||
aecpc->lastError = AEC_UNSPECIFIED_ERROR;
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aecpc->far_pre_buf);
|
||||
WebRtc_MoveReadPtr(aecpc->far_pre_buf, -PART_LEN); // Start overlap.
|
||||
|
||||
aecpc->initFlag = initCheck; // indicates that initialization has been done
|
||||
|
@ -11,8 +11,8 @@
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_INTERNAL_H_
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/modules/audio_processing/aec/aec_core.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
|
||||
typedef struct {
|
||||
int delayCtr;
|
||||
|
@ -14,10 +14,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/real_fft.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
|
||||
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/system_wrappers/interface/compile_assert_c.h"
|
||||
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
@ -13,9 +13,9 @@
|
||||
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_CORE_H_
|
||||
#define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_AECM_CORE_H_
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_defines.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
#ifdef _MSC_VER // visual c++
|
||||
|
@ -14,10 +14,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/real_fft.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
|
||||
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
#include "webrtc/system_wrappers/interface/compile_assert_c.h"
|
||||
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
@ -15,9 +15,9 @@
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webrtc/common_audio/ring_buffer.h"
|
||||
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
||||
#include "webrtc/modules/audio_processing/aecm/aecm_core.h"
|
||||
#include "webrtc/modules/audio_processing/utility/ring_buffer.h"
|
||||
|
||||
#define BUF_SIZE_FRAMES 50 // buffer size (frames)
|
||||
// Maximum length of resampled signal. Must be an integer multiple of frames
|
||||
@ -182,11 +182,7 @@ int32_t WebRtcAecm_Init(void *aecmInst, int32_t sampFreq)
|
||||
}
|
||||
|
||||
// Initialize farend buffer
|
||||
if (WebRtc_InitBuffer(aecm->farendBuf) == -1)
|
||||
{
|
||||
aecm->lastError = AECM_UNSPECIFIED_ERROR;
|
||||
return -1;
|
||||
}
|
||||
WebRtc_InitBuffer(aecm->farendBuf);
|
||||
|
||||
aecm->initFlag = kInitCheck; // indicates that initialization has been done
|
||||
|
||||
|
@ -129,8 +129,6 @@
|
||||
'utility/delay_estimator_wrapper.h',
|
||||
'utility/fft4g.c',
|
||||
'utility/fft4g.h',
|
||||
'utility/ring_buffer.c',
|
||||
'utility/ring_buffer.h',
|
||||
'voice_detection_impl.cc',
|
||||
'voice_detection_impl.h',
|
||||
],
|
||||
|
@ -194,7 +194,6 @@
|
||||
'audio_processing/transient/wpd_node_unittest.cc',
|
||||
'audio_processing/transient/wpd_tree_unittest.cc',
|
||||
'audio_processing/utility/delay_estimator_unittest.cc',
|
||||
'audio_processing/utility/ring_buffer_unittest.cc',
|
||||
'bitrate_controller/bitrate_controller_unittest.cc',
|
||||
'bitrate_controller/remb_suppressor_unittest.cc',
|
||||
'bitrate_controller/send_side_bandwidth_estimation_unittest.cc',
|
||||
|
Reference in New Issue
Block a user