#include "play_queue.h" | #include "play_queue.h" | ||||
#include "play_sd_raw.h" | #include "play_sd_raw.h" | ||||
#include "play_sd_wav.h" | #include "play_sd_wav.h" | ||||
#include "record_queue.h" | |||||
#include "synth_tonesweep.h" | #include "synth_tonesweep.h" | ||||
#include "synth_sine.h" | #include "synth_sine.h" | ||||
#include "synth_waveform.h" | #include "synth_waveform.h" |
<script type="text/javascript"> | |||||
RED.nodes.registerType('AudioRecordQueue',{ | |||||
shortName: "queue", | |||||
inputs:1, | |||||
outputs:0, | |||||
category: 'record-function', | |||||
color:"#E6E0F8", | |||||
icon: "arrow-in.png" | |||||
}); | |||||
</script> | |||||
<script type="text/x-red" data-help-name="AudioRecordQueue"> | |||||
<h3>Summary</h3> | |||||
<p>Record audio data by sending to the Arduino sketch. This object allows | |||||
sketch code to receive audio packets.</p> | |||||
<h3>Audio Connections</h3> | |||||
<table class=doc align=center cellpadding=3> | |||||
<tr class=top><th>Port</th><th>Purpose</th></tr> | |||||
<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>available</span>();</p> | |||||
<p class=desc>Returns the number of audio packets available to read. | |||||
</p> | |||||
<p class=func><span class=keyword>readBuffer</span>();</p> | |||||
<p class=desc>Read a single audio packet. A pointer to a 128 sample | |||||
array of 16 bit integers is returned. NULL is returned if no packets | |||||
are available. | |||||
</p> | |||||
<p class=func><span class=keyword>freeBuffer</span>();</p> | |||||
<p class=desc>Release the memory from the previously read packet returned | |||||
from readBuffer(). Only a single packet at a time may be read, and | |||||
each packet must be freed with this function, to return the memory to | |||||
the audio library. | |||||
</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 | |||||
sketch to write data to media or do other high-latency tasks. | |||||
The actual packets are taken | |||||
from the pool created by AudioMemory(). | |||||
</p> | |||||
</script> | |||||
<script type="text/x-red" data-template-name="AudioRecordQueue"> | |||||
<div class="form-row"> | |||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> | |||||
<input type="text" id="node-input-name" placeholder="Name"> | |||||
</div> | |||||
</script> | |||||
<script type="text/javascript"> | <script type="text/javascript"> | ||||
RED.nodes.registerType('AudioSynthWaveformSine',{ | RED.nodes.registerType('AudioSynthWaveformSine',{ | ||||
shortName: "sine", | shortName: "sine", |
/* Audio Library for Teensy 3.X | |||||
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com | |||||
* | |||||
* Development of this audio library was funded by PJRC.COM, LLC by sales of | |||||
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop | |||||
* open source software by purchasing Teensy or other PJRC products. | |||||
* | |||||
* Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
* of this software and associated documentation files (the "Software"), to deal | |||||
* in the Software without restriction, including without limitation the rights | |||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
* copies of the Software, and to permit persons to whom the Software is | |||||
* furnished to do so, subject to the following conditions: | |||||
* | |||||
* The above copyright notice, development funding notice, and this permission | |||||
* notice shall be included in all copies or substantial portions of the Software. | |||||
* | |||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||||
* THE SOFTWARE. | |||||
*/ | |||||
#include "record_queue.h" | |||||
#include "utility/dspinst.h" | |||||
int AudioRecordQueue::available(void) | |||||
{ | |||||
uint32_t h, t; | |||||
h = head; | |||||
t = tail; | |||||
if (h > t) return h - t; | |||||
return 53 + h - t; | |||||
} | |||||
int16_t * AudioRecordQueue::readBuffer(void) | |||||
{ | |||||
audio_block_t *block; | |||||
uint32_t t; | |||||
if (userblock) return NULL; | |||||
t = tail; | |||||
if (t == head) return NULL; | |||||
if (++t >= 53) t = 0; | |||||
userblock = queue[t]; | |||||
tail = t; | |||||
return userblock->data; | |||||
} | |||||
void AudioRecordQueue::freeBuffer(void) | |||||
{ | |||||
if (userblock == NULL) return; | |||||
release(userblock); | |||||
userblock = NULL; | |||||
} | |||||
void AudioRecordQueue::update(void) | |||||
{ | |||||
audio_block_t *block; | |||||
uint32_t h; | |||||
block = receiveReadOnly(); | |||||
if (!block) return; | |||||
h = head + 1; | |||||
if (h >= 53) h = 0; | |||||
if (h == tail) { | |||||
release(block); | |||||
} else { | |||||
queue[h] = block; | |||||
head = h; | |||||
} | |||||
} | |||||
/* Audio Library for Teensy 3.X | |||||
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com | |||||
* | |||||
* Development of this audio library was funded by PJRC.COM, LLC by sales of | |||||
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop | |||||
* open source software by purchasing Teensy or other PJRC products. | |||||
* | |||||
* Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
* of this software and associated documentation files (the "Software"), to deal | |||||
* in the Software without restriction, including without limitation the rights | |||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
* copies of the Software, and to permit persons to whom the Software is | |||||
* furnished to do so, subject to the following conditions: | |||||
* | |||||
* The above copyright notice, development funding notice, and this permission | |||||
* notice shall be included in all copies or substantial portions of the Software. | |||||
* | |||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||||
* THE SOFTWARE. | |||||
*/ | |||||
#ifndef record_queue_h_ | |||||
#define record_queue_h_ | |||||
#include "AudioStream.h" | |||||
class AudioRecordQueue : public AudioStream | |||||
{ | |||||
public: | |||||
AudioRecordQueue(void) : AudioStream(0, NULL), | |||||
userblock(NULL), head(0), tail(0) { } | |||||
int available(void); | |||||
int16_t * readBuffer(void); | |||||
void freeBuffer(void); | |||||
virtual void update(void); | |||||
private: | |||||
audio_block_t *inputQueueArray[1]; | |||||
audio_block_t *queue[53]; | |||||
audio_block_t *userblock; | |||||
volatile uint8_t head, tail; | |||||
}; | |||||
#endif |