use crate::common::spsc::RtStatusFlags;
use crate::dsp::adaptive::AdaptiveCompute;
use crate::dsp::cabsim::adapter::CabSimAdapter;
use crate::dsp::gate::{DynamicHysteresis, GateParams};
use crate::dsp::resampler::NamResampler;
use crate::models::StaticModel;
use super::bridge::DspBridgeWriter;
use crate::dsp::oversample::OversampleEngine;
pub struct DspPipelineContext<'a> {
pub resampler: &'a mut NamResampler,
pub os_l: &'a mut OversampleEngine,
pub os_r: &'a mut OversampleEngine,
pub active_model_l: &'a mut Option<Box<StaticModel>>,
pub active_model_r: &'a mut Option<Box<StaticModel>>,
pub input_gain_mult: f32,
pub output_gain_mult: f32,
pub gate_params: &'a GateParams,
pub silence_hysteresis: &'a mut DynamicHysteresis,
pub mono_hysteresis: &'a mut DynamicHysteresis,
pub threshold_open_sq: f32,
pub threshold_close_sq: f32,
pub process_mono: &'a mut bool,
pub rt_status: &'a RtStatusFlags,
pub adaptive: &'a mut AdaptiveCompute,
pub bridge_writer: Option<DspBridgeWriter>,
pub conv: Option<&'a mut CabSimAdapter>,
}
impl<'a> DspPipelineContext<'a> {
#[expect(
clippy::too_many_arguments,
reason = "DspPipelineContext mirrors the public struct literal; all non-optional components are mandatory"
)]
pub fn from_parts(
resampler: &'a mut NamResampler,
os_l: &'a mut OversampleEngine,
os_r: &'a mut OversampleEngine,
active_model_l: &'a mut Option<Box<StaticModel>>,
active_model_r: &'a mut Option<Box<StaticModel>>,
input_gain_mult: f32,
output_gain_mult: f32,
gate_params: &'a GateParams,
silence_hysteresis: &'a mut DynamicHysteresis,
mono_hysteresis: &'a mut DynamicHysteresis,
threshold_open_sq: f32,
threshold_close_sq: f32,
process_mono: &'a mut bool,
rt_status: &'a RtStatusFlags,
adaptive: &'a mut AdaptiveCompute,
) -> Self {
Self {
resampler,
os_l,
os_r,
active_model_l,
active_model_r,
input_gain_mult,
output_gain_mult,
gate_params,
silence_hysteresis,
mono_hysteresis,
threshold_open_sq,
threshold_close_sq,
process_mono,
rt_status,
adaptive,
bridge_writer: None,
conv: None,
}
}
pub fn with_bridge_writer(mut self, bridge_writer: DspBridgeWriter) -> Self {
self.bridge_writer = Some(bridge_writer);
self
}
pub fn with_conv(mut self, conv: &'a mut CabSimAdapter) -> Self {
self.conv = Some(conv);
self
}
}
pub struct DspBuffers<'a> {
pub resamp_mid_l: &'a mut [f32],
pub resamp_mid_r: &'a mut [f32],
pub resamp_out_l: &'a mut [f32],
pub resamp_out_r: &'a mut [f32],
pub model_out_l: &'a mut [f32],
pub model_out_r: &'a mut [f32],
pub os_in_l: &'a mut [f32],
pub os_in_r: &'a mut [f32],
pub os_model_l: &'a mut [f32],
pub os_model_r: &'a mut [f32],
pub crossfade_scratch_l: &'a mut [f32],
pub crossfade_scratch_r: &'a mut [f32],
}
impl<'a> DspBuffers<'a> {
#[expect(
clippy::too_many_arguments,
reason = "DspBuffers mirrors the public struct literal; all working slices are mandatory"
)]
pub fn from_parts(
resamp_mid_l: &'a mut [f32],
resamp_mid_r: &'a mut [f32],
resamp_out_l: &'a mut [f32],
resamp_out_r: &'a mut [f32],
model_out_l: &'a mut [f32],
model_out_r: &'a mut [f32],
os_in_l: &'a mut [f32],
os_in_r: &'a mut [f32],
os_model_l: &'a mut [f32],
os_model_r: &'a mut [f32],
crossfade_scratch_l: &'a mut [f32],
crossfade_scratch_r: &'a mut [f32],
) -> Self {
Self {
resamp_mid_l,
resamp_mid_r,
resamp_out_l,
resamp_out_r,
model_out_l,
model_out_r,
os_in_l,
os_in_r,
os_model_l,
os_model_r,
crossfade_scratch_l,
crossfade_scratch_r,
}
}
#[expect(
clippy::too_many_arguments,
reason = "DspBuffers mirrors the public struct literal; all stage slices are mandatory"
)]
pub fn new(
resamp_mid_l: &'a mut [f32],
resamp_mid_r: &'a mut [f32],
resamp_out_l: &'a mut [f32],
resamp_out_r: &'a mut [f32],
model_out_l: &'a mut [f32],
model_out_r: &'a mut [f32],
os_in_l: &'a mut [f32],
os_in_r: &'a mut [f32],
os_model_l: &'a mut [f32],
os_model_r: &'a mut [f32],
) -> Self {
Self::from_parts(
resamp_mid_l,
resamp_mid_r,
resamp_out_l,
resamp_out_r,
model_out_l,
model_out_r,
os_in_l,
os_in_r,
os_model_l,
os_model_r,
&mut [],
&mut [],
)
}
pub fn with_crossfade_scratch_l(mut self, crossfade_scratch_l: &'a mut [f32]) -> Self {
self.crossfade_scratch_l = crossfade_scratch_l;
self
}
pub fn with_crossfade_scratch_r(mut self, crossfade_scratch_r: &'a mut [f32]) -> Self {
self.crossfade_scratch_r = crossfade_scratch_r;
self
}
}