chore: stabilize current head before Phase 10a QC

This commit is contained in:
2026-05-10 23:00:25 +01:00
parent c95a5da077
commit b463c32f17
24 changed files with 238 additions and 89 deletions

View File

@@ -15,5 +15,7 @@ pub async fn decode_and_resample(path: &Path) -> Result<AudioSamples> {
resample_to_16khz(&audio)
})
.await
.map_err(|e| magnotia_core::error::MagnotiaError::AudioDecodeFailed(format!("Task join error: {e}")))?
.map_err(|e| {
magnotia_core::error::MagnotiaError::AudioDecodeFailed(format!("Task join error: {e}"))
})?
}

View File

@@ -99,7 +99,9 @@ fn decode_media_stream(
.ok_or_else(|| MagnotiaError::AudioDecodeFailed("Unknown sample rate".into()))?;
if sample_rate == 0 {
return Err(MagnotiaError::AudioDecodeFailed("Invalid sample rate: 0".into()));
return Err(MagnotiaError::AudioDecodeFailed(
"Invalid sample rate: 0".into(),
));
}
let track_id = track.id;
@@ -166,7 +168,9 @@ fn decode_media_stream(
}
if samples.is_empty() {
return Err(MagnotiaError::AudioDecodeFailed("No audio data decoded".into()));
return Err(MagnotiaError::AudioDecodeFailed(
"No audio data decoded".into(),
));
}
Ok(AudioSamples::new(samples, sample_rate, 1))

View File

@@ -77,7 +77,9 @@ impl StreamingResampler {
INPUT_CHUNK,
1, // mono
)
.map_err(|e| MagnotiaError::AudioDecodeFailed(format!("StreamingResampler init failed: {e}")))?;
.map_err(|e| {
MagnotiaError::AudioDecodeFailed(format!("StreamingResampler init failed: {e}"))
})?;
Ok(Self::Sinc {
resampler,
@@ -142,7 +144,9 @@ impl StreamingResampler {
let input = vec![chunk];
let result = resampler.process(&input, None).map_err(|e| {
MagnotiaError::AudioDecodeFailed(format!("StreamingResampler flush failed: {e}"))
MagnotiaError::AudioDecodeFailed(format!(
"StreamingResampler flush failed: {e}"
))
})?;
let Some(mut out) = result.into_iter().next() else {

View File

@@ -42,8 +42,9 @@ impl WavWriter {
};
let file = std::fs::File::create(path).map_err(MagnotiaError::Io)?;
let buffered = BufWriter::new(file);
let inner = hound::WavWriter::new(buffered, spec)
.map_err(|e| MagnotiaError::Io(std::io::Error::other(format!("WAV create failed: {e}"))))?;
let inner = hound::WavWriter::new(buffered, spec).map_err(|e| {
MagnotiaError::Io(std::io::Error::other(format!("WAV create failed: {e}")))
})?;
Ok(Self {
inner,
samples_since_flush: 0,
@@ -76,9 +77,9 @@ impl WavWriter {
/// `Self::DEFAULT_FLUSH_EVERY_SAMPLES` — but may do so at natural
/// boundaries (end-of-utterance, UI events) for tighter recovery.
pub fn flush(&mut self) -> Result<()> {
self.inner
.flush()
.map_err(|e| MagnotiaError::Io(std::io::Error::other(format!("WAV flush failed: {e}"))))?;
self.inner.flush().map_err(|e| {
MagnotiaError::Io(std::io::Error::other(format!("WAV flush failed: {e}")))
})?;
self.samples_since_flush = 0;
Ok(())
}
@@ -110,14 +111,14 @@ pub fn write_wav(path: &Path, audio: &AudioSamples) -> Result<()> {
for &sample in audio.samples() {
let clamped = sample.clamp(-1.0, 1.0);
let int_sample = (clamped * i16::MAX as f32) as i16;
writer
.write_sample(int_sample)
.map_err(|e| MagnotiaError::Io(std::io::Error::other(format!("WAV write failed: {e}"))))?;
writer.write_sample(int_sample).map_err(|e| {
MagnotiaError::Io(std::io::Error::other(format!("WAV write failed: {e}")))
})?;
}
writer
.finalize()
.map_err(|e| MagnotiaError::Io(std::io::Error::other(format!("WAV finalize failed: {e}"))))?;
writer.finalize().map_err(|e| {
MagnotiaError::Io(std::io::Error::other(format!("WAV finalize failed: {e}")))
})?;
Ok(())
}