| @@ -667,6 +667,11 @@ | |||
| <tr class=odd><td align=center>In 0</td><td>Sound To Access</td></tr> | |||
| </table> | |||
| <h3>Functions</h3> | |||
| <p class=func><span class=keyword>begin</span>();</p> | |||
| <p class=desc>Begin capturing incoming audio to the queue. After calling | |||
| begin, readBuffer() and freeBuffer(), or clear() must be used frequently | |||
| to prevent the queue from filling up. | |||
| </p> | |||
| <p class=func><span class=keyword>available</span>();</p> | |||
| <p class=desc>Returns the number of audio packets available to read. | |||
| </p> | |||
| @@ -681,8 +686,14 @@ | |||
| each packet must be freed with this function, to return the memory to | |||
| the audio library. | |||
| </p> | |||
| <p class=func><span class=keyword>clear</span>();</p> | |||
| <p class=desc>Discard all audio held in the queue. | |||
| </p> | |||
| <p class=func><span class=keyword>end</span>();</p> | |||
| <p class=desc>Stop capturing incoming audio into the queue. Data already | |||
| captured remains in the queue and may be read with readBuffer(). | |||
| </p> | |||
| <h3>Notes</h3> | |||
| <p>TODO: many caveats....</p> | |||
| <p> | |||
| Up to 52 packets may be queued by this object, which allows approximately | |||
| 150 ms of audio to be held in the queue, to allow time for the Arduino | |||
| @@ -26,6 +26,8 @@ AudioOutputAnalog KEYWORD2 | |||
| AudioPlayMemory KEYWORD2 | |||
| AudioPlaySdRaw KEYWORD2 | |||
| AudioPlaySdWav KEYWORD2 | |||
| AudioPlayQueue KEYWORD2 | |||
| AudioRecordQueue KEYWORD2 | |||
| AudioSynthToneSweep KEYWORD2 | |||
| AudioSynthWaveform KEYWORD2 | |||
| AudioSynthWaveformSine KEYWORD2 | |||
| @@ -34,10 +34,26 @@ int AudioRecordQueue::available(void) | |||
| h = head; | |||
| t = tail; | |||
| if (h > t) return h - t; | |||
| if (h >= t) return h - t; | |||
| return 53 + h - t; | |||
| } | |||
| void AudioRecordQueue::clear(void) | |||
| { | |||
| audio_block_t *block; | |||
| 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) | |||
| { | |||
| @@ -67,6 +83,10 @@ void AudioRecordQueue::update(void) | |||
| block = receiveReadOnly(); | |||
| if (!block) return; | |||
| if (!enabled) { | |||
| release(block); | |||
| return; | |||
| } | |||
| h = head + 1; | |||
| if (h >= 53) h = 0; | |||
| if (h == tail) { | |||
| @@ -32,17 +32,25 @@ | |||
| class AudioRecordQueue : public AudioStream | |||
| { | |||
| public: | |||
| AudioRecordQueue(void) : AudioStream(0, NULL), | |||
| userblock(NULL), head(0), tail(0) { } | |||
| AudioRecordQueue(void) : AudioStream(1, inputQueueArray), | |||
| userblock(NULL), head(0), tail(0), enabled(0) { } | |||
| void begin(void) { | |||
| clear(); | |||
| enabled = 1; | |||
| } | |||
| int available(void); | |||
| void clear(void); | |||
| int16_t * readBuffer(void); | |||
| void freeBuffer(void); | |||
| void end(void) { | |||
| enabled = 0; | |||
| } | |||
| virtual void update(void); | |||
| private: | |||
| audio_block_t *inputQueueArray[1]; | |||
| audio_block_t *queue[53]; | |||
| audio_block_t * volatile queue[53]; | |||
| audio_block_t *userblock; | |||
| volatile uint8_t head, tail; | |||
| volatile uint8_t head, tail, enabled; | |||
| }; | |||
| #endif | |||