Skip to main content

ConversionPlan

Struct ConversionPlan 

Source
pub struct ConversionPlan { /* private fields */ }
Expand description

How to turn source into target: the steps, what they cost, and a sentence for a status line.

Implementations§

Source§

impl ConversionPlan

Source

pub fn between( source: &StreamRequest, target: &StreamFormat, options: &ConvertOptions, ) -> Result<Self, ConvertError>

The plan for what the host wants to play (source, a PCM request) and what the DAC runs (target, the negotiated format). The source samples are in the layout the request’s bit depth implies (16-bit, packed 24-bit, 32-bit) unless ConvertOptions::source_sample says otherwise. DoP and native DSD are refused: converting them would destroy them.

Source

pub fn pcm( source: PcmFormat, target: PcmFormat, options: &ConvertOptions, ) -> Result<Self, ConvertError>

The plan between two PCM formats.

Examples found in repository?
examples/convert_bench.rs (line 21)
16fn run(label: &str, source: PcmFormat, target: PcmFormat, quality: Quality) {
17    let options = ConvertOptions {
18        quality,
19        ..ConvertOptions::default()
20    };
21    let plan = ConversionPlan::pcm(source, target, &options).unwrap();
22    let build = Instant::now();
23    let mut converter = Converter::new(&plan).unwrap();
24    let build_ms = build.elapsed().as_secs_f64() * 1000.0;
25
26    let chunk_frames = source.sample_rate as usize / 100;
27    let chunk: Vec<u8> =
28        (0..chunk_frames * usize::from(source.channels) * source.sample.bytes_per_sample())
29            .map(|i| (i.wrapping_mul(2_654_435_761) >> 13) as u8)
30            .collect();
31    let mut output = vec![0u8; converter.min_output_bytes().max(1 << 20)];
32    let seconds = 10;
33    let start = Instant::now();
34    let mut produced = 0usize;
35    for _ in 0..seconds * 100 {
36        let done = converter.process(&chunk, &mut output).unwrap();
37        produced += done.produced;
38    }
39    let elapsed = start.elapsed().as_secs_f64();
40    std::hint::black_box(produced);
41    println!(
42        "{label:<46} build {build_ms:6.1} ms   {:6.1}x realtime   {:5.2}% of a core",
43        seconds as f64 / elapsed,
44        elapsed / seconds as f64 * 100.0
45    );
46}
Source

pub fn source(&self) -> PcmFormat

Source

pub fn target(&self) -> PcmFormat

Source

pub fn options(&self) -> &ConvertOptions

Source

pub fn steps(&self) -> &[Step]

Source

pub fn kind(&self) -> ConversionKind

The worst of the steps: ConversionKind::None if there are none.

Source

pub fn description(&self) -> &str

A sentence that says what is done and how much it costs, for a status line or a log.

Source

pub fn resamples(&self) -> bool

Whether the sample rate changes.

Source

pub fn preserves_bit_perfect(&self) -> bool

Whether a bit-perfect target stream is still bit-perfect with respect to the source.

Trait Implementations§

Source§

impl Clone for ConversionPlan

Source§

fn clone(&self) -> Self

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 Debug for ConversionPlan

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ConversionPlan

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ConversionPlan

Auto Trait Implementations§

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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.