Skip to main content

ALAW

Struct ALAW 

Source
pub struct ALAW(/* private fields */);
Expand description

A-law companded sample, as defined by ITU-T G.711. Stored as 1 byte. A single byte has no byte order, so there are no little endian and big endian variants.

A-law fits the dynamic range of a 13 bit linear value into 8 bits, using a piecewise linear approximation of a logarithmic curve. The closest numeric type is i16, and the decoded values are scaled to that range. The largest representable magnitude is 32256, so the range does not quite reach the limits of an i16. A-law has no code for exact silence, the two smallest magnitudes are +8 and -8.

Note that i16 is wider than the 256 values this format can represent, so unlike the linear formats, from_number quantizes and a number does not survive a roundtrip unchanged. Quantizing an already quantized value changes nothing further.

Note that a byte value of zero is not silence. It decodes to -5504. The A-law code for the smallest positive value is 0xD5.

This is the format used for telephony in Europe and most of the world. It appears as WAVE_FORMAT_ALAW in wav files, as PCMA in RTP streams, and as SND_PCM_FORMAT_A_LAW in ALSA.

Trait Implementations§

Source§

impl BytesSample for ALAW

Source§

const BYTES_PER_SAMPLE: usize = 1

The number of bytes making up each sample value.
Source§

type NumericType = i16

The closest matching numeric type.
Source§

fn zero() -> Self

Create a sample with all bytes set to zero. Read more
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.
Source§

impl Clone for ALAW

Source§

fn clone(&self) -> ALAW

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ALAW

Source§

impl Debug for ALAW

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for ALAW

§

impl RefUnwindSafe for ALAW

§

impl Send for ALAW

§

impl Sync for ALAW

§

impl Unpin for ALAW

§

impl UnsafeUnpin for ALAW

§

impl UnwindSafe for ALAW

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<V> RawSample for V

Source§

fn to_scaled_float<T>(&self) -> T

Convert the sample value to a float in the range -1.0 .. +1.0.
Source§

fn from_scaled_float<T>(value: T) -> ConversionResult<V>

Convert a float in the range -1.0 .. +1.0 to a sample value. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.