Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
MPAI-Private
MPAI-CAE
eae
Commits
92a4f8d8
Commit
92a4f8d8
authored
Jul 03, 2022
by
Mert Burkay Çöteli
Browse files
220703 commit
parent
2ad915e8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Packager/packager.cpp
0 → 100644
View file @
92a4f8d8
#include
"packager.h"
packager
::
packager
(
char
audioscene_geometry
[],
char
microphonearray_geometry
[],
double
*
interleavedmultichannelaudio
)
{
// parsing and serializing Audio Scene Geometry
json
j_complete
=
json
::
parse
(
audioscene_geometry
);
*
BlockIndex
=
static_cast
<
double
>
(
j_complete
[
"BlockIndex"
]);
*
BlockStart
=
static_cast
<
double
>
(
j_complete
[
"BlockStart"
]);
*
BlockEnd
=
static_cast
<
double
>
(
j_complete
[
"BlockEnd"
]);
*
SpeechCount
=
static_cast
<
unsigned
char
>
(
j_complete
[
"SpeechCount"
]);
// parsing and serializing Microphone Array Geometry
json
j_complete_mag
=
json
::
parse
(
microphonearray_geometry
);
*
BlockSize
=
blocksizes
[
static_cast
<
int
>
(
j_complete_mag
[
"BlockSize"
])];
*
SamplingRate
=
samplingrates
[
static_cast
<
int
>
(
j_complete_mag
[
"SamplingRate"
])];
*
SampleType
=
sampletypes
[
static_cast
<
int
>
(
j_complete_mag
[
"SampleType"
])];
for
(
int
klm
=
0
;
klm
<
*
SpeechCount
;
klm
++
)
{
unsigned
char
*
speechuuid
;
//;
insertnewspeech
(
static_cast
<
double
>
(
j_complete
[
"SpeechList"
][
klm
][
"AzimuthDirection"
]),
static_cast
<
double
>
(
j_complete
[
"SpeechList"
][
klm
][
"ElevationDirection"
]),
static_cast
<
double
>
(
j_complete
[
"SpeechList"
][
klm
][
"Distance"
]),
static_cast
<
unsigned
char
>
(
j_complete
[
"SpeechList"
][
klm
][
"DistanceFlag"
]),
(
int
)(
*
BlockSize
),
interleavedmultichannelaudio
,
static_cast
<
int
>
(
j_complete
[
"SpeechList"
][
klm
][
"ChannelID"
]),
speechuuid
);
}
};
void
packager
::
insertnewspeech
(
double
m_Azimuth
,
double
m_Elevation
,
double
m_Distance
,
unsigned
char
m_DistanceFlag
,
int
m_blocksize
,
double
*
m_interleavedmultichannel
,
int
ChannelID
,
unsigned
char
*
uuid
)
{
SpeechInfo
m_speech
=
SpeechInfo
();
*
m_speech
.
Azimuth
=
m_Azimuth
;
*
m_speech
.
Elevation
=
m_Elevation
;
*
m_speech
.
Distance
=
m_Distance
;
*
m_speech
.
DistanceFlag
=
m_DistanceFlag
;
m_speech
.
speechdata
=
m_interleavedmultichannel
;
Speech
.
push_back
(
m_speech
);
};
\ No newline at end of file
Packager/packager.h
0 → 100644
View file @
92a4f8d8
#pragma once
#include
<vector>
#include
<nlohmann/json.hpp>
using
namespace
std
;
using
json
=
nlohmann
::
json
;
class
SpeechInfo
{
public:
unsigned
char
Speechuuid
[
16
];
unsigned
char
Azimuth
[
4
];
unsigned
char
Elevation
[
4
];
unsigned
char
Distance
[
4
];
unsigned
char
DistanceFlag
[
1
];
double
*
speechdata
;
};
class
packager
{
public:
packager
(
char
audioscene_geometry
[],
char
microphonearray_geometry
[],
double
*
interleavedmultichannelaudio
);
void
insertnewspeech
(
double
m_Azimuth
,
double
m_Elevation
,
double
m_Distance
,
unsigned
char
m_DistanceFlag
,
int
m_blocksize
,
double
*
m_interleavedmultichannel
,
int
ChannelID
,
unsigned
char
*
uuid
);
private:
unsigned
char
Header
[
3
]
=
{
0x45
,
0x41
,
0x45
};
unsigned
char
BlockIndex
[
8
];
unsigned
char
BlockStart
[
8
];
unsigned
char
BlockEnd
[
8
];
unsigned
char
BlockSize
[
1
];
unsigned
char
SamplingRate
[
1
];
unsigned
char
SpeechCount
[
1
];
unsigned
char
SampleType
[
1
];
unsigned
char
Checksum
[
1
];
vector
<
SpeechInfo
>
Speech
;
int
samplingrates
[
8
]
=
{
16000
,
24000
,
32000
,
44100
,
48000
,
64000
,
96000
,
192000
};
int
sampletypes
[
3
]
=
{
16
,
24
,
32
};
int
blocksizes
[
7
]
=
{
64
,
128
,
256
,
512
,
1024
,
2048
,
4096
};
};
SoundFieldDescription/micarray.cpp
0 → 100644
View file @
92a4f8d8
#include
"micarray.h"
micarray
::
micarray
()
{
this
->
numberofmicrophones
=
32
;
}
vector
<
float
>
micarray
::
getmicthetas
()
{
return
microphonetheta
;
}
vector
<
float
>
micarray
::
getmicphis
()
{
return
microphonephi
;
}
void
micarray
::
addnewmicrophone
(
float
mic_x
,
float
mic_y
,
float
mic_z
,
float
mic_ld_x
,
float
mic_ld_y
,
float
mic_ld_z
,
float
ma_x
,
float
ma_y
,
float
ma_z
)
{
float
x
=
mic_x
;
float
y
=
mic_y
;
float
z
=
mic_z
;
float
microphone_phi
;
float
microphone_theta
;
float
microphone_distance
;
microphone_x
.
push_back
(
x
);
microphone_y
.
push_back
(
y
);
microphone_z
.
push_back
(
z
);
ConvertCartesionToSpherical
(
microphone_distance
,
microphone_theta
,
microphone_phi
,
x
,
y
,
z
);
microphonetheta
.
push_back
(
microphone_theta
);
microphonephi
.
push_back
(
microphone_phi
);
microphonedistance
.
push_back
(
microphone_distance
);
}
void
micarray
::
ConvertCartesionToSpherical
(
float
&
distance
,
float
&
theta
,
float
&
phi
,
float
&
x
,
float
&
y
,
float
&
z
)
{
phi
=
atan2
(
y
,
x
);
if
(
phi
<
0.0
)
phi
+=
2.0
*
PI
;
theta
=
atan2
(
sqrt
(
x
*
x
+
y
*
y
)
,
z
);
if
(
theta
<
0.0
)
theta
+=
1.0
*
PI
;
distance
=
sqrt
(
x
*
x
+
y
*
y
+
z
*
z
);
}
void
micarray
::
ConvertSphericalToCartesian
(
float
&
distance
,
float
&
theta
,
float
&
phi
,
float
&
x
,
float
&
y
,
float
&
z
)
{
x
=
distance
*
sin
(
theta
)
*
cos
(
phi
);
y
=
distance
*
sin
(
theta
)
*
sin
(
phi
);
z
=
distance
*
cos
(
theta
);
}
\ No newline at end of file
SoundFieldDescription/micarray.h
0 → 100644
View file @
92a4f8d8
#pragma once
#include
<string>
#include
<vector>
#include
<complex>
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
using
namespace
std
;
class
micarray
{
public:
micarray
();
vector
<
float
>
getmicthetas
();
vector
<
float
>
getmicphis
();
void
addnewmicrophone
(
float
mic_x
,
float
mic_y
,
float
mic_z
,
float
mic_ld_x
,
float
mic_ld_y
,
float
mic_ld_z
,
float
ma_x
,
float
ma_y
,
float
ma_z
);
private:
void
ConvertCartesionToSpherical
(
float
&
distance
,
float
&
theta
,
float
&
phi
,
float
&
x
,
float
&
y
,
float
&
z
);
void
ConvertSphericalToCartesian
(
float
&
distance
,
float
&
theta
,
float
&
phi
,
float
&
x
,
float
&
y
,
float
&
z
);
int
numberofmicrophones
;
vector
<
float
>
microphonetheta
;
vector
<
float
>
microphonephi
;
vector
<
float
>
microphonedistance
;
vector
<
float
>
microphone_x
;
vector
<
float
>
microphone_y
;
vector
<
float
>
microphone_z
;
};
SoundFieldDescription/soundfielddescription.cpp
View file @
92a4f8d8
#include
"soundfielddescription.h"
//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);
//}
soundfielddescription
::
soundfielddescription
(
string
json_textaddress
)
soundfielddescription
::
soundfielddescription
()
{
char
text
[]
=
R"(
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Microphone Array Geometry",
"MicrophoneArrayType": 0,
"MicrophoneArrayScat": 0,
"MicrophoneArrayFilterURI": "filter.file",
"SamplingRate": 4,
"SampleType": 2,
"BlockSize": 5,
"NumberofMicrophones": 32,
"MicrophoneList" : [
{"xCoord" : 0.93358,"yCoord" : 0.0,"zCoord" : 0.35836,"directivity" : 0.0,"micxLookCoord" : 0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : 0.35836},
{"xCoord" : 0.84804,"yCoord" : 0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.84804,"micyLookCoord" : 0.52991,"miczLookCoord" : 0.0},
{"xCoord" : 0.93358,"yCoord" : 0.0,"zCoord" : -0.35836,"directivity" : 0.0,"micxLookCoord" : 0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : -0.35836},
{"xCoord" : 0.84804,"yCoord" : -0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.84804,"micyLookCoord" : -0.52991,"miczLookCoord" : 0.0},
{"xCoord" : 0.52991,"yCoord" : 0.0,"zCoord" : 0.84804,"directivity" : 0.0,"micxLookCoord" : 0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : 0.84804},
{"xCoord" : 0.57922,"yCoord" : 0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : 0.35836,"yCoord" : 0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.35836,"micyLookCoord" : 0.93358,"miczLookCoord" : 0.0},
{"xCoord" : 0.57922,"yCoord" : 0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : 0.52991,"yCoord" : 0.0,"zCoord" : -0.84804,"directivity" : 0.0,"micxLookCoord" : 0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : -0.84804},
{"xCoord" : 0.57922,"yCoord" : -0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : 0.35836,"yCoord" : -0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.35836,"micyLookCoord" : -0.93358,"miczLookCoord" : 0.0},
{"xCoord" : 0.57922,"yCoord" : -0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.00625,"yCoord" : 0.35831,"zCoord" : 0.93358,"directivity" : 0.0,"micxLookCoord" : -0.00625,"micyLookCoord" : 0.35831,"miczLookCoord" : 0.93358},
{"xCoord" : 0.0,"yCoord" : 0.84804,"zCoord" : 0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : 0.84804,"miczLookCoord" : 0.52991},
{"xCoord" : 0.0,"yCoord" : 0.85716,"zCoord" : -0.51503,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : 0.85716,"miczLookCoord" : -0.51503},
{"xCoord" : 0.006254,"yCoord" : 0.35831,"zCoord" : -0.93358,"directivity" : 0.0,"micxLookCoord" : 0.006254,"micyLookCoord" : 0.35831,"miczLookCoord" : -0.93358},
{"xCoord" : -0.93358,"yCoord" : 0.0,"zCoord" : 0.35836,"directivity" : 0.0,"micxLookCoord" : -0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : 0.35836},
{"xCoord" : -0.84804,"yCoord" : -0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.84804,"micyLookCoord" : -0.52991,"miczLookCoord" : 0.0},
{"xCoord" : -0.93358,"yCoord" : 0.0,"zCoord" : -0.35836,"directivity" : 0.0,"micxLookCoord" : -0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : -0.35836},
{"xCoord" : -0.84804,"yCoord" : 0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.84804,"micyLookCoord" : 0.52991,"miczLookCoord" : 0.0},
{"xCoord" : -0.52991,"yCoord" : 0.0,"zCoord" : 0.84804,"directivity" : 0.0,"micxLookCoord" : -0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : 0.84804},
{"xCoord" : -0.57922,"yCoord" : -0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.35836,"yCoord" : -0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.35836,"micyLookCoord" : -0.93358,"miczLookCoord" : 0.0},
{"xCoord" : -0.57922,"yCoord" : -0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : -0.52991,"yCoord" : 0.0,"zCoord" : -0.84804,"directivity" : 0.0,"micxLookCoord" : -0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : -0.84804},
{"xCoord" : -0.57922,"yCoord" : 0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : -0.35836,"yCoord" : 0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.35836,"micyLookCoord" : 0.93358,"miczLookCoord" : 0.0},
{"xCoord" : -0.57922,"yCoord" : 0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.00625,"yCoord" : -0.35831,"zCoord" : 0.93358,"directivity" : 0.0,"micxLookCoord" : -0.00625,"micyLookCoord" : -0.35831,"miczLookCoord" : 0.93358},
{"xCoord" : 0.0,"yCoord" : -0.84804,"zCoord" : 0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : -0.84804,"miczLookCoord" : 0.52991},
{"xCoord" : 0.0,"yCoord" : -0.84804,"zCoord" : -0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : -0.84804,"miczLookCoord" : -0.52991},
{"xCoord" : 0.00625,"yCoord" : -0.35831,"zCoord" : -0.93358,"directivity" : 0.0,"micxLookCoord" : 0.00625,"micyLookCoord" : -0.35831,"miczLookCoord" : -0.93358}
],
"MicrophoneArrayLookCoord" : {"xLookCoord" : 0.0, "yLookCoord" : 0.0, "zLookCoord" : 0.0}
}
)"
;
// parsing and serializing JSON
json
j_complete
=
json
::
parse
(
text
);
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
();
}
void
*
soundfielddescription
::
calcsphericalharmonics
(
double
*
pressure_real_in
,
double
*
pressure_imag_in
,
double
*
shd_realpart_out
,
double
*
shd_imagpart_out
)
{
...
...
@@ -18,7 +91,7 @@ void* soundfielddescription::calcsphericalharmonics(double* pressure_real_in, do
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
));
model
::
point
<
double
,
2
,
cs
::
spherical
<
radian
>
>
p1
((
micanglestheta
.
at
(
ml
)
*
PI
/
180
),
(
micanglesphi
.
at
(
ml
)
*
PI
/
180
));
int
counter
=
0
;
// SHD calculations according to the spherical harmonics
for
(
int
sph_n
=
0
;
sph_n
<=
SHDorder
;
sph_n
++
)
...
...
SoundFieldDescription/soundfielddescription.h
View file @
92a4f8d8
#pragma once
#include
"micarray.h"
#ifndef Q_MOC_RUN
#include
"boost/geometry.hpp"
#endif
...
...
@@ -11,22 +13,54 @@
#include
"boost/math/special_functions/spherical_harmonic.hpp"
#include
"boost/variant/get.hpp"
#include
<nlohmann/json.hpp>
#define SHDorder 1
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
using
namespace
std
;
using
namespace
boost
::
geometry
;
using
namespace
boost
::
math
;
using
json
=
nlohmann
::
json
;
enum
class
ArrayType
{
Spherical
,
Circular
,
Planar
,
Linear
,
Other
};
enum
class
ArrayScattering
{
Rigid
,
Open
,
OtherArray
};
class
soundfielddescription
{
public:
soundfielddescription
(
string
json_textaddress
);
soundfielddescription
();
void
*
calcsphericalharmonics
(
double
*
pressure_real_in
,
double
*
pressure_imag_in
,
double
*
shd_realpart_out
,
double
*
shd_imagpart_out
);
private:
float
*
micanglestheta
;
float
*
micanglesphi
;
vector
<
float
>
micanglestheta
;
vector
<
float
>
micanglesphi
;
int
nofmicrophones
;
int
nofsamples
;
ArrayType
array_type
;
ArrayScattering
array_scattering_type
;
int
sampling_rate
;
int
sample_type
;
int
block_size
;
int
samplingrates
[
8
]
=
{
16000
,
24000
,
32000
,
44100
,
48000
,
64000
,
96000
,
192000
};
int
sampletypes
[
3
]
=
{
16
,
24
,
32
};
int
blocksizes
[
7
]
=
{
64
,
128
,
256
,
512
,
1024
,
2048
,
4096
};
micarray
microphone_array_params
;
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment