summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-12-19 04:50:02 +0100
committerUros Majstorovic <majstor@majstor.org>2019-12-19 04:50:02 +0100
commit08d725acb1638106bab46e29be8496b5d6db1cd3 (patch)
tree89ed80c9fa3094a29ad4b7ac5a20948fd34cce75
parentb66e67e3a5f2680ee0e44228fce0fcaeff87206b (diff)
flush buffer on cell pcm start
-rw-r--r--code/esp32/components/eos/cell_pcm.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/code/esp32/components/eos/cell_pcm.c b/code/esp32/components/eos/cell_pcm.c
index 426cd5f..71fe2f9 100644
--- a/code/esp32/components/eos/cell_pcm.c
+++ b/code/esp32/components/eos/cell_pcm.c
@@ -31,6 +31,7 @@ static unsigned char *pcm_bufq_array[PCM_SIZE_BUFQ];
static EOSMsgQ pcm_evt_q;
static EOSMsgItem pcm_evtq_array[PCM_SIZE_BUFQ];
+static char pcm_running;
static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1};
@@ -207,12 +208,16 @@ int eos_pcm_push(unsigned char *data, size_t size) {
unsigned char *buf = NULL;
ssize_t esize;
int rv;
+ char running;
if (size > PCM_MIC_WM) return EOS_ERR;
xSemaphoreTake(mutex, portMAX_DELAY);
- buf = eos_bufq_pop(&pcm_buf_q);
+ running = pcm_running;
+ if (running) buf = eos_bufq_pop(&pcm_buf_q);
xSemaphoreGive(mutex);
+
+ if (!running) return EOS_ERR;
if (buf == NULL) return EOS_ERR_EMPTY;
esize = eos_pcm_expand(buf, data, size);
@@ -238,8 +243,26 @@ void eos_pcm_start(void) {
xQueueSend(i2s_queue, (void *)&evt, portMAX_DELAY);
i2s_zero_dma_buffer(I2S_NUM_0);
i2s_start(I2S_NUM_0);
+ xSemaphoreTake(mutex, portMAX_DELAY);
+ while (1) {
+ unsigned char _type;
+ unsigned char *buf;
+ uint16_t len;
+
+ eos_msgq_pop(&pcm_evt_q, &_type, &buf, &len, NULL);
+ if (buf) {
+ eos_bufq_push(&pcm_buf_q, buf);
+ } else {
+ break;
+ }
+ }
+ pcm_running = 1;
+ xSemaphoreGive(mutex);
}
void eos_pcm_stop(void) {
i2s_stop(I2S_NUM_0);
+ xSemaphoreTake(mutex, portMAX_DELAY);
+ pcm_running = 0;
+ xSemaphoreGive(mutex);
}