1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! # Generators
//! 
//! Module including many of the common/basic sound types, including sine,
//! sawtooth, square, white noise, and more.

use super::*;
use std::rc::Rc;

pub mod zero;
pub mod noise;
pub mod sawtooth;
pub mod sine;
pub mod square;
pub mod triangle;
pub mod mono_wav;

pub use zero::*;
pub use noise::*;
pub use sawtooth::*;
pub use sine::*;
pub use square::*;
pub use triangle::*;
pub use mono_wav::*;

/// Frequency Moderator. This trait defines types who take in a frequency as a
/// primary argument.
pub trait FreqMod {
    /// Creates a new object for the given frequency.
    /// 
    /// # Parameters
    /// 
    /// * `f` - The frequency for the new object
    fn new(f: MathT) -> Self;

    /// Sets the frequency of the given object.
    /// 
    /// # Parameters
    /// 
    /// * `f` - The new frequency.
    fn set_frequency(&mut self, f: MathT);

    /// Gets the current frequency of the given object.
    fn get_frequency(&self) -> MathT;
}

/// The `Generator` trait defines types that create audio samples.
pub trait Generator
{
    /// Generates a rendered audio sample
    fn process(&mut self) -> SampleT;
}

/// Type alias for a [`Generator`] wrapped in an [`Rc`].
/// 
/// [`Generator`]: trait.Generator.html
/// [`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
pub type GeneratorRc = Rc<dyn Generator>;