WavPlayer.h changed to circuit board
Dependents: WavPlayerSD WavPlayerUSB WavPlayerUSB WavPlayerSD_CB
RingBuffer/RingBuffer.cpp@4:b0186c8dca92, 2019-04-14 (annotated)
- Committer:
- JostBaus
- Date:
- Sun Apr 14 16:22:17 2019 +0000
- Revision:
- 4:b0186c8dca92
- Parent:
- 0:3695886f3495
Changed pins to match the circuit board, Replaced the wav_player.h lib with another one
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p07gbar | 0:3695886f3495 | 1 | |
p07gbar | 0:3695886f3495 | 2 | |
p07gbar | 0:3695886f3495 | 3 | #include "RingBuffer.h" |
p07gbar | 0:3695886f3495 | 4 | //Serial debug(USBTX,USBRX); |
p07gbar | 0:3695886f3495 | 5 | |
p07gbar | 0:3695886f3495 | 6 | RingBuffer::RingBuffer() |
p07gbar | 0:3695886f3495 | 7 | { |
p07gbar | 0:3695886f3495 | 8 | Start = 0; |
p07gbar | 0:3695886f3495 | 9 | Finish = 0; |
p07gbar | 0:3695886f3495 | 10 | for(int i = 0; i < RBLENGTH; i++) |
p07gbar | 0:3695886f3495 | 11 | { |
p07gbar | 0:3695886f3495 | 12 | for(int j = 0; j<RBWIDTH; j++) |
p07gbar | 0:3695886f3495 | 13 | { |
p07gbar | 0:3695886f3495 | 14 | Buffer[i][j] = 0; |
p07gbar | 0:3695886f3495 | 15 | } |
p07gbar | 0:3695886f3495 | 16 | } |
p07gbar | 0:3695886f3495 | 17 | //debug.baud(115200); |
p07gbar | 0:3695886f3495 | 18 | } |
p07gbar | 0:3695886f3495 | 19 | |
p07gbar | 0:3695886f3495 | 20 | int RingBuffer::addToBuffer(int* input) |
p07gbar | 0:3695886f3495 | 21 | { |
p07gbar | 0:3695886f3495 | 22 | if(Finish == Start && Samples != 0) |
p07gbar | 0:3695886f3495 | 23 | { |
p07gbar | 0:3695886f3495 | 24 | return -1; |
p07gbar | 0:3695886f3495 | 25 | } |
p07gbar | 0:3695886f3495 | 26 | else |
p07gbar | 0:3695886f3495 | 27 | { |
p07gbar | 0:3695886f3495 | 28 | for(int i = 0; i < RBWIDTH; i++) |
p07gbar | 0:3695886f3495 | 29 | { |
p07gbar | 0:3695886f3495 | 30 | Buffer[Finish][i] = input[i]; |
p07gbar | 0:3695886f3495 | 31 | } |
p07gbar | 0:3695886f3495 | 32 | sortFinishNS(); |
p07gbar | 0:3695886f3495 | 33 | return 0; |
p07gbar | 0:3695886f3495 | 34 | } |
p07gbar | 0:3695886f3495 | 35 | |
p07gbar | 0:3695886f3495 | 36 | } |
p07gbar | 0:3695886f3495 | 37 | |
p07gbar | 0:3695886f3495 | 38 | |
p07gbar | 0:3695886f3495 | 39 | int RingBuffer::addToBufferS(int input, int across) |
p07gbar | 0:3695886f3495 | 40 | { |
p07gbar | 0:3695886f3495 | 41 | Buffer[Finish][across] = input; |
p07gbar | 0:3695886f3495 | 42 | return 0; |
p07gbar | 0:3695886f3495 | 43 | } |
p07gbar | 0:3695886f3495 | 44 | |
p07gbar | 0:3695886f3495 | 45 | |
p07gbar | 0:3695886f3495 | 46 | |
p07gbar | 0:3695886f3495 | 47 | int RingBuffer::nextBuffer() |
p07gbar | 0:3695886f3495 | 48 | { |
p07gbar | 0:3695886f3495 | 49 | sortFinishNS(); |
p07gbar | 0:3695886f3495 | 50 | return 0; |
p07gbar | 0:3695886f3495 | 51 | } |
p07gbar | 0:3695886f3495 | 52 | |
p07gbar | 0:3695886f3495 | 53 | |
p07gbar | 0:3695886f3495 | 54 | |
p07gbar | 0:3695886f3495 | 55 | void RingBuffer::readFirst(int* output) |
p07gbar | 0:3695886f3495 | 56 | { |
p07gbar | 0:3695886f3495 | 57 | for(int i = 0; i < RBWIDTH; i++) |
p07gbar | 0:3695886f3495 | 58 | { |
p07gbar | 0:3695886f3495 | 59 | output[i] = Buffer[Start][i]; |
p07gbar | 0:3695886f3495 | 60 | } |
p07gbar | 0:3695886f3495 | 61 | } |
p07gbar | 0:3695886f3495 | 62 | |
p07gbar | 0:3695886f3495 | 63 | int RingBuffer::readFirstS(int across) |
p07gbar | 0:3695886f3495 | 64 | { |
p07gbar | 0:3695886f3495 | 65 | return Buffer[Start][across]; |
p07gbar | 0:3695886f3495 | 66 | } |
p07gbar | 0:3695886f3495 | 67 | |
p07gbar | 0:3695886f3495 | 68 | |
p07gbar | 0:3695886f3495 | 69 | |
p07gbar | 0:3695886f3495 | 70 | void RingBuffer::readAt(int* output, int at) |
p07gbar | 0:3695886f3495 | 71 | { |
p07gbar | 0:3695886f3495 | 72 | for(int i = 0; i < RBWIDTH; i++) |
p07gbar | 0:3695886f3495 | 73 | { |
p07gbar | 0:3695886f3495 | 74 | output[i] = Buffer[at][i]; |
p07gbar | 0:3695886f3495 | 75 | } |
p07gbar | 0:3695886f3495 | 76 | } |
p07gbar | 0:3695886f3495 | 77 | |
p07gbar | 0:3695886f3495 | 78 | int RingBuffer::readAtS(int at, int across) |
p07gbar | 0:3695886f3495 | 79 | { |
p07gbar | 0:3695886f3495 | 80 | return Buffer[at][across]; |
p07gbar | 0:3695886f3495 | 81 | } |
p07gbar | 0:3695886f3495 | 82 | |
p07gbar | 0:3695886f3495 | 83 | |
p07gbar | 0:3695886f3495 | 84 | |
p07gbar | 0:3695886f3495 | 85 | void RingBuffer::readLast(int*output) |
p07gbar | 0:3695886f3495 | 86 | { |
p07gbar | 0:3695886f3495 | 87 | for(int i = 0; i < RBWIDTH; i++) |
p07gbar | 0:3695886f3495 | 88 | { |
p07gbar | 0:3695886f3495 | 89 | output[i] = Buffer[Finish-1][i]; |
p07gbar | 0:3695886f3495 | 90 | } |
p07gbar | 0:3695886f3495 | 91 | } |
p07gbar | 0:3695886f3495 | 92 | |
p07gbar | 0:3695886f3495 | 93 | |
p07gbar | 0:3695886f3495 | 94 | int RingBuffer::readLastS(int across) |
p07gbar | 0:3695886f3495 | 95 | { |
p07gbar | 0:3695886f3495 | 96 | return Buffer[Finish-1][across]; |
p07gbar | 0:3695886f3495 | 97 | } |
p07gbar | 0:3695886f3495 | 98 | |
p07gbar | 0:3695886f3495 | 99 | void RingBuffer::usedFirst() |
p07gbar | 0:3695886f3495 | 100 | { |
p07gbar | 0:3695886f3495 | 101 | sortStartUS(); |
p07gbar | 0:3695886f3495 | 102 | } |
p07gbar | 0:3695886f3495 | 103 | |
p07gbar | 0:3695886f3495 | 104 | void RingBuffer::usedLast() |
p07gbar | 0:3695886f3495 | 105 | { |
p07gbar | 0:3695886f3495 | 106 | Finish--; |
p07gbar | 0:3695886f3495 | 107 | Samples--; |
p07gbar | 0:3695886f3495 | 108 | } |
p07gbar | 0:3695886f3495 | 109 | |
p07gbar | 0:3695886f3495 | 110 | int RingBuffer::numberStored() |
p07gbar | 0:3695886f3495 | 111 | { |
p07gbar | 0:3695886f3495 | 112 | if(Samples > RBLENGTH) |
p07gbar | 0:3695886f3495 | 113 | { |
p07gbar | 0:3695886f3495 | 114 | if(Finish < Start) |
p07gbar | 0:3695886f3495 | 115 | { |
p07gbar | 0:3695886f3495 | 116 | Samples = Finish + (RBLENGTH - Start); |
p07gbar | 0:3695886f3495 | 117 | } |
p07gbar | 0:3695886f3495 | 118 | else |
p07gbar | 0:3695886f3495 | 119 | { |
p07gbar | 0:3695886f3495 | 120 | Samples = Start - Finish; |
p07gbar | 0:3695886f3495 | 121 | } |
p07gbar | 0:3695886f3495 | 122 | } |
p07gbar | 0:3695886f3495 | 123 | return Samples; |
p07gbar | 0:3695886f3495 | 124 | } |
p07gbar | 0:3695886f3495 | 125 | |
p07gbar | 0:3695886f3495 | 126 | void RingBuffer::sortFinishNS() |
p07gbar | 0:3695886f3495 | 127 | { |
p07gbar | 0:3695886f3495 | 128 | Finish++; |
p07gbar | 0:3695886f3495 | 129 | Samples++; |
p07gbar | 0:3695886f3495 | 130 | if(Finish == RBLENGTH) |
p07gbar | 0:3695886f3495 | 131 | { |
p07gbar | 0:3695886f3495 | 132 | Finish = 0; |
p07gbar | 0:3695886f3495 | 133 | //debug.printf("\n\rBOO! %3i %3i\n\r",Start, Finish); |
p07gbar | 0:3695886f3495 | 134 | } |
p07gbar | 0:3695886f3495 | 135 | |
p07gbar | 0:3695886f3495 | 136 | } |
p07gbar | 0:3695886f3495 | 137 | |
p07gbar | 0:3695886f3495 | 138 | void RingBuffer::sortStartUS() |
p07gbar | 0:3695886f3495 | 139 | { |
p07gbar | 0:3695886f3495 | 140 | Start++; |
p07gbar | 0:3695886f3495 | 141 | Samples--; |
p07gbar | 0:3695886f3495 | 142 | if(Start == RBLENGTH) |
p07gbar | 0:3695886f3495 | 143 | { |
p07gbar | 0:3695886f3495 | 144 | Start = 0; |
p07gbar | 0:3695886f3495 | 145 | } |
p07gbar | 0:3695886f3495 | 146 | } |