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
impl Pulse
Sourcepub const fn new(volume: u8) -> Self
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.
Sourcepub const fn note(self, note: Note, octave: u8) -> Self
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.
Sourcepub const fn at_period(self, period: u16) -> Self
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.
Sourcepub const fn duty(self, duty: Duty) -> Self
pub const fn duty(self, duty: Duty) -> Self
Set the fraction of each cycle the wave spends high.
Sourcepub const fn envelope(self, pace: u8, increase: bool) -> Self
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.
Sourcepub const fn length(self, ticks: u8) -> Self
pub const fn length(self, ticks: u8) -> Self
Stop the channel after ticks of a 256 Hz count, at most 64.
Sourcepub fn play_ch1(&self, sweep: Sweep)
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.
Sourcepub fn retune_ch1(&self)
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.
Sourcepub fn retune_ch2(&self)
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.
Sourcepub fn set_duty_ch1(&self)
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.
Sourcepub fn set_duty_ch2(&self)
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.