all of the changes

This commit is contained in:
2026-10-23 18:29:51 +02:00
parent 4c435fdd76
commit 5607dcf2b5
73 changed files with 4365 additions and 2059 deletions

View File

@@ -65,17 +65,23 @@ struct Metrics {
}
};
template <class Scenario>
void capture(const std::string &prefix, int frames, float pedal, OutdoorScene scene, TwoStrokeConfig config) {
void capture(const std::string &prefix, int frames, float pedal, OutdoorScene scene, TwoStrokeConfig config, PipeSolver solver, float fixed_rpm, float warmup) {
std::unique_ptr<Scenario> s;
if constexpr (std::is_same_v<Scenario, TwoStrokeScenario>) s = std::make_unique<Scenario>(44100, config);
else s = std::make_unique<Scenario>();
s->set_pipe_solver(solver);
s->throttle = pedal;
s->set_audio_scene(scene);
for(int i=0; i<int(std::lround(warmup*44100)); ++i) {
if(fixed_rpm>0) s->crankshaft.omega=fixed_rpm*2*pi/60;
s->process();
}
Wav rendered(prefix + "-rendered.wav", frames), dry(prefix + "-dry.wav", frames),
raw(prefix + "-unfiltered.wav", frames);
Metrics m, d, r;
int cuts = 0;
for (int i = 0; i < frames; i++) {
if(fixed_rpm>0) s->crankshaft.omega=fixed_rpm*2*pi/60;
auto f = s->process(), df = s->dry_audio(), rf = s->unfiltered_audio();
m.add(f);
d.add(df);
@@ -96,10 +102,9 @@ void capture(const std::string &prefix, int frames, float pedal, OutdoorScene sc
int main(int argc, char **argv) {
try {
std::string scenario = "twin", prefix = "build/audio/twin", scene = "wall";
float seconds = 6, pedal = 1;
float seconds = 6, pedal = 1, fixed_rpm = 0, warmup = 0;
TwoStrokeConfig config;
bool turbo_enabled = false;
std::string turbo_name;
PipeSolver solver=PipeSolver::Rusanov;
for (int i = 1; i < argc; i++) {
std::string key = argv[i];
if (i + 1 >= argc)
@@ -113,11 +118,9 @@ int main(int argc, char **argv) {
seconds = std::stof(value);
else if (key == "--throttle")
pedal = std::stof(value);
else if (key == "--turbo") {
if (value != "none" && value != "vz21" && value != "gt17") throw std::runtime_error("choose none, vz21 or gt17 turbo");
turbo_name = value;
turbo_enabled = value != "none";
}
else if (key == "--warmup") warmup=std::stof(value);
else if (key == "--rpm") fixed_rpm=std::stof(value);
else if (key == "--solver") solver=parse_pipe_solver(value);
else if (key == "--exhaust") {
if (value == "racing") config.exhaust = TwoStrokeExhaust::Racing;
else if (value == "straight") config.exhaust = TwoStrokeExhaust::Straight;
@@ -131,6 +134,9 @@ int main(int argc, char **argv) {
if (!std::isfinite(seconds) || seconds <= 0 || seconds > 600 || !std::isfinite(pedal) || pedal < 0 ||
pedal > 1)
throw std::runtime_error("invalid capture duration or throttle");
if(!std::isfinite(fixed_rpm) || fixed_rpm<0 || fixed_rpm>30000)
throw std::runtime_error("invalid capture RPM");
if(!std::isfinite(warmup) || warmup<0 || warmup>600) throw std::runtime_error("invalid warmup");
OutdoorScene selected;
if (scene == "dry")
selected = OutdoorScene::Dry;
@@ -140,27 +146,21 @@ int main(int argc, char **argv) {
selected = OutdoorScene::Wall;
else if (scene == "woodland")
selected = OutdoorScene::Woodland;
else if (scene == "tunnel")
selected = OutdoorScene::Tunnel;
else
throw std::runtime_error("invalid scene");
if (!std::filesystem::path(prefix).parent_path().empty())
std::filesystem::create_directories(std::filesystem::path(prefix).parent_path());
const int frames = int(std::lround(seconds * 44100));
if (turbo_name.empty() && scenario == "b205") turbo_enabled = true;
if (!turbo_name.empty() && turbo_name!="none" &&
!((turbo_name=="vz21" && scenario=="twin") || (turbo_name=="gt17" && scenario=="b205")))
throw std::runtime_error("use gt17 with b205 or vz21 with twin");
if (scenario == "twin" && turbo_enabled)
capture<TurboTwinScenario>(prefix, frames, pedal, selected, config);
else if (scenario == "twin")
capture<FourStrokeTwinScenario>(prefix, frames, pedal, selected, config);
else if (scenario == "b205" && turbo_enabled)
capture<SaabTurboScenario>(prefix, frames, pedal, selected, config);
if (scenario == "twin")
capture<FourStrokeTwinScenario>(prefix, frames, pedal, selected, config, solver, fixed_rpm, warmup);
else if (scenario == "b205")
capture<SaabB205Scenario>(prefix, frames, pedal, selected, config);
capture<SaabB205Scenario>(prefix, frames, pedal, selected, config, solver, fixed_rpm, warmup);
else if (scenario == "two-stroke")
capture<TwoStrokeScenario>(prefix, frames, pedal, selected, config);
capture<TwoStrokeScenario>(prefix, frames, pedal, selected, config, solver, fixed_rpm, warmup);
else if (scenario == "v8")
capture<AmericanV8Scenario>(prefix, frames, pedal, selected, config);
capture<AmericanV8Scenario>(prefix, frames, pedal, selected, config, solver, fixed_rpm, warmup);
else
throw std::runtime_error("choose twin, two-stroke, b205 or v8");
} catch (const std::exception &e) {