#![deny(rustdoc::broken_intra_doc_links)] #![warn(missing_docs)]
#![cfg_attr(feature = "unstable", feature(portable_simd))]
#[allow(unused)]
use crate::audio_backend::AudioBackend;
#[allow(unused)]
use crate::gen::Gen;
#[allow(unused)]
use crate::sphere::KnystSphere;
use audio_backend::AudioBackendError;
use core::fmt::Debug;
use modal_interface::SphereError;
use resources::ResourcesError;
use std::ops::{Deref, DerefMut};
#[allow(unused_imports)]
use graph::{Connection, Graph, RunGraph};
pub use modal_interface::knyst_commands;
pub use resources::Resources;
#[allow(unused_imports)]
#[cfg(all(debug_assertions, feature = "assert_no_alloc"))]
use assert_no_alloc::*;
#[cfg(all(debug_assertions, feature = "assert_no_alloc"))]
#[global_allocator]
static A: AllocDisabler = AllocDisabler;
pub mod audio_backend;
pub mod buffer;
pub mod controller;
pub mod envelope;
pub mod gen;
pub mod graph;
pub mod handles;
pub mod inspection;
mod internal_filter;
pub mod modal_interface;
pub mod node_buffer;
pub mod offline;
pub mod prelude;
pub mod resources;
pub mod scheduling;
pub mod sphere;
pub mod time;
pub mod trig;
pub mod wavetable;
pub mod wavetable_aa;
pub mod xorrng;
#[derive(thiserror::Error, Debug)]
pub enum KnystError {
#[error("Error adding or removing connections: {0}")]
ConnectionError(#[from] graph::connection::ConnectionError),
#[error("Error freeing a node: {0}")]
FreeError(#[from] graph::FreeError),
#[error("Error pushing a node: {0}]")]
PushError(#[from] graph::PushError),
#[error("Error scheduling a change: {0}")]
ScheduleError(#[from] graph::ScheduleError),
#[error("Error with the RunGraph: {0}")]
RunGraphError(#[from] graph::run_graph::RunGraphError),
#[error("Resources error : {0}")]
ResourcesError(#[from] ResourcesError),
#[error("Sphere error : {0}")]
SphereError(#[from] SphereError),
#[error("Audio backend error : {0}")]
AudioBackendError(#[from] AudioBackendError),
}
#[inline]
#[must_use]
pub fn db_to_amplitude(db: Sample) -> Sample {
(10.0 as Sample).powf(db / 20.0)
}
#[inline]
#[must_use]
pub fn amplitude_to_db(amplitude: Sample) -> Sample {
20.0 * amplitude.log10()
}
pub type Sample = f32;
pub type Trig = Sample;
#[derive(Copy, Clone, Debug)]
pub struct SampleRate(pub Sample);
impl SampleRate {
#[inline(always)]
#[allow(missing_docs)]
pub fn to_f64(self) -> f64 {
self.0 as f64
}
#[allow(missing_docs)]
#[inline(always)]
pub fn to_usize(self) -> usize {
self.0 as usize
}
}
impl Deref for SampleRate {
type Target = Sample;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for SampleRate {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From<SampleRate> for f64 {
fn from(value: SampleRate) -> Self {
value.0 as f64
}
}
impl From<f32> for SampleRate {
fn from(value: f32) -> Self {
Self(value as Sample)
}
}
impl From<f64> for SampleRate {
fn from(value: f64) -> Self {
Self(value as Sample)
}
}
#[derive(Copy, Clone, Debug)]
pub struct BlockSize(pub usize);
impl From<BlockSize> for usize {
#[inline(always)]
fn from(value: BlockSize) -> Self {
value.0
}
}
impl From<usize> for BlockSize {
fn from(value: usize) -> Self {
Self(value)
}
}
impl Deref for BlockSize {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for BlockSize {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}