1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 12 мая 2019 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef CORE_3D_RAYTRACE_H_
23 #define CORE_3D_RAYTRACE_H_
24 
25 #include <data/cstorage.h>
26 #include <core/3d/common.h>
27 #include <core/status.h>
28 
29 namespace lsp
30 {
31     enum rt_audio_source_t
32     {
33         RT_AS_TRIANGLE,     // For debug purposes
34         RT_AS_TETRA,        // Tetrahedron source
35         RT_AS_OCTA,         // Octa source
36         RT_AS_BOX,          // Simple box source
37         RT_AS_ICO,          // Icosahedron source
38         RT_AS_CYLINDER,     // Cylinder
39         RT_AS_CONE,         // Cone
40         RT_AS_OCTASPHERE,   // Omni source (octasphere)
41         RT_AS_ICOSPHERE,    // Omni source (icosphere)
42         RT_AS_FSPOT,        // Flat spot
43         RT_AS_CSPOT,        // Cylindric spot
44         RT_AS_SSPOT,        // Spherical spot
45     };
46 
47     enum rt_audio_capture_t
48     {
49         RT_AC_CARDIO,
50         RT_AC_SCARDIO,
51         RT_AC_HCARDIO,
52         RT_AC_BIDIR,
53         RT_AC_EIGHT,
54         RT_AC_OMNI
55     };
56 
57     enum rt_capture_config_t
58     {
59         RT_CC_MONO,
60         RT_CC_XY,
61         RT_CC_AB,
62         RT_CC_ORTF,
63         RT_CC_MS
64     };
65 
66     typedef struct room_source_config_t
67     {
68         point3d_t               sPos;       // Position in 3D space
69         float                   fYaw;       // Yaw angle (degrees)
70         float                   fPitch;     // Pitch angle (degrees)
71         float                   fRoll;      // Roll angle (degrees)
72         rt_audio_source_t       enType;     // Type of source
73         float                   fSize;      // Size/radius [m]
74         float                   fHeight;    // Height [m]
75         float                   fAngle;     // Dispersion angle [0..100] %
76         float                   fCurvature; // Additional curvature [0..100] %
77         float                   fAmplitude; // Initial amplitude of the signal
78     } room_source_config_t;
79 
80     // Source configuration
81     typedef struct rt_source_settings_t
82     {
83         matrix3d_t              pos;        // Position and direction of source
84         rt_audio_source_t       type;       // Type of the the source
85         float                   size;       // Size/radius [m]
86         float                   height;     // Height [m]
87         float                   angle;      // Dispersion angle [0..100] %
88         float                   curvature;  // Additional curvature [0..100] %
89         float                   amplitude;  // Initial amplitude of the signal
90     } room_source_settings_t;
91 
92     // Capture configuration
93     typedef struct room_capture_config_t
94     {
95         point3d_t               sPos;       // Position in 3D space
96         float                   fYaw;       // Yaw angle (degrees)
97         float                   fPitch;     // Pitch angle (degrees)
98         float                   fRoll;      // Roll angle (degrees)
99         float                   fCapsule;   // Capsule size
100         rt_capture_config_t     sConfig;    // Capture configuration
101         float                   fAngle;     // Capture angle between microphones
102         float                   fDistance;  // Capture distance between AB microphones
103         rt_audio_capture_t      enDirection;// Capture microphone direction
104         rt_audio_capture_t      enSide;     // Side microphone direction
105     } room_capture_config_t;
106 
107     typedef struct rt_capture_settings_t
108     {
109         matrix3d_t              pos;        // Position in 3D space
110         float                   radius;     // Capture radius
111         rt_audio_capture_t      type;       // Capture type
112     } rt_capture_settings_t;
113 
114     /**
115      * Generate raytracing source groups' mesh according to settings of the audio source
116      * The function does not apply transform matrix to the output
117      *
118      * @param out raytracing groups
119      * @param cfg source configuration
120      * @return status of operation
121      */
122     status_t rt_gen_source_mesh(cstorage<rt_group_t> &out, const rt_source_settings_t *cfg);
123 
124     /**
125      * Generate raytracing capture mesh groups according to settings of the audio capture
126      * The function does not apply transform matrix to the output
127      *
128      * @param out triangle mesh
129      * @param cfg source configuration
130      * @return status of operation
131      */
132     status_t rt_gen_capture_mesh(cstorage<raw_triangle_t> &out, const rt_capture_settings_t *cfg);
133 
134     /**
135      * Configure capture
136      * @param n number of captures generated
137      * @param settings array of two structures to store capture settings
138      * @param cfg capture configuration
139      * @return status of operation
140      */
141     status_t rt_configure_capture(size_t *n, rt_capture_settings_t *settings, const room_capture_config_t *cfg);
142 
143     /**
144      * Configure source settings
145      * @param out source settings
146      * @param in source configuration
147      * @return status of operation
148      */
149     status_t rt_configure_source(rt_source_settings_t *out, const room_source_config_t *in);
150 
151 
152 
153 }
154 
155 
156 #endif /* CORE_3D_RAYTRACE_H_ */
157