https://forum.pjrc.com/threads/58477-extend-Queue-object-for-Teensy-4-0-to-more-blocksdds
| if (!userblock) return; | if (!userblock) return; | ||||
| h = head + 1; | h = head + 1; | ||||
| if (h >= 32) h = 0; | |||||
| if (h >= max_buffers) h = 0; | |||||
| while (tail == h) ; // wait until space in the queue | while (tail == h) ; // wait until space in the queue | ||||
| queue[h] = userblock; | queue[h] = userblock; | ||||
| head = h; | head = h; | ||||
| t = tail; | t = tail; | ||||
| if (t != head) { | if (t != head) { | ||||
| if (++t >= 32) t = 0; | |||||
| if (++t >= max_buffers) t = 0; | |||||
| block = queue[t]; | block = queue[t]; | ||||
| tail = t; | tail = t; | ||||
| transmit(block); | transmit(block); |
| class AudioPlayQueue : public AudioStream | class AudioPlayQueue : public AudioStream | ||||
| { | { | ||||
| private: | |||||
| #if defined(__IMXRT1062__) || defined(__MK66FX1M0__) || defined(__MK64FX512__) | |||||
| static const int max_buffers = 80; | |||||
| #else | |||||
| static const int max_buffers = 32; | |||||
| #endif | |||||
| public: | public: | ||||
| AudioPlayQueue(void) : AudioStream(0, NULL), | AudioPlayQueue(void) : AudioStream(0, NULL), | ||||
| userblock(NULL), head(0), tail(0) { } | userblock(NULL), head(0), tail(0) { } | ||||
| //bool isPlaying(void) { return playing; } | //bool isPlaying(void) { return playing; } | ||||
| virtual void update(void); | virtual void update(void); | ||||
| private: | private: | ||||
| audio_block_t *queue[32]; | |||||
| audio_block_t *queue[max_buffers]; | |||||
| audio_block_t *userblock; | audio_block_t *userblock; | ||||
| volatile uint8_t head, tail; | volatile uint8_t head, tail; | ||||
| }; | }; |
| h = head; | h = head; | ||||
| t = tail; | t = tail; | ||||
| if (h >= t) return h - t; | if (h >= t) return h - t; | ||||
| return 53 + h - t; | |||||
| return max_buffers + h - t; | |||||
| } | } | ||||
| void AudioRecordQueue::clear(void) | void AudioRecordQueue::clear(void) | ||||
| } | } | ||||
| t = tail; | t = tail; | ||||
| while (t != head) { | while (t != head) { | ||||
| if (++t >= 53) t = 0; | |||||
| if (++t >= max_buffers) t = 0; | |||||
| release(queue[t]); | release(queue[t]); | ||||
| } | } | ||||
| tail = t; | tail = t; | ||||
| if (userblock) return NULL; | if (userblock) return NULL; | ||||
| t = tail; | t = tail; | ||||
| if (t == head) return NULL; | if (t == head) return NULL; | ||||
| if (++t >= 53) t = 0; | |||||
| if (++t >= max_buffers) t = 0; | |||||
| userblock = queue[t]; | userblock = queue[t]; | ||||
| tail = t; | tail = t; | ||||
| return userblock->data; | return userblock->data; | ||||
| return; | return; | ||||
| } | } | ||||
| h = head + 1; | h = head + 1; | ||||
| if (h >= 53) h = 0; | |||||
| if (h >= max_buffers) h = 0; | |||||
| if (h == tail) { | if (h == tail) { | ||||
| release(block); | release(block); | ||||
| } else { | } else { |
| class AudioRecordQueue : public AudioStream | class AudioRecordQueue : public AudioStream | ||||
| { | { | ||||
| private: | |||||
| #if defined(__IMXRT1062__) || defined(__MK66FX1M0__) || defined(__MK64FX512__) | |||||
| static const int max_buffers = 209; | |||||
| #else | |||||
| static const int max_buffers = 53; | |||||
| #endif | |||||
| public: | public: | ||||
| AudioRecordQueue(void) : AudioStream(1, inputQueueArray), | AudioRecordQueue(void) : AudioStream(1, inputQueueArray), | ||||
| userblock(NULL), head(0), tail(0), enabled(0) { } | userblock(NULL), head(0), tail(0), enabled(0) { } | ||||
| virtual void update(void); | virtual void update(void); | ||||
| private: | private: | ||||
| audio_block_t *inputQueueArray[1]; | audio_block_t *inputQueueArray[1]; | ||||
| audio_block_t * volatile queue[53]; | |||||
| audio_block_t * volatile queue[max_buffers]; | |||||
| audio_block_t *userblock; | audio_block_t *userblock; | ||||
| volatile uint8_t head, tail, enabled; | volatile uint8_t head, tail, enabled; | ||||
| }; | }; |