-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPatternAudio_Z_WaveSingle.h
251 lines (203 loc) · 6.37 KB
/
PatternAudio_Z_WaveSingle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* Aurora: https://github.com/pixelmatix/aurora
* Copyright (c) 2014 Jason Coon
*
* 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 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 PatternAudioWaveSingle_H
#define PatternAudioWaveSingle_H
class PatternAudioWaveSingle : public Drawable {
private:
uint8_t x0,y0,x1,y1;
bool flipVert = false;
bool diagonalLines = true;
bool diagonalOffset = 4;
uint8_t caleido = 0;
public:
PatternAudioWaveSingle()
{
name = (char *)"Audio Wave Single";
id2 = 1;
}
// #############
// ### START ###
// #############
void start(uint8_t _pattern){
flipVert = random(0,2); // 50% chance of bveing flipped
caleido = random(0,3); // 1 in 3 change of not getting caleidoscope
diagonalLines = random(0,10); // 1 in 10 chance we'll get dialgonal lines
diagonalOffset = diagonalLines ? 0 : 4;
// overidden for testing
caleido = 0;
flipVert = 0;
diagonalLines = 0;
diagonalOffset = 0;
};
// ##################
// ### DRAW FRAME ###
// ##################
unsigned int drawFrame(uint8_t _pattern, uint8_t _total) {
uint8_t data1;
uint8_t data2;
// temporary
effects.DimAll(100);
// draw on full screen
//bool invert = 0;
int8_t invert2 = -1;
for (byte i = 0; i < MATRIX_WIDTH - 4; i=i+2)
{
// use the 16 bins for these!
data1 = fftData.specData32[i/2] / 6;
data2 = fftData.specData32[(i/2) + 1] / 6;
// limit peaks
if (data1 > MATRIX_HEIGHT - 10) data1 = MATRIX_HEIGHT - 10;
if (data2 > MATRIX_HEIGHT - 10) data2 = MATRIX_HEIGHT - 10;
x0 = i;
y0 = (-data1 * invert2) + MATRIX_CENTER_Y;
x1 = x0 + 4;
y1 = (data2 * invert2) + MATRIX_CENTER_Y;
/*
if (!invert) {
x0 = i;
y0 = -data1 + MATRIX_CENTRE_Y;
x1 = x0 + 4;
y1 = data2 + MATRIX_CENTRE_Y;
}
else {
x0 = i;
y0 = data1 + MATRIX_CENTRE_Y;
x1 = x0 + 4;
y1 = -data2 + MATRIX_CENTRE_Y;
}
*/
// TODO: only draw bars if there is non zero data
if (!fftData.noAudio)
effects.BresenhamLine(x0, y0, x1, y1, 16);
// invert direction next loop
//invert = !invert;
invert2 = -invert2;
}
// TODO: only draw bars if there is non zero data
// final clean-up line
if (!fftData.noAudio)
effects.BresenhamLine(x1, y1, MATRIX_WIDTH, MATRIX_CENTER_Y, 16);
/*
// 16 simple peak only bars
// no caleidoscope version
if (!caleido)
{
// draw on full screen
uint8_t data;
for (byte i = 0; i < 64; i=i+4)
{
data = serialData.specData16[i/4] / 3;
if (data > 63) data = 63;
x1 = i;
x2 = i+4;
if (flipVert) {
y1 = data;
y2 = y1 + diagonalOffset;
}
else {
y1 = MATRIX_HEIGHT - data;
y2 = y1 - diagonalOffset;
}
// only draw bars if there is non zero data
if (data)
effects.BresenhamLine(x1, y1, x2, y2, dma_display->color565(128, 128, 128));
}
}
else
{
// draw on quarter of screen an create caleido effect
uint8_t data;
for (byte i = 0; i < 32; i=i+2)
{
data = serialData.specData16[i/2] / 6;
if (data > 31) data = 31;
x1 = i;
x2 = i+4;
if (flipVert) {
y1 = data;
y2 = y1 + (diagonalOffset/2);
}
else {
y1 = MATRIX_HEIGHT - data - 32;
y2 = y1 - (diagonalOffset/2);
}
// only draw bars if there is non zero data
if (data)
effects.BresenhamLine(x1, y1, x2, y2, dma_display->color565(128, 128, 128));
}
switch (caleido) {
case 1:
effects.Caleidoscope1();
break;
case 2:
effects.Caleidoscope2();
break;
}
}
*/
/*
// centered spectrum analyser
uint8_t space;
for (byte i = 0; i < 32; i++)
{
x1 = i;
y1 = MATRIX_HEIGHT - 1;
x2 = i;
y2 = MATRIX_HEIGHT -(serialData.specData32[i] / 3);
space = 64 - (y1 - y2);
y1 = y1 - (space/2);
y2 = y2 - (space/2);
effects.BresenhamLine(x1, y1, x2, y2, dma_display->color565(128, 128, 128));
}
*/
/*
for (byte i = 0; i < MATRIX_WIDTH; i++)
{
//effects.BresenhamLine(i, serialData.spec255Data[i] / 3, i, 0, dma_display->color565(128, 128, 128));
effects.BresenhamLine(i, MATRIX_WIDTH - 1, i, MATRIX_HEIGHT -(serialData.spec255Data[i] / 3), dma_display->color565(128, 128, 128));
}
*/
/*
for (byte i = 0; i < 32; i++)
{
effects.BresenhamLine(i, MATRIX_WIDTH - 1, i, MATRIX_HEIGHT -(serialData.specData32[i] / 3), dma_display->color565(128, 128, 128));
}
*/
/*
for (byte i = 0; i < 8; i++)
{
effects.BresenhamLine(i*2, MATRIX_WIDTH - 1, i*2, MATRIX_HEIGHT -(serialData.specData8[i] / 3), dma_display->color565(128, 128, 128));
}
*/
//////effects.ShowFrame();
return 0;
}
};
#endif
/*
//for (byte i = 0; i < MATRIX_WIDTH; i++)
for (byte i = 0; i < 32; i++)
{
effects.BresenhamLine(i, serialData.spec255Data[i] / 3, i, 0, dma_display->color565(128, 128, 128));
//effects.BresenhamLine(i, MATRIX_WIDTH - 1, i, MATRIX_HEIGHT -(serialData.specData32[i] / 3), dma_display->color565(128, 128, 128));
}
*/