瀏覽代碼

Can now cycle through different audio visualizations with button.

Also better filtering for audio data in AudioFirmware.
Thomas Buck 12 年之前
父節點
當前提交
cf21cd3ae3
共有 7 個檔案被更改,包括 702 行新增644 行删除
  1. 11
    4
      AudioFirmware/eq.c
  2. 42
    36
      AudioFirmware/main.hex
  3. 2
    1
      CubeFirmware/animations.c
  4. 2
    2
      CubeFirmware/header/visualizer.h
  5. 34
    30
      CubeFirmware/main.c
  6. 570
    559
      CubeFirmware/main.hex
  7. 41
    12
      CubeFirmware/visualizer.c

+ 11
- 4
AudioFirmware/eq.c 查看文件

@@ -46,6 +46,7 @@ uint8_t result[7] = {128, 128, 128, 128, 128, 128, 128};
46 46
 void equalizerInit(void);
47 47
 uint8_t *equalizerGet(void);
48 48
 void calcMultiplicator(uint8_t *d);
49
+void heightenTreble(uint8_t *d);
49 50
 void filterNoise(uint8_t *data);
50 51
 uint8_t getOffset(void);
51 52
 
@@ -74,8 +75,10 @@ uint8_t *equalizerGet(void) {
74 75
 	asm volatile ("nop"); // Ensure minimal reset pulse width
75 76
 	asm volatile ("nop"); // 2 NOPs at 16MHz are enough...
76 77
 
77
-	filterNoise(result);
78
-	calcMultiplicator(result);
78
+	filterNoise(result); // Filter lower values
79
+	heightenTreble(result); // Heighten higher frequencies, cause they seem damped
80
+	calcMultiplicator(result); // Multiply with Poti Position
81
+	filterNoise(result); // Filter lower values
79 82
 
80 83
 	return result;
81 84
 }
@@ -89,11 +92,15 @@ void calcMultiplicator(uint8_t *d) {
89 92
 	}
90 93
 }
91 94
 
95
+void heightenTreble(uint8_t *d) {
96
+	d[6] = d[5] * 10 / 15; // Get practically nothing on this channel. So fake something...
97
+}
98
+
92 99
 void filterNoise(uint8_t *data) {
93 100
 	uint8_t i;
94 101
 	for (i = 0; i < 7; i++) {
95
-		if (data[i] <= 40) {
96
-			data[i] = 0;
102
+		if (data[i] < 60) {
103
+			data[i] = data[i] * 10 / 15; // / 1.5
97 104
 		}
98 105
 	}
99 106
 }

+ 42
- 36
AudioFirmware/main.hex 查看文件

@@ -1,47 +1,53 @@
1 1
 :1000000012C02CC02BC02AC029C028C027C026C0BF
2 2
 :1000100025C024C023C022C021C020C01FC01EC0D4
3
-:100020001DC0CEC01BC011241FBECFE5D4E0DEBF73
4
-:10003000CDBF10E0A0E6B0E0E0EDF2E002C0059038
3
+:100020001DC0E9C01BC011241FBECFE5D4E0DEBF58
4
+:10003000CDBF10E0A0E6B0E0ECE2F3E002C0059036
5 5
 :100040000D92AE36B107D9F710E0AEE6B0E001C0D0
6
-:100050001D92A037B107E1F702D038C1D1CFCF93BD
6
+:100050001D92A037B107E1F702D066C1D1CFCF938F
7 7
 :1000600014BE88E10FB6F89481BD11BC0FBE86E0C6
8
-:1000700087BB8CE084BB11BA82E4F6D02ED03DD091
8
+:1000700087BB8CE084BB11BA82E411D12ED03DD075
9 9
 :1000800078942DE088E190E00FB6F894A89581BDB2
10
-:100090000FBE21BD80E690E0F0D0C4E0FCD0882304
11
-:1000A00029F088B38C2788BB61D0E7D0A895F6CF1C
10
+:100090000FBE21BD80E690E00BD1C4E017D18823CC
11
+:1000A00029F088B38C2788BB76D002D1A895F6CFEB
12 12
 :1000B00097B1907F97B997B18F70892B87B9369A8E
13 13
 :1000C000089581E0369980E00895FBDF8823E9F305
14 14
 :1000D000369824B135B1C901089517B83E9A86B152
15 15
 :1000E000856086B9379A80E0E3DFEFDF0895EDDFC2
16 16
 :1000F00096958795969587950895AB9AAA980895B1
17
-:10010000E82FF92F87E09081993208F4108281500E
18
-:1001100031968823C1F7089581E0CADFE8DF0895AA
19
-:100120001F93CF93DF93D82FC92FF6DF90E08C5920
20
-:100130009F4F6AE070E0B6D09B01CE01E92FF82F07
21
-:1001400010E0CAE0D0E0408150E0249FC001259F2C
22
-:10015000900D349F900D1124BE01A4D061931F5FB8
23
-:10016000173089F7DF91CF911F910895CF93DF93D7
24
-:10017000AB988FE191E00197F1F700C00000C0E675
25
-:10018000D0E0AA9A95E69A95F1F70000AA9880EC3B
26
-:100190008A95F1F780E08CDFAADF899390E0C7367B
27
-:1001A000D90779F7AB9A00000000CE010797A8DFC6
28
-:1001B000CE010797B5DFCE010797DF91CF91089564
29
-:1001C0001F920F920FB60F9211248F939F93EF936C
30
-:1001D000FF9381B190E0887F883B9105C1F0893B16
31
-:1001E00091053CF4883A910559F0803B910581F5E1
32
-:1001F00007C0803C910531F1883C910549F522C04A
33
-:1002000081E080936F008091670083B915C0809171
34
-:100210006F00863040F010926F0080916D0083B9BE
35
-:1002200086B78F7B11C0E82FF0E0E959FF4F90812E
36
-:1002300093B98F5F80936F0086B7806486BF1092FA
37
-:100240006E0006C086B7806486BF81E080936E0032
38
-:1002500086B7806886BFFF91EF919F918F910F9035
39
-:100260000FBE0F901F901895882311F481E001C0F4
40
-:100270008E7F82B985E486BF0895282F392FD90152
41
-:10028000E7E6F0E08D91819380E0EE36F807D1F754
42
-:1002900010926E00089581E090916E00992309F408
43
-:1002A00080E00895AA1BBB1B51E107C0AA1FBB1F1A
44
-:1002B000A617B70710F0A61BB70B881F991F5A95F2
45
-:1002C000A9F780959095BC01CD010895F894FFCFD2
46
-:0E02D0008080808080808042424242424242D2
17
+:10010000FC0195818AE0989FC00111246FE070E0A6
18
+:10011000F8D066830895CF93E82FF92F40E0CAE026
19
+:100120002FE030E080818C3330F48C9FC0011124AB
20
+:10013000B901E7D060834F5F3196473099F7CF918F
21
+:10014000089581E0B5DFD3DF08951F93CF93DF9348
22
+:10015000D82FC92FF6DF90E08C599F4F6AE070E0EE
23
+:10016000BCD09B01CE01E92FF82F10E0CAE0D0E00F
24
+:10017000408150E0249FC001259F900D349F900D39
25
+:100180001124BE01AAD061931F5F173089F7DF9158
26
+:10019000CF911F910895CF93DF93AB988FE191E0BA
27
+:1001A0000197F1F700C00000C0E6D0E0AA9A95E6FA
28
+:1001B0009A95F1F70000AA9880EC8A95F1F780E013
29
+:1001C00077DF95DF899390E0C736D90779F7AB9A47
30
+:1001D00000000000CE0107979EDFCE01079790DF59
31
+:1001E000CE010797B2DFCE01079795DFCE010797C3
32
+:1001F000DF91CF9108951F920F920FB60F921124A5
33
+:100200008F939F93EF93FF9381B190E0887F883B1A
34
+:100210009105C1F0893B91053CF4883A910559F06C
35
+:10022000803B910581F507C0803C910531F1883C08
36
+:10023000910549F522C081E080936F0080916700AD
37
+:1002400083B915C080916F00863040F010926F0026
38
+:1002500080916D0083B986B78F7B11C0E82FF0E0E5
39
+:10026000E959FF4F908193B98F5F80936F0086B7F4
40
+:10027000806486BF10926E0006C086B7806486BF19
41
+:1002800081E080936E0086B7806886BFFF91EF9112
42
+:100290009F918F910F900FBE0F901F9018958823FC
43
+:1002A00011F481E001C08E7F82B985E486BF089594
44
+:1002B000282F392FD901E7E6F0E08D91819380E076
45
+:1002C000EE36F807D1F710926E00089581E0909114
46
+:1002D0006E00992309F480E00895AA1BBB1B51E12D
47
+:1002E00007C0AA1FBB1FA617B70710F0A61BB70BA6
48
+:1002F000881F991F5A95A9F780959095BC01CD014B
49
+:10030000089597FB092E07260AD077FD04D0E5DF74
50
+:1003100006D000201AF4709561957F4F0895F6F786
51
+:0C032000909581959F4F0895F894FFCFB1
52
+:0E032C00808080808080804242424242424275
47 53
 :00000001FF

+ 2
- 1
CubeFirmware/animations.c 查看文件

@@ -195,7 +195,6 @@ void zWave2(void) {
195 195
 
196 196
 void tinyCube(void) {
197 197
 	uint8_t *buff;
198
-	int8_t x, y, z;
199 198
 
200 199
 	buff = buffNew();
201 200
 
@@ -245,6 +244,7 @@ void smallCube (void){
245 244
 	buffClearAllPixels(buff);
246 245
 	free(buff);
247 246
 }
247
+
248 248
 void bigCube (void) {
249 249
 	uint8_t *buff;
250 250
 	int8_t x, y, z;
@@ -278,6 +278,7 @@ void bigCube (void) {
278 278
 
279 279
 	free(buff);
280 280
 }
281
+
281 282
 void fullCube (void) {
282 283
 	uint8_t *buff;
283 284
 	int8_t x, y, z;

+ 2
- 2
CubeFirmware/header/visualizer.h 查看文件

@@ -20,5 +20,5 @@
20 20
  * You should have received a copy of the GNU General Public License
21 21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22 22
  */
23
-void simpleVisualization(uint8_t *data);
24
-void wave3DVisualization(uint8_t *data);
23
+uint8_t numberOfVisualizations(void);
24
+void runVisualization(uint8_t *data, uint8_t id);

+ 34
- 30
CubeFirmware/main.c 查看文件

@@ -74,6 +74,7 @@ void printTime(void);
74 74
 uint8_t shouldRestart = 0;
75 75
 uint8_t refreshAnimationCount = 1;
76 76
 uint8_t lastButtonState = 0;
77
+uint8_t maxButtonState = 0;
77 78
 uint8_t mcusr_mirror;
78 79
 char buffer[11];
79 80
 
@@ -85,7 +86,7 @@ uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: idle switch
85 86
 int main(void) {
86 87
 	uint8_t *audioData = NULL;
87 88
 	uint8_t *imageData = NULL;
88
-	uint8_t i, length = 0, lastMode;
89
+	uint8_t i, length = 0;
89 90
 	uint16_t count;
90 91
 	uint64_t lastChecked;
91 92
 	uint8_t idleCounter = 0;
@@ -147,10 +148,12 @@ int main(void) {
147 148
 	}
148 149
 #endif
149 150
 
150
-	lastMode = audioModeSelected();
151
+	maxButtonState = numberOfVisualizations() + 1; // All visualizations and anim mode
152
+
153
+	audioModeSelected();
151 154
 	lastChecked = getSystemTime();
152 155
 
153
-	i = 0;
156
+	i = 0; // Image count
154 157
 	count = getAnimationCount();
155 158
 
156 159
 	while (1) {
@@ -159,12 +162,13 @@ int main(void) {
159 162
 			wdt_reset();
160 163
 		}
161 164
 
162
-		if(lastMode) {
163
-			// Get Audio Data and visualize it
165
+		if(lastButtonState >= 1) {
166
+			// Get Audio Data and visualize it.
167
+			// Visualization id is in (lastButtonState - 1)
164 168
 			if (isFinished()) {
165 169
 				audioData = getAudioData(); // Not malloc'ed => Don't free
166 170
 				if (audioData != NULL) {
167
-					simpleVisualization(audioData);
171
+					runVisualization(audioData, lastButtonState - 1);
168 172
 				}
169 173
 			}
170 174
 		} else {
@@ -237,7 +241,7 @@ int main(void) {
237 241
 #endif
238 242
 
239 243
 		if ((getSystemTime() - lastChecked) > 150) { // Check button state every 150ms
240
-			lastMode = audioModeSelected();
244
+			audioModeSelected();
241 245
 			lastChecked = getSystemTime();
242 246
 		} 
243 247
 	}
@@ -246,6 +250,29 @@ int main(void) {
246 250
 	return 0;
247 251
 }
248 252
 
253
+uint8_t audioModeSelected(void) {
254
+	// Pushbutton: PB0, Low active
255
+
256
+	if (!(PINB & (1 << PB0))) {
257
+		// Button pushed
258
+		if (lastButtonState < (maxButtonState - 1)) {
259
+			lastButtonState++;
260
+		} else {
261
+			lastButtonState = 0;
262
+		}
263
+
264
+#ifdef DEBUG
265
+		if (lastButtonState) {
266
+			serialWriteString(getString(38));
267
+		} else {
268
+			serialWriteString(getString(39));
269
+		}
270
+#endif
271
+
272
+	}
273
+	return lastButtonState;
274
+}
275
+
249 276
 #ifdef DEBUG
250 277
 uint8_t selfTest(void) {
251 278
 	uint8_t result = NOERROR;
@@ -510,26 +537,3 @@ void printTime(void) {
510 537
 	}
511 538
 }
512 539
 #endif
513
-
514
-uint8_t audioModeSelected(void) {
515
-	// Pushbutton: PB0, Low active
516
-
517
-	if (!(PINB & (1 << PB0))) {
518
-		// Button pushed
519
-		if (lastButtonState == 0) {
520
-			lastButtonState = 1;
521
-		} else {
522
-			lastButtonState = 0;
523
-		}
524
-
525
-#ifdef DEBUG
526
-		if (lastButtonState) {
527
-			serialWriteString(getString(38));
528
-		} else {
529
-			serialWriteString(getString(39));
530
-		}
531
-#endif
532
-
533
-	}
534
-	return lastButtonState;
535
-}

+ 570
- 559
CubeFirmware/main.hex
文件差異過大導致無法顯示
查看文件


+ 41
- 12
CubeFirmware/visualizer.c 查看文件

@@ -27,30 +27,59 @@
27 27
 #include <cube.h>
28 28
 #include <buffhelp.h>
29 29
 
30
-void simpleVisualization(uint8_t *data) {
31
-	uint8_t *buff;
32
-	int8_t i, h, max, d;
30
+void simpleVisualization(uint8_t *data);
31
+void fullDepthVisualization(uint8_t *data);
33 32
 
34
-	buff = buffNew();
33
+#define NUMOFVISUALIZATIONS 2
35 34
 
36
-	buffClearAllPixels(buff);
35
+void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
36
+													&fullDepthVisualization };
37
+
38
+uint8_t numberOfVisualizations(void) {
39
+	return NUMOFVISUALIZATIONS;
40
+}
37 41
 
42
+void runVisualization(uint8_t *data, uint8_t id) {
43
+	if (id < NUMOFVISUALIZATIONS)
44
+		visualizations[id](data);
45
+}
46
+
47
+void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z) {
48
+	uint8_t i, h, max;
38 49
 	for(i = 0; i < 7; i++) {
39 50
 		max = data[i] / 31;
40
-		
41
-		// d = 7;
42
-		for (d = 0; d < 8; d++) {
43
-			// h = max;
44
-			for (h = 0; h < max; h++) {
45
-				buffSetPixel(buff, i, h, d);
51
+		for (h = 0; h < max; h++) {
52
+			if (i == 0) {
53
+				buffSetPixel(buff, i, h / 2, z);
46 54
 			}
55
+			buffSetPixel(buff, i + 1, h, z);
47 56
 		}
48 57
 	}
58
+}
59
+
60
+void simpleVisualization(uint8_t *data) {
61
+	uint8_t *buff;
62
+	buff = buffNew();
63
+
64
+	buffClearAllPixels(buff);
65
+
66
+	simpleVUMeter(data, buff, 7);
49 67
 
50 68
 	setImage(buff);
51 69
 	buffFree(buff);
52 70
 }
53 71
 
54
-void wave3DVisualization(uint8_t *data) {
72
+void fullDepthVisualization(uint8_t *data) {
73
+	uint8_t *buff;
74
+	uint8_t i;
75
+	buff = buffNew();
76
+
77
+	buffClearAllPixels(buff);
78
+
79
+	for (i = 0; i < 8; i++) {
80
+		simpleVUMeter(data, buff, i);
81
+	}
55 82
 
83
+	setImage(buff);
84
+	buffFree(buff);
56 85
 }

Loading…
取消
儲存