Skip to main content

BytesSample

Trait BytesSample 

Source
pub trait BytesSample {
    type NumericType: Copy;

    const BYTES_PER_SAMPLE: usize;

    // Required methods
    fn from_slice(bytes: &[u8]) -> Self;
    fn as_slice(&self) -> &[u8] ;
    fn as_mut_slice(&mut self) -> &mut [u8] ;
    fn to_number(&self) -> Self::NumericType;
    fn from_number(value: Self::NumericType) -> Self;
}
Expand description

A trait for converting samples stored as raw bytes into a numerical type. Each implementation defines the associated type NumericType, which is the nearest matching numeric type for the original format. If a direct match exists, this is used. For example signed 16 bit integer samples use i16. For formats that don’t have a direct match, the next larger numeric type is used. For example for 24 bit signed integers, this means i32. The values are scaled to use the full range of the NumericType associated type.

Required Associated Constants§

Source

const BYTES_PER_SAMPLE: usize

The number of bytes making up each sample value.

Required Associated Types§

Source

type NumericType: Copy

The closest matching numeric type.

Required Methods§

Source

fn from_slice(bytes: &[u8]) -> Self

Create a new ByteSample from a slice of raw bytes. The slice length must be at least the number of bytes for a sample value.

Source

fn as_slice(&self) -> &[u8]

Return the raw bytes as a slice.

Source

fn as_mut_slice(&mut self) -> &mut [u8]

Return the raw bytes as a mutable slice.

Source

fn to_number(&self) -> Self::NumericType

Convert the raw bytes to a numerical value.

Source

fn from_number(value: Self::NumericType) -> Self

Convert a numerical value to raw bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl BytesSample for F32_BE

Source§

impl BytesSample for F32_LE

Source§

impl BytesSample for F64_BE

Source§

impl BytesSample for F64_LE

Source§

impl BytesSample for I16_BE

Source§

impl BytesSample for I16_LE

Source§

impl BytesSample for I24_4LJ_BE

24 bit signed integer, big endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.

Source§

impl BytesSample for I24_4LJ_LE

24 bit signed integer, little endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.

Source§

impl BytesSample for I24_4RJ_BE

24 bit signed integer, big endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.

Source§

impl BytesSample for I24_4RJ_LE

24 bit signed integer, little endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.

Source§

impl BytesSample for I24_BE

24 bit signed integer, big endian, stored as 3 bytes without padding.

Source§

impl BytesSample for I24_LE

24 bit signed integer, little endian, stored as 3 bytes without padding.

Source§

impl BytesSample for I32_BE

Source§

impl BytesSample for I32_LE

Source§

impl BytesSample for I64_BE

Source§

impl BytesSample for I64_LE

Source§

impl BytesSample for U16_BE

Source§

impl BytesSample for U16_LE

Source§

impl BytesSample for U24_4LJ_BE

24 bit unsigned integer, big endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.

Source§

impl BytesSample for U24_4LJ_LE

24 bit unsigned integer, little endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.

Source§

impl BytesSample for U24_4RJ_BE

24 bit unsigned integer, big endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.

Source§

impl BytesSample for U24_4RJ_LE

24 bit unsigned integer, little endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.

Source§

impl BytesSample for U24_BE

24 bit unsigned integer, big endian, stored as 3 bytes without padding.

Source§

impl BytesSample for U24_LE

24 bit unsigned integer, little endian, stored as 3 bytes without padding.

Source§

impl BytesSample for U32_BE

Source§

impl BytesSample for U32_LE

Source§

impl BytesSample for U64_BE

Source§

impl BytesSample for U64_LE