diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-04-11 22:53:00 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-04-11 22:56:43 +0200 |
commit | 0ba699511c136e0215fd2f75e2800be920221497 (patch) | |
tree | 93ada6042e058a9d0dcf074246b6c58fb282cdf7 /src/simulator | |
parent | 7c7cd71c56808610be6af41dbeb09637026414bb (diff) | |
download | glutte-o-matic-0ba699511c136e0215fd2f75e2800be920221497.tar.gz glutte-o-matic-0ba699511c136e0215fd2f75e2800be920221497.tar.bz2 glutte-o-matic-0ba699511c136e0215fd2f75e2800be920221497.zip |
Rework tone detector
- Send buffer pointers from ISR to userspace
- Use ADC interrupt to fetch data, not TIM6
- Increase size of buffer and do double-buffering
- Implement DTMF detectors
- Compare relative results instead of using absolute thresholds
- Add an IIR averaging filter on the results
Diffstat (limited to 'src/simulator')
-rw-r--r-- | src/simulator/src/Audio/audio_in.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/simulator/src/Audio/audio_in.c b/src/simulator/src/Audio/audio_in.c index d17e8bc..097eaf0 100644 --- a/src/simulator/src/Audio/audio_in.c +++ b/src/simulator/src/Audio/audio_in.c @@ -33,24 +33,30 @@ pa_simple *s_in = NULL; +static int16_t buffers[2][AUDIO_IN_BUF_LEN]; +static int current_buffer = 0; + static QueueHandle_t adc2_values_queue; static void audio_buffer_reader(void __attribute__((unused))*args) { while (1) { - int16_t buffer[AUDIO_IN_BUF_LEN]; - pa_simple_read(s_in, buffer, AUDIO_IN_BUF_LEN * sizeof(int16_t), NULL); + pa_simple_read(s_in, buffers[current_buffer], AUDIO_IN_BUF_LEN * sizeof(int16_t), NULL); + int success = xQueueSendToBack( adc2_values_queue, - buffer, + ¤t_buffer, portMAX_DELAY); assert(success); + + current_buffer = (current_buffer + 1) % 2; + taskYIELD(); } } -void audio_in_initialize(int rate) { +void audio_in_initialize() { int error; static pa_sample_spec ss = { @@ -59,12 +65,12 @@ void audio_in_initialize(int rate) { .channels = 1 }; - ss.rate = rate; + ss.rate = AUDIO_IN_RATE; s_in = pa_simple_new(NULL, "GlutteR", PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error); assert(s_in); - adc2_values_queue = xQueueCreate(4, AUDIO_IN_BUF_LEN); + adc2_values_queue = xQueueCreate(4, sizeof(current_buffer)); assert(adc2_values_queue); TaskHandle_t task_handle; @@ -77,8 +83,13 @@ void audio_in_initialize(int rate) { &task_handle); } -void audio_in_get_buffer(int16_t *buffer /*of length AUDIO_IN_BUF_LEN*/ ) +int32_t audio_in_get_buffer(int16_t **buffer /*of length AUDIO_IN_BUF_LEN*/ ) { - while (!xQueueReceive(adc2_values_queue, buffer, portMAX_DELAY)) {} + int last_written_buffer = 0; + while (!xQueueReceive(adc2_values_queue, &last_written_buffer, portMAX_DELAY)) {} + + *buffer = buffers[last_written_buffer]; + + return 0; } |