From fd18185e0748d88298b2c04bebd1a5abda70e5c2 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sat, 9 Jan 2021 14:25:19 -0600 Subject: [PATCH] Add FLAC support. --- Cargo.toml | 1 + src/lib.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9643125..e417c37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,6 @@ edition = "2018" alto = "3" anyhow = "1" bevy = "0.4" +claxon = "0.4" hound = "3" lewton = "0.10" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ad37739..0991477 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,25 @@ impl AssetLoader for BufferAssetLoader { let cursor = Cursor::new(bytes.to_vec()); let buffer: Option = match load_context.path().extension().unwrap().to_str().unwrap() { + "flac" => { + let reader = claxon::FlacReader::new(cursor); + if let Ok(mut reader) = reader { + let mut samples: Vec = vec![]; + for sample in reader.samples() { + if let Ok(sample) = sample { + samples.push(sample as i16); + } + } + let info = reader.streaminfo(); + Some(Buffer { + samples, + sample_rate: info.sample_rate as i32, + channels: info.channels as u16, + }) + } else { + None + } + } "ogg" => { let mut stream = OggStreamReader::new(cursor)?; let mut samples: Vec = vec![]; @@ -78,7 +97,7 @@ impl AssetLoader for BufferAssetLoader { } fn extensions(&self) -> &[&str] { - &["mp3", "ogg", "wav"] + &["flac", "ogg", "wav"] } } @@ -240,6 +259,7 @@ fn source_update( .map(|v| v.translation) .or_else(|| transform.map(|v| v.translation)); if let Some(translation) = translation { + // println!("Translation: {:?}", translation); source.set_relative(false); source .set_position([translation.x, translation.y, translation.z])