scuffle_ffmpeg/enums/av_sample_format.rs
1use nutype_enum::nutype_enum;
2
3use crate::ffi::*;
4
5nutype_enum! {
6 /// Audio sample formats used in FFmpeg's `AVSampleFormat` enumeration.
7 ///
8 /// The sample format defines how audio samples are stored in memory, including:
9 /// - **Bit depth** (8-bit, 16-bit, 32-bit, 64-bit)
10 /// - **Signed vs Unsigned** (U8 is unsigned, others are signed)
11 /// - **Floating-point vs Integer**
12 /// - **Packed vs Planar** (Planar formats store each channel separately)
13 ///
14 /// See the official FFmpeg documentation:
15 /// <https://ffmpeg.org/doxygen/trunk/samplefmt_8h.html>
16 pub enum AVSampleFormat(i32) {
17 /// No sample format specified or unknown format.
18 /// Corresponds to `AV_SAMPLE_FMT_NONE`.
19 None = AV_SAMPLE_FMT_NONE,
20
21 /// Unsigned 8-bit PCM format (0 to 255 range).
22 /// - **Binary representation**: `0bxxxxxxxx` (8 bits)
23 /// - **Range**: `[0, 255]`
24 /// - **Stored as**: `u8`
25 /// - **Interleaved**
26 /// Corresponds to `AV_SAMPLE_FMT_U8`.
27 U8 = AV_SAMPLE_FMT_U8,
28
29 /// Signed 16-bit PCM format.
30 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
31 /// - **Range**: `[-32,768, 32,767]`
32 /// - **Stored as**: `i16`
33 /// - **Interleaved**
34 /// Corresponds to `AV_SAMPLE_FMT_S16`.
35 S16 = AV_SAMPLE_FMT_S16,
36
37 /// Signed 32-bit PCM format.
38 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
39 /// - **Range**: `[-2^31, 2^31-1]`
40 /// - **Stored as**: `i32`
41 /// - **Interleaved**
42 /// Corresponds to `AV_SAMPLE_FMT_S32`.
43 S32 = AV_SAMPLE_FMT_S32,
44
45 /// 32-bit Floating-point PCM format.
46 /// - **Binary representation**: IEEE-754 32-bit float
47 /// - **Range**: `[-1.0, 1.0]` (normalized)
48 /// - **Stored as**: `f32`
49 /// - **Interleaved**
50 /// Corresponds to `AV_SAMPLE_FMT_FLT`.
51 Flt = AV_SAMPLE_FMT_FLT,
52
53 /// 64-bit Floating-point PCM format.
54 /// - **Binary representation**: IEEE-754 64-bit float
55 /// - **Range**: `[-1.0, 1.0]` (normalized)
56 /// - **Stored as**: `f64`
57 /// - **Interleaved**
58 /// Corresponds to `AV_SAMPLE_FMT_Dbl`.
59 Dbl = AV_SAMPLE_FMT_DBL,
60
61 /// **Planar** Unsigned 8-bit PCM format.
62 /// - **Binary representation**: `0bxxxxxxxx` (8 bits)
63 /// - **Range**: `[0, 255]`
64 /// - **Stored as**: `u8`
65 /// - **Planar (separate channel planes)**
66 /// Corresponds to `AV_SAMPLE_FMT_U8P`.
67 U8p = AV_SAMPLE_FMT_U8P,
68
69 /// **Planar** Signed 16-bit PCM format.
70 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxx` (16 bits)
71 /// - **Range**: `[-32,768, 32,767]`
72 /// - **Stored as**: `i16`
73 /// - **Planar (separate channel planes)**
74 /// Corresponds to `AV_SAMPLE_FMT_S16P`.
75 S16p = AV_SAMPLE_FMT_S16P,
76
77 /// **Planar** Signed 32-bit PCM format.
78 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` (32 bits)
79 /// - **Range**: `[-2^31, 2^31-1]`
80 /// - **Stored as**: `i32`
81 /// - **Planar (separate channel planes)**
82 /// Corresponds to `AV_SAMPLE_FMT_S32P`.
83 S32p = AV_SAMPLE_FMT_S32P,
84
85 /// **Planar** 32-bit Floating-point PCM format.
86 /// - **Binary representation**: IEEE-754 32-bit float
87 /// - **Range**: `[-1.0, 1.0]` (normalized)
88 /// - **Stored as**: `f32`
89 /// - **Planar (separate channel planes)**
90 /// Corresponds to `AV_SAMPLE_FMT_FLTP`.
91 Fltp = AV_SAMPLE_FMT_FLTP,
92
93 /// **Planar** 64-bit Floating-point PCM format.
94 /// - **Binary representation**: IEEE-754 64-bit float
95 /// - **Range**: `[-1.0, 1.0]` (normalized)
96 /// - **Stored as**: `f64`
97 /// - **Planar (separate channel planes)**
98 /// Corresponds to `AV_SAMPLE_FMT_DBLP`.
99 Dblp = AV_SAMPLE_FMT_DBLP,
100
101 /// Signed 64-bit PCM format.
102 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
103 /// - **Range**: `[-2^63, 2^63-1]`
104 /// - **Stored as**: `i64`
105 /// - **Interleaved**
106 /// Corresponds to `AV_SAMPLE_FMT_S64`.
107 S64 = AV_SAMPLE_FMT_S64,
108
109 /// **Planar** Signed 64-bit PCM format.
110 /// - **Binary representation**: `0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
111 /// - **Range**: `[-2^63, 2^63-1]`
112 /// - **Stored as**: `i64`
113 /// - **Planar (separate channel planes)**
114 /// Corresponds to `AV_SAMPLE_FMT_S64P`.
115 S64p = AV_SAMPLE_FMT_S64P,
116
117 /// Number of sample formats available (internal use only).
118 /// **DO NOT USE** if linking dynamically, as the number may change.
119 /// Corresponds to `AV_SAMPLE_FMT_NB`.
120 Nb = AV_SAMPLE_FMT_NB,
121 }
122}
123
124impl PartialEq<i32> for AVSampleFormat {
125 fn eq(&self, other: &i32) -> bool {
126 self.0 == *other
127 }
128}
129
130impl From<u32> for AVSampleFormat {
131 fn from(value: u32) -> Self {
132 AVSampleFormat(value as i32)
133 }
134}
135
136impl From<AVSampleFormat> for u32 {
137 fn from(value: AVSampleFormat) -> Self {
138 value.0 as u32
139 }
140}