Skip to content

Commit 8615160

Browse files
authored
doc: improvements for SampleFormat (#885)
* doc: fix SampleFormat inconsistencies * doc: add more documentation for SampleFormat
1 parent 8f1a946 commit 8615160

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/samples_formats.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,61 @@ use wasm_bindgen::prelude::*;
44

55
pub use dasp_sample::{FromSample, Sample, I24, I48, U24, U48};
66

7-
/// Format that each sample has.
7+
/// Format that each sample has. Usually, this corresponds to the sampling
8+
/// depth of the audio source. For example, 16 bit quantized samples can be
9+
/// encoded in `i16` or `u16`. Note that the sampling depth is not directly
10+
/// visible for formats where [`is_float`] is true.
11+
///
12+
/// Also note that the backend must support the encoding of the quantized
13+
/// samples in the given format, as there is no generic transformation from one
14+
/// format into the other done inside the frontend-library code. You can query
15+
/// the supported formats by using [`supported_input_configs`].
16+
///
17+
/// A good rule of thumb is to use [`SampleFormat::I16`] as this covers typical
18+
/// music (WAV, MP3) as well as typical audio input devices on most platforms,
19+
///
20+
/// [`is_float`]: SampleFormat::is_float
21+
/// [`supported_input_configs`]: crate::Device::supported_input_configs
822
#[cfg_attr(target_os = "emscripten", wasm_bindgen)]
923
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1024
#[non_exhaustive]
1125
pub enum SampleFormat {
12-
/// `i8` with a valid range of 'u8::MIN..=u8::MAX' with `0` being the origin
26+
/// `i8` with a valid range of `i8::MIN..=i8::MAX` with `0` being the origin.
1327
I8,
1428

15-
/// `i16` with a valid range of 'u16::MIN..=u16::MAX' with `0` being the origin
29+
/// `i16` with a valid range of `i16::MIN..=i16::MAX` with `0` being the origin.
1630
I16,
1731

1832
// /// `I24` with a valid range of '-(1 << 23)..(1 << 23)' with `0` being the origin
1933
// I24,
20-
/// `i32` with a valid range of 'u32::MIN..=u32::MAX' with `0` being the origin
34+
/// `i32` with a valid range of `i32::MIN..=i32::MAX` with `0` being the origin.
2135
I32,
2236

2337
// /// `I24` with a valid range of '-(1 << 47)..(1 << 47)' with `0` being the origin
2438
// I48,
25-
/// `i64` with a valid range of 'u64::MIN..=u64::MAX' with `0` being the origin
39+
/// `i64` with a valid range of `i64::MIN..=i64::MAX` with `0` being the origin.
2640
I64,
2741

28-
/// `u8` with a valid range of 'u8::MIN..=u8::MAX' with `1 << 7 == 128` being the origin
42+
/// `u8` with a valid range of `u8::MIN..=u8::MAX` with `1 << 7 == 128` being the origin.
2943
U8,
3044

31-
/// `u16` with a valid range of 'u16::MIN..=u16::MAX' with `1 << 15 == 32768` being the origin
45+
/// `u16` with a valid range of `u16::MIN..=u16::MAX` with `1 << 15 == 32768` being the origin.
3246
U16,
3347

3448
// /// `U24` with a valid range of '0..16777216' with `1 << 23 == 8388608` being the origin
3549
// U24,
36-
/// `u32` with a valid range of 'u32::MIN..=u32::MAX' with `1 << 31` being the origin
50+
/// `u32` with a valid range of `u32::MIN..=u32::MAX` with `1 << 31` being the origin.
3751
U32,
3852

3953
// /// `U48` with a valid range of '0..(1 << 48)' with `1 << 47` being the origin
4054
// U48,
41-
/// `u64` with a valid range of 'u64::MIN..=u64::MAX' with `1 << 63` being the origin
55+
/// `u64` with a valid range of `u64::MIN..=u64::MAX` with `1 << 63` being the origin.
4256
U64,
4357

44-
/// `f32` with a valid range of `-1.0..1.0` with `0.0` being the origin
58+
/// `f32` with a valid range of `-1.0..1.0` with `0.0` being the origin.
4559
F32,
4660

47-
/// `f64` with a valid range of -1.0..1.0 with 0.0 being the origin
61+
/// `f64` with a valid range of `-1.0..1.0` with `0.0` being the origin.
4862
F64,
4963
}
5064

0 commit comments

Comments
 (0)