#include "soundfielddescription.h"


soundfielddescription::soundfielddescription(string json_textaddress)
{

}
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
            model::point<double, 2, cs::spherical<radian> > p1((*(micanglestheta + ml) * PI / 180), (*(micanglesphi + ml) * PI / 180));
            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;
}