GithubHelp home page GithubHelp logo

hexagon5un / embed_with_elliot-circular_buffer Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 6.0 160 KB

Demo code to go along with Hackaday article on circular buffers

License: MIT License

Makefile 44.57% C 43.20% C++ 10.42% Shell 1.81%

embed_with_elliot-circular_buffer's People

Contributors

hexagon5un avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

embed_with_elliot-circular_buffer's Issues

using circular buffer for audio samples

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

define BUFFER_SIZE 16

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;
}
}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.