oadsrust 0.3.0

Content-addressed dataset packs and loaders for OA
// @generated by tool/gen/ds/generate.py — edit tool/gen/ds/schema/packs.json instead.
use crate::core::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const VCTK_PACK: Pack = Pack {
	name: "vctk",
	version: "0.92.0",
	license: "CC-BY-4.0",
	files: &[PackFile {
		name: "DS_10283_3443.zip",
		size: 11_749_118_645,
		shake256: "c19bf0fe7668604ce2b590e63fc52f54b63645f59b2f83600cce812da0a7c0a9",
		urls: &["https://datashare.ed.ac.uk/download/DS_10283_3443.zip"],
	}],
};

/// PCM samples per second; every clip is 48,000 Hz mono FLAC.
pub const SAMPLE_RATE: usize = 48000;

/// Load options for [`Vctk`][crate::audio::vctk::Vctk].
#[derive(Clone, Debug)]
pub struct VctkConfig {
	/// Microphone channel to index; see
	/// [`VctkMic`][super::VctkMic].
	pub mic: super::VctkMic,
	/// Cache root override. `None` resolves `OA_DATA_DIR`, then the platform
	/// cache directory; see [`data_root`](crate::pack::data_root).
	pub cache_dir: Option<PathBuf>,
}

impl Default for VctkConfig {
	fn default() -> Self {
		Self {
			mic: super::VctkMic::Mic1,
			cache_dir: None,
		}
	}
}

impl VctkConfig {
	/// Construct the record with its default state.
	#[inline]
	#[must_use]
	pub fn new() -> Self {
		Self::default()
	}
}

impl super::Vctk {
	/// Decode the selected split and upload it on this thread's
	/// default engine.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_on`](Self::load_on).
	#[inline]
	pub fn load(config: &VctkConfig) -> Result<Self> {
		Self::load_on(&Engine::current()?, config)
	}

	/// Decode the selected split and upload it on `engine`.
	///
	/// This is the [`load`](Self::load) contract evaluated on
	/// `engine` instead of this thread's default engine.
	///
	/// # Errors
	///
	/// Returns the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_on(engine: &Engine, config: &VctkConfig) -> Result<Self> {
		Self::load_with_progress_on(engine, config, &mut |_| true)
	}

	/// [`load`](Self::load) with a fetch progress callback.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_with_progress(
		config: &VctkConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}