mirror of
https://github.com/jscrane/r65emu.git
synced 2024-12-30 09:30:46 +00:00
cleanup sound
This commit is contained in:
parent
6b0f1c387d
commit
96440c61f5
11
sound.cpp
11
sound.cpp
@ -3,17 +3,19 @@
|
|||||||
#include "timed.h"
|
#include "timed.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
|
static Sound *s;
|
||||||
|
|
||||||
#if defined(DAC_SOUND) && defined(ESP_PLATFORM)
|
#if defined(DAC_SOUND) && defined(ESP_PLATFORM)
|
||||||
#include <driver/dac.h>
|
#include <driver/dac.h>
|
||||||
|
|
||||||
static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
|
||||||
static dac_channel_t channel;
|
static dac_channel_t channel;
|
||||||
|
|
||||||
static volatile const uint8_t *_bytes;
|
|
||||||
static volatile unsigned _size, _off;
|
|
||||||
|
|
||||||
void IRAM_ATTR timer_callback() {
|
void IRAM_ATTR timer_callback() {
|
||||||
|
s->on_tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR Sound::on_tick() {
|
||||||
portENTER_CRITICAL_ISR(&mux);
|
portENTER_CRITICAL_ISR(&mux);
|
||||||
|
|
||||||
if (_off < _size)
|
if (_off < _size)
|
||||||
@ -32,6 +34,7 @@ void Sound::begin(unsigned pin, unsigned freq) {
|
|||||||
else if (pin == 26)
|
else if (pin == 26)
|
||||||
channel = DAC_CHANNEL_2;
|
channel = DAC_CHANNEL_2;
|
||||||
|
|
||||||
|
s = this;
|
||||||
timer_create(freq, &timer_callback);
|
timer_create(freq, &timer_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
sound.h
5
sound.h
@ -5,6 +5,11 @@ class Sound {
|
|||||||
public:
|
public:
|
||||||
void begin(unsigned pin, unsigned freq);
|
void begin(unsigned pin, unsigned freq);
|
||||||
const uint8_t *play(const uint8_t *bytes, unsigned size);
|
const uint8_t *play(const uint8_t *bytes, unsigned size);
|
||||||
|
void on_tick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
volatile const uint8_t *_bytes;
|
||||||
|
volatile unsigned _size, _off;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user