oadsrust 0.2.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::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const CREMA_D_PACK: Pack = Pack {
	name: "crema_d",
	version: "1.0.0",
	license: "Open Database License + custom use terms",
	files: &[PackFile {
		name: "crema-d-mirror-main.tar.gz",
		size: 2_934_014_374,
		shake256: "48a4e8126c03cf2bc3f1853866ecc2ea23b6659cd14ce05fd9fc4c658347e718",
		urls: &[
			"https://gitlab.com/cs-cooper-lab/crema-d-mirror/-/archive/main/crema-d-mirror-main.tar.gz",
		],
	}],
};

/// Emotion labels in canonical order; label index `i` names `CLASSES[i]`.
pub const CLASSES: [&str; 6] = ["NEU", "HAP", "SAD", "ANG", "FEA", "DIS"];

/// PCM samples per second; every clip is 16,000 Hz mono 16-bit.
pub const SAMPLE_RATE: usize = 16000;

/// Derived speaker-disjoint split selection; the corpus ships no official split.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum CremaDSplit {
	/// ~81% of clips; actors not in validation/test.
	#[default]
	Train,
	/// Actors at sorted positions i%10==5.
	Validation,
	/// Actors at sorted positions i%10==0.
	Test,
}

/// Load options for [`CremaD`][crate::audio::crema_d::CremaD].
#[derive(Clone, Debug)]
pub struct CremaDConfig {
	/// Which derived speaker-disjoint split to materialize.
	pub split: CremaDSplit,
	/// 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 CremaDConfig {
	fn default() -> Self {
		Self {
			split: CremaDSplit::Train,
			cache_dir: None,
		}
	}
}

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

impl super::CremaD {
	/// 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: &CremaDConfig) -> 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: &CremaDConfig) -> 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: &CremaDConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}