fn step(&mut self, div: u16) -> Option<u16> {
        if self.step_duration == 0 {
            // Sweep OFF, do nothing
            return Some(div);
        }

        self.counter += 1;
        self.counter %= self.step_duration;

        if self.counter != 0 {
            // Do nothing and wait for the next step
            return Some(div);
        }

        // Update the frequency
        let offset = div >> (self.shift as usize);

        match self.direction {
            SweepDirection::Up => {
                let div = div + offset;

                if div > 0x7ff {
                    // We stop on overflow
                    None
                } else {
                    Some(div)
                }
            }
            SweepDirection::Down => {
                if self.shift == 0 || offset > div {
                    // If the substraction would underflow we do
                    // nothing
                    Some(div)
                } else {
                    Some(div - offset)
                }
            }
        }
    }
/// Step through the Sweep state machine, returning the updated
/// divider or None if the sound must be stopped
Step through the Sweep state machine, returning the updated
divider or None if the sound must be stopped
Step through the Sweep state machine returning the updated divider or None if the sound must be stopped
fn step(&mut self, div: u16) -> Option<u16> {
        if self.step_duration == 0 {
            // Sweep OFF, do nothing
            return Some(div);
        }
        self.counter += 1;
        self.counter %= self.step_duration;
        if self.counter != 0 {
            // Do nothing and wait for the next step
            return Some(div);
        }
        // Update the frequency
        let offset = div >> (self.shift as usize);
        match self.direction {
            SweepDirection::Up => {
                let div = div + offset;
                if div > 0x7ff {
                    // We stop on overflow
                    None
                } else {
                    Some(div)
                }
            }
            SweepDirection::Down => {
                if self.shift == 0 || offset > div {
                    // If the substraction would underflow we do
                    // nothing
                    Some(div)
                } else {
                    Some(div - offset)
                }
            }
        }
    }
fn step ( & mut self , div : u16 ) -> Option < u16 > { if self . step_duration == 0 { // Sweep OFF, do nothing return Some ( div ) ; } self . counter += 1 ; self . counter %= self . step_duration ; if self . counter != 0 { // Do nothing and wait for the next step return Some ( div ) ; } // Update the frequency let offset = div >> ( self . shift as usize ) ; match self . direction { SweepDirection :: Up => { let div = div + offset ; if div > 0x7ff { // We stop on overflow None } else { Some ( div ) } } SweepDirection :: Down => { if self . shift == 0 || offset > div { // If the substraction would underflow we do // nothing Some ( div ) } else { Some ( div - offset ) } } } }
Step through the Sweep state machine, returning the updated
divider or None if the sound must be stopped
Step through the Sweep state machine returning the updated divider or None if the sound must be stopped
&mut self
div
u16
&mut self
div
u16