diff --git a/src/main.cpp b/src/main.cpp index 96ac429..47da70a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,42 @@ SDCard sdcard; Sound sound; Ringbuf ringbuf = Ringbuf((size_t) BUF_LENGTH); -void sd_read_task(void *pvParameter) { - sdcard.open("/T1.wav"); +TaskHandle_t xTaskRead = NULL; +TaskHandle_t xTaskWrite = NULL; +bool playing = false; + +static const char *soundFile[3][3] = {{"/T0.wav", "/T1.wav", "/T2.wav"}, + {"/T3.wav", "/T4.wav", "/T5.wav"}, + {"/T6.wav", "/T7.wav", "/T8.wav"}}; + +void i2s_write_task(void *pvParameter) { + sound.play(); + for ( ;; ) { + //TickType_t delay = 10 / portTICK_PERIOD_MS; // max delay: 10ms instead of portMAX_DELAY + uint16_t *start_ptr = ringbuf.getRead(); + size_t size_avail = ringbuf.getReadAvail(); + int num_samples = 0; + for (int i=0; iread_pos = 0; this->write_pos = 0; this->full = false; + this->active = false; } Ringbuf::~Ringbuf() { diff --git a/src/ringbuf.h b/src/ringbuf.h index 97b627e..4409376 100644 --- a/src/ringbuf.h +++ b/src/ringbuf.h @@ -17,6 +17,7 @@ class Ringbuf { void setWrite(size_t bytes); void setRead(size_t bytes); bool full; + bool active = false; private: }; diff --git a/src/sound.cpp b/src/sound.cpp index 17b4148..0845ebb 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -76,10 +76,12 @@ void Sound::init() { void Sound::play() { i2s_start(i2s_num); + playing = true; } void Sound::stop() { i2s_stop(i2s_num); + playing = false; } void Sound::end() { diff --git a/src/sound.h b/src/sound.h index 763e4bc..452f5a9 100644 --- a/src/sound.h +++ b/src/sound.h @@ -27,6 +27,7 @@ class Sound { void stop(); int render_sample_block(uint16_t *sample_buf_left, uint16_t *sample_buf_right, int num_samples); const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM; + bool playing; private: i2sbuffer_t buffer;