U10: ec-aac delete wrap_sbr and aacenc_rt examples and the ec-matroska dev-dependency (only the deleted real-library tests used it)
Browse files at this commit2fb2a9c742d98da97545604d23f00a22f06e04b5Parent: b5223b74 changed files +0 -216
- Cargo.lock +0 -1
- crates/ec-aac/Cargo.toml +0 -1
- crates/ec-aac/examples/aacenc_rt.rs +0 -105
- crates/ec-aac/examples/wrap_sbr.rs +0 -109
Cargo.lockmodified+0 -1
| @@ -372,7 +372,6 @@ version = "0.1.0" | ||
| 372 | 372 | dependencies = [ |
| 373 | 373 | "ec-core", |
| 374 | 374 | "ec-dsp", |
| 375 | - "ec-matroska", | |
| 376 | 375 | "ec-mp4", |
| 377 | 376 | "ec-testkit", |
| 378 | 377 | ] |
crates/ec-aac/Cargo.tomlmodified+0 -1
| @@ -12,5 +12,4 @@ ec-dsp = { workspace = true } | ||
| 12 | 12 | |
| 13 | 13 | [dev-dependencies] |
| 14 | 14 | ec-mp4 = { workspace = true } |
| 15 | -ec-matroska = { workspace = true } | |
| 16 | 15 | ec-testkit.workspace = true |
crates/ec-aac/examples/aacenc_rt.rsdeleted+0 -105
| @@ -1,105 +0,0 @@ | ||
| 1 | -//! AAC-LC encode speed relative to realtime, which is how the crate's encode | |
| 2 | -//! perf claim is measured: a deterministic tonal-plus-transient program, ten | |
| 3 | -//! seconds, at the seat's rates (stereo 256 kbit/s, 5.1 512 kbit/s), the | |
| 4 | -//! shortest wall of several alternating repetitions. | |
| 5 | -//! | |
| 6 | -//! ```text | |
| 7 | -//! cargo run --release -p ec-aac --example aacenc_rt | |
| 8 | -//! ``` | |
| 9 | - | |
| 10 | -use std::time::Instant; | |
| 11 | - | |
| 12 | -use ec_aac::{AacEncoder, AacEncoderConfig}; | |
| 13 | - | |
| 14 | -/// Deterministic tonal stacks with periodic noise bursts: enough tonality for | |
| 15 | -/// the spreading function to bite, enough attacks to exercise the short-block | |
| 16 | -/// path. | |
| 17 | -struct Lcg(u64); | |
| 18 | -impl Lcg { | |
| 19 | - fn next_f32(&mut self) -> f32 { | |
| 20 | - self.0 = self | |
| 21 | - .0 | |
| 22 | - .wrapping_mul(6364136223846793005) | |
| 23 | - .wrapping_add(1442695040888963407); | |
| 24 | - ((self.0 >> 40) as f32 / 16777216.0) * 2.0 - 1.0 | |
| 25 | - } | |
| 26 | -} | |
| 27 | - | |
| 28 | -fn channel(f0: f64, seed: u64, rate: u32, secs: usize, burst_period: f64) -> Vec<f32> { | |
| 29 | - let mut noise = Lcg(seed); | |
| 30 | - let mut out = Vec::with_capacity(secs * rate as usize); | |
| 31 | - for i in 0..secs * rate as usize { | |
| 32 | - let t = i as f64 / rate as f64; | |
| 33 | - let frac = (t % burst_period) / burst_period; | |
| 34 | - let burst = (-frac * 18.0_f64).exp() as f32; | |
| 35 | - let stack = (f0.sin() * 0.5 | |
| 36 | - + (f0 * 3.0).sin() * 0.15 | |
| 37 | - + (f0 * 5.0 + 0.31 * (6.0 * std::f64::consts::TAU * t).sin()).sin() * 0.08) | |
| 38 | - as f32 | |
| 39 | - * (0.7 + 0.3 * (0.5 * std::f64::consts::TAU * t).sin()) as f32; | |
| 40 | - out.push(stack + burst * noise.next_f32() * 0.3); | |
| 41 | - } | |
| 42 | - out | |
| 43 | -} | |
| 44 | - | |
| 45 | -fn program(channels: usize, rate: u32, secs: usize) -> Vec<f32> { | |
| 46 | - let stereo = [0x5EED_1234u64, 0xC0FF_EE01]; | |
| 47 | - let five_one = [0x5EED_1234, 0xC0FF_EE01, 0xABCD_0001, 0xABCD_0002, 0xABCD_0003, 0xABCD_0004]; | |
| 48 | - let f0s = [220.0f64, 277.0, 330.0, 55.0, 196.0, 246.9]; | |
| 49 | - let periods = [0.9f64, 0.8, 1.1, 1.3, 0.7, 0.85]; | |
| 50 | - let seeds: &[u64] = if channels == 2 { | |
| 51 | - &stereo | |
| 52 | - } else { | |
| 53 | - &five_one | |
| 54 | - }; | |
| 55 | - let chans: Vec<Vec<f32>> = (0..channels) | |
| 56 | - .map(|c| channel(f0s[c], seeds[c], rate, secs, periods[c])) | |
| 57 | - .collect(); | |
| 58 | - let mut pcm = Vec::with_capacity(chans[0].len() * channels); | |
| 59 | - for i in 0..chans[0].len() { | |
| 60 | - for c in &chans { | |
| 61 | - pcm.push(c[i]); | |
| 62 | - } | |
| 63 | - } | |
| 64 | - pcm | |
| 65 | -} | |
| 66 | - | |
| 67 | -fn encode(pcm: &[f32], channels: usize, kbps: u32) -> usize { | |
| 68 | - let mut enc = AacEncoder::new(AacEncoderConfig { | |
| 69 | - bitrate_bps: kbps * 1_000, | |
| 70 | - ..Default::default() | |
| 71 | - }); | |
| 72 | - enc.push_pcm(pcm, channels as u16, 48_000).expect("pcm accepted"); | |
| 73 | - enc.finish(); | |
| 74 | - let mut bytes = 0usize; | |
| 75 | - while let Ok(p) = enc.next_packet() { | |
| 76 | - bytes += p.data.len(); | |
| 77 | - } | |
| 78 | - bytes | |
| 79 | -} | |
| 80 | - | |
| 81 | -fn main() { | |
| 82 | - let reps: usize = std::env::var("REPS") | |
| 83 | - .ok() | |
| 84 | - .and_then(|s| s.parse().ok()) | |
| 85 | - .unwrap_or(7); | |
| 86 | - for (channels, kbps) in [(2usize, 256u32), (6, 512)] { | |
| 87 | - let pcm = program(channels, 48_000, 10); | |
| 88 | - let secs = pcm.len() as f64 / (48_000.0 * channels as f64); | |
| 89 | - let _ = encode(&pcm, channels, kbps); // warm | |
| 90 | - let mut walls = Vec::with_capacity(reps); | |
| 91 | - for _ in 0..reps { | |
| 92 | - let t0 = Instant::now(); | |
| 93 | - let bytes = encode(&pcm, channels, kbps); | |
| 94 | - walls.push((t0.elapsed().as_secs_f64(), bytes)); | |
| 95 | - } | |
| 96 | - walls.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); | |
| 97 | - let (wall, bytes) = walls[0]; | |
| 98 | - println!( | |
| 99 | - "{channels}ch {kbps}k: min {wall:.4}s = {:.1}x realtime ({} B, {} reps)", | |
| 100 | - secs / wall, | |
| 101 | - bytes, | |
| 102 | - reps | |
| 103 | - ); | |
| 104 | - } | |
| 105 | -} |
crates/ec-aac/examples/wrap_sbr.rsdeleted+0 -109
| @@ -1,109 +0,0 @@ | ||
| 1 | -//! Wraps a bare ADTS stream (the SBR patch-map probes' | |
| 2 | -//! `scripts/aac-tables/sbrpatchmap.py` output) in an mp4 container carrying | |
| 3 | -//! an EXPLICIT-SBR AudioSpecificConfig as its `esds` -- the instrument | |
| 4 | -//! round-30's blocker needed: a bare `.aac` file carries no out-of-band | |
| 5 | -//! AudioSpecificConfig at all, so a decoder that trusts one (rather than | |
| 6 | -//! only its bare-ADTS implicit per-frame SBR detection) has nothing to arm | |
| 7 | -//! HE-AAC output from and locks to core-rate. | |
| 8 | -//! | |
| 9 | -//! Matroska was tried first (`MatroskaMuxer`, dev-dep already proven to | |
| 10 | -//! round-trip `CodecPrivate` byte-for-byte in | |
| 11 | -//! `crates/ec-aac/tests/sbr_real_library.rs`) but the reference decoder's | |
| 12 | -//! Matroska demuxer reads the *codec ID string* ("A_AAC" vs. | |
| 13 | -//! "A_AAC/MPEG4/SBR") for its reported profile, not just the `CodecPrivate` | |
| 14 | -//! bytes our `MatroskaMuxer` writes generically -- it still upgraded the | |
| 15 | -//! reported sample rate to the extension rate (proving it DOES parse | |
| 16 | -//! `CodecPrivate` for that), but kept reporting profile "LC". mp4's `esds` | |
| 17 | -//! carries the same explicit-SBR AudioSpecificConfig and needs no such | |
| 18 | -//! sibling string, matching the real `~/Music/reeln.mp4` fixture's | |
| 19 | -//! own container exactly. | |
| 20 | -//! | |
| 21 | -//! `stream()`/`stream_one_band()`'s probe frames are full ADTS (7-byte | |
| 22 | -//! header + raw_data_block); this strips the header off each frame and | |
| 23 | -//! remuxes the raw access units into an mp4 track whose `esds` is | |
| 24 | -//! `write_audio_specific_config` with `object_type = AOT_SBR` and an | |
| 25 | -//! explicit `extension_sample_rate`. | |
| 26 | -//! | |
| 27 | -//! usage: wrap_sbr_mkv <in.aac> <core_rate> <ext_rate> <channels> <out.mp4> | |
| 28 | -use std::fs::File; | |
| 29 | - | |
| 30 | -use ec_aac::{AOT_SBR, AudioSpecificConfig, sf_index_for_rate, write_audio_specific_config}; | |
| 31 | -use ec_core::{ | |
| 32 | - AudioParameters, ChannelLayout, CodecId, CodecParameters, MediaParameters, Muxer, Packet, | |
| 33 | - StreamInfo, TimeBase, | |
| 34 | -}; | |
| 35 | -use ec_mp4::Mp4Muxer; | |
| 36 | - | |
| 37 | -fn main() { | |
| 38 | - let args: Vec<String> = std::env::args().collect(); | |
| 39 | - assert_eq!( | |
| 40 | - args.len(), | |
| 41 | - 6, | |
| 42 | - "usage: wrap_sbr_mkv <in.aac> <core_rate> <ext_rate> <channels> <out.mkv>" | |
| 43 | - ); | |
| 44 | - let data = std::fs::read(&args[1]).expect("input readable"); | |
| 45 | - let core_rate: u32 = args[2].parse().expect("core_rate is a number"); | |
| 46 | - let ext_rate: u32 = args[3].parse().expect("ext_rate is a number"); | |
| 47 | - let channels: u16 = args[4].parse().expect("channels is a number"); | |
| 48 | - | |
| 49 | - // Strip each ADTS frame down to its raw access unit (no header, no CRC). | |
| 50 | - let mut aus = Vec::new(); | |
| 51 | - let mut at = 0usize; | |
| 52 | - while at + 7 <= data.len() { | |
| 53 | - let Ok(header) = ec_aac::parse_adts(&data[at..]) else { | |
| 54 | - break; | |
| 55 | - }; | |
| 56 | - let end = (at + header.frame_length).min(data.len()); | |
| 57 | - aus.push(data[at + header.header_len..end].to_vec()); | |
| 58 | - at = end; | |
| 59 | - } | |
| 60 | - assert!(!aus.is_empty(), "no ADTS frames found in {}", args[1]); | |
| 61 | - | |
| 62 | - let sf_index = sf_index_for_rate(core_rate).expect("core_rate is a valid AAC rate"); | |
| 63 | - let channel_config = channels as u8; | |
| 64 | - let asc = write_audio_specific_config(&AudioSpecificConfig { | |
| 65 | - object_type: AOT_SBR, | |
| 66 | - sample_rate: core_rate, | |
| 67 | - sf_index, | |
| 68 | - channels, | |
| 69 | - channel_config, | |
| 70 | - sbr_present: true, | |
| 71 | - ps_present: false, | |
| 72 | - extension_sample_rate: Some(ext_rate), | |
| 73 | - pce: Vec::new(), | |
| 74 | - }); | |
| 75 | - | |
| 76 | - let time_base = TimeBase::from_rate(core_rate); | |
| 77 | - let layout = if channels == 1 { | |
| 78 | - ChannelLayout::Mono | |
| 79 | - } else { | |
| 80 | - ChannelLayout::Stereo | |
| 81 | - }; | |
| 82 | - let mut params = CodecParameters::new(CodecId::Aac); | |
| 83 | - params.extradata = Some(asc.into()); | |
| 84 | - params.media = MediaParameters::Audio(AudioParameters { | |
| 85 | - sample_rate: core_rate, | |
| 86 | - layout, | |
| 87 | - format: None, | |
| 88 | - bits_per_sample: None, | |
| 89 | - }); | |
| 90 | - let mut info = StreamInfo::new(0, time_base, params); | |
| 91 | - info.default = true; | |
| 92 | - | |
| 93 | - let out = File::create(&args[5]).expect("output creatable"); | |
| 94 | - let mut muxer = Mp4Muxer::new(out).expect("mp4 muxer opens"); | |
| 95 | - muxer.add_stream(info).expect("stream declared"); | |
| 96 | - for (i, au) in aus.iter().enumerate() { | |
| 97 | - let pts = i as i64 * 1024; | |
| 98 | - let packet = Packet::new(0, time_base, au.as_slice()) | |
| 99 | - .with_pts(pts) | |
| 100 | - .with_duration(1024); | |
| 101 | - muxer.write_packet(&packet).expect("packet written"); | |
| 102 | - } | |
| 103 | - muxer.finish().expect("finished"); | |
| 104 | - eprintln!( | |
| 105 | - "wrote {} ({} frames, core={core_rate}Hz ext={ext_rate}Hz ch={channels})", | |
| 106 | - args[5], | |
| 107 | - aus.len() | |
| 108 | - ); | |
| 109 | -} |