Function sample::signal::square [] [src]

pub fn square<S>(phase: Phase<S>) -> Square<S>

Produces a Signal that yields a square wave oscillating at the given hz.

Example

extern crate sample;

use sample::signal;

fn main() {
    // Generates a square wave signal at 1hz to be sampled 4 times per second.
    let mut signal = signal::rate(4.0).const_hz(1.0).square();
    assert_eq!(signal.next(), Some([1.0]));
    assert_eq!(signal.next(), Some([1.0]));
    assert_eq!(signal.next(), Some([-1.0]));
    assert_eq!(signal.next(), Some([-1.0]));
}