94{
95 const Acoustics::DuctSpec spec { .length = length, .sample_rate =
m_rate, .mouth_volume = mouth_volume };
96
97 std::expected<Acoustics::DuctGrid, Acoustics::DuctError> grid = std::unexpected(Acoustics::DuctError::INVALID_PROFILE);
98 if (!profile.radii.empty()) {
99 grid = Acoustics::make_duct_grid(spec, profile.radii);
100 } else if (profile.function) {
101 grid = Acoustics::make_duct_grid(spec, profile.function);
102 }
103
104 if (!grid) {
107 return nullptr;
108 }
109
110 if (!mouth || !bell
114 "DuctNetwork terminations cannot terminate the {} interval duct", grid->intervals);
115 return nullptr;
116 }
117
118 auto prepared = std::make_shared<Prepared>();
119 prepared->spec = spec;
120 prepared->pressure.assign(grid->intervals + 1, 0.0);
121 prepared->velocity.assign(grid->intervals, 0.0);
122 prepared->grid = std::move(*grid);
123 prepared->mouth = mouth;
124 prepared->bell = bell;
125
126 prepared->friction = losses.friction;
127 prepared->viscosity = losses.viscosity;
128 if (losses.automatic) {
129 const auto& areas = prepared->grid.area;
130 const double mean_area = std::accumulate(areas.begin(), areas.end(), 0.0) / static_cast<double>(areas.size());
131 std::tie(prepared->friction, prepared->viscosity) = Acoustics::viscothermal_rates(
132 std::sqrt(mean_area / std::numbers::pi), spec.sound_speed, spec.air_density);
133 }
134
135 if (!prepared->loss.configure(prepared->grid, prepared->friction, prepared->viscosity)) {
137 "DuctNetwork wall losses of {} and {} cannot be applied", prepared->friction, prepared->viscosity);
138 return nullptr;
139 }
140
141 return prepared;
142}
#define MF_WARN(comp, ctx,...)
@ Configuration
Configuration and parameter updates.
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
constexpr std::string_view enum_to_string(EnumType value) noexcept
Universal enum to string converter using magic_enum (original case).