rtx-nn / rtx-multimodal: cargo fmt reformatting
Pure formatting changes across rtx-nn (conv_transpose1d, conv/mod, rnn/lstm) and rtx-multimodal (audio/generation, audio/source_separation): multi-line braces, trailing commas, import ordering. No logic changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This commit is contained in:
@@ -113,7 +113,11 @@ impl DemucsModel {
|
||||
/// For audio longer than `segment_length`, the input is split into overlapping
|
||||
/// segments, each processed independently, then recombined via overlap-add with
|
||||
/// a triangular cross-fade window.
|
||||
pub fn separate(&mut self, waveform: &[f32], channels: usize) -> Result<Vec<StemOutput>, DemucsError> {
|
||||
pub fn separate(
|
||||
&mut self,
|
||||
waveform: &[f32],
|
||||
channels: usize,
|
||||
) -> Result<Vec<StemOutput>, DemucsError> {
|
||||
if waveform.is_empty() {
|
||||
return Err(DemucsError::EmptyInput);
|
||||
}
|
||||
@@ -138,7 +142,8 @@ impl DemucsModel {
|
||||
|
||||
// 4. Run inference on each segment
|
||||
let stem_types = StemType::stems_for(self.config.num_stems);
|
||||
let mut stem_accumulators: Vec<Vec<f32>> = vec![vec![0.0; total_frames * channels]; self.config.num_stems];
|
||||
let mut stem_accumulators: Vec<Vec<f32>> =
|
||||
vec![vec![0.0; total_frames * channels]; self.config.num_stems];
|
||||
let mut weight_accumulator: Vec<f32> = vec![0.0; total_frames];
|
||||
|
||||
for (start_frame, chunk) in &segments {
|
||||
@@ -208,7 +213,12 @@ impl DemucsModel {
|
||||
}
|
||||
|
||||
/// Segment audio into overlapping chunks.
|
||||
fn segment(&self, channel_first: &[f32], channels: usize, total_frames: usize) -> Vec<(usize, Vec<f32>)> {
|
||||
fn segment(
|
||||
&self,
|
||||
channel_first: &[f32],
|
||||
channels: usize,
|
||||
total_frames: usize,
|
||||
) -> Vec<(usize, Vec<f32>)> {
|
||||
let seg_len = self.config.segment_length;
|
||||
let hop = ((1.0 - self.config.overlap) * seg_len as f32) as usize;
|
||||
let hop = hop.max(1);
|
||||
@@ -272,14 +282,19 @@ impl DemucsModel {
|
||||
let mut inputs = HashMap::new();
|
||||
inputs.insert("mix".to_string(), &input_tensor);
|
||||
|
||||
let outputs = self.session.run(inputs)
|
||||
let outputs = self
|
||||
.session
|
||||
.run(inputs)
|
||||
.map_err(|e| DemucsError::Inference(e.to_string()))?;
|
||||
|
||||
// Extract the output tensor (first output, whatever its name)
|
||||
let output_tensor = outputs.into_values().next()
|
||||
let output_tensor = outputs
|
||||
.into_values()
|
||||
.next()
|
||||
.ok_or_else(|| DemucsError::Inference("no output tensor from ONNX model".into()))?;
|
||||
|
||||
let output_data = output_tensor.to_vec_f32()
|
||||
let output_data = output_tensor
|
||||
.to_vec_f32()
|
||||
.map_err(|e| DemucsError::Inference(e.to_string()))?;
|
||||
|
||||
Ok(output_data)
|
||||
@@ -292,7 +307,11 @@ fn normalize(samples: &[f32]) -> (Vec<f32>, f32) {
|
||||
return (vec![], 1.0);
|
||||
}
|
||||
|
||||
let mean_sq: f64 = samples.iter().map(|&s| (s as f64) * (s as f64)).sum::<f64>() / samples.len() as f64;
|
||||
let mean_sq: f64 = samples
|
||||
.iter()
|
||||
.map(|&s| (s as f64) * (s as f64))
|
||||
.sum::<f64>()
|
||||
/ samples.len() as f64;
|
||||
let rms = mean_sq.sqrt() as f32;
|
||||
let scale = rms.max(1e-8);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user