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 F32BE

Source§

impl BytesSample for F32LE

Source§

impl BytesSample for F64BE

Source§

impl BytesSample for F64LE

Source§

impl BytesSample for I16BE

Source§

impl BytesSample for I16LE

Source§

impl BytesSample for I24BE<3>

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

Source§

impl BytesSample for I24BE<4>

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

Source§

impl BytesSample for I24LE<3>

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

Source§

impl BytesSample for I24LE<4>

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

Source§

impl BytesSample for I32BE

Source§

impl BytesSample for I32LE

Source§

impl BytesSample for I64BE

Source§

impl BytesSample for I64LE

Source§

impl BytesSample for U16BE

Source§

impl BytesSample for U16LE

Source§

impl BytesSample for U24BE<3>

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

Source§

impl BytesSample for U24BE<4>

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

Source§

impl BytesSample for U24LE<3>

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

Source§

impl BytesSample for U24LE<4>

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

Source§

impl BytesSample for U32BE

Source§

impl BytesSample for U32LE

Source§

impl BytesSample for U64BE

Source§

impl BytesSample for U64LE