uni_snd/
lib.rs

1#![recursion_limit = "256"]
2extern crate cpal;
3extern crate uni_app;
4
5pub mod snd;
6pub use self::snd::*;
7
8#[derive(Debug, Clone, Copy)]
9/// error produced when creating the [`SoundDriver`]
10pub enum SoundError {
11    /// sound initialization was a success
12    NoError,
13    /// no sound device was found
14    NoDevice,
15    /// could not create an output stream
16    OutputStream,
17    /// unsupported output stream format
18    UnknownStreamFormat,
19}
20
21/// You must provide a struct implementing this trait to the driver.
22///
23/// This is what generates the samples to be send to the audio output.
24pub trait SoundGenerator<T>: Send {
25    /// the sound driver calls this function during initialization to provide the audio interface sample rate.
26    fn init(&mut self, sample_rate: f32);
27    /// Because the sound generator runs in a separate thread,
28    /// you can only communicate with it through events using [`SoundDriver::send_event`].
29    /// This is where you should handle those events.
30    fn handle_event(&mut self, evt: T);
31    /// This is the function generating the samples.
32    /// Remember this is stereo output, you have to generate samples alternatively for the left and right channels.
33    /// Sample values should be between -1.0 and 1.0.
34    fn next_value(&mut self) -> f32;
35}