Trait audio_generator::Generator[][src]

pub trait Generator {
    type Sample;
    fn sample(&mut self) -> Self::Sample;

    fn iter(self) -> Iter<Self>
    where
        Self: Sized
, { ... }
fn amplitude(self, amplitude: f32) -> Amplitude<Self>
    where
        Self: Sized
, { ... } }

The trait for an audio generator.

Associated Types

type Sample[src]

The sample that is generated.

Loading content...

Required methods

fn sample(&mut self) -> Self::Sample[src]

Generate the next sample from the generator. Advances the underlying generator to the next sample.

Examples

use audio_generator::{Generator, Sin};

let mut g = Sin::new(440.0, 44100.0);
assert_eq!(g.sample(), 0.0);
assert!(g.sample() > 0.0);
Loading content...

Provided methods

fn iter(self) -> Iter<Self> where
    Self: Sized
[src]

Construct an iterator from this generator.

use audio_generator::{Generator, Sin};

let mut g = Sin::new(440.0, 44100.0).amplitude(0.5);
let samples = g.iter().take(10).collect::<Vec<f32>>();

assert_eq!(samples.len(), 10);

fn amplitude(self, amplitude: f32) -> Amplitude<Self> where
    Self: Sized
[src]

Modify the amplitude of the sample.

Examples

use audio_generator::{Generator, Sin};

let mut a = Sin::new(440.0, 44100.0).amplitude(0.1);
let mut b = Sin::new(440.0, 44100.0).amplitude(0.1);

for _ in 0..100 {
    assert!(a.sample().abs() <= b.sample().abs());
}
Loading content...

Implementors

impl Generator for Sin[src]

type Sample = f32

Loading content...