Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exclude = ["plugins/cli2", "plugins/db", "plugins/export"]

[workspace.dependencies]
hypr-aec = { path = "crates/aec", package = "aec" }
hypr-afconvert = { path = "crates/afconvert", package = "afconvert" }
hypr-agc = { path = "crates/agc", package = "agc" }
hypr-am = { path = "crates/am", package = "am" }
hypr-am2 = { path = "crates/am2", package = "am2" }
Expand Down
7 changes: 7 additions & 0 deletions crates/afconvert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "afconvert"
version = "0.1.0"
edition = "2024"

[dependencies]
thiserror = { workspace = true }
39 changes: 39 additions & 0 deletions crates/afconvert/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::path::{Path, PathBuf};
use std::process::Command;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("afconvert failed: {0}")]
Failed(String),
}

pub fn to_wav(source_path: &Path) -> Result<PathBuf, Error> {
let file_stem = source_path
.file_stem()
.unwrap_or_default()
.to_string_lossy();
let wav_path = std::env::temp_dir().join(format!(
"{}_afconvert_{}.wav",
file_stem,
std::process::id()
));

let output = Command::new("afconvert")
.arg("-f")
.arg("WAVE")
.arg("-d")
.arg("LEI16")
.arg(source_path)
.arg(&wav_path)
.output()?;

if !output.status.success() {
let _ = std::fs::remove_file(&wav_path);
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(Error::Failed(stderr.into_owned()));
}

Ok(wav_path)
}
1 change: 1 addition & 0 deletions plugins/fs-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ serde_yaml = { workspace = true }
specta = { workspace = true, features = ["serde_json"] }

glob = "0.3"
hypr-afconvert = { workspace = true }
rayon = { workspace = true }
rodio = { workspace = true, features = ["symphonia-all"] }

Expand Down
29 changes: 28 additions & 1 deletion plugins/fs-sync/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ pub fn import_audio(
target_path: &Path,
) -> Result<PathBuf, AudioProcessingError> {
let file = File::open(source_path)?;
let decoder = rodio::Decoder::try_from(file)?;
match rodio::Decoder::try_from(file) {
Ok(decoder) => import_audio_from_decoder(decoder, tmp_path, target_path),
Err(_original_err) => {
#[cfg(target_os = "macos")]
{
let wav_path = hypr_afconvert::to_wav(source_path)
.map_err(|e| AudioProcessingError::AfconvertFailed(e.to_string()))?;
let result = (|| {
let file = File::open(&wav_path)?;
let decoder = rodio::Decoder::try_from(file)?;
import_audio_from_decoder(decoder, tmp_path, target_path)
})();
let _ = std::fs::remove_file(&wav_path);
result
}
#[cfg(not(target_os = "macos"))]
{
Err(_original_err.into())
}
}
}
}

fn import_audio_from_decoder<R: std::io::Read + std::io::Seek>(
decoder: rodio::Decoder<R>,
tmp_path: &Path,
target_path: &Path,
) -> Result<PathBuf, AudioProcessingError> {
let channel_count_raw = decoder.channels().max(1);
let channel_count_u8 = u8::try_from(channel_count_raw).map_err(|_| {
AudioProcessingError::UnsupportedChannelCount {
Expand Down
2 changes: 2 additions & 0 deletions plugins/fs-sync/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
EmptyInput,
#[error("audio_import_invalid_target_rate")]
InvalidTargetSampleRate,
#[error("audio_import_afconvert_failed: {0}")]
AfconvertFailed(String),

Check warning on line 45 in plugins/fs-sync/src/error.rs

View workflow job for this annotation

GitHub Actions / desktop_ci (linux, depot-ubuntu-22.04-8)

variant `AfconvertFailed` is never constructed

Check warning on line 45 in plugins/fs-sync/src/error.rs

View workflow job for this annotation

GitHub Actions / desktop_ci (linux, depot-ubuntu-22.04-8)

variant `AfconvertFailed` is never constructed
}

#[derive(Debug, thiserror::Error)]
Expand Down
Loading