Skip to content

Commit fde9a04

Browse files
Flush output buffer after transmission & startup (#45)
During transmission, the buffer is being filled with data received. However the concept of walkie talkie is that it is not being buffered, as it creates problems.
1 parent 1b3df6a commit fde9a04

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/audio_output/src/OutputBuffer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,14 @@ class OutputBuffer
100100
}
101101
xSemaphoreGive(m_semaphore);
102102
}
103+
104+
void flush()
105+
{
106+
// flush all samples in the outputbuffer
107+
xSemaphoreTake(m_semaphore, portMAX_DELAY);
108+
m_read_head = 0;
109+
m_write_head = 0;
110+
m_available_samples = 0;
111+
xSemaphoreGive(m_semaphore);
112+
}
103113
};

src/Application.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void Application::begin()
9999
pinMode(GPIO_TRANSMIT_BUTTON, INPUT_PULLDOWN);
100100
// start off with i2S output running
101101
m_output->start(SAMPLE_RATE);
102+
// flush all samples received during startup
103+
m_output_buffer->flush();
102104
// start the main task for the application
103105
TaskHandle_t task_handle;
104106
xTaskCreate(application_task, "application_task", 8192, this, 1, &task_handle);
@@ -132,7 +134,10 @@ void Application::loop()
132134
m_transport->add_sample(samples[i]);
133135
}
134136
}
137+
// send all packets still in the transport buffer
135138
m_transport->flush();
139+
// throw away all packets that have been received during transmission
140+
m_output_buffer->flush();
136141
// finished transmitting stop the input and start the output
137142
Serial.println("Finished transmitting");
138143
m_indicator_led->set_is_flashing(false, 0xff0000);

0 commit comments

Comments
 (0)