| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | #[test] |
| 9 | fn 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 | |
| 15 | assert_eq!(rusty_aac::sf_index_for_rate(37_000), None); |
| 16 | } |
| 17 | |
| 18 | #[test] |
| 19 | fn a_multichannel_track_builds_from_its_audio_specific_config() { |
| 20 | |
| 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 | |
| 28 | |
| 29 | #[test] |
| 30 | fn 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 | |
| 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 | } |