1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Audio frame type.
//!
//! This module provides [`AudioFrame`] for working with decoded audio frames.
//!
//! # Examples
//!
//! ```
//! use ff_format::{AudioFrame, SampleFormat, Rational, Timestamp};
//!
//! // Create a stereo F32 audio frame with 1024 samples
//! let channels = 2u32;
//! let samples = 1024usize;
//! let sample_rate = 48000u32;
//!
//! let frame = AudioFrame::empty(
//! samples,
//! channels,
//! sample_rate,
//! SampleFormat::F32,
//! ).unwrap();
//!
//! assert_eq!(frame.samples(), 1024);
//! assert_eq!(frame.channels(), 2);
//! assert_eq!(frame.sample_rate(), 48000);
//! assert!(!frame.format().is_planar());
//! ```
use crate::;
/// A decoded audio frame.
///
/// This structure holds audio sample data and metadata for a segment of audio.
/// It supports both packed (interleaved) formats where all channels are
/// interleaved in a single buffer, and planar formats where each channel
/// is stored in a separate buffer.
///
/// # Memory Layout
///
/// For packed (interleaved) formats (I16, F32, etc.):
/// - Single plane containing interleaved samples: L R L R L R ...
/// - Total size: `samples * channels * bytes_per_sample`
///
/// For planar formats (I16p, F32p, etc.):
/// - One plane per channel
/// - Each plane size: `samples * bytes_per_sample`
///
/// # Examples
///
/// ```
/// use ff_format::{AudioFrame, SampleFormat, Timestamp, Rational};
///
/// // Create a stereo F32 frame with 1024 samples at 48kHz
/// let frame = AudioFrame::empty(1024, 2, 48000, SampleFormat::F32).unwrap();
///
/// assert_eq!(frame.samples(), 1024);
/// assert_eq!(frame.channels(), 2);
/// assert_eq!(frame.sample_rate(), 48000);
/// assert_eq!(frame.format(), SampleFormat::F32);
///
/// // Duration of this frame: 1024 / 48000 ≈ 21.33ms
/// let duration = frame.duration();
/// assert!((duration.as_secs_f64() - 0.02133).abs() < 0.001);
/// ```