Support arbitrary input/output rates and downmixing in AudioProcessing.

Select "processing" rates based on the input and output sampling rates.
Resample the input streams to those rates, and if necessary to the
output rate.

- Remove deprecated stream format APIs.
- Remove deprecated device sample rate APIs.
- Add a ChannelBuffer class to help manage deinterleaved channels.
- Clean up the splitting filter state.
- Add a unit test which verifies the output against known-working
native format output.

BUG=2894
R=aluebs@webrtc.org, bjornv@webrtc.org, xians@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/9919004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5959 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org
2014-04-22 21:00:04 +00:00
parent 34fe0153b9
commit ddbb8a2c24
23 changed files with 1291 additions and 693 deletions

View File

@ -9,6 +9,7 @@
*/
#include "webrtc/audio_processing/debug.pb.h"
#include "webrtc/modules/audio_processing/common.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
@ -18,37 +19,6 @@ namespace webrtc {
static const AudioProcessing::Error kNoErr = AudioProcessing::kNoError;
#define EXPECT_NOERR(expr) EXPECT_EQ(kNoErr, (expr))
static const int kChunkSizeMs = 10;
// Helper to encapsulate a contiguous data buffer with access to a pointer
// array of the deinterleaved channels.
template <typename T>
class ChannelBuffer {
public:
ChannelBuffer(int samples_per_channel, int num_channels)
: data_(new T[samples_per_channel * num_channels]),
channels_(new T*[num_channels]),
samples_per_channel_(samples_per_channel) {
memset(data_.get(), 0, sizeof(T) * samples_per_channel * num_channels);
for (int i = 0; i < num_channels; ++i)
channels_[i] = &data_[i * samples_per_channel];
}
~ChannelBuffer() {}
void CopyFrom(const void* channel_ptr, int index) {
memcpy(channels_[index], channel_ptr, samples_per_channel_ * sizeof(T));
}
T* data() { return data_.get(); }
T* channel(int index) { return channels_[index]; }
T** channels() { return channels_.get(); }
private:
scoped_ptr<T[]> data_;
scoped_ptr<T*[]> channels_;
int samples_per_channel_;
};
// Exits on failure; do not use in unit tests.
static inline FILE* OpenFile(const std::string& filename, const char* mode) {
FILE* file = fopen(filename.c_str(), mode);
@ -59,10 +29,15 @@ static inline FILE* OpenFile(const std::string& filename, const char* mode) {
return file;
}
static inline int SamplesFromRate(int rate) {
return AudioProcessing::kChunkSizeMs * rate / 1000;
}
static inline void SetFrameSampleRate(AudioFrame* frame,
int sample_rate_hz) {
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = kChunkSizeMs * sample_rate_hz / 1000;
frame->samples_per_channel_ = AudioProcessing::kChunkSizeMs *
sample_rate_hz / 1000;
}
template <typename T>