SAF
Loading...
Searching...
No Matches
test__reverb_module.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2021 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
25#include "saf_test.h"
26
28 void* hIms;
29 float maxTime_s;
30 float mov_src_pos[3], mov_rec_pos[3];
31 int sourceID_1, sourceID_2, sourceID_3, sourceID_4, sourceID_5, receiverID;
32 int i;
33
34 /* Config */
35 const int sh_order = 3;
36 const int nBands = 7;
37 const float abs_wall[7][6] = /* Absorption Coefficients per Octave band, and per wall */
38 { {0.180791250f, 0.207307300f, 0.134990800f, 0.229002250f, 0.212128400f, 0.241055000f},
39 {0.225971250f, 0.259113700f, 0.168725200f, 0.286230250f, 0.265139600f, 0.301295000f},
40 {0.258251250f, 0.296128100f, 0.192827600f, 0.327118250f, 0.303014800f, 0.344335000f},
41 {0.301331250f, 0.345526500f, 0.224994001f, 0.381686250f, 0.353562000f, 0.401775000f},
42 {0.361571250f, 0.414601700f, 0.269973200f, 0.457990250f, 0.424243600f, 0.482095000f},
43 {0.451931250f, 0.518214500f, 0.337442000f, 0.572446250f, 0.530266000f, 0.602575000f},
44 {0.602591250f, 0.690971300f, 0.449934800f, 0.763282250f, 0.707040400f, 0.803455000f} };
45 const float src_pos[3] = {5.1f, 6.0f, 1.1f};
46 const float src2_pos[3] = {2.1f, 1.0f, 1.3f};
47 const float src3_pos[3] = {4.4f, 3.0f, 1.4f};
48 const float src4_pos[3] = {6.4f, 4.0f, 1.3f};
49 const float src5_pos[3] = {8.5f, 5.0f, 1.8f};
50 const float rec_pos[3] = {8.8f, 5.5f, 0.9f};
51 const float roomdims[3] = {10.0f, 7.0f, 3.0f};
52
53 /* Set-up the shoebox room simulator, with two sources and one spherical harmonic receiver */
54 ims_shoebox_create(&hIms, (float*)roomdims, (float*)abs_wall, 125.0f, nBands, 343.0f, 48e3f);
55 sourceID_1 = ims_shoebox_addSource(hIms, (float*)src_pos, NULL);
56 sourceID_2 = ims_shoebox_addSource(hIms, (float*)src2_pos, NULL);
57 receiverID = ims_shoebox_addReceiverSH(hIms, sh_order, (float*)rec_pos, NULL);
58
59 /* Moving source No.1 and the receiver */
60 maxTime_s = 0.05f; /* 50ms */
61 memcpy(mov_src_pos, src_pos, 3*sizeof(float));
62 memcpy(mov_rec_pos, rec_pos, 3*sizeof(float));
63 for(i=0; i<0; i++){
64 mov_src_pos[1] = 2.0f + (float)i/100.0f;
65 mov_rec_pos[0] = 3.0f + (float)i/100.0f;
66 ims_shoebox_updateSource(hIms, sourceID_1, mov_src_pos);
67 ims_shoebox_updateReceiver(hIms, receiverID, mov_rec_pos);
68 ims_shoebox_computeEchograms(hIms, -1, maxTime_s);
70 }
71
72 /* Remove source No.1 */
74
75 /* Add 3 more sources, then remove 2, and add one back again
76 * (Just messing around, trying to trip up an IMS internal assertion) */
77 sourceID_3 = ims_shoebox_addSource(hIms, (float*)src3_pos, NULL);
78 sourceID_4 = ims_shoebox_addSource(hIms, (float*)src4_pos, NULL);
79 sourceID_5 = ims_shoebox_addSource(hIms, (float*)src5_pos, NULL);
80 ims_shoebox_removeSource(hIms, sourceID_3);
81 ims_shoebox_removeSource(hIms, sourceID_4);
82 sourceID_4 = ims_shoebox_addSource(hIms, (float*)src4_pos, NULL);
83
84 /* Continue rendering */
85 for(i=0; i<10; i++){
86 mov_src_pos[1] = 2.0f + (float)i/10.0f;
87 mov_rec_pos[0] = 3.0f + (float)i/10.0f;
88 ims_shoebox_updateSource(hIms, sourceID_4, mov_src_pos);
89 ims_shoebox_updateReceiver(hIms, receiverID, mov_rec_pos);
90 ims_shoebox_computeEchograms(hIms, -1, maxTime_s);
92 }
93
94 /* clean-up */
96}
97
99 void* hIms;
100 float maxTime_s;
101 float mov_src_pos[3], mov_rec_pos[3];
102 float** src_sigs, ***rec_sh_outsigs;
103 int sourceIDs[4], receiverIDs[1];
104 int i;
105
106 /* Config */
107 const int signalLength = 10000;
108 const int sh_order = 3;
109 const int nBands = 5;
110 const float abs_wall[5][6] = /* Absorption Coefficients per Octave band, and per wall */
111 { {0.180791250f, 0.207307300f, 0.134990800f, 0.229002250f, 0.212128400f, 0.241055000f},
112 {0.225971250f, 0.259113700f, 0.168725200f, 0.286230250f, 0.265139600f, 0.301295000f},
113 {0.258251250f, 0.296128100f, 0.192827600f, 0.327118250f, 0.303014800f, 0.344335000f},
114 {0.301331250f, 0.345526500f, 0.224994001f, 0.381686250f, 0.353562000f, 0.401775000f},
115 {0.361571250f, 0.414601700f, 0.269973200f, 0.457990250f, 0.424243600f, 0.482095000f} };
116 const float src_pos[3] = {5.1f, 6.0f, 1.1f};
117 const float src2_pos[3] = {2.1f, 1.0f, 1.3f};
118 const float src3_pos[3] = {3.1f, 5.0f, 2.3f};
119 const float src4_pos[3] = {7.1f, 2.0f, 1.4f};
120 const float rec_pos[3] = {8.8f, 5.5f, 0.9f};
121 const float roomdims[3] = {10.0f, 7.0f, 3.0f};
122
123 /* Allocate memory for 4 sources and 1 spherical harmonic receiver */
124 rec_sh_outsigs = (float***)malloc3d(1, ORDER2NSH(sh_order), signalLength, sizeof(float));
125 src_sigs = (float**)malloc2d(4, signalLength, sizeof(float));
126 rand_m1_1(FLATTEN2D(src_sigs), 4*signalLength);
127
128 /* Set-up the shoebox room simulator for these four sources and SH receiver */
129 ims_shoebox_create(&hIms, (float*)roomdims, (float*)abs_wall, 250.0f, nBands, 343.0f, 48e3f);
130 sourceIDs[0] = ims_shoebox_addSource(hIms, (float*)src_pos, &src_sigs[0]);
131 sourceIDs[1] = ims_shoebox_addSource(hIms, (float*)src2_pos, &src_sigs[1]);
132 sourceIDs[2] = ims_shoebox_addSource(hIms, (float*)src3_pos, &src_sigs[2]);
133 sourceIDs[3] = ims_shoebox_addSource(hIms, (float*)src4_pos, &src_sigs[3]);
134 receiverIDs[0] = ims_shoebox_addReceiverSH(hIms, sh_order, (float*)rec_pos, &rec_sh_outsigs[0]);
135
136 /* Moving source No.1 and the receiver */
137 maxTime_s = 0.025f; /* 50ms */
138 memcpy(mov_src_pos, src_pos, 3*sizeof(float));
139 memcpy(mov_rec_pos, rec_pos, 3*sizeof(float));
140 for(i=0; i<1; i++){
141 mov_src_pos[1] = 2.0f + (float)i/100.0f;
142 mov_rec_pos[0] = 3.0f + (float)i/100.0f;
143 ims_shoebox_updateSource(hIms, sourceIDs[0], mov_src_pos);
144 ims_shoebox_updateReceiver(hIms, receiverIDs[0], mov_rec_pos);
145 ims_shoebox_computeEchograms(hIms, -1, maxTime_s);
146 ims_shoebox_applyEchogramTD(hIms, receiverIDs[0], signalLength, 0);
147 }
148
149 /* clean-up */
150 free(src_sigs);
151 free(rec_sh_outsigs);
152 ims_shoebox_destroy(&hIms);
153}
void ims_shoebox_removeSource(void *hIms, int sourceID)
Removes a specific source from the simulation.
Definition saf_reverb.c:793
int ims_shoebox_addReceiverSH(void *hIms, int sh_order, float rec_xyz[3], float ***pSH_sigs)
Adds a spherical harmonic (SH) receiver object to the simulator of a given order, and returns a uniqu...
Definition saf_reverb.c:650
int ims_shoebox_addSource(void *hIms, float src_xyz[3], float **pSrc_sig)
Adds a source object to the simulator, and returns a unique ID corresponding to it.
Definition saf_reverb.c:599
void ims_shoebox_applyEchogramTD(void *hIms, long receiverID, int nSamples, int fractionalDelaysFLAG)
Applies the currently computed echograms in the time-domain, for all sources, for one specified recei...
Definition saf_reverb.c:298
void ims_shoebox_updateSource(void *hIms, int sourceID, float new_position_xyz[3])
Updates the position of a specific source in the simulation.
Definition saf_reverb.c:705
void ims_shoebox_computeEchograms(void *hIms, int maxN, float maxTime_ms)
Computes echograms for all active source/receiver combinations.
Definition saf_reverb.c:185
void ims_shoebox_updateReceiver(void *hIms, int receiverID, float new_position_xyz[3])
Updates the position of a specific receiver in the simulation.
Definition saf_reverb.c:749
void ims_shoebox_destroy(void **phIms)
Destroys an instance of ims_shoebox room simulator.
Definition saf_reverb.c:141
void ims_shoebox_renderRIRs(void *hIms, int fractionalDelayFLAG)
Renders room impulse responses for all active source/receiver combinations.
Definition saf_reverb.c:260
void ims_shoebox_create(void **phIms, float roomDimensions[3], float *abs_wall, float lowestOctaveBand, int nOctBands, float c_ms, float fs)
Creates an instance of ims_shoebox room simulator.
Definition saf_reverb.c:37
#define ORDER2NSH(order)
Converts spherical harmonic order to number of spherical harmonic components i.e: (order+1)^2.
Definition saf_sh.h:51
void rand_m1_1(float *vector, int length)
Generates random numbers between -1 and 1 and stores them in the input vector.
void ** malloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:89
void *** malloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size)
3-D malloc (contiguously allocated, so use free() as usual to deallocate)
Definition md_malloc.c:151
#define FLATTEN2D(A)
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other func...
Definition md_malloc.h:65
Unit test program for the Spatial_Audio_Framework.
void test__ims_shoebox_RIR(void)
Testing the ims shoebox simulator, when generating room impulse respones (RIRs) from the computed ech...
void test__ims_shoebox_TD(void)
Testing the ims shoebox simulator, when applying the echograms in the time- domain.