45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#ifndef DACPLAYER_H
|
|
#define DACPLAYER_H
|
|
#include "oneway.h"
|
|
#include "gpio.h"
|
|
#include "tone.h"
|
|
#include "audio.h"
|
|
#include "pwmclass.h"
|
|
#include "cache.h"
|
|
|
|
/// Třída, která hraje čistě na pozadí.
|
|
class MidiPlayer : public OneWay<uint16_t> {
|
|
// Veřejné metody
|
|
public:
|
|
/// Konstruktor
|
|
explicit MidiPlayer (GpioClass & io) noexcept;
|
|
unsigned Send (uint16_t * const ptr, const unsigned len) override;
|
|
void stop ();
|
|
void pass ();
|
|
protected:
|
|
// Chráněné metody
|
|
/// Obsluha tónu
|
|
void ToneChange (void);
|
|
/// Obsluha vzorku
|
|
short nextSample (void);
|
|
/// Generuj vzorek pro všechny tóny @return Vzorek
|
|
short genSample (void) {
|
|
int res = 0;
|
|
for (unsigned int i=0; i<maxGens; i++) res += gens[i].step();
|
|
// Pro jistotu omezíme - předejdeme chrastění
|
|
if (res > maxValue) res = maxValue;
|
|
if (res < minValue) res = minValue;
|
|
return (res);
|
|
}
|
|
private:
|
|
GpioClass & led;
|
|
Tone gens[maxGens]; /// Generátory tónů
|
|
unsigned passcnt;
|
|
volatile bool running;
|
|
Cache<uint32_t, 8u> scores;
|
|
Cache<uint8_t, 16u> melody;
|
|
volatile int pause;
|
|
|
|
};
|
|
|
|
#endif // DACPLAYER_H
|