Skip to content

Commit

Permalink
Merge pull request #751 from AmbientRun/revert_optivorbis
Browse files Browse the repository at this point in the history
Temporarily remove optivorbis until the libgit2-sys build dependency is addressed due to the heavy impact on compile times.
  • Loading branch information
Pombal authored Aug 25, 2023
2 parents c49df61 + ba45aca commit 769e9a5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ symphonia = { version = "0.5", default-features = false, features = [
"wav",
] }
vorbis_rs = "0.3.0"
optivorbis = "0.1.4"
colored = "2.0.0"
directories = "5.0.1"
ulid = { version = "1.0.0", features = ["serde"] }
Expand Down
1 change: 0 additions & 1 deletion app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ fn setup_logging() -> anyhow::Result<()> {
"symphonia_bundle_mp3",
"wgpu_core",
"wgpu_hal",
"optivorbis",
"symphonia_format_wav",
],
),
Expand Down
2 changes: 1 addition & 1 deletion crates/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ async-trait = { workspace = true }
dyn-clonable = { workspace = true }
symphonia = { workspace = true }
vorbis_rs = { workspace = true }
optivorbis = { workspace = true }
rand = { workspace = true }
chrono = { workspace = true }
21 changes: 6 additions & 15 deletions crates/build/src/pipelines/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use ambient_native_std::asset_url::AssetType;
use ambient_pipeline_types::audio::AudioPipeline;
use ambient_world_audio::AudioNode;
use anyhow::Context;
use optivorbis::Remuxer;
use std::io::Cursor;
use tracing::{info_span, Instrument};

use super::{
Expand Down Expand Up @@ -149,6 +147,9 @@ async fn symphonia_convert(ext: &str, input: Vec<u8>) -> anyhow::Result<Vec<u8>>
.make(&track.codec_params, &dec_opts)
.context("Failed to create audio decoder")?;

// randomize an ogg stream serial number
let stream_serial: i32 = rand::random();

// retrieve the sampling rate from the input file
let sampling_rate: NonZeroU32 = decoder
.codec_params()
Expand All @@ -174,7 +175,7 @@ async fn symphonia_convert(ext: &str, input: Vec<u8>) -> anyhow::Result<Vec<u8>>

// create the ogg Vorbis encoder
let mut encoder = VorbisEncoder::new(
0, // OptiVorbis already randomizes serials
stream_serial,
[("", ""); 0], // no tags
sampling_rate,
channels,
Expand Down Expand Up @@ -221,16 +222,6 @@ async fn symphonia_convert(ext: &str, input: Vec<u8>) -> anyhow::Result<Vec<u8>>

// finish encoding
let output = encoder.finish()?;
let output_size = output.len();
tracing::debug!("Encoded samples for {output_size} bytes");

// optimize generated file
let mut optimized_output = Vec::with_capacity(output_size);
optivorbis::OggToOgg::new_with_defaults().remux(Cursor::new(output), &mut optimized_output)?;
tracing::debug!(
"Optimized samples from {output_size} bytes -> {} bytes",
optimized_output.len()
);

Ok(optimized_output)
tracing::debug!("Encoded {} samples", output.len());
Ok(output)
}

0 comments on commit 769e9a5

Please sign in to comment.