feat: adapt to real usage
CI / Rust CI (push) Failing after 1m3s

This commit is contained in:
2026-09-06 12:29:45 +02:00
parent e2fee36cdb
commit af2e7dc602
13 changed files with 2580 additions and 2515 deletions
+38 -28
View File
@@ -7,18 +7,16 @@ use std::{
time::Duration,
};
use strum::IntoEnumIterator;
use crate::{
common::errors::{DSPError, ValidationError},
common::errors::DSPError,
dsp408::{
mapper::{
self,
constants::{CONFIG_CHUNK_INDEX_MAX, PRESET_INDEX_MAX},
constants::{CONFIG_CHUNK_INDEX_MAX, PRESET_INDEX_MAX, delay_range},
response::map_response,
},
protocol::{commands, config::decode_config, frame::extract_frame},
types,
types::{self},
},
};
@@ -154,6 +152,13 @@ impl DSP408 {
Ok(())
}
fn convert_delay_unit(value: f32, from: types::DelayUnit, to: types::DelayUnit) -> f32 {
let (_, from_max) = delay_range(from);
let (_, to_max) = delay_range(to);
(value / from_max) * to_max
}
// ---------- Commands ----------
// Command `0x10`
pub fn connect(&mut self) -> Result<(), DSPError> {
@@ -320,7 +325,20 @@ impl DSP408 {
return Ok(false);
}
self.state_mut()?.current_config.delay_unit = unit;
let state = self.state_mut()?;
let old_unit = state.current_config.delay_unit;
if old_unit != unit {
for input in state.current_config.input_states.values_mut() {
input.delay = Self::convert_delay_unit(input.delay, old_unit, unit);
}
for output in state.current_config.output_states.values_mut() {
output.delay = Self::convert_delay_unit(output.delay, old_unit, unit);
}
}
state.current_config.delay_unit = unit;
Ok(true)
}
@@ -810,8 +828,12 @@ impl DSP408 {
match channel {
types::Channel::Input(input) => {
state.current_config.input_state_mut(input).peq_chain.bands
[band as usize] = peq;
state
.current_config
.input_state_mut(input)
.peq_chain
.bands
.insert(band, peq);
}
types::Channel::Output(output) => {
@@ -819,7 +841,8 @@ impl DSP408 {
.current_config
.output_state_mut(output)
.peq_chain
.bands[band as usize] = peq;
.bands
.insert(band, peq);
}
}
@@ -947,7 +970,7 @@ impl DSP408 {
}
// Command `0x38` (Set Delay)
pub fn set_channel_delay(
pub fn set_delay(
&mut self,
channel: types::Channel,
delay: f32,
@@ -1350,19 +1373,12 @@ impl DSP408 {
let state = self.state_mut()?;
let index = types::InputChannel::iter()
.position(|x| x == input_channel)
.ok_or_else(|| {
DSPError::Validation(ValidationError::Value(
"Invalid input channel".to_string(),
))
})?;
state
.current_config
.output_state_mut(output_channel)
.matrix_routes
.gains[index] = gain;
.gains
.insert(input_channel, gain);
Ok(true)
}
@@ -1398,19 +1414,13 @@ impl DSP408 {
let state = self.state_mut()?;
let index = types::DiscreteFrequency::iter()
.position(|x| x == frequency_band)
.ok_or_else(|| {
DSPError::Validation(ValidationError::Value(
"Invalid GEQ frequency band".to_string(),
))
})?;
state
.current_config
.input_state_mut(input_channel)
.geq
.gains[index] = gain;
.gains
.insert(frequency_band, gain);
Ok(true)
}