3 #include "raytracer/postprocess.h" 5 #include "waveguide/canonical.h" 6 #include "waveguide/config.h" 7 #include "waveguide/postprocess.h" 10 #include "core/sum_ranges.h" 12 #include "audio_file/audio_file.h" 17 template <
typename Histogram>
20 util::aligned::vector<waveguide::bandpass_band> waveguide;
23 template <
typename Histogram>
24 auto make_combined_results(
26 util::aligned::vector<waveguide::bandpass_band> waveguide) {
28 std::move(waveguide)};
33 template <
typename LoIt,
typename HiIt>
34 auto crossover_filter(LoIt b_lo,
41 frequency_domain::best_fft_length(std::max(
42 std::distance(b_lo, e_lo), std::distance(b_hi, e_hi)))
47 const auto run_filter = [&](
auto b,
auto e,
auto mag_func) {
48 auto ret = std::vector<float>(std::distance(b, e));
49 filt.run(b, e, begin(ret), [&](
auto cplx,
auto freq) {
50 return cplx *
static_cast<float>(mag_func(freq, cutoff, width, l));
56 run_filter(b_lo, e_lo, frequency_domain::compute_lopass_magnitude);
58 run_filter(b_hi, e_hi, frequency_domain::compute_hipass_magnitude);
60 return core::sum_vectors(lo, hi);
67 auto operator()(T&& t)
const {
68 return t.valid_hz.get_max();
72 template <
typename Histogram,
typename Method>
75 const glm::vec3& source_position,
76 const glm::vec3& receiver_position,
79 double output_sample_rate) {
81 const auto waveguide_processed =
82 waveguide::postprocess(input.waveguide,
84 environment.acoustic_impedance,
87 const auto raytracer_processed = raytracer::postprocess(input.raytracer,
94 const auto make_iterator = [](
auto it) {
95 return util::make_mapping_iterator_adapter(std::move(it),
99 if (input.waveguide.empty()) {
100 return raytracer_processed;
103 const auto cutoff = *std::max_element(make_iterator(begin(input.waveguide)),
104 make_iterator(end(input.waveguide))) /
106 const auto width = 0.2;
107 auto filtered = crossover_filter(begin(waveguide_processed),
108 end(waveguide_processed),
109 begin(raytracer_processed),
110 end(raytracer_processed),
115 const auto window_length =
116 std::min(filtered.size(),
117 static_cast<size_t>(std::floor(
118 distance(source_position, receiver_position) *
119 output_sample_rate / environment.speed_of_sound)));
121 if (window_length == 0) {
125 const auto window = core::left_hanning(std::floor(window_length));
133 [](
auto envelope,
auto signal) {
return envelope * signal; });
Structured this way so that I can keep all fftw linkage internal.
Definition: filter.h:12
Definition: postprocess.h:18
Definition: pressure.h:22
Definition: canonical.h:18
Definition: environment.h:6
Definition: capsule_base.h:9
Definition: postprocess.h:65