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_UTILS_H_ |
18 | #define RESONANCE_AUDIO_DSP_UTILS_H_ |
19 | |
20 | #include "base/audio_buffer.h" |
21 | |
22 | namespace vraudio { |
23 | |
24 | // Generates a gaussian white noise signal. |
25 | // |
26 | // @param mean The mean distribution parameter. |
27 | // @param std_deviation The standard deviation distribution parameter. |
28 | // @param seed A seed for the random generator. |
29 | // @param noise_channel Buffer channel in which to store the noise. |
30 | void GenerateGaussianNoise(float mean, float std_deviation, unsigned seed, |
31 | AudioBuffer::Channel* noise_channel); |
32 | |
33 | // Generates a gaussian white noise signal. |
34 | // |
35 | // @param min The lowest value in the distribution. |
36 | // @param max The highest value in te distribution, must be > min. |
37 | // @param seed A seed for the random generator. |
38 | // @param noise_channel Buffer channel in which to store the noise. |
39 | void GenerateUniformNoise(float min, float max, unsigned seed, |
40 | AudioBuffer::Channel* noise_channel); |
41 | |
42 | // Generates a band limited gaussian white noise signal, one octave band wide. |
43 | // |
44 | // @param center_frequency Center frequency of the given octave band in Hz. |
45 | // @param sampling_rate System sampling rate in Hz. |
46 | // @param seed A seed for the random generator. |
47 | // @param noise_buffer Buffer in which to store the band limited noise. |
48 | void GenerateBandLimitedGaussianNoise(float center_frequency, int sampling_rate, |
49 | unsigned seed, AudioBuffer* noise_buffer); |
50 | |
51 | // Genarates a pair of decorrelation filters (for use in low quality/high |
52 | // effiency mode reverb). |
53 | // |
54 | // @param sampling_rate System sampling rate in Hz. |
55 | // @return Buffer containing the stereo filters. |
56 | std::unique_ptr<AudioBuffer> GenerateDecorrelationFilters(int sampling_rate); |
57 | |
58 | // Returns the number of octave bands necessary for the given |sampling_rate|. |
59 | // |
60 | // @param sampling_rate Sampling rate in Hertz. |
61 | // @return Number of reverb octave bands. |
62 | size_t GetNumReverbOctaveBands(int sampling_rate); |
63 | |
64 | // Converts the given |milliseconds| to number of samples with the given |
65 | // |sampling_rate|. This method should *not* be used when more precise |
66 | // (double-precission) value is desired. |
67 | // |
68 | // @param milliseconds Milliseconds in single-precission floating point. |
69 | // @param sampling_rate Sampling rate in Hertz. |
70 | // @return Number of samples. |
71 | size_t GetNumSamplesFromMilliseconds(float milliseconds, int sampling_rate); |
72 | |
73 | // Ceils the given |size| to the next multiple of given |frames_per_buffer|. |
74 | // |
75 | // @param size Input size in frames. |
76 | // @param frames_per_buffer Frames per buffer. |
77 | // @return Ceiled size in frames. |
78 | size_t CeilToMultipleOfFramesPerBuffer(size_t size, size_t frames_per_buffer); |
79 | |
80 | // Generates a Hann window (used for smooth onset and tapering of the generated |
81 | // reverb response tails). |
82 | // |
83 | // @param full_window True to generate a full window, false to generate a half. |
84 | // @param window_length Length of the window to be generated. Must be less than |
85 | // or equal to the number of frames in the |buffer|. |
86 | // @param buffer AudioBuffer::Channel to which the window is written, the number |
87 | // of frames will be the length in samples of the generated Hann window. |
88 | void GenerateHannWindow(bool full_window, size_t window_length, |
89 | AudioBuffer::Channel* buffer); |
90 | |
91 | } // namespace vraudio |
92 | |
93 | #endif // RESONANCE_AUDIO_DSP_UTILS_H_ |
94 | |