3
3
#include " data_file.hpp"
4
4
#include " utils.hpp"
5
5
6
+ using json = nlohmann::json;
7
+
6
8
namespace {
7
- ear::PolarPosition load_position (const rapidjson::Value &position_j)
9
+ ear::PolarPosition load_position (const json &position_j)
8
10
{
9
- return {position_j[ " azimuth" ]. GetDouble (),
10
- position_j[ " elevation" ]. GetDouble (),
11
- position_j[ " distance" ]. GetDouble ()};
11
+ return {position_j. at ( " azimuth" ). template get < double > (),
12
+ position_j. at ( " elevation" ). template get < double > (),
13
+ position_j. at ( " distance" ). template get < double > ()};
12
14
}
13
15
14
- ear::Channel load_channel (const rapidjson::Value &channel_j)
16
+ ear::Channel load_channel (const json &channel_j)
15
17
{
16
18
ear::Channel channel;
17
- channel.name (channel_j[ " name" ]. GetString ());
19
+ channel.name (channel_j. at ( " name" ). template get <std::string> ());
18
20
19
- channel.polarPosition (load_position (channel_j[ " polar_position" ] ));
20
- channel.polarPositionNominal (load_position (channel_j[ " polar_nominal_position" ] ));
21
+ channel.polarPosition (load_position (channel_j. at ( " polar_position" ) ));
22
+ channel.polarPositionNominal (load_position (channel_j. at ( " polar_nominal_position" ) ));
21
23
22
- const auto &az_range_j = channel_j[ " az_range" ]. GetArray ();
23
- channel.azimuthRange ({{az_range_j[ 0 ]. GetDouble (), az_range_j[ 1 ]. GetDouble ()}} );
24
+ auto az_range = channel_j. at ( " az_range" ). template get <std::pair< double , double >> ();
25
+ channel.azimuthRange (az_range );
24
26
25
- const auto &el_range_j = channel_j[ " el_range" ]. GetArray ();
26
- channel.elevationRange ({{el_range_j[ 0 ]. GetDouble (), el_range_j[ 1 ]. GetDouble ()}} );
27
+ auto el_range = channel_j. at ( " el_range" ). template get <std::pair< double , double >> ();
28
+ channel.elevationRange (el_range );
27
29
28
- channel.isLfe (channel_j[ " is_lfe" ]. GetBool ());
30
+ channel.isLfe (channel_j. at ( " is_lfe" ). get < bool > ());
29
31
30
32
return channel;
31
33
}
32
34
33
- ear::Layout load_layout (const rapidjson::Value &layout_j)
35
+ ear::Layout load_layout (const json &layout_j)
34
36
{
37
+ const json::array_t &channels_j = layout_j.at (" channels" ).template get_ref <const json::array_t &>();
38
+
35
39
std::vector<ear::Channel> channels;
36
- for (auto &channel_j : layout_j[" channels" ].GetArray ()) {
37
- channels.push_back (load_channel (channel_j));
38
- }
40
+ for (const auto &channel_j : channels_j) channels.push_back (load_channel (channel_j));
39
41
40
- return {layout_j[ " name" ]. GetString (), channels};
42
+ return {layout_j. at ( " name" ). template get <std::string> (), channels};
41
43
}
42
44
43
45
void check (bool x, const std::string &message)
@@ -55,13 +57,13 @@ Panner::Panner(const std::string &brir_file_name)
55
57
56
58
check_data_file_version (tf);
57
59
58
- views = tf.unpack <float >(tf.metadata [ " views" ] );
59
- brirs = tf.unpack <float >(tf.metadata [ " brirs" ] );
60
- delays = tf.unpack <float >(tf.metadata [ " delays" ] );
61
- decorrelation_filters = tf.unpack <float >(tf.metadata [ " decorrelation_filters" ] );
62
- fs = tf.metadata [ " fs" ]. GetDouble ();
63
- decorrelation_delay_ = tf.metadata [ " decorrelation_delay" ]. GetDouble ();
64
- front_loudspeaker_ = tf.metadata [ " front_loudspeaker" ]. GetUint ();
60
+ views = tf.unpack <float >(tf.metadata . at ( " views" ) );
61
+ brirs = tf.unpack <float >(tf.metadata . at ( " brirs" ) );
62
+ delays = tf.unpack <float >(tf.metadata . at ( " delays" ) );
63
+ decorrelation_filters = tf.unpack <float >(tf.metadata . at ( " decorrelation_filters" ) );
64
+ fs = tf.metadata . at ( " fs" ). template get < double > ();
65
+ decorrelation_delay_ = tf.metadata . at ( " decorrelation_delay" ). template get < double > ();
66
+ front_loudspeaker_ = tf.metadata . at ( " front_loudspeaker" ). template get < size_t > ();
65
67
66
68
// check and unpack dimensions
67
69
check (views->ndim () == 2 , " views must have 2 dimensions" );
@@ -93,11 +95,11 @@ Panner::Panner(const std::string &brir_file_name)
93
95
94
96
// load layout
95
97
ear::Layout layout;
96
- if (tf.metadata [ " layout" ]. IsString ()) {
97
- std::string layout_name = tf.metadata [ " layout" ]. GetString ();
98
+ if (tf.metadata . at ( " layout" ). is_string ()) {
99
+ std::string layout_name = tf.metadata . at ( " layout" ). template get <std::string> ();
98
100
layout = ear::getLayout (layout_name).withoutLfe ();
99
101
} else {
100
- layout = load_layout (tf.metadata [ " layout" ] );
102
+ layout = load_layout (tf.metadata . at ( " layout" ) );
101
103
}
102
104
103
105
// make gain calculators
@@ -110,9 +112,9 @@ Panner::Panner(const std::string &brir_file_name)
110
112
temp_direct_diffuse.resize (num_gains () * 2 );
111
113
temp_direct_speakers.resize (num_gains ());
112
114
113
- if (tf.metadata .HasMember (" gain_norm_quick" )) {
115
+ if (tf.metadata .contains (" gain_norm_quick" )) {
114
116
gain_comp_type = GainCompType::QUICK;
115
- gain_comp_factors = tf.unpack <float >(tf.metadata [ " gain_norm_quick" ][ " factors" ] );
117
+ gain_comp_factors = tf.unpack <float >(tf.metadata . at ( " gain_norm_quick" ). at ( " factors" ) );
116
118
check (gain_comp_factors->ndim () == 5 , " gain comp factors must have 5 dimensions" );
117
119
// TODO: check max delays?
118
120
check (gain_comp_factors->shape (1 ) == n_views_, " gain comp factors axis 1 is wrong size" );
@@ -123,13 +125,14 @@ Panner::Panner(const std::string &brir_file_name)
123
125
check (gain_comp_factors->shape (4 ) == 2 , " gain comp factors axis 4 is wrong size" );
124
126
}
125
127
126
- check (tf.metadata .HasMember (" hoa" ), " HOA decoder not present" );
127
- hoa_irs = tf.unpack <float >(tf.metadata [ " hoa" ][ " irs" ] );
128
+ check (tf.metadata .contains (" hoa" ), " HOA decoder not present" );
129
+ hoa_irs = tf.unpack <float >(tf.metadata . at ( " hoa" ). at ( " irs" ) );
128
130
check (hoa_irs->ndim () == 3 , " HOA decoder must have 3 dimensions" );
129
131
n_hoa_channels_ = hoa_irs->shape (0 );
130
132
check (hoa_irs->shape (1 ) == 2 , " HOA decoder axis 1 is wrong size" );
131
133
132
- if (tf.metadata [" hoa" ].HasMember (" delay" )) hoa_delay_ = tf.metadata [" hoa" ][" delay" ].GetDouble ();
134
+ if (tf.metadata .at (" hoa" ).contains (" delay" ))
135
+ hoa_delay_ = tf.metadata .at (" hoa" ).at (" delay" ).template get <double >();
133
136
134
137
hoa_order_ = ((size_t )std::round (std::sqrt (n_hoa_channels_))) - 1 ;
135
138
size_t nch_for_order = (hoa_order_ + 1 ) * (hoa_order_ + 1 );
0 commit comments