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_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_ |
18 | #define RESONANCE_AUDIO_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_ |
19 | |
20 | #include <vector> |
21 | |
22 | #include "base/audio_buffer.h" |
23 | |
24 | namespace vraudio { |
25 | |
26 | // Updater for the |ReverbOnsetCompensator|. |
27 | class ReverbOnsetUpdateProcessor { |
28 | public: |
29 | // Constructs a update processor for the sprectral reverb onset compensator. |
30 | // |
31 | // @param frames_per_buffer_ System buffer length in frames. |
32 | // @param sampling_rate System sample rate. |
33 | // @param base_curves Constituent curve used for envelope generation. |
34 | // @param ader_curves Constituent curve used for envelope generation. |
35 | ReverbOnsetUpdateProcessor(size_t frames_per_buffer, int sampling_rate, |
36 | AudioBuffer* base_curves, |
37 | AudioBuffer* adder_curves); |
38 | |
39 | // Sets reverberation times in different frequency bands. |
40 | // |
41 | // @param rt60_values |kNumReverbOctaveBands| values denoting the |
42 | // reverberation decay time to -60dB in octave bands starting at |
43 | // |kLowestOctaveBand|. |
44 | void SetReverbTimes(const float* rt60_values); |
45 | |
46 | // Sets the gain applied to the overall compensation envelope. |
47 | // |
48 | // @param gain Gain applied to overall envelope. |
49 | void SetGain(float gain) { gain_ = gain; } |
50 | |
51 | // Processes the next tail update. |
52 | // |
53 | // @param bandpassed_noise_left Pre-computed bandpassed noise buffer. |
54 | // @param bandpassed_noise_right Pre-computed bandpassed noise buffer. |
55 | // @param kernel_channel_left Kernel channel to fill in the processed output. |
56 | // @param kernel_channel_right Kernel channel to fill in the processed output. |
57 | // @return True if the tail update continues. |
58 | bool Process(const std::vector<AudioBuffer>& bandpassed_noise_left, |
59 | const std::vector<AudioBuffer>& bandpassed_noise_right, |
60 | AudioBuffer::Channel* kernel_channel_left, |
61 | AudioBuffer::Channel* kernel_channel_right); |
62 | |
63 | // Returns the partition index of the current update state. |
64 | // |
65 | // @return Current partition index. |
66 | size_t GetCurrentPartitionIndex() const { |
67 | const size_t frames_per_buffer = band_buffer_.num_frames(); |
68 | DCHECK_NE(frames_per_buffer, 0U); |
69 | return tail_update_cursor_ / frames_per_buffer; |
70 | } |
71 | |
72 | // Disable copy and assignment operator. |
73 | ReverbOnsetUpdateProcessor(ReverbOnsetUpdateProcessor const&) = delete; |
74 | void operator=(ReverbOnsetUpdateProcessor const&) = delete; |
75 | |
76 | private: |
77 | // System sample rate. |
78 | int sampling_rate_; |
79 | |
80 | // Current frame position of the reverb tail to be updated. |
81 | size_t tail_update_cursor_; |
82 | |
83 | // Length of the new reverb tail to be replaced in frames. |
84 | size_t tail_length_; |
85 | |
86 | // Gain applied to the reverb compensation. |
87 | float gain_; |
88 | |
89 | // Indices of the multiplication factor to be used to create the onset |
90 | // compensation curve at each frequency band. |
91 | std::vector<int> curve_indices_; |
92 | |
93 | // Decay coefficients per each band of the reverb tail, used below 0.15s |
94 | // @48kHz. |
95 | std::vector<float> pure_decay_coefficients_; |
96 | |
97 | // Decay exponential per each band of the reverb tail, used below 0.15s |
98 | // @48kHz. |
99 | std::vector<float> pure_decay_exponents_; |
100 | |
101 | // Temporary buffers used to process the decayed noise per each band. |
102 | AudioBuffer band_buffer_; |
103 | AudioBuffer envelope_buffer_; |
104 | |
105 | // Pointers to audio buffers owned by the |ReverbOnsetCompensator| storing the |
106 | // constituent curves used to generate the onset compensation envelopes. |
107 | AudioBuffer* base_curves_; |
108 | AudioBuffer* adder_curves_; |
109 | }; |
110 | |
111 | } // namespace vraudio |
112 | |
113 | #endif // RESONANCE_AUDIO_DSP_REVERB_ONSET_UPDATE_PROCESSOR_H_ |
114 | |