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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use nutype_enum::nutype_enum;
use crate::ffi::*;
const _: () = {
assert!(std::mem::size_of::<AVSampleFormat>() == std::mem::size_of_val(&AV_SAMPLE_FMT_NONE));
};
nutype_enum! {
/// Audio sample formats used in FFmpeg's `AVSampleFormat` enumeration.
///
/// The sample format defines how audio samples are stored in memory, including:
/// - **Bit depth** (8-bit, 16-bit, 32-bit, 64-bit)
/// - **Signed vs Unsigned** (U8 is unsigned, others are signed)
/// - **Floating-point vs Integer**
/// - **Packed vs Planar** (Planar formats store each channel separately)
///
/// See the official FFmpeg documentation:
/// <https://ffmpeg.org/doxygen/trunk/samplefmt_8h.html>
pub enum AVSampleFormat(i32) {
/// No sample format specified or unknown format.
/// Corresponds to `AV_SAMPLE_FMT_NONE`.
None = AV_SAMPLE_FMT_NONE as _,
/// Unsigned 8-bit PCM format (0 to 255 range).
/// - **Binary representation**: `0bxxxxxxxx` (8 bits)
/// - **Range**: `[0, 255]`
/// - **Stored as**: `u8`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_U8`.
U8 = AV_SAMPLE_FMT_U8 as _,
/// Signed 16-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
/// - **Range**: `[-32,768, 32,767]`
/// - **Stored as**: `i16`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_S16`.
S16 = AV_SAMPLE_FMT_S16 as _,
/// Signed 32-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
/// - **Range**: `[-2^31, 2^31-1]`
/// - **Stored as**: `i32`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_S32`.
S32 = AV_SAMPLE_FMT_S32 as _,
/// 32-bit Floating-point PCM format.
/// - **Binary representation**: IEEE-754 32-bit float
/// - **Range**: `[-1.0, 1.0]` (normalized)
/// - **Stored as**: `f32`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_FLT`.
Flt = AV_SAMPLE_FMT_FLT as _,
/// 64-bit Floating-point PCM format.
/// - **Binary representation**: IEEE-754 64-bit float
/// - **Range**: `[-1.0, 1.0]` (normalized)
/// - **Stored as**: `f64`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_Dbl`.
Dbl = AV_SAMPLE_FMT_DBL as _,
/// **Planar** Unsigned 8-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxx` (8 bits)
/// - **Range**: `[0, 255]`
/// - **Stored as**: `u8`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_U8P`.
U8p = AV_SAMPLE_FMT_U8P as _,
/// **Planar** Signed 16-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
/// - **Range**: `[-32,768, 32,767]`
/// - **Stored as**: `i16`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_S16P`.
S16p = AV_SAMPLE_FMT_S16P as _,
/// **Planar** Signed 32-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
/// - **Range**: `[-2^31, 2^31-1]`
/// - **Stored as**: `i32`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_S32P`.
S32p = AV_SAMPLE_FMT_S32P as _,
/// **Planar** 32-bit Floating-point PCM format.
/// - **Binary representation**: IEEE-754 32-bit float
/// - **Range**: `[-1.0, 1.0]` (normalized)
/// - **Stored as**: `f32`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_FLTP`.
Fltp = AV_SAMPLE_FMT_FLTP as _,
/// **Planar** 64-bit Floating-point PCM format.
/// - **Binary representation**: IEEE-754 64-bit float
/// - **Range**: `[-1.0, 1.0]` (normalized)
/// - **Stored as**: `f64`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_DBLP`.
Dblp = AV_SAMPLE_FMT_DBLP as _,
/// Signed 64-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
/// - **Range**: `[-2^63, 2^63-1]`
/// - **Stored as**: `i64`
/// - **Interleaved**
/// Corresponds to `AV_SAMPLE_FMT_S64`.
S64 = AV_SAMPLE_FMT_S64 as _,
/// **Planar** Signed 64-bit PCM format.
/// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
/// - **Range**: `[-2^63, 2^63-1]`
/// - **Stored as**: `i64`
/// - **Planar (separate channel planes)**
/// Corresponds to `AV_SAMPLE_FMT_S64P`.
S64p = AV_SAMPLE_FMT_S64P as _,
/// Number of sample formats available (internal use only).
/// **DO NOT USE** if linking dynamically, as the number may change.
/// Corresponds to `AV_SAMPLE_FMT_NB`.
Nb = AV_SAMPLE_FMT_NB as _,
}
}
impl PartialEq<i32> for AVSampleFormat {
fn eq(&self, other: &i32) -> bool {
self.0 == *other
}
}
impl From<u32> for AVSampleFormat {
fn from(value: u32) -> Self {
AVSampleFormat(value as _)
}
}
impl From<AVSampleFormat> for u32 {
fn from(value: AVSampleFormat) -> Self {
value.0 as u32
}
}