### Example: using Backend::new and start_audio_thread Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search= Shows how to create a Backend, start an audio thread with a custom renderer, and sleep for 30 seconds. This example is from examples/custom_renderer.rs and demonstrates the usage of Backend::new and start_audio_thread. ```rust fn main() { let renderer = RendererHandle::new(CustomRenderer { frame: 0 }); thread::spawn(|| { let mut backend = Backend::new(); backend .start_audio_thread(Device::Default, StreamSettings::default(), renderer) .expect("failed to start audio thread"); }); thread::sleep(Duration::from_secs(30)); } ``` -------------------------------- ### Mixer::init_ex Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html?search= Starts the audio thread with custom backend settings. ```APIDOC ## Mixer::init_ex ### Description Start the audio thread with custom backend settings. ### Method Action ### Signature `pub fn init_ex(&self, device: Device, settings: StreamSettings)` ### Parameters - **device** (Device) - Required - The audio device to use. Set to `Device::Default` for defaults. - **settings** (StreamSettings) - Required - The audio stream configuration. Set to `None` for defaults. ### Returns None ``` -------------------------------- ### pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search= Starts the audio thread with the given device, settings, and renderer. Returns an error if the stream fails to start. ```APIDOC ## pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer ### Description Starts the audio thread with the specified device, settings, and renderer. ### Method ```rust pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer, ``` ### Parameters - `device` (Device) - Required - The audio device to use. - `settings` (StreamSettings) - Required - The stream settings. - `renderer` (RendererHandle) - Required - The renderer handle that manages the custom renderer. ### Returns `Result<(), KaError>` - Ok if the audio thread started successfully, otherwise an error. ``` -------------------------------- ### Mixer::init Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html?search= Starts the audio thread with default backend settings. ```APIDOC ## Mixer::init ### Description Start the audio thread with default backend settings. ### Method Action ### Signature `pub fn init(&self)` ### Parameters None ### Returns None ``` -------------------------------- ### Backend::start_audio_thread Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html Starts the audio thread. ```APIDOC ## Backend::start_audio_thread ### Description Starts the audio thread. ### Method `pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer` ### Parameters - `device` (Device) - Required - The audio device to use. - `settings` (StreamSettings) - Required - The stream settings. - `renderer` (RendererHandle) - Required - The renderer handle. ### Returns - `Result<(), KaError>` - Ok if the audio thread started successfully, otherwise an error. ### Example ```rust let mut backend = Backend::new(); backend.start_audio_thread(Device::Default, StreamSettings::default(), renderer).expect("failed to start audio thread"); ``` ``` -------------------------------- ### Sound::loop_start_secs Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Returns the starting point of the loop as seconds. ```APIDOC ## Sound::loop_start_secs ### Description Returns the starting point of the loop as seconds. ### Method `pub fn loop_start_secs(&self) -> f64` ### Returns - `f64` - The loop start in seconds. ``` -------------------------------- ### Backend::start_audio_thread() Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts the audio thread with the given device, settings, and renderer. ```APIDOC ## Backend::start_audio_thread() ### Description Starts the audio thread with the given device, settings, and renderer. ### Method `pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer` ### Parameters - `device` (Device) - Required - The audio device to use. - `settings` (StreamSettings) - Required - The stream settings. - `renderer` (RendererHandle) - Required - The renderer handle. ### Returns - `Result<(), KaError>` - `Ok(())` on success, `Err(KaError)` on failure. ### Example ```rust backend.start_audio_thread(Device::Default, StreamSettings::default(), renderer).expect("failed to start audio thread"); ``` ``` -------------------------------- ### Sound::loop_start Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Returns the starting point of the loop as a frame index. ```APIDOC ## Sound::loop_start ### Description Returns the starting point of the loop as a frame index. ### Method `pub fn loop_start(&self) -> usize` ### Returns - `usize` - The loop start frame index. ``` -------------------------------- ### Backend::start_audio_thread Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search=u32+-%3E+bool Starts the audio thread with the given device, settings, and renderer. ```APIDOC ## Backend::start_audio_thread ### Description Starts the audio thread. ### Method `pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer` ### Parameters - **device** (Device) - Required - The audio device to use. - **settings** (StreamSettings) - Required - The stream settings. - **renderer** (RendererHandle) - Required - The renderer handle. ### Returns - `Result<(), KaError>` - `Ok(())` on success, or an error. ### Example rust backend.start_audio_thread(Device::Default, StreamSettings::default(), renderer).expect("failed to start audio thread"); ``` -------------------------------- ### add_sound Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.DefaultRenderer.html?search= Starts playing a sound. Accepts a type that can be converted into a SoundHandle. ```APIDOC ## add_sound ### Description Starts playing a sound. Accepts a type that can be converted into a `SoundHandle`. ### Method `pub fn add_sound(&mut self, sound: impl Into)` ### Parameters - **sound** (impl Into) - Required - The sound to start playing. ### Returns `()` ``` -------------------------------- ### SoundHandle::loop_start_secs Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Returns the loop start time in seconds of the underlying Sound. ```APIDOC ## SoundHandle::loop_start_secs ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn loop_start_secs(&self) -> f64` ### Returns - `f64` - The loop start time in seconds. ``` -------------------------------- ### SoundHandle::loop_start Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Returns the loop start index of the underlying Sound. ```APIDOC ## SoundHandle::loop_start ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn loop_start(&self) -> usize` ### Returns - `usize` - The loop start index. ``` -------------------------------- ### Basic usage: include_sound and Mixer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html Shows how to include a sound file into the executable and play it using the Mixer. The include_sound! macro requires the 'symphonia' feature. The example demonstrates creating a mixer, initializing it, playing a sound, setting volume, and waiting for playback to finish. ```rust use kittyaudio::{include_sound, Mixer}; fn main() { // include a sound into the executable. // this type can be cheaply cloned. let sound = include_sound!("jump.ogg").unwrap(); // create sound mixer let mut mixer = Mixer::new(); mixer.init(); // use init_ex to specify settings let playing_sound = mixer.play(sound); playing_sound.set_volume(0.5); // decrease volume mixer.wait(); // wait for all sounds to finish } ``` -------------------------------- ### Command::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Command.html?search=u32+-%3E+bool Creates a new Command with the specified change, easing, start delay, and duration. ```APIDOC ## Command::new ### Description Creates a new `Command` with the given change, easing, start delay, and duration. ### Method `pub const fn new(change: Change, easing: Easing, start_after: f64, duration: f64) -> Self` ### Parameters - `change` (Change) - Required - What variable to change. - `easing` (Easing) - Required - The curve of the motion. - `start_after` (f64) - Required - Time left before the command starts. - `duration` (f64) - Required - How much time the command lasts (in seconds). ### Returns - `Self` - The newly created `Command`. ``` -------------------------------- ### Command::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Command.html Creates a new Command with the specified change, easing, start delay, and duration. ```APIDOC ## Command::new ### Description Creates a new `Command` with the given change, easing, start delay, and duration. ### Method `pub const fn new(change: Change, easing: Easing, start_after: f64, duration: f64) -> Self` ### Parameters - `change` (Change) - Required - What variable to change. - `easing` (Easing) - Required - The curve of the motion. - `start_after` (f64) - Required - Time left before the command starts. - `duration` (f64) - Required - How much time the command lasts (in seconds). ### Returns A new `Command` instance. ``` -------------------------------- ### Command::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Command.html?search= Creates a new Command with the specified change, easing, start delay, and duration. ```APIDOC ## Command::new ### Description Creates a new `Command` with the given parameters. ### Method `pub const fn new(change: Change, easing: Easing, start_after: f64, duration: f64) -> Self` ### Parameters - `change` (Change) - Required - What variable to change. - `easing` (Easing) - Required - The curve of the motion. - `start_after` (f64) - Required - Time left before the command starts. - `duration` (f64) - Required - How much time the command lasts (in seconds). ### Returns A new `Command` instance. ``` -------------------------------- ### Using Frame::from_mono in custom renderer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Frame.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example from examples/custom_renderer.rs (line 15) showing how to use Frame::from_mono to create a frame from a single value. ```rust fn next_frame(&mut self, sample_rate: u32) -> Frame { self.frame += 1; let time = self.frame as f64 / sample_rate as f64; let value = (time.sin() * 1200.0).sin() * 0.5; Frame::from_mono(value as f32) } ``` -------------------------------- ### Resampler::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Resampler.html Creates a new Resampler instance with a given starting index. ```APIDOC ## Resampler::new ### Description Creates a new `Resampler` with the specified starting index. ### Method `pub const fn new(starting_index: usize) -> Self` ### Parameters - `starting_index` (usize) - Required - The initial index for the resampler. ### Returns A new `Resampler` instance. ``` -------------------------------- ### DefaultRenderer::add_sound Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.DefaultRenderer.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts playing a sound by adding it to the renderer. Accepts any type that can be converted into a SoundHandle. ```APIDOC ## DefaultRenderer::add_sound ### Description Starts playing a sound by adding it to the renderer. Accepts any type that can be converted into a `SoundHandle`. ### Method `pub fn add_sound(&mut self, sound: impl Into)` ### Parameters - **sound** (`impl Into`) - Required - The sound to start playing. ### Returns `()` (unit) ``` -------------------------------- ### pub fn resume(&mut self) Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=std%3A%3Avec Resumes the sound if paused. This won't immediately start the audio signal, but smoothly interpolates the last audio value for 4 frames. ```APIDOC ## pub fn resume(&mut self) ### Description Resumes the sound if paused. This won't immediately start the audio signal, but smoothly interpolates the last audio value for 4 frames. ### Method resume ### Parameters None ### Returns None ``` -------------------------------- ### Using Frame::from_mono in custom renderer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Frame.html?search= Example from examples/custom_renderer.rs (line 15) showing how to use Frame::from_mono to generate a mono audio frame from a sine wave value. ```rust 11 fn next_frame(&mut self, sample_rate: u32) -> Frame { 12 self.frame += 1; 13 let time = self.frame as f64 / sample_rate as f64; 14 let value = (time.sin() * 1200.0).sin() * 0.5; 15 Frame::from_mono(value as f32) 16 } ``` -------------------------------- ### SoundHandle::next_frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Gets the next frame from the underlying Sound at the given sample rate. ```APIDOC ## SoundHandle::next_frame ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn next_frame(&self, sample_rate: u32) -> Option` ### Parameters - **sample_rate** (u32) - The sample rate. ### Returns - `Option` - The next frame, if available. ``` -------------------------------- ### SoundHandle::next_frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search=std%3A%3Avec Gets the next frame of audio data from the underlying Sound. ```APIDOC ## SoundHandle::next_frame ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn next_frame(&self, sample_rate: u32) -> Option` ### Parameters - **sample_rate** (u32) - The sample rate to use. ### Returns - **Option** - The next frame, or `None` if no more frames. ``` -------------------------------- ### Parameter::start_tween Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Parameter.html Starts a tween animation towards the given target value. ```APIDOC ## Parameter::start_tween ### Description Starts a tween animation towards the specified target value. ### Method `pub fn start_tween(&mut self, value: T)` ### Parameters - `value` (T) - Required - The target value to tween to. ``` -------------------------------- ### pub fn panning(&mut self) -> f32 Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=std%3A%3Avec Gets the audio panning. Panning of 0.0 means hard left, 0.5 means center (default), 1.0 means hard right. Returns the panning value. ```APIDOC ## pub fn panning(&mut self) -> f32 ### Description Gets the audio panning. Panning of 0.0 means hard left, 0.5 means center (default), 1.0 means hard right. Returns the panning value. ### Method panning ### Parameters None ### Returns - **f32** - The current panning value. ``` -------------------------------- ### pub fn new() -> Self Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search= Creates a new `Backend` instance with default settings. ```APIDOC ## pub fn new() -> Self ### Description Creates a new `Backend`. ### Method `new` ### Signature ```rust pub fn new() -> Self ``` ### Returns A new `Backend` instance. ``` -------------------------------- ### Command::value Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Command.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the value of the command at a given time. ```APIDOC ## Command::value ### Description Gets the value of the command at a given time. ### Method `pub fn value(&self, t: f32) -> f32` ### Parameters - **t** (f32) - Required - The time at which to evaluate the command. ### Returns - **f32** - The value of the command at the given time. ``` -------------------------------- ### Backend::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html Creates a new Backend instance. ```APIDOC ## Backend::new ### Description Creates a new `Backend` instance. ### Method `pub fn new() -> Self` ### Parameters None. ### Returns - `Self` - A new `Backend` instance. ### Example ```rust let mut backend = Backend::new(); ``` ``` -------------------------------- ### pub fn new() -> Self Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.RecordMixer.html?search=u32+-%3E+bool Creates a new audio recording mixer. ```APIDOC ## [FUNCTION] pub fn new() -> Self ### Description Create a new audio recording mixer. ### Signature ```rust pub fn new() -> Self ``` ### Parameters None. ### Returns - (Self) - A new RecordMixer instance. ``` -------------------------------- ### Mixer::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html?search= Creates a new audio mixer instance. ```APIDOC ## Mixer::new ### Description Creates a new audio mixer. ### Method Constructor ### Signature `pub fn new() -> Self` ### Parameters None ### Returns - **Self** - A new `Mixer` instance. ``` -------------------------------- ### Device::default_device Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/enum.Device.html?search= Gets the default audio device as a Device::Custom variant. ```APIDOC ## Device::default_device ### Description Get the default device as `Device::Custom`. ### Method `pub fn default_device() -> Result` ### Returns - `Result` - `Ok(Device::Custom(default_cpal_device))` if successful, otherwise `Err(KaError)`. ``` -------------------------------- ### Command::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Command.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new Command with the specified change, easing, start_after, and duration. ```APIDOC ## Command::new ### Description Creates a new `Command` with the given change, easing, start delay, and duration. ### Method `pub const fn new(change: Change, easing: Easing, start_after: f64, duration: f64) -> Self` ### Parameters - **change** (Change) - Required - What variable to change. - **easing** (Easing) - Required - The curve of the motion. - **start_after** (f64) - Required - Time left before the command starts. - **duration** (f64) - Required - How much time the command lasts (in seconds). ### Returns - **Self** - A new `Command` instance. ``` -------------------------------- ### SoundHandle::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Creates a new SoundHandle from a Sound. ```APIDOC ## SoundHandle::new ### Description Make a new `SoundHandle` from a `Sound`. ### Method `pub fn new(sound: Sound) -> Self` ### Parameters - **sound** (Sound) - The sound to wrap. ### Returns - `Self` - A new `SoundHandle`. ``` -------------------------------- ### pub fn play(&self, sound: impl Into) -> SoundHandle Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.RecordMixer.html?search=u32+-%3E+bool Play a Sound in the recording mixer. The samples are processed only when fill_buffer is called. Cloning a Sound does not take extra memory because Sound shares frame data with all clones. ```APIDOC ## [FUNCTION] pub fn play(&self, sound: impl Into) -> SoundHandle ### Description Play a Sound in the recording mixer. The samples of the sound are only processed when fill_buffer is called. Note that cloning a Sound does not take extra memory as Sound shares frame data with all clones. ### Signature ```rust pub fn play(&self, sound: impl Into) -> SoundHandle ``` ### Parameters - `sound` (impl Into) - Required - The sound to play in this mixer. ### Returns - `SoundHandle` - A handle to the played sound. ``` -------------------------------- ### Parameter Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Parameter.html?search=u32+-%3E+bool A parameter that implements tweening of the underlying value. It provides methods to create, start, stop, and update tweens. ```APIDOC ## Struct Parameter ### Description A parameter (used in `crate::Sound`) that implements tweening the underlying value. ### Fields - **value**: T - Last tweened value. If no commands are running, this is the same as the base value. - **base_value**: T - Value before the last command started. ### Methods #### `pub const fn new(value: T) -> Self` Create a new `Parameter`. #### `pub fn start_tween(&mut self, value: T)` Start the tween. #### `pub fn stop_tween(&mut self)` Stop any tweening. #### `pub fn update(&mut self, value: T, t: f32)` Update the tween state with a given time. ### Trait Implementations - `Clone` for `Parameter` where `T: Clone + Tweenable` - `Copy` for `Parameter` where `T: Copy + Tweenable` - `Debug` for `Parameter` where `T: Debug + Tweenable` - `From for Parameter` - `From for Parameter` - `PartialEq` for `Parameter` where `T: PartialEq + Tweenable` - `StructuralPartialEq` for `Parameter` where `T: PartialEq + Tweenable` ``` -------------------------------- ### Device::default_device Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/enum.Device.html?search=u32+-%3E+bool Gets the default audio device. Returns a Result containing the Device or an error if no default device is available. ```APIDOC ## Device::default_device ### Description Gets the default audio device. Returns a Result containing the Device or an error if no default device is available. ### Method default_device ### Signature pub fn default_device() -> Result ### Returns - **Result** - Ok(Device) if a default device exists, otherwise an error. ### Errors - **KaError** - Returned if no default device is available. ``` -------------------------------- ### Device::supported_buffer_size Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/enum.Device.html?search=u32+-%3E+bool Gets the supported buffer size for the device. Returns a Result containing the supported buffer size or an error if it cannot be determined. ```APIDOC ## Device::supported_buffer_size ### Description Gets the supported buffer size for the device. Returns a Result containing the supported buffer size or an error if it cannot be determined. ### Method supported_buffer_size ### Signature pub fn supported_buffer_size(self, host: Host) -> Result ### Parameters - **self** (Device) - Required - The device for which to get the supported buffer size. - **host** (Host) - Required - The audio host to query. ### Returns - **Result** - Ok(SupportedBufferSize) if successful, otherwise an error. ### Errors - **KaError** - Returned if the supported buffer size cannot be determined. ``` -------------------------------- ### Sound::panning Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the current audio panning. Panning of 0.0 means hard left, 0.5 center (default), 1.0 hard right. ```APIDOC ## Sound::panning ### Description Get the audio panning. * Panning of 0.0 means hard left panning * Panning of 0.5 means center panning (default) * Panning of 1.0 means hard right panning ### Method `pub fn panning(&mut self) -> f32` ### Parameters None. ### Returns - `f32` - The panning value. ``` -------------------------------- ### Device Enum Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/enum.Device.html Documentation for the Device enum and its associated methods in the kittyaudio crate. ```APIDOC ## Device Enum ### Description Specifies what device `cpal` should use. Use `Device::Default` for the default OS audio device, `Device::Name` to select by name, or `Device::Custom` to use a `cpal::Device` directly. ### Variants - **Default** - Use the default OS audio device. - **Name(String)** - Specify a device by name. - **Custom(Device)** - Use a `cpal::Device`. ### Methods #### `from_name(name: &str) -> Result` Finds a `cpal` audio output device by name. #### `default_device() -> Result` Get the default device as `Device::Custom`. #### `cpal_device(self, host: Host) -> Result` Find the cpal device that matches `Device`'s criteria. Returns `KaError::NoOutputDevice` if not found. #### `supported_buffer_size(self, host: Host) -> Result` Get the supported buffer size for this device. Returns `KaError::NoOutputDevice` if not found. #### `name(self) -> Result` Return the cpal device name. ### Trait Implementations - `Default` - Returns the default value for the type. - Auto traits: `Freeze`, `RefUnwindSafe`, `Send`, `Sync`, `Unpin`, `UnsafeUnpin`, `UnwindSafe`. - Blanket implementations: `Any`, `Borrow`, `BorrowMut`, `Duplex`, `From`, `FromSample`, `Into`, `IntoSample`, `ToSample`, `TryFrom`, `TryInto`. ``` -------------------------------- ### pub fn next_frame(&self, sample_rate: u32) -> Frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.RecordMixer.html?search=u32+-%3E+bool Render the next audio frame. See the DefaultRenderer for details on rendering behavior. ```APIDOC ## [FUNCTION] pub fn next_frame(&self, sample_rate: u32) -> Frame ### Description Render the next audio frame. See DefaultRenderer for details. ### Signature ```rust pub fn next_frame(&self, sample_rate: u32) -> Frame ``` ### Parameters - `sample_rate` (u32) - Required - The sample rate to use when rendering the frame. ### Returns - `Frame` - The next audio frame. ``` -------------------------------- ### device_names() Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/fn.device_names.html?search= Returns all device names available on the system. This function is part of the kittyaudio crate's public API and returns a Result with a vector of strings or a KaError. ```APIDOC ## Function device_names ### Description Returns all device names available on the system. ### Signature rust pub fn device_names() -> Result, KaError> ### Parameters None ### Return Value - **Result, KaError>** - On success, returns a vector of device name strings. On failure, returns a KaError. ### Example rust let names = device_names(); ``` -------------------------------- ### Sound::from_path Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html Creates a Sound from a file path. ```APIDOC ## Sound::from_path ### Description Creates a `Sound` from a file path using `symphonia` for decoding. ### Method `from_path` ### Parameters - `path` (`impl AsRef`) - Required - The path to the audio file. ### Returns - `Result` - The created `Sound` or an error. ### Required Features - `symphonia` ``` -------------------------------- ### pub fn index(&self) -> usize Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=std%3A%3Avec Returns the current index in the source sound data. This index can be modified with commands. ```APIDOC ## pub fn index(&self) -> usize ### Description Returns the current index in the source sound data. This index can be modified with commands. ### Method index ### Parameters None ### Returns - **usize** - The current index in the source sound data. ``` -------------------------------- ### Sound::next_frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html Renders the next frame. ```APIDOC ## Sound::next_frame ### Description Renders the next frame. If the sound has ended, returns `None`. ### Method `next_frame` ### Parameters - `sample_rate` (`u32`) - Required - The sample rate for rendering. ### Returns - `Option` - The next frame, or `None` if ended. ``` -------------------------------- ### SoundHandle Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Handle to a playing sound, allowing control over playback. ```APIDOC ## [STRUCT] SoundHandle ### Description Wraps a `Sound` so it can be returned to the user after `play`. ### Methods - `set_volume(volume)` - Sets the volume of the sound. ``` -------------------------------- ### fn next_frame(&mut self, sample_rate: u32) -> Frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/trait.Renderer.html Renders the next audio frame. The backend provides the sample rate and expects the left and right channel values as a Frame. ```APIDOC ## fn next_frame(&mut self, sample_rate: u32) -> Frame ### Description Renders the next audio frame. The backend provides the sample rate and expects the left and right channel values as a `Frame`. ### Method `next_frame` ### Parameters - `sample_rate` (u32) - The sample rate provided by the backend. ### Returns - `Frame` - The rendered audio frame containing left and right channel values. ### Notes You can use a `crate::Resampler` to resample audio data. ``` -------------------------------- ### Backend Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Manages the audio backend and stream. ```APIDOC ## [STRUCT] Backend ### Description A wrapper around `cpal`'s stream. The `Backend` will check for device changes or disconnections, handle errors and manage the stream. ``` -------------------------------- ### Sound::set_volume Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html Sets the volume. ```APIDOC ## Sound::set_volume ### Description Sets the current volume. Returns the previous volume value. ### Method `set_volume` ### Parameters - `volume` (`f32`) - Required - The new volume. ### Returns - `f32` - The previous volume. ``` -------------------------------- ### pub fn base_index(&self) -> usize Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=std%3A%3Avec Returns the current index in the source sound data. This index cannot be modified with commands. ```APIDOC ## pub fn base_index(&self) -> usize ### Description Returns the current index in the source sound data. This index cannot be modified with commands. ### Method base_index ### Parameters None ### Returns - **usize** - The current index in the source sound data. ``` -------------------------------- ### Sound::from_path Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Creates a Sound from a file path. Required features: symphonia. ```APIDOC ## Sound::from_path ### Description Creates a `Sound` from a file path. ### Method `pub fn from_path(path: impl AsRef) -> Result` ### Parameters - **path** (impl AsRef) - Required - The file path to the audio file. ### Returns - `Result` - The created `Sound` or an error. ### Required Features `symphonia` ``` -------------------------------- ### KaError Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Error type for the kittyaudio crate. ```APIDOC ## [ENUM] KaError ### Description KittyAudio's error type. ``` -------------------------------- ### Mixer::play Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html?search= Plays a sound, returning a handle to it. Cloning a Sound does not take extra memory. ```APIDOC ## Mixer::play ### Description Play a `Sound`. Cloning a `Sound` does not take any extra memory, as `Sound` shares frame data with all clones. ### Method Action ### Signature `pub fn play(&mut self, sound: impl Into) -> SoundHandle` ### Parameters - **sound** (impl Into) - Required - The sound to play. ### Returns - **SoundHandle** - A handle to the playing sound. ``` -------------------------------- ### StreamSettings Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Settings for the audio stream. ```APIDOC ## [STRUCT] StreamSettings ### Description Wrapper around `cpal`'s stream settings. ``` -------------------------------- ### include_sound!($path:expr) Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/macro.include_sound.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Includes a sound file in the executable at compile time. This macro is a shorthand for Sound::from_cursor(Cursor::new(include_bytes!(path))). It requires the 'symphonia' feature to be enabled. ```APIDOC ## include_sound!($path:expr) ### Description Includes a sound in the executable. The `symphonia` feature must be enabled for this macro to exist. This is a shorthand for `Sound::from_cursor(Cursor::new(include_bytes!(path)))`. ### Macro Signature ```rust macro_rules! include_sound { ($path:expr) => { ... }; } ``` ### Parameters - **$path** (expression) - Required - The path to the sound file to include. ### Requirements - The `symphonia` feature must be enabled. ### Example ```rust let sound = include_sound!("path/to/sound.ogg"); ``` ``` -------------------------------- ### pub fn fill_buffer(&self, sample_rate: u32, frames: &mut [Frame]) Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.RecordMixer.html?search=u32+-%3E+bool Fill the given buffer with audio samples. When the buffer is processed, no other samples are rendered before the next call to this function. ```APIDOC ## [FUNCTION] pub fn fill_buffer(&self, sample_rate: u32, frames: &mut [Frame]) ### Description Fill the given buffer with audio samples. When the buffer is processed, no other samples are rendered before the next call to this function. ### Signature ```rust pub fn fill_buffer(&self, sample_rate: u32, frames: &mut [Frame]) ``` ### Parameters - `sample_rate` (u32) - Required - The sample rate to use when generating audio frames. - `frames` (&mut [Frame]) - Required - A mutable slice of Frame values to be filled with audio data. ### Returns - None. ``` -------------------------------- ### Frame::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Frame.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new audio frame from left and right values. ```APIDOC ## Frame::new ### Description Creates a new audio frame from left and right values. ### Method `pub const fn new(left: f32, right: f32) -> Self` ### Parameters - **left** (f32) - Required - Left channel value. - **right** (f32) - Required - Right channel value. ### Returns - **Frame** - A new Frame with the given left and right values. ``` -------------------------------- ### Sound::from_cursor Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html Creates a Sound from a Cursor of bytes. ```APIDOC ## Sound::from_cursor ### Description Creates a `Sound` from a `Cursor` of bytes using `symphonia` for decoding. ### Method `from_cursor` ### Parameters - `cursor` (`Cursor`) - Required - The cursor containing audio bytes. ### Returns - `Result` - The created `Sound` or an error. ### Required Features - `symphonia` ``` -------------------------------- ### device_names Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/fn.device_names.html Returns all device names available on the system. ```APIDOC ## device_names ### Description Returns all device names available on the system. ### Method Function call ### Signature ```rust pub fn device_names() -> Result, KaError> ``` ### Parameters None ### Return Value - **Result, KaError>** - On success, returns a vector of device names as strings. On failure, returns a `KaError`. ``` -------------------------------- ### Mixer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html Documentation for the Mixer struct in the kittyaudio crate, including its fields, methods, and trait implementations. ```APIDOC ## Mixer ### Description Audio mixer. The mixing is done by the `Renderer` (`RendererHandle`), and the audio playback is handled by the `Backend`. ### Fields - `renderer: RendererHandle` - Handle to the default audio renderer. - `backend: Arc>` - Handle to the underlying audio backend. ### Methods #### `new` Create a new audio mixer. ```rust pub fn new() -> Self ``` #### `backend` Get a lock on the underlying backend. ```rust pub fn backend(&self) -> MutexGuard<'_, Backend> ``` #### `play` Play a `Sound`. Note: Cloning a `Sound` _does not_ take any extra memory, as `Sound` shares frame data with all clones. ```rust pub fn play(&mut self, sound: impl Into) -> SoundHandle ``` #### `handle_errors` Handle stream errors. ```rust pub fn handle_errors(&mut self, err_fn: impl FnMut(StreamError)) ``` #### `init` Start the audio thread with default backend settings. ```rust pub fn init(&self) ``` #### `init_ex` Start the audio thread with custom backend settings. - `device`: The audio device to use. Set to `Device::Default` for defaults. - `stream_config`: The audio stream configuration. Set to `None` for defaults. - `sample_format`: The audio sample format. Set to `None` for defaults. ```rust pub fn init_ex(&self, device: Device, settings: StreamSettings) ``` #### `wait` Block the thread until all sounds are finished. ```rust pub fn wait(&self) ``` #### `is_finished` Return whether all sounds are finished or not. ```rust pub fn is_finished(&self) -> bool ``` #### `next_frame` Render the next audio frame. See `DefaultRenderer` for details. ```rust pub fn next_frame(&self, sample_rate: u32) -> Frame ``` ### Trait Implementations - `Clone` for `Mixer` - `Default` for `Mixer` ### Auto Trait Implementations - `!RefUnwindSafe` - `!UnwindSafe` - `Freeze` - `Send` - `Sync` - `Unpin` - `UnsafeUnpin` ### Blanket Implementations - `Any`, `Borrow`, `BorrowMut`, `CloneToUninit`, `Duplex`, `From`, `FromSample`, `Into`, `IntoSample`, `ToOwned`, `ToSample`, `TryFrom`, `TryInto` ``` -------------------------------- ### Sound::next_frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Renders the next frame at the given sample rate. ```APIDOC ## Sound::next_frame ### Description Render the next frame. If the sound has ended, return `None`. ### Method `pub fn next_frame(&mut self, sample_rate: u32) -> Option` ### Parameters - **sample_rate** (u32) - Required - Sample rate for rendering. ### Return Value `Option` ``` -------------------------------- ### Parameter::new Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Parameter.html Creates a new Parameter with the given initial value. ```APIDOC ## Parameter::new ### Description Creates a new `Parameter` with the specified initial value. ### Method `pub const fn new(value: T) -> Self` ### Parameters - `value` (T) - Required - The initial value for the parameter. ### Returns A new `Parameter` instance. ``` -------------------------------- ### SoundHandle::resume Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Resumes the underlying Sound. ```APIDOC ## SoundHandle::resume ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn resume(&self)` ``` -------------------------------- ### Device Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Enum specifying the audio device. ```APIDOC ## [ENUM] Device ### Description Specifies what device `cpal` should use. ``` -------------------------------- ### Device::from_name Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/enum.Device.html?search= Finds a cpal audio output device by name and returns a Device::Custom variant. ```APIDOC ## Device::from_name ### Description Finds a `cpal` audio output device (`cpal::Device`) by name and returns it as a `Device::Custom` variant. ### Method `pub fn from_name(name: &str) -> Result` ### Parameters - **name** (`&str`) - The name of the device to find. ### Returns - `Result` - `Ok(Device::Custom(cpal_device))` if found, otherwise `Err(KaError)`. ``` -------------------------------- ### SoundHandle::add_command Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Adds a command to the underlying Sound. ```APIDOC ## SoundHandle::add_command ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn add_command(&self, command: Command)` ### Parameters - **command** (Command) - The command to add. ``` -------------------------------- ### Sound::reset Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Resets the sound to the beginning. ```APIDOC ## Sound::reset ### Description Resets the sound to the beginning. ### Method `pub fn reset(&mut self)` ``` -------------------------------- ### Parameter Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Parameter.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Documentation for the Parameter struct and its methods. ```APIDOC ## Parameter ### Description A parameter (used in `crate::Sound`) that implements tweening the underlying value. ### Fields - `value: T` - Last tweened value. If no commands are running, this is the same as the base value. - `base_value: T` - Value before the last command started. ### Methods #### `new(value: T) -> Self` Create a new `Parameter`. #### `start_tween(&mut self, value: T)` Start the tween. #### `stop_tween(&mut self)` Stop any tweening. #### `update(&mut self, value: T, t: f32)` Update the tween state with a given time. ### Trait Implementations - `Clone` for `Parameter` - `Copy` for `Parameter` - `Debug` for `Parameter` - `From for Parameter` - `From for Parameter` - `PartialEq` for `Parameter` - `StructuralPartialEq` for `Parameter` ``` -------------------------------- ### Sound::from_media_source Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html Creates a Sound from a MediaSource. ```APIDOC ## Sound::from_media_source ### Description Creates a `Sound` from a `MediaSource` using `symphonia` for decoding. ### Method `from_media_source` ### Parameters - `media_source` (`impl MediaSource + 'static`) - Required - The media source to decode. ### Returns - `Result` - The created `Sound` or an error. ### Required Features - `symphonia` ``` -------------------------------- ### Backend Methods Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Backend.html?search=std%3A%3Avec Methods for the Backend struct that can be called directly by users. ```APIDOC ## Backend::new ### Description Creates a new `Backend` instance. ### Method `pub fn new() -> Self` ### Parameters None. ### Returns A new `Backend` instance. ### Example ```rust let mut backend = Backend::new(); ``` ``` ```APIDOC ## Backend::handle_errors ### Description Handle all errors in the error queue. ### Method `pub fn handle_errors(&mut self, err_fn: impl FnMut(StreamError))` ### Parameters - **err_fn** (closure) - Required - A closure that will be called for each error in the queue. ### Returns Nothing. ``` ```APIDOC ## Backend::start_audio_thread ### Description Starts the audio thread. ### Method `pub fn start_audio_thread(&mut self, device: Device, settings: StreamSettings, renderer: RendererHandle) -> Result<(), KaError> where R: Renderer` ### Parameters - **device** (Device) - Required - The audio device to use. - **settings** (StreamSettings) - Required - The stream settings. - **renderer** (RendererHandle) - Required - The renderer handle. ### Returns `Result<(), KaError>` - Ok if the audio thread started successfully, otherwise an error. ### Example ```rust backend.start_audio_thread(Device::Default, StreamSettings::default(), renderer).expect("failed to start audio thread"); ``` ``` ```APIDOC ## Backend::stop_stream ### Description Stop the audio thread at the next stream check. ### Method `pub fn stop_stream(&mut self)` ### Parameters None. ### Returns Nothing. ``` -------------------------------- ### Renderer Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Trait for custom audio renderers. ```APIDOC ## [TRAIT] Renderer ### Description The audio renderer trait. Can be used to make custom audio renderers. ``` -------------------------------- ### Mixer::next_frame Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Mixer.html?search= Renders the next audio frame. ```APIDOC ## Mixer::next_frame ### Description Render the next audio frame. See `DefaultRenderer` for details. ### Method Action ### Signature `pub fn next_frame(&self, sample_rate: u32) -> Frame` ### Parameters - **sample_rate** (u32) - Required - The sample rate for the frame. ### Returns - **Frame** - The rendered audio frame. ``` -------------------------------- ### Sound::from_frames Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Creates a Sound from a slice of frames and a sample rate. ```APIDOC ## Sound::from_frames ### Description Creates a `Sound` from a slice of `Frame`s and a sample rate. ### Method `pub fn from_frames(sample_rate: u32, frames: &[Frame]) -> Self` ### Parameters - **sample_rate** (u32) - Required - The sample rate of the audio. - **frames** (&[Frame]) - Required - The audio frames. ### Returns - `Self` - The created `Sound`. ``` -------------------------------- ### include_sound Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/index.html?search=std%3A%3Avec Macro to include a sound file into the executable at compile time. ```APIDOC ## [MACRO] include_sound ### Description Includes a sound in the executable. The `symphonia` feature must be enabled for this macro to exist. ### Usage `include_sound!(path)` ### Parameters - **path** (string literal) - Required - Path to the audio file to include. ### Returns - `Result` - The included sound, or an error if loading fails. ``` -------------------------------- ### Sound::from_boxed_media_source Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Creates a Sound from a boxed MediaSource. Required features: symphonia. ```APIDOC ## Sound::from_boxed_media_source ### Description Creates a `Sound` from a boxed `MediaSource`. ### Method `pub fn from_boxed_media_source(media_source: Box) -> Result` ### Parameters - **media_source** (Box) - Required - The media source to decode. ### Returns - `Result` - The created `Sound` or an error. ### Required Features `symphonia` ``` -------------------------------- ### include_sound macro definition Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/macro.include_sound.html Shows the macro_rules! definition for include_sound, which accepts a single path expression. The macro is available only when the `symphonia` feature is enabled. ```rust macro_rules! include_sound { ($path:expr) => { ... }; } ``` -------------------------------- ### Sound::add_command Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.Sound.html?search= Adds a command to the sound. ```APIDOC ## Sound::add_command ### Description Adds a command to the sound. See `Command` for more details. ### Method `pub fn add_command(&mut self, command: Command)` ### Parameters - **command** (Command) - Required - The command to add. ``` -------------------------------- ### SoundHandle::sample_rate Source: https://docs.rs/kittyaudio/0.2.0/kittyaudio/struct.SoundHandle.html?search= Returns the sample rate of the underlying Sound. ```APIDOC ## SoundHandle::sample_rate ### Description Delegate to the underlying `Sound`’s method. ### Method `pub fn sample_rate(&self) -> u32` ### Returns - `u32` - The sample rate. ```