forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB5c8eff8Tahinli2 months ago2949 commits

edith_surface.rs73 lines, 2.9 KiBHistoryRawDownload
1//! The call sites edith actually has, compiled and run against the shim.
2//!
3//! Each one mirrors a line in the replica: `audio.rs:1731` builds the decoder
4//! for a multichannel track from its AudioSpecificConfig, `export.rs:1678`
5//! turns a sample rate into a `samplingFrequencyIndex`, and `export.rs:1756`
6//! plus `mux.rs:2116` drive the encoder over a mix.
7
8#[test]
9fn sf_index_for_rate_covers_the_rates_the_exporter_offers() {
10 assert_eq!(rusty_aac::sf_index_for_rate(48_000), Some(3));
11 assert_eq!(rusty_aac::sf_index_for_rate(44_100), Some(4));
12 assert_eq!(rusty_aac::sf_index_for_rate(96_000), Some(0));
13 assert_eq!(rusty_aac::sf_index_for_rate(8_000), Some(11));
14 // The exporter's own error path: a rate AAC cannot carry.
15 assert_eq!(rusty_aac::sf_index_for_rate(37_000), None);
16}
17
18#[test]
19fn a_multichannel_track_builds_from_its_audio_specific_config() {
20 // 5.1 at 48 kHz, which is what a film's mkv hands over as CodecPrivate.
21 let asc = rusty_aac::audio_specific_config_bytes(48_000, 6);
22 let decoder = rusty_aac::AacDecoder::with_config_bytes(&asc).expect("decoder builds");
23 assert_eq!(decoder.output_sample_rate(), Some(48_000));
24 assert_eq!(decoder.sbr_support(), rusty_aac::SbrSupport::NotSignalled);
25}
26
27/// `export.rs:1756`: the caller's bitrate over the config's defaults, PCM in,
28/// packets out until `Eof`.
29#[test]
30fn the_export_encoder_loop_runs_to_eof() {
31 let rate = 48_000u32;
32 let channels = 2u16;
33 let frames = rate as usize;
34 let mut pcm = Vec::with_capacity(frames * usize::from(channels));
35 for i in 0..frames {
36 let s = (i as f32 * 440.0 * std::f32::consts::TAU / rate as f32).sin() * 0.5;
37 for _ in 0..channels {
38 pcm.push(s);
39 }
40 }
41 let mut encoder = rusty_aac::AacEncoder::new(rusty_aac::AacEncoderConfig {
42 bitrate_bps: 256 * 1_000,
43 ..Default::default()
44 });
45 encoder
46 .push_pcm(&pcm, channels, rate)
47 .expect("pcm accepted");
48 encoder.finish();
49 let mut packets = Vec::new();
50 while let Ok(packet) = encoder.next_packet() {
51 assert_eq!(packet.duration, 1024, "one AAC frame per packet");
52 assert!(!packet.data.is_empty(), "a packet with no payload");
53 packets.push(packet);
54 }
55 assert!(
56 packets.len() > 10,
57 "a second of audio is many packets, got {}",
58 packets.len()
59 );
60 assert_eq!(encoder.sample_rate(), rate);
61 assert_eq!(encoder.channels(), channels);
62
63 // And the packets are a stream this family's own decoder reads back.
64 let asc = rusty_aac::audio_specific_config_bytes(rate, channels);
65 let mut decoder = rusty_aac::AacDecoder::with_config_bytes(&asc).expect("decoder builds");
66 let mut decoded = 0usize;
67 for packet in &packets {
68 let audio = decoder.decode(&packet.data, None).expect("packet decodes");
69 assert_eq!(audio.channels, channels);
70 decoded += audio.frames();
71 }
72 assert_eq!(decoded, packets.len() * 1024);
73}