Add LappedTransform accessors.
These are necessary for clients to validate that they conform to its API. R=andrew@webrtc.org Review URL: https://webrtc-codereview.appspot.com/53519005 Cr-Commit-Position: refs/heads/master@{#9327}
This commit is contained in:
@@ -24,8 +24,8 @@ void LappedTransform::BlockThunk::ProcessBlock(const float* const* input,
|
||||
int num_input_channels,
|
||||
int num_output_channels,
|
||||
float* const* output) {
|
||||
CHECK_EQ(num_input_channels, parent_->in_channels_);
|
||||
CHECK_EQ(num_output_channels, parent_->out_channels_);
|
||||
CHECK_EQ(num_input_channels, parent_->num_in_channels_);
|
||||
CHECK_EQ(num_output_channels, parent_->num_out_channels_);
|
||||
CHECK_EQ(parent_->block_length_, num_frames);
|
||||
|
||||
for (int i = 0; i < num_input_channels; ++i) {
|
||||
@@ -52,25 +52,38 @@ void LappedTransform::BlockThunk::ProcessBlock(const float* const* input,
|
||||
}
|
||||
}
|
||||
|
||||
LappedTransform::LappedTransform(int in_channels, int out_channels,
|
||||
int chunk_length, const float* window,
|
||||
int block_length, int shift_amount,
|
||||
LappedTransform::LappedTransform(int num_in_channels,
|
||||
int num_out_channels,
|
||||
int chunk_length,
|
||||
const float* window,
|
||||
int block_length,
|
||||
int shift_amount,
|
||||
Callback* callback)
|
||||
: blocker_callback_(this),
|
||||
in_channels_(in_channels),
|
||||
out_channels_(out_channels),
|
||||
num_in_channels_(num_in_channels),
|
||||
num_out_channels_(num_out_channels),
|
||||
block_length_(block_length),
|
||||
chunk_length_(chunk_length),
|
||||
block_processor_(callback),
|
||||
blocker_(
|
||||
chunk_length_, block_length_, in_channels_, out_channels_, window,
|
||||
shift_amount, &blocker_callback_),
|
||||
blocker_(chunk_length_,
|
||||
block_length_,
|
||||
num_in_channels_,
|
||||
num_out_channels_,
|
||||
window,
|
||||
shift_amount,
|
||||
&blocker_callback_),
|
||||
fft_(RealFourier::Create(RealFourier::FftOrder(block_length_))),
|
||||
cplx_length_(RealFourier::ComplexLength(fft_->order())),
|
||||
real_buf_(in_channels, block_length_, RealFourier::kFftBufferAlignment),
|
||||
cplx_pre_(in_channels, cplx_length_, RealFourier::kFftBufferAlignment),
|
||||
cplx_post_(out_channels, cplx_length_, RealFourier::kFftBufferAlignment) {
|
||||
CHECK(in_channels_ > 0 && out_channels_ > 0);
|
||||
real_buf_(num_in_channels,
|
||||
block_length_,
|
||||
RealFourier::kFftBufferAlignment),
|
||||
cplx_pre_(num_in_channels,
|
||||
cplx_length_,
|
||||
RealFourier::kFftBufferAlignment),
|
||||
cplx_post_(num_out_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(block_processor_);
|
||||
@@ -81,9 +94,8 @@ LappedTransform::LappedTransform(int in_channels, int out_channels,
|
||||
|
||||
void LappedTransform::ProcessChunk(const float* const* in_chunk,
|
||||
float* const* out_chunk) {
|
||||
blocker_.ProcessChunk(in_chunk, chunk_length_, in_channels_, out_channels_,
|
||||
out_chunk);
|
||||
blocker_.ProcessChunk(in_chunk, chunk_length_, num_in_channels_,
|
||||
num_out_channels_, out_chunk);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ class LappedTransform {
|
||||
virtual ~Callback() {}
|
||||
|
||||
virtual void ProcessAudioBlock(const std::complex<float>* const* in_block,
|
||||
int in_channels, int frames,
|
||||
int out_channels,
|
||||
int num_in_channels, int frames,
|
||||
int num_out_channels,
|
||||
std::complex<float>* const* out_block) = 0;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ 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 in_channels, int out_channels, int chunk_length,
|
||||
LappedTransform(int num_in_channels, int num_out_channels, int chunk_length,
|
||||
const float* window, int block_length, int shift_amount,
|
||||
Callback* callback);
|
||||
~LappedTransform() {}
|
||||
@@ -63,7 +63,24 @@ class LappedTransform {
|
||||
// to ProcessChunk via the parameter in_chunk.
|
||||
//
|
||||
// Returns the same chunk_length passed to the LappedTransform constructor.
|
||||
int get_chunk_length() const { return chunk_length_; }
|
||||
int chunk_length() const { return chunk_length_; }
|
||||
|
||||
// Get the number of input channels.
|
||||
//
|
||||
// This is the number of arrays that must be passed to ProcessChunk via
|
||||
// in_chunk.
|
||||
//
|
||||
// Returns the same num_in_channels passed to the LappedTransform constructor.
|
||||
int num_in_channels() const { return num_in_channels_; }
|
||||
|
||||
// Get the number of output channels.
|
||||
//
|
||||
// This is the number of arrays that must be passed to ProcessChunk via
|
||||
// out_chunk.
|
||||
//
|
||||
// Returns the same num_out_channels passed to the LappedTransform
|
||||
// constructor.
|
||||
int num_out_channels() const { return num_out_channels_; }
|
||||
|
||||
private:
|
||||
// Internal middleware callback, given to the blocker. Transforms each block
|
||||
@@ -80,8 +97,8 @@ class LappedTransform {
|
||||
LappedTransform* const parent_;
|
||||
} blocker_callback_;
|
||||
|
||||
const int in_channels_;
|
||||
const int out_channels_;
|
||||
const int num_in_channels_;
|
||||
const int num_out_channels_;
|
||||
|
||||
const int block_length_;
|
||||
const int chunk_length_;
|
||||
|
||||
@@ -177,26 +177,26 @@ TEST(LappedTransformTest, Callbacks) {
|
||||
ASSERT_EQ(kChunkLength / kBlockLength, call.block_num());
|
||||
}
|
||||
|
||||
TEST(LappedTransformTest, get_chunk_length) {
|
||||
TEST(LappedTransformTest, chunk_length) {
|
||||
const int kBlockLength = 64;
|
||||
FftCheckerCallback call;
|
||||
const float window[kBlockLength] = {};
|
||||
|
||||
// Make sure that get_chunk_length returns the same value passed to the
|
||||
// Make sure that chunk_length returns the same value passed to the
|
||||
// LappedTransform constructor.
|
||||
{
|
||||
const int kExpectedChunkLength = 512;
|
||||
const LappedTransform trans(1, 1, kExpectedChunkLength, window,
|
||||
kBlockLength, kBlockLength, &call);
|
||||
|
||||
EXPECT_EQ(kExpectedChunkLength, trans.get_chunk_length());
|
||||
EXPECT_EQ(kExpectedChunkLength, trans.chunk_length());
|
||||
}
|
||||
{
|
||||
const int kExpectedChunkLength = 160;
|
||||
const LappedTransform trans(1, 1, kExpectedChunkLength, window,
|
||||
kBlockLength, kBlockLength, &call);
|
||||
|
||||
EXPECT_EQ(kExpectedChunkLength, trans.get_chunk_length());
|
||||
EXPECT_EQ(kExpectedChunkLength, trans.chunk_length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user