-
-
- #include <Arduino.h>
- #include "play_queue.h"
- #include "utility/dspinst.h"
-
- bool AudioPlayQueue::available(void)
- {
- if (userblock) return true;
- userblock = allocate();
- if (userblock) return true;
- return false;
- }
-
- int16_t * AudioPlayQueue::getBuffer(void)
- {
- if (userblock) return userblock->data;
- while (1) {
- userblock = allocate();
- if (userblock) return userblock->data;
- yield();
- }
- }
-
- void AudioPlayQueue::playBuffer(void)
- {
- uint32_t h;
-
- if (!userblock) return;
- h = head + 1;
- if (h >= max_buffers) h = 0;
- while (tail == h) ;
- queue[h] = userblock;
- head = h;
- userblock = NULL;
- }
-
- void AudioPlayQueue::update(void)
- {
- audio_block_t *block;
- uint32_t t;
-
- t = tail;
- if (t != head) {
- if (++t >= max_buffers) t = 0;
- block = queue[t];
- tail = t;
- transmit(block);
- release(block);
- }
- }
|