use super::models::ModelSet;
use super::weights::WeightList;
use crate::compat::OnceCell;
pub const LIBOPUS_VERSION: &str = "1.6.1";
#[repr(C, align(64))]
pub struct Aligned<const N: usize>(pub [u8; N]);
#[cfg(feature = "deep-plc")]
macro_rules! blob {
($name:ident, $file:literal) => {
static $name: Aligned<{ include_bytes!(concat!("../../dnn-weights/", $file)).len() }> =
Aligned(*include_bytes!(concat!("../../dnn-weights/", $file)));
};
}
#[cfg(feature = "deep-plc")]
blob!(PITCHDNN, "pitchdnn.bin");
#[cfg(feature = "deep-plc")]
blob!(PLC, "plc.bin");
#[cfg(feature = "deep-plc")]
blob!(FARGAN, "fargan.bin");
#[cfg(feature = "dred")]
blob!(DRED_RDOVAE_ENC, "dred_rdovae_enc.bin");
#[cfg(feature = "dred")]
blob!(DRED_RDOVAE_DEC, "dred_rdovae_dec.bin");
#[cfg(feature = "osce")]
blob!(LACE, "lace.bin");
#[cfg(feature = "osce")]
blob!(NOLACE, "nolace.bin");
#[cfg(feature = "osce-bwe")]
blob!(BBWENET, "bbwenet.bin");
#[cfg(feature = "deep-plc")]
pub fn pitchdnn() -> &'static [u8] {
&PITCHDNN.0
}
#[cfg(feature = "deep-plc")]
pub fn plc() -> &'static [u8] {
&PLC.0
}
#[cfg(feature = "deep-plc")]
pub fn fargan() -> &'static [u8] {
&FARGAN.0
}
#[cfg(feature = "dred")]
pub fn dred_rdovae_enc() -> &'static [u8] {
&DRED_RDOVAE_ENC.0
}
#[cfg(feature = "dred")]
pub fn dred_rdovae_dec() -> &'static [u8] {
&DRED_RDOVAE_DEC.0
}
#[cfg(feature = "osce")]
pub fn lace() -> &'static [u8] {
&LACE.0
}
#[cfg(feature = "osce")]
pub fn nolace() -> &'static [u8] {
&NOLACE.0
}
#[cfg(feature = "osce-bwe")]
pub fn bbwenet() -> &'static [u8] {
&BBWENET.0
}
pub fn blobs() -> &'static [(&'static str, &'static [u8])] {
static BLOBS: &[(&str, &[u8])] = &[
#[cfg(feature = "deep-plc")]
("pitchdnn.bin", &PITCHDNN.0),
#[cfg(feature = "deep-plc")]
("fargan.bin", &FARGAN.0),
#[cfg(feature = "deep-plc")]
("plc.bin", &PLC.0),
#[cfg(feature = "dred")]
("dred_rdovae_enc.bin", &DRED_RDOVAE_ENC.0),
#[cfg(feature = "dred")]
("dred_rdovae_dec.bin", &DRED_RDOVAE_DEC.0),
#[cfg(feature = "osce")]
("lace.bin", &LACE.0),
#[cfg(feature = "osce")]
("nolace.bin", &NOLACE.0),
#[cfg(feature = "osce-bwe")]
("bbwenet.bin", &BBWENET.0),
];
BLOBS
}
pub fn weights() -> &'static WeightList<'static> {
static LIST: OnceCell<WeightList<'static>> = OnceCell::new();
LIST.get(|| {
let mut list = WeightList::empty();
for &(_, blob) in blobs() {
if list.push(blob).is_err() {
return WeightList::empty();
}
}
list
})
}
pub fn models() -> &'static ModelSet<'static> {
static MODELS: OnceCell<ModelSet<'static>> = OnceCell::new();
unsafe {
MODELS.get_or_write(|p| {
ModelSet::write_new(p);
let _ = (*p).load(weights());
for &(_, blob) in blobs() {
super::holder::prefault(blob);
}
})
}
}
#[cfg(feature = "dred")]
pub fn rdovae_dec() -> Option<&'static super::models::dred_rdovae_dec::RdovaeDec<'static>> {
static MODEL: OnceCell<Option<super::models::dred_rdovae_dec::RdovaeDec<'static>>> = OnceCell::new();
MODEL
.get(|| {
let model = super::models::dred_rdovae_dec::RdovaeDec::init(weights()).ok();
super::holder::prefault(dred_rdovae_dec());
model
})
.as_ref()
}
#[cfg(feature = "dred")]
pub fn dred_enc() -> Option<&'static super::models::DredEncModels<'static>> {
static MODEL: OnceCell<Option<super::models::DredEncModels<'static>>> = OnceCell::new();
MODEL
.get(|| {
let model = super::models::DredEncModels::init(weights()).ok();
super::holder::prefault(dred_rdovae_enc());
super::holder::prefault(pitchdnn());
model
})
.as_ref()
}