|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
-
-
- #include <Arduino.h>
- #include "record_queue.h"
- #include "utility/dspinst.h"
-
-
- int AudioRecordQueue::available(void)
- {
- uint32_t h, t;
-
- h = head;
- t = tail;
- if (h >= t) return h - t;
- return 53 + h - t;
- }
-
- void AudioRecordQueue::clear(void)
- {
- uint32_t t;
-
- if (userblock) {
- release(userblock);
- userblock = NULL;
- }
- t = tail;
- while (t != head) {
- if (++t >= 53) t = 0;
- release(queue[t]);
- }
- tail = t;
- }
-
- int16_t * AudioRecordQueue::readBuffer(void)
- {
- uint32_t t;
-
- if (userblock) return NULL;
- t = tail;
- if (t == head) return NULL;
- if (++t >= 53) t = 0;
- userblock = queue[t];
- tail = t;
- return userblock->data;
- }
-
- void AudioRecordQueue::freeBuffer(void)
- {
- if (userblock == NULL) return;
- release(userblock);
- userblock = NULL;
- }
-
- void AudioRecordQueue::update(void)
- {
- audio_block_t *block;
- uint32_t h;
-
- block = receiveReadOnly();
- if (!block) return;
- if (!enabled) {
- release(block);
- return;
- }
- h = head + 1;
- if (h >= 53) h = 0;
- if (h == tail) {
- release(block);
- } else {
- queue[h] = block;
- head = h;
- }
- }
-
-
|