This is early stages of my project, the idea of this project is to be able to mix a guitar with windows sounds in reverse such as instrumental background music or trance music perhaps or maybe another fellow guitarist you may have downloaded from the internet. Microphone or guitar pin is p19 I would use a microphone for drums:) and that it for the moment, the code makes the mbed act as usb speaker that excepts a guitar or microphone input, but with a twist it all in reverse like a guitar reverse effects pedal but only you can mix anything you can get from the internet or any windows sound.

Dependencies:   mbed

Committer:
mbed2f
Date:
Sun Jan 08 17:28:24 2012 +0000
Revision:
0:7610d342c76e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed2f 0:7610d342c76e 1 #ifndef CIRCBUFFER_H
mbed2f 0:7610d342c76e 2 #define CIRCBUFFER_H
mbed2f 0:7610d342c76e 3
mbed2f 0:7610d342c76e 4 template <class T>
mbed2f 0:7610d342c76e 5 class CircBuffer {
mbed2f 0:7610d342c76e 6 public:
mbed2f 0:7610d342c76e 7 CircBuffer(int length) {
mbed2f 0:7610d342c76e 8 write = 0;
mbed2f 0:7610d342c76e 9 read = 0;
mbed2f 0:7610d342c76e 10 size = length + 1;
mbed2f 0:7610d342c76e 11 buf = (T *)malloc(size * sizeof(T));
mbed2f 0:7610d342c76e 12 };
mbed2f 0:7610d342c76e 13
mbed2f 0:7610d342c76e 14 bool isFull() {
mbed2f 0:7610d342c76e 15 return ((write + 1) % size == read);
mbed2f 0:7610d342c76e 16 };
mbed2f 0:7610d342c76e 17
mbed2f 0:7610d342c76e 18 bool isEmpty() {
mbed2f 0:7610d342c76e 19 return (read == write);
mbed2f 0:7610d342c76e 20 };
mbed2f 0:7610d342c76e 21
mbed2f 0:7610d342c76e 22 void queue(T k) {
mbed2f 0:7610d342c76e 23 if (isFull()) {
mbed2f 0:7610d342c76e 24 read++;
mbed2f 0:7610d342c76e 25 read %= size;
mbed2f 0:7610d342c76e 26 }
mbed2f 0:7610d342c76e 27 buf[write++] = k;
mbed2f 0:7610d342c76e 28 write %= size;
mbed2f 0:7610d342c76e 29 }
mbed2f 0:7610d342c76e 30
mbed2f 0:7610d342c76e 31 uint16_t available() {
mbed2f 0:7610d342c76e 32 return (write >= read) ? write - read : size - read + write;
mbed2f 0:7610d342c76e 33 };
mbed2f 0:7610d342c76e 34
mbed2f 0:7610d342c76e 35 bool dequeue(T * c) {
mbed2f 0:7610d342c76e 36 bool empty = isEmpty();
mbed2f 0:7610d342c76e 37 if (!empty) {
mbed2f 0:7610d342c76e 38 *c = buf[read++];
mbed2f 0:7610d342c76e 39 read %= size;
mbed2f 0:7610d342c76e 40 }
mbed2f 0:7610d342c76e 41 return(!empty);
mbed2f 0:7610d342c76e 42 };
mbed2f 0:7610d342c76e 43
mbed2f 0:7610d342c76e 44 private:
mbed2f 0:7610d342c76e 45 volatile uint16_t write;
mbed2f 0:7610d342c76e 46 volatile uint16_t read;
mbed2f 0:7610d342c76e 47 uint16_t size;
mbed2f 0:7610d342c76e 48 T * buf;
mbed2f 0:7610d342c76e 49 };
mbed2f 0:7610d342c76e 50
mbed2f 0:7610d342c76e 51 #endif