hexagon5un / embed_with_elliot-circular_buffer Goto Github PK
View Code? Open in Web Editor NEWDemo code to go along with Hackaday article on circular buffers
License: MIT License
Demo code to go along with Hackaday article on circular buffers
License: MIT License
hi, I'm trying to use your circular buffer to buffer audio samples before sending them on over an RF module with an arduino due and an audio codec. There is actually a 64byte fifo buffer on the RF IC but I'd like to learn how to use circular buffers all the same !
I am finding it difficult to understand where or how i should copy in the samples to the curcular buffer. I would be greatful if you could point me in the right direction. hopfuly i'm not totally off track !! i removed all the RF and audio Codec code to try and make my problem clearer..
the samples come in at one sample at a time, so i'm not sure about your dump to UART example using a for loop.. should I send the cucular array one byte at a time and the array decides where the next free slot in the array is ?
Also where would I read data from ? how do I point to the least oldest byte in the array so I can send that over my RF module..
`// arduino circular buffer, digital audio TX
enum BufferStatus {BUFFER_OK, BUFFER_EMPTY, BUFFER_FULL};
enum BufferStatus status;
uint8_t byte_from_buffer;
uint8_t tempy;
enum BufferStatus status_tx;
uint8_t newAudioSamples[16]; // samples come in one at a time , but I could make a normal array of 16 bytes at a time ?
struct Buffer {
uint8_t data[BUFFER_SIZE];
uint8_t newest_index;
uint8_t oldest_index;};
// checks for writing data into the circular buffer ?
enum BufferStatus bufferWrite(uint8_t byte){
uint8_t next_index = (buffer.newest_index+1) % BUFFER_SIZE;
if (next_index == buffer.oldest_index){
return BUFFER_FULL;
}
buffer.data[buffer.newest_index] = byte;
buffer.newest_index = next_index;
return BUFFER_OK;
}
// checks for reading data from the circular buffer ?
enum BufferStatus bufferRead(uint8_t *byte){
if (buffer.newest_index == buffer.oldest_index){
return BUFFER_EMPTY;
}
*byte = buffer.data[buffer.oldest_index];
buffer.oldest_index = (buffer.oldest_index+1) % BUFFER_SIZE;
return BUFFER_OK;
}
void setup()
{
// initialise_audio_codec();
// initialise_RFmodule();
}
void loop()
{
rxDATA(); // recieve samples into circular buffer
txDATA(); // send samples form circular buffer to RF module
}
// RECIEVE DATA INTO BUFFER IF ROOM
void rxDATA
{
status_tx = bufferRead(&tx_buffer, &tempy);
if (status_tx == BUFFER_EMPTY){
return 0;
}
else {
for (uint8_t i=0; i<BUFFER_SIZE; i++){
&buffer.data(i) = newAudioSamples(i); /// ????? // should i specify an array position for samples, would'nt it be differnt? ?? how do i write into circular buffer?
}}
}
// SEND DATA
void txDATA
{
status = bufferRead(&byte_from_buffer);
if (status == BUFFER_OK) { /* we have data */
for (uint8_t i=0; i<BUFFER_SIZE; i++){
RH_RF24.send (&buffer.data(i) // dump TX data over RF module ??? do i need to specify an array position ??
}}
else
{
return;
}
}
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.