RISC-V/V003/keyboard/generator.h

23 lines
514 B
C
Raw Normal View History

2024-04-23 14:16:07 +02:00
#ifndef GENERATOR_H
#define GENERATOR_H
#include "oneway.h"
extern "C" const int16_t sin_tab[];
/* Něco jako DDS, přesná frekvence není řešena (závisí na TIM1). */
class Generator {
unsigned base, freq;
public:
explicit Generator () noexcept : base(0u), freq (0u) {};
int16_t step () {
const int16_t r = sin_tab [base >> 24];
base += freq;
return r;
}
void set (const unsigned f) {
if (!f) base = 0u;
freq = f;
}
protected:
};
#endif // GENERATOR_H