Skip to main content

Pulse

Struct Pulse 

Source
pub struct Pulse { /* private fields */ }
Expand description

A pulse channel’s settings.

Channels 1 and 2 differ only in that 1 has a frequency sweep, so one of these plays on either.

Implementations§

Source§

impl Pulse

Source

pub const fn new(volume: u8) -> Self

A 50% square wave at volume, out of 15, and the lowest period.

A volume of 0 is not a quiet sound but a stopped channel: it turns the DAC off, and a channel whose DAC is off will not start.

Source

pub const fn note(self, note: Note, octave: u8) -> Self

Tune to note at octave.

C2 through B5 comes out within about five cents. There is nothing below C2 to reach and the pitch stops there; above B5 the period value runs out of resolution and drifts, a quarter tone off by the eighth octave.

Source

pub const fn at_period(self, period: u16) -> Self

Tune to a period value, which counts up rather than down: the larger it is, the higher the pitch. At most $7FF.

Source

pub const fn duty(self, duty: Duty) -> Self

Set the fraction of each cycle the wave spends high.

Source

pub const fn envelope(self, pace: u8, increase: bool) -> Self

Step the volume every pace ticks of a 64 Hz count, up or down.

A pace of 0 holds the volume where Pulse::new put it.

Source

pub const fn length(self, ticks: u8) -> Self

Stop the channel after ticks of a 256 Hz count, at most 64.

Source

pub fn play_ch1(&self, sweep: Sweep)

Play on channel 1, with sweep bending the pitch as it goes.

The sweep is asked for because it belongs to the channel rather than to these settings, and one left over from an earlier sound would bend this one. Sweep::new leaves the pitch alone.

The trigger decides whether a sweep runs at all, so a note started without one cannot be given one part way through.

A rising sweep is checked against the top as the note is triggered: a step that would carry a high note past $7FF in one move cuts it before anything is heard. The smaller the step number, the larger the move. A falling sweep cannot reach the top and is never cut.

Source

pub fn play_ch2(&self)

Play on channel 2.

Source

pub fn retune_ch1(&self)

Change the pitch on channel 1 without starting the note over.

A running sweep holds its own copy of the pitch and writes that back at its next step, so this reaches a channel playing without one.

Source

pub fn retune_ch2(&self)

Change the pitch on channel 2 without starting the note over.

The envelope and the waveform carry on from where they are, as a slide or a vibrato needs. Pulse::play_ch2 restarts both.

Source

pub fn set_duty_ch1(&self)

Change the duty on channel 1 without starting the note over.

The length timer shares the register and starts over with it.

Source

pub fn set_duty_ch2(&self)

Change the duty on channel 2 without starting the note over.

The length timer shares the register and starts over with it.

Trait Implementations§

Source§

impl Clone for Pulse

Source§

fn clone(&self) -> Pulse

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Pulse

Source§

impl Eq for Pulse

Source§

impl PartialEq for Pulse

Source§

fn eq(&self, other: &Pulse) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Pulse

Auto Trait Implementations§

§

impl BankSafe for Pulse

§

impl Freeze for Pulse

§

impl RefUnwindSafe for Pulse

§

impl Send for Pulse

§

impl Sync for Pulse

§

impl Unpin for Pulse

§

impl UnsafeUnpin for Pulse

§

impl UnwindSafe for Pulse

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CellValue for T
where T: Copy + BankSafe,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.