android_media/constants.rs
1/// Audio sample rate enumeration
2///
3/// Defines standard sample rates supported by the Android audio system.
4/// The sample rate is the number of audio samples captured per second, measured in Hz.
5///
6/// # Examples
7///
8/// ```no_run
9/// use android_media::SampleRate;
10/// let rate = SampleRate::Rate16000;
11/// assert_eq!(rate.value(), 16000);
12/// ```
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum SampleRate {
15 /// 8000 Hz - commonly used for speech recognition
16 Rate8000 = 8000,
17 /// 16000 Hz - standard sample rate for voice applications
18 Rate16000 = 16000,
19 /// 22050 Hz - half of CD quality
20 Rate22050 = 22050,
21 /// 44100 Hz - CD audio standard sample rate
22 Rate44100 = 44100,
23 /// 48000 Hz - professional audio standard sample rate
24 Rate48000 = 48000,
25}
26
27impl SampleRate {
28 /// Get the integer value of the sample rate
29 ///
30 /// # Returns
31 ///
32 /// Returns the sample rate value in Hz (e.g., 16000, 44100, etc.)
33 ///
34 /// # Examples
35 ///
36 /// ```no_run
37 /// use android_media::SampleRate;
38 /// assert_eq!(SampleRate::Rate16000.value(), 16000);
39 /// ```
40 pub const fn value(&self) -> i32 {
41 *self as i32
42 }
43}
44
45/// Audio encoding format enumeration
46///
47/// Defines audio data encoding formats, i.e., how each audio sample is represented.
48/// Different encoding formats correspond to different audio quality and storage requirements.
49///
50/// # Examples
51///
52/// ```no_run
53/// use android_media::AudioEncoding;
54/// let encoding = AudioEncoding::Pcm16bit;
55/// assert_eq!(encoding.value(), 2);
56/// assert_eq!(encoding.bytes_per_sample(), 2);
57/// ```
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum AudioEncoding {
60 /// 8-bit PCM encoding - 1 byte per sample
61 Pcm8bit = 3,
62 /// 16-bit PCM encoding - 2 bytes per sample, most commonly used
63 Pcm16bit = 2,
64 /// 32-bit float PCM encoding - 4 bytes per sample, provides higher dynamic range
65 PcmFloat = 4,
66}
67
68impl AudioEncoding {
69 /// Get the integer value of the encoding format
70 ///
71 /// # Returns
72 ///
73 /// Returns the encoding format identifier in the Android system
74 ///
75 /// # Examples
76 ///
77 /// ```no_run
78 /// use android_media::AudioEncoding;
79 /// assert_eq!(AudioEncoding::Pcm16bit.value(), 2);
80 /// ```
81 pub const fn value(&self) -> i32 {
82 *self as i32
83 }
84
85 /// Get the number of bytes per sample
86 ///
87 /// # Returns
88 ///
89 /// Returns the number of bytes occupied by each audio sample in this encoding format
90 ///
91 /// # Examples
92 ///
93 /// ```no_run
94 /// use android_media::AudioEncoding;
95 /// assert_eq!(AudioEncoding::Pcm8bit.bytes_per_sample(), 1);
96 /// assert_eq!(AudioEncoding::Pcm16bit.bytes_per_sample(), 2);
97 /// assert_eq!(AudioEncoding::PcmFloat.bytes_per_sample(), 4);
98 /// ```
99 pub const fn bytes_per_sample(&self) -> i32 {
100 match self {
101 Self::Pcm8bit => 1,
102 Self::Pcm16bit => 2,
103 Self::PcmFloat => 4,
104 }
105 }
106}
107
108/// Audio channel configuration - Input (Microphone)
109///
110/// Defines channel configurations for audio input (recording), supporting mono and stereo.
111/// Different channel configurations affect recording quality and storage space.
112///
113/// # Examples
114///
115/// ```no_run
116/// use android_media::ChannelInConfig;
117/// let config = ChannelInConfig::Mono;
118/// assert_eq!(config.value(), 16);
119/// assert_eq!(config.channel_count(), 1);
120/// ```
121#[derive(Debug, Clone, Copy, PartialEq, Eq)]
122pub enum ChannelInConfig {
123 /// Mono recording - each sample point contains data from one channel
124 Mono = 16,
125 /// Stereo recording - each sample point contains data from left and right channels
126 Stereo = 12,
127}
128
129impl ChannelInConfig {
130 /// Get the integer value of the channel configuration
131 ///
132 /// # Returns
133 ///
134 /// Returns the channel configuration identifier in the Android system
135 ///
136 /// # Examples
137 ///
138 /// ```no_run
139 /// use android_media::ChannelInConfig;
140 /// assert_eq!(ChannelInConfig::Mono.value(), 16);
141 /// ```
142 pub const fn value(&self) -> i32 {
143 *self as i32
144 }
145
146 /// Get the number of channels
147 ///
148 /// # Returns
149 ///
150 /// Returns the number of channels in this configuration (1 = mono, 2 = stereo)
151 ///
152 /// # Examples
153 ///
154 /// ```no_run
155 /// use android_media::ChannelInConfig;
156 /// assert_eq!(ChannelInConfig::Mono.channel_count(), 1);
157 /// assert_eq!(ChannelInConfig::Stereo.channel_count(), 2);
158 /// ```
159 pub const fn channel_count(&self) -> i32 {
160 match self {
161 Self::Mono => 1,
162 Self::Stereo => 2,
163 }
164 }
165}
166
167/// Audio channel configuration - Output (Player)
168///
169/// Defines channel configurations for audio output (playback), supporting mono and stereo.
170///
171/// # Examples
172///
173/// ```no_run
174/// use android_media::ChannelOutConfig;
175/// let config = ChannelOutConfig::Mono;
176/// assert_eq!(config.value(), 4);
177/// assert_eq!(config.channel_count(), 1);
178/// ```
179#[derive(Debug, Clone, Copy, PartialEq, Eq)]
180pub enum ChannelOutConfig {
181 /// Mono playback - suitable for voice announcements, etc.
182 Mono = 4,
183 /// Stereo playback - suitable for music playback, etc.
184 Stereo = 12,
185}
186
187impl ChannelOutConfig {
188 /// Get the integer value of the channel configuration
189 ///
190 /// # Returns
191 ///
192 /// Returns the channel configuration identifier in the Android system
193 ///
194 /// # Examples
195 ///
196 /// ```no_run
197 /// use android_media::ChannelOutConfig;
198 /// assert_eq!(ChannelOutConfig::Mono.value(), 4);
199 /// ```
200 pub const fn value(&self) -> i32 {
201 *self as i32
202 }
203
204 /// Get the number of channels
205 ///
206 /// # Returns
207 ///
208 /// Returns the number of channels in this configuration (1 = mono, 2 = stereo)
209 ///
210 /// # Examples
211 ///
212 /// ```no_run
213 /// use android_media::ChannelOutConfig;
214 /// assert_eq!(ChannelOutConfig::Mono.channel_count(), 1);
215 /// assert_eq!(ChannelOutConfig::Stereo.channel_count(), 2);
216 /// ```
217 pub const fn channel_count(&self) -> i32 {
218 match self {
219 Self::Mono => 1,
220 Self::Stereo => 2,
221 }
222 }
223}
224
225/// Audio source type
226///
227/// Defines various audio input sources supported by the Android audio system.
228/// Different audio sources are suitable for different application scenarios.
229///
230/// # Examples
231///
232/// ```no_run
233/// use android_media::AudioSource;
234/// let source = AudioSource::Mic;
235/// assert_eq!(source.value(), 1);
236/// ```
237#[derive(Debug, Clone, Copy, PartialEq, Eq)]
238pub enum AudioSource {
239 /// Default audio source
240 Default = 0,
241 /// Main microphone - most commonly used recording source
242 Mic = 1,
243 /// Camera audio - used for video recording
244 Camcorder = 5,
245 /// Voice recognition - optimized for speech recognition scenarios with noise suppression
246 VoiceRecognition = 6,
247 /// Voice communication - optimized for call scenarios with echo cancellation
248 VoiceCommunication = 7,
249}
250
251impl AudioSource {
252 /// Get the integer value of the audio source
253 ///
254 /// # Returns
255 ///
256 /// Returns the audio source identifier in the Android system
257 ///
258 /// # Examples
259 ///
260 /// ```no_run
261 /// use android_media::AudioSource;
262 /// assert_eq!(AudioSource::Mic.value(), 1);
263 /// ```
264 pub const fn value(&self) -> i32 {
265 *self as i32
266 }
267}
268
269/// Audio recorder state
270///
271/// Defines the various states of the audio recorder.
272///
273/// # Examples
274///
275/// ```no_run
276/// use android_media::RecorderState;
277/// assert_eq!(RecorderState::Uninitialized.value(), 0);
278/// assert_eq!(RecorderState::Initialized.value(), 1);
279/// assert_eq!(RecorderState::Recording.value(), 3);
280/// ```
281#[derive(Debug, Clone, Copy, PartialEq, Eq)]
282pub enum RecorderState {
283 /// Uninitialized state
284 Uninitialized = 0,
285 /// Initialized state, ready to start recording
286 Initialized = 1,
287 /// Recording state
288 Recording = 3,
289}
290
291impl RecorderState {
292 /// Get the integer value of the state
293 ///
294 /// # Returns
295 ///
296 /// Returns the state identifier in the Android system
297 ///
298 /// # Examples
299 ///
300 /// ```no_run
301 /// use android_media::RecorderState;
302 /// assert_eq!(RecorderState::Initialized.value(), 1);
303 /// ```
304 pub const fn value(&self) -> i32 {
305 *self as i32
306 }
307
308 /// Get the state value after stopping
309 ///
310 /// In Android, after stopping recording, the recorder returns to the initialized state.
311 ///
312 /// # Returns
313 ///
314 /// Returns the value of the initialized state (1)
315 ///
316 /// # Examples
317 ///
318 /// ```no_run
319 /// use android_media::RecorderState;
320 /// assert_eq!(RecorderState::stopped(), 1);
321 /// ```
322 pub const fn stopped() -> i32 {
323 Self::Initialized.value()
324 }
325}
326
327/// Player mode
328///
329/// Defines the two playback modes of the audio player.
330/// Different modes are suitable for different use cases.
331///
332/// # Examples
333///
334/// ```no_run
335/// use android_media::PlayerMode;
336/// let mode = PlayerMode::Stream;
337/// assert_eq!(mode.value(), 1);
338/// ```
339#[derive(Debug, Clone, Copy, PartialEq, Eq)]
340pub enum PlayerMode {
341 /// Static mode - suitable for playing short audio files
342 ///
343 /// In static mode, audio data is loaded into memory in one go before playback,
344 /// suitable for playing shorter, fixed audio files (e.g., prompts, sound effects).
345 Static = 0,
346 /// Stream mode - suitable for playing long audio files or real-time audio streams
347 ///
348 /// In stream mode, audio data is written to the player in chunks, suitable for playing
349 /// longer audio or real-time audio streams (e.g., music, real-time call audio).
350 Stream = 1,
351}
352
353impl PlayerMode {
354 /// Get the integer value of the playback mode
355 ///
356 /// # Returns
357 ///
358 /// Returns the playback mode identifier in the Android system
359 ///
360 /// # Examples
361 ///
362 /// ```no_run
363 /// use android_media::PlayerMode;
364 /// assert_eq!(PlayerMode::Stream.value(), 1);
365 /// ```
366 pub const fn value(&self) -> i32 {
367 *self as i32
368 }
369}