1 | /* |
2 | Copyright 2018 Google Inc. All Rights Reserved. |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS-IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | |
17 | #ifndef RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_ |
18 | #define RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_ |
19 | |
20 | #include "base/audio_buffer.h" |
21 | |
22 | namespace vraudio { |
23 | |
24 | // Class that takes two input buffers and produces an output buffer by applying |
25 | // linear crossfade between the inputs. |
26 | class BufferCrossfader { |
27 | public: |
28 | explicit BufferCrossfader(size_t num_frames); |
29 | |
30 | // Applies linear crossfade for given input buffers and stores the result in |
31 | // |output| buffer. Note that, in-place processing is *not* supported by this |
32 | // method, the output buffer must be different than the input buffers. |
33 | // |
34 | // @param input_fade_in Input buffer to fade-in to. |
35 | // @param input_fade_out Input buffer to fade-out from. |
36 | // @param output Output buffer to store the crossfaded result. |
37 | void ApplyLinearCrossfade(const AudioBuffer& input_fade_in, |
38 | const AudioBuffer& input_fade_out, |
39 | AudioBuffer* output) const; |
40 | |
41 | private: |
42 | // Stereo audio buffer to store crossfade decay and growth multipliers. |
43 | AudioBuffer crossfade_buffer_; |
44 | }; |
45 | |
46 | } // namespace vraudio |
47 | |
48 | #endif // RESONANCE_AUDIO_UTILS_BUFFER_CROSSFADER_H_ |
49 | |