Pārlūkot izejas kodu

Finish AudioRecordQueue and Record example

dds
PaulStoffregen pirms 11 gadiem
vecāks
revīzija
aea5f90081
4 mainītis faili ar 47 papildinājumiem un 6 dzēšanām
  1. +12
    -1
      gui/list.html
  2. +2
    -0
      keywords.txt
  3. +21
    -1
      record_queue.cpp
  4. +12
    -4
      record_queue.h

+ 12
- 1
gui/list.html Parādīt failu

<tr class=odd><td align=center>In 0</td><td>Sound To Access</td></tr> <tr class=odd><td align=center>In 0</td><td>Sound To Access</td></tr>
</table> </table>
<h3>Functions</h3> <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=func><span class=keyword>available</span>();</p>
<p class=desc>Returns the number of audio packets available to read. <p class=desc>Returns the number of audio packets available to read.
</p> </p>
each packet must be freed with this function, to return the memory to each packet must be freed with this function, to return the memory to
the audio library. the audio library.
</p> </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> <h3>Notes</h3>
<p>TODO: many caveats....</p>
<p> <p>
Up to 52 packets may be queued by this object, which allows approximately 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 150 ms of audio to be held in the queue, to allow time for the Arduino

+ 2
- 0
keywords.txt Parādīt failu

AudioPlayMemory KEYWORD2 AudioPlayMemory KEYWORD2
AudioPlaySdRaw KEYWORD2 AudioPlaySdRaw KEYWORD2
AudioPlaySdWav KEYWORD2 AudioPlaySdWav KEYWORD2
AudioPlayQueue KEYWORD2
AudioRecordQueue KEYWORD2
AudioSynthToneSweep KEYWORD2 AudioSynthToneSweep KEYWORD2
AudioSynthWaveform KEYWORD2 AudioSynthWaveform KEYWORD2
AudioSynthWaveformSine KEYWORD2 AudioSynthWaveformSine KEYWORD2

+ 21
- 1
record_queue.cpp Parādīt failu



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 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) int16_t * AudioRecordQueue::readBuffer(void)
{ {


block = receiveReadOnly(); block = receiveReadOnly();
if (!block) return; if (!block) return;
if (!enabled) {
release(block);
return;
}
h = head + 1; h = head + 1;
if (h >= 53) h = 0; if (h >= 53) h = 0;
if (h == tail) { if (h == tail) {

+ 12
- 4
record_queue.h Parādīt failu

class AudioRecordQueue : public AudioStream class AudioRecordQueue : public AudioStream
{ {
public: 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); int available(void);
void clear(void);
int16_t * readBuffer(void); int16_t * readBuffer(void);
void freeBuffer(void); void freeBuffer(void);
void end(void) {
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 *queue[53];
audio_block_t * volatile queue[53];
audio_block_t *userblock; audio_block_t *userblock;
volatile uint8_t head, tail;
volatile uint8_t head, tail, enabled;
}; };


#endif #endif

Notiek ielāde…
Atcelt
Saglabāt