soundfielddescription.cpp 3.08 KB
Newer Older
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
1
2
#include "soundfielddescription.h"

Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
3
4
5
6
//template <typename Enumeration> auto as_integer(Enumeration const value)->typename std::underlying_type<SamplingRate>::type
//{
//	return static_cast<typename std::underlying_type<Enumeration>::type(value);
//}
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
7

Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
8

9
soundfielddescription::soundfielddescription(char microphone_array_geometry[])
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
10
{
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
11
    // parsing and serializing JSON
12
    json j_complete = json::parse(microphone_array_geometry);
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

	nofmicrophones = j_complete["NumberofMicrophones"];
	array_type = (ArrayType)j_complete["MicrophoneArrayType"];
	array_scattering_type = (ArrayScattering)j_complete["MicrophoneArrayScat"];
	sampling_rate = samplingrates[static_cast<int>(j_complete["SamplingRate"])];
	sample_type = sampletypes[static_cast<int>(j_complete["SampleType"])];
	block_size = blocksizes[static_cast<int>(j_complete["BlockSize"])];

	microphone_array_params = micarray();

	for (int klm = 0; klm < nofmicrophones; klm++)
	{
		microphone_array_params.addnewmicrophone(j_complete["MicrophoneList"][klm]["xCoord"], j_complete["MicrophoneList"][klm]["yCoord"], j_complete["MicrophoneList"][klm]["zCoord"], j_complete["MicrophoneList"][klm]["micxLookCoord"], j_complete["MicrophoneList"][klm]["micyLookCoord"], j_complete["MicrophoneList"][klm]["miczLookCoord"], j_complete["MicrophoneArrayLookCoord"]["xLookCoord"], j_complete["MicrophoneArrayLookCoord"]["yLookCoord"], j_complete["MicrophoneArrayLookCoord"]["zLookCoord"]);
	}
	micanglestheta = microphone_array_params.getmicthetas();
	micanglesphi = microphone_array_params.getmicphis();

Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
}
void* soundfielddescription::calcsphericalharmonics(double* pressure_real_in, double* pressure_imag_in, double* shd_realpart_out, double* shd_imagpart_out)
{
    int nof_sph = (int)(pow(SHDorder + 1, 2));
    for (int sn = 0; sn < nofsamples; sn++)
    {

        //malloc with zero valued spherical harmonics
        complex<double>* sph_harmonics = (complex<double>*)calloc(nof_sph, sizeof(complex<double>));

        //SHD computation according to the recording microphones
        for (int ml = 0; ml < nofmicrophones; ml++)
        {
            // get the microphone coordinates in theta/phi
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
44
            model::point<double, 2, cs::spherical<radian> > p1((micanglestheta.at(ml) * PI / 180), (micanglesphi.at(ml) * PI / 180));
Mert Burkay Çöteli's avatar
Mert Burkay Çöteli committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
            int counter = 0;
            // SHD calculations according to the spherical harmonics
            for (int sph_n = 0; sph_n <= SHDorder; sph_n++)
            {
                for (int sph_m = ((-1) * sph_n); sph_m <= sph_n; sph_m++)
                {
                    complex<double> calcharmonic_conj = conj((complex<double>)boost::math::spherical_harmonic(sph_n, sph_m, get<0>(p1), get<1>(p1)));
                    *(sph_harmonics + counter) += complex<double>(pressure_real_in[sn* nofmicrophones + ml], pressure_imag_in[sn * nofmicrophones + ml]) * calcharmonic_conj;
                    shd_realpart_out[sn * nof_sph + counter] = sph_harmonics[counter].real();
                    shd_imagpart_out[sn * nof_sph + counter] = sph_harmonics[counter].imag();
                    counter++;
                }
            }
        }
    }
    return 0;
}