Add turbocharged twin scenario and cross-platform test harness
This commit is contained in:
72
include/FluidSim/OutdoorAudio.hpp
Normal file
72
include/FluidSim/OutdoorAudio.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "FluidSim/AudioProcessing.hpp"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace fluidsim::port {
|
||||
enum class OutdoorScene { Dry, Field, Wall, Woodland };
|
||||
const char *scene_name(OutdoorScene scene);
|
||||
|
||||
struct OutdoorAudioConfig {
|
||||
Vec3 listener{1.6f, 1.0f, 2.0f};
|
||||
Vec3 listener_right{1.0f, 0.0f, 0.0f};
|
||||
Vec3 intake_position{-0.2f, 0.7f, 0.0f};
|
||||
Vec3 exhaust_position{0.55f, 0.5f, 0.0f};
|
||||
float ear_spacing{0.18f}, sound_speed{343.0f};
|
||||
float ground_y{0.0f}, wall_x{-1.5f};
|
||||
float ground_reflection{0.35f}, wall_reflection{0.65f};
|
||||
float pressure_gain{0.005f}; // 200 Pa per device full scale, not speaker SPL.
|
||||
float monitor_cutoff_hz{6000.0f}; // Second-order acquisition/rendering filter.
|
||||
};
|
||||
|
||||
// Static geometric direct/first-order reflection paths plus an explicitly
|
||||
// approximate diffuse tail. No feedback into the fluid/combustion simulation.
|
||||
class OutdoorAudio {
|
||||
public:
|
||||
explicit OutdoorAudio(int sample_rate = 44100, OutdoorAudioConfig config = {});
|
||||
AudioFrame process(float intake_mass_flow, float exhaust_mass_flow);
|
||||
void set_scene(OutdoorScene scene) { scene_ = scene; }
|
||||
OutdoorScene scene() const { return scene_; }
|
||||
void set_monitor_filter(bool enabled) { monitor_filter_ = enabled; } // Set before playback/capture.
|
||||
AudioFrame dry_frame() const { return last_dry_; }
|
||||
AudioFrame unfiltered_frame() const { return last_raw_; }
|
||||
|
||||
private:
|
||||
struct LowPass {
|
||||
float b0{}, b1{}, b2{}, a1{}, a2{}, z1{}, z2{};
|
||||
float process(float x);
|
||||
};
|
||||
struct Path {
|
||||
std::size_t delay_left{}, delay_right{};
|
||||
float fraction_left{}, fraction_right{}, gain_left{}, gain_right{}, alpha{1};
|
||||
float state_left{}, state_right{};
|
||||
int group{}; // direct, ground, wall, trees
|
||||
};
|
||||
struct Emitter {
|
||||
std::vector<float> filtered, raw;
|
||||
std::vector<Path> paths;
|
||||
std::size_t position{};
|
||||
float previous_flow{};
|
||||
LowPass filter;
|
||||
};
|
||||
struct TailLine {
|
||||
std::vector<float> buffer;
|
||||
std::size_t position{};
|
||||
float gain{}, state{};
|
||||
};
|
||||
int rate_{};
|
||||
OutdoorAudioConfig config_;
|
||||
OutdoorScene scene_{OutdoorScene::Wall};
|
||||
bool monitor_filter_{true};
|
||||
std::array<Emitter, 2> emitters_;
|
||||
std::array<TailLine, 4> tail_;
|
||||
std::array<float, 4> weights_{1, 0, 0, 0};
|
||||
float scene_alpha_{}, tail_alpha_{}, tail_mix_{};
|
||||
AudioFrame last_dry_{}, last_raw_{};
|
||||
void configure_emitter(Emitter &emitter, Vec3 position);
|
||||
AudioFrame render(Emitter &emitter, float flow, AudioFrame &dry, AudioFrame &raw);
|
||||
AudioFrame diffuse(float input);
|
||||
};
|
||||
} // namespace fluidsim::port
|
||||
Reference in New Issue
Block a user