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
impl ConversionPlan
Sourcepub fn between(
source: &StreamRequest,
target: &StreamFormat,
options: &ConvertOptions,
) -> Result<Self, ConvertError>
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.
Sourcepub fn pcm(
source: PcmFormat,
target: PcmFormat,
options: &ConvertOptions,
) -> Result<Self, ConvertError>
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}pub fn source(&self) -> PcmFormat
pub fn target(&self) -> PcmFormat
pub fn options(&self) -> &ConvertOptions
pub fn steps(&self) -> &[Step]
Sourcepub fn kind(&self) -> ConversionKind
pub fn kind(&self) -> ConversionKind
The worst of the steps: ConversionKind::None if there are none.
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
A sentence that says what is done and how much it costs, for a status line or a log.
Sourcepub fn preserves_bit_perfect(&self) -> bool
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
impl Clone for ConversionPlan
Source§impl Debug for ConversionPlan
impl Debug for ConversionPlan
Source§impl PartialEq for ConversionPlan
impl PartialEq for ConversionPlan
impl StructuralPartialEq for ConversionPlan
Auto Trait Implementations§
impl Forget for ConversionPlan
impl Freeze for ConversionPlan
impl Move for ConversionPlan
impl RefUnwindSafe for ConversionPlan
impl Send for ConversionPlanwhere
RawVecInner: Send,
impl Sync for ConversionPlanwhere
RawVecInner: Sync,
impl Unpin for ConversionPlan
impl UnsafeUnpin for ConversionPlanwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<Step>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl UnwindSafe for ConversionPlanwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more