style: cargo fmt --workspace (whitespace/wrapping only, no semantic change)
Whole-workspace rustfmt pass picked up while iterating on Mamba GPU backward work. Verified formatting-only via diff sampling; no logic changed. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
//!
|
||||
//! The algorithm is particularly useful as a fast, non-neural baseline vocoder.
|
||||
|
||||
use rtx_tensor::{ComplexTensor, Device, Tensor};
|
||||
use rtx_tensor::signal::{stft, istft, WindowType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::{MelConfig, MelSpectrogram, Vocoder};
|
||||
use crate::error::{Result, TtsError};
|
||||
use super::{Vocoder, MelSpectrogram, MelConfig};
|
||||
use rtx_tensor::signal::{WindowType, istft, stft};
|
||||
use rtx_tensor::{ComplexTensor, Device, Tensor};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Configuration for Griffin-Lim algorithm
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -48,16 +48,24 @@ impl GriffinLimConfig {
|
||||
return Err(TtsError::InvalidConfig("FFT size must be > 0".to_string()));
|
||||
}
|
||||
if self.hop_length == 0 {
|
||||
return Err(TtsError::InvalidConfig("Hop length must be > 0".to_string()));
|
||||
return Err(TtsError::InvalidConfig(
|
||||
"Hop length must be > 0".to_string(),
|
||||
));
|
||||
}
|
||||
if self.win_length == 0 || self.win_length > self.n_fft {
|
||||
return Err(TtsError::InvalidConfig("Window length must be > 0 and <= n_fft".to_string()));
|
||||
return Err(TtsError::InvalidConfig(
|
||||
"Window length must be > 0 and <= n_fft".to_string(),
|
||||
));
|
||||
}
|
||||
if self.n_iter == 0 {
|
||||
return Err(TtsError::InvalidConfig("Number of iterations must be > 0".to_string()));
|
||||
return Err(TtsError::InvalidConfig(
|
||||
"Number of iterations must be > 0".to_string(),
|
||||
));
|
||||
}
|
||||
if self.sample_rate == 0 {
|
||||
return Err(TtsError::InvalidConfig("Sample rate must be > 0".to_string()));
|
||||
return Err(TtsError::InvalidConfig(
|
||||
"Sample rate must be > 0".to_string(),
|
||||
));
|
||||
}
|
||||
self.mel_config.validate()?;
|
||||
Ok(())
|
||||
@@ -100,7 +108,9 @@ impl GriffinLim {
|
||||
fn reconstruct_phase(&self, magnitude: &Tensor) -> Result<Tensor> {
|
||||
let dims = magnitude.dims();
|
||||
if dims.len() != 2 {
|
||||
return Err(TtsError::InvalidInput("Magnitude must be 2D [n_freqs, time_frames]".to_string()));
|
||||
return Err(TtsError::InvalidInput(
|
||||
"Magnitude must be 2D [n_freqs, time_frames]".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let n_freqs = dims[0];
|
||||
@@ -119,20 +129,26 @@ impl GriffinLim {
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
// Convert to radians (0 to 2π)
|
||||
let phase_data = phase.to_cpu()
|
||||
let phase_data = phase
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
let phase_rad: Vec<f32> = phase_data.iter().map(|&p| p * 2.0 * std::f32::consts::PI).collect();
|
||||
let phase_rad: Vec<f32> = phase_data
|
||||
.iter()
|
||||
.map(|&p| p * 2.0 * std::f32::consts::PI)
|
||||
.collect();
|
||||
let mut phase_tensor = Tensor::from_data(phase_rad, vec![n_freqs, n_frames], &self.device)
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
// Get magnitude data
|
||||
let mag_data = magnitude.to_cpu()
|
||||
let mag_data = magnitude
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
// Griffin-Lim iterations
|
||||
for _iter in 0..self.config.n_iter {
|
||||
// Construct complex spectrum from magnitude and phase
|
||||
let phase_data = phase_tensor.to_cpu()
|
||||
let phase_data = phase_tensor
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
let mut real_data = Vec::with_capacity(n_freqs * n_frames);
|
||||
@@ -174,9 +190,15 @@ impl GriffinLim {
|
||||
.map_err(|e| TtsError::VocodingError(format!("STFT failed: {}", e)))?;
|
||||
|
||||
// Extract phase from new spectrum
|
||||
let new_real = stft_result.stft.real().to_cpu()
|
||||
let new_real = stft_result
|
||||
.stft
|
||||
.real()
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
let new_imag = stft_result.stft.imag().to_cpu()
|
||||
let new_imag = stft_result
|
||||
.stft
|
||||
.imag()
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
let new_phase_data: Vec<f32> = new_real
|
||||
@@ -190,7 +212,8 @@ impl GriffinLim {
|
||||
}
|
||||
|
||||
// Final reconstruction
|
||||
let phase_data = phase_tensor.to_cpu()
|
||||
let phase_data = phase_tensor
|
||||
.to_cpu()
|
||||
.map_err(|e| TtsError::TensorError(e.to_string()))?;
|
||||
|
||||
let mut real_data = Vec::with_capacity(n_freqs * n_frames);
|
||||
|
||||
Reference in New Issue
Block a user