2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_COMMON_AUDIO_LAPPED_TRANSFORM_H_
12 #define WEBRTC_COMMON_AUDIO_LAPPED_TRANSFORM_H_
16 #include "webrtc/base/checks.h"
17 #include "webrtc/common_audio/blocker.h"
18 #include "webrtc/common_audio/real_fourier.h"
19 #include "webrtc/system_wrappers/interface/aligned_array.h"
20 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
24 // Helper class for audio processing modules which operate on frequency domain
25 // input derived from the windowed time domain audio stream.
27 // The input audio chunk is sliced into possibly overlapping blocks, multiplied
28 // by a window and transformed with an FFT implementation. The transformed data
29 // is supplied to the given callback for processing. The processed output is
30 // then inverse transformed into the time domain and spliced back into a chunk
31 // which constitutes the final output of this processing module.
32 class LappedTransform {
36 virtual ~Callback() {}
38 virtual void ProcessAudioBlock(const std::complex<float>* const* in_block,
39 int in_channels, int frames,
41 std::complex<float>* const* out_block) = 0;
44 // Construct a transform instance. |chunk_length| is the number of samples in
45 // each channel. |window| defines the window, owned by the caller (a copy is
46 // made internally); can be NULL to disable windowing entirely.
47 // |block_length| defines the length of a block, in samples, even when
48 // windowing is disabled. |shift_length| is in samples. |callback| is the
49 // caller-owned audio processing function called for each block of the input
51 LappedTransform(int in_channels, int out_channels, int chunk_length,
52 const float* window, int block_length, int shift_amount,
56 // Main audio processing helper method. Internally slices |in_chunk| into
57 // blocks, transforms them to frequency domain, calls the callback for each
58 // block and returns a de-blocked time domain chunk of audio through
59 // |out_chunk|. Both buffers are caller-owned.
60 void ProcessChunk(const float* const* in_chunk, float* const* out_chunk);
63 // Internal middleware callback, given to the blocker. Transforms each block
64 // and hands it over to the processing method given at construction time.
65 friend class BlockThunk;
66 class BlockThunk : public BlockerCallback {
68 explicit BlockThunk(LappedTransform* parent) : parent_(parent) {}
69 virtual ~BlockThunk() {}
71 virtual void ProcessBlock(const float* const* input, int num_frames,
72 int num_input_channels, int num_output_channels,
73 float* const* output);
76 LappedTransform* parent_;
84 int window_shift_amount_;
88 Callback* block_processor_;
89 scoped_ptr<Blocker> blocker_;
93 AlignedArray<float> real_buf_;
94 AlignedArray<std::complex<float> > cplx_pre_;
95 AlignedArray<std::complex<float> > cplx_post_;
100 #endif // WEBRTC_COMMON_AUDIO_LAPPED_TRANSFORM_H_