PaulStoffregen 4 years ago
parent
commit
0d02a205df
4 changed files with 20 additions and 8 deletions
  1. +2
    -2
      play_queue.cpp
  2. +7
    -1
      play_queue.h
  3. +4
    -4
      record_queue.cpp
  4. +7
    -1
      record_queue.h

+ 2
- 2
play_queue.cpp View File

@@ -52,7 +52,7 @@ void AudioPlayQueue::playBuffer(void)

if (!userblock) return;
h = head + 1;
if (h >= 32) h = 0;
if (h >= max_buffers) h = 0;
while (tail == h) ; // wait until space in the queue
queue[h] = userblock;
head = h;
@@ -66,7 +66,7 @@ void AudioPlayQueue::update(void)

t = tail;
if (t != head) {
if (++t >= 32) t = 0;
if (++t >= max_buffers) t = 0;
block = queue[t];
tail = t;
transmit(block);

+ 7
- 1
play_queue.h View File

@@ -32,6 +32,12 @@

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:
AudioPlayQueue(void) : AudioStream(0, NULL),
userblock(NULL), head(0), tail(0) { }
@@ -44,7 +50,7 @@ public:
//bool isPlaying(void) { return playing; }
virtual void update(void);
private:
audio_block_t *queue[32];
audio_block_t *queue[max_buffers];
audio_block_t *userblock;
volatile uint8_t head, tail;
};

+ 4
- 4
record_queue.cpp View File

@@ -36,7 +36,7 @@ int AudioRecordQueue::available(void)
h = head;
t = tail;
if (h >= t) return h - t;
return 53 + h - t;
return max_buffers + h - t;
}

void AudioRecordQueue::clear(void)
@@ -49,7 +49,7 @@ void AudioRecordQueue::clear(void)
}
t = tail;
while (t != head) {
if (++t >= 53) t = 0;
if (++t >= max_buffers) t = 0;
release(queue[t]);
}
tail = t;
@@ -62,7 +62,7 @@ int16_t * AudioRecordQueue::readBuffer(void)
if (userblock) return NULL;
t = tail;
if (t == head) return NULL;
if (++t >= 53) t = 0;
if (++t >= max_buffers) t = 0;
userblock = queue[t];
tail = t;
return userblock->data;
@@ -87,7 +87,7 @@ void AudioRecordQueue::update(void)
return;
}
h = head + 1;
if (h >= 53) h = 0;
if (h >= max_buffers) h = 0;
if (h == tail) {
release(block);
} else {

+ 7
- 1
record_queue.h View File

@@ -32,6 +32,12 @@

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:
AudioRecordQueue(void) : AudioStream(1, inputQueueArray),
userblock(NULL), head(0), tail(0), enabled(0) { }
@@ -49,7 +55,7 @@ public:
virtual void update(void);
private:
audio_block_t *inputQueueArray[1];
audio_block_t * volatile queue[53];
audio_block_t * volatile queue[max_buffers];
audio_block_t *userblock;
volatile uint8_t head, tail, enabled;
};

Loading…
Cancel
Save