RavEngine
Loading...
Searching...
No Matches
collection_kernel.h
1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
18#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
19
20#include "geometrical_acoustics/acoustic_listener.h"
21#include "geometrical_acoustics/acoustic_ray.h"
22
23namespace vraudio {
24
25// A class modeling the collection of energy contributions from an acoustic ray.
27 public:
28 // Constructor.
29 //
30 // @param listener_sphere_radius Radius of listener spheres (m).
31 // @param sampling_rate Sampling rate (Hz). Together with speed of sound we
32 // can convert a physical time to an index in an impulse response array.
33 CollectionKernel(float listener_sphere_radius, float sampling_rate);
34
35 // Collects contributions from a ray to a listener's impulse response.
36 //
37 // @param ray AcousticRay whose contribution is to be collected.
38 // @param weight Weight of the contribution on |ray|.
39 // @param listener AcousticListener to which the contribution from |ray| is
40 // added in-place.
41 void Collect(const AcousticRay& ray, float weight,
42 AcousticListener* listener) const;
43
44 // Collects contributions from a diffuse-rain ray to a listener's impulse
45 // response.
46 //
47 // @param diffuse_rain_ray Diffuse-rain ray whose contribution is to be
48 // collected.
49 // @param weight Weight of the contribution on |diffuse_rain_ray|.
50 // @param direction_pdf The probability density function that a ray is in
51 // the direction of |diffuse_rain_ray|, with density taken over the solid
52 // angle. Used to scale the energy contributions. The unit is
53 // 1 / steradian.
54 // @param listener AcousticListener to which the contribution from |ray| is
55 // added in-place.
56 void CollectDiffuseRain(const AcousticRay& diffuse_rain_ray, float weight,
57 float direction_pdf,
58 AcousticListener* listener) const;
59
60 private:
61 // Because we use a sphere to collect rays, the number of rays (and therefore
62 // the amount of energy) collected is proportional to the cross section area
63 // of the sphere, i.e. energy ~ R^2, where R is the sphere radius. But
64 // because the energy at a listener position should be independent of the
65 // sphere radius (which is an artificial construct), we need to factor out
66 // the radius-dependency, by multiplying the sum of energy with a constant,
67 // |sphere_size_energy_factor_|.
68 //
69 // In our implementation, this constant is defined such that a listener
70 // 1.0 meter away from the source would give an attenuation of 1.0.
71 const float sphere_size_energy_factor_;
72
73 // Converting traveled distance in meter to an index in the impulse response
74 // array: index = distance (m) / speed_of_sound (m/s) * sampling_rate (1/s).
75 const float distance_to_impulse_response_index_;
76};
77
78} // namespace vraudio
79#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_COLLECTION_KERNEL_H_
Definition collection_kernel.h:26
Definition acoustic_listener.h:28