Browse Source

Change dsp::Counter to dsp::ClockDivider

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
e8fc76ca8b
1 changed files with 18 additions and 19 deletions
  1. +18
    -19
      include/dsp/digital.hpp

+ 18
- 19
include/dsp/digital.hpp View File

@@ -130,36 +130,35 @@ struct Timer {
};


/** Counts the number of `process()` calls.
If `period > 0`, `count` is reset to 0 when that number is reached.
Useful for clock dividing and waiting to fill a fixed buffer.
*/
struct Counter {
int count;
int period = 0;

Counter() {
struct ClockDivider {
int clock;
int division = 1;

ClockDivider() {
reset();
}

void reset() {
count = 0;
clock = 0;
}

void setPeriod(int period) {
this->period = period;
reset();
void setDivision(int division) {
this->division = division;
}

int getDivision() {
return division;
}

int getCount() {
return count;
int getClock() {
return clock;
}

/** Returns true when the counter reaches `period` and resets. */
/** Returns true when the clock reaches `division` and resets. */
bool process() {
count++;
if (count == period) {
count = 0;
clock++;
if (clock >= division) {
clock = 0;
return true;
}
return false;


Loading…
Cancel
Save