Selaa lähdekoodia

Audio Visualizer.

Wrote new audio visualizer. Created help functions to operate on a 3D
image buffer.
Thomas Buck 12 vuotta sitten
vanhempi
commit
50254710ec

+ 89
- 0
CubeFirmware/buffhelp.c Näytä tiedosto

@@ -0,0 +1,89 @@
1
+/*
2
+ * buffhelp.h
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+#include <avr/io.h>
24
+#include <stdint.h>
25
+#include <stdlib.h>
26
+#include <serial.h>
27
+#include <strings.h>
28
+
29
+uint8_t *buffNew(void) {
30
+	uint8_t *tmp = (uint8_t *)malloc(64);
31
+	if (tmp == NULL) {
32
+#ifdef DEBUG
33
+		serialWriteString(getString(24));
34
+#endif
35
+		while(1); // Ran out of heap => Watchdog Reset
36
+	}
37
+	return tmp;
38
+}
39
+
40
+void buffSetPixel(uint8_t *buffer, uint8_t x, uint8_t y, uint8_t z) {
41
+	buffer[(8 * z) + (7 - y)] |= (1 << x);
42
+}
43
+
44
+void buffClearPixel(uint8_t *buffer, uint8_t x, uint8_t y, uint8_t z) {
45
+	buffer[(8 * z) + (7 - y)] &= ~(1 << x);
46
+}
47
+
48
+void buffFillRect(uint8_t *buffer, uint8_t x1, uint8_t y1, uint8_t z1,
49
+					uint8_t x2, uint8_t y2, uint8_t z2, uint8_t value) {
50
+	uint8_t depth, depthMax, depthMin, x, xMax, xMin, y, yMax, yMin;
51
+
52
+	if (z1 <= z2) {
53
+		depthMin = z1;
54
+		depthMax = z2;
55
+	} else {
56
+		depthMin = z2;
57
+		depthMax = z1;
58
+	}
59
+	if (x1 <= x2) {
60
+		xMin = x1;
61
+		xMax = x2;
62
+	} else {
63
+		xMin = x2;
64
+		xMax = x1;
65
+	}
66
+	if (y1 <= y2) {
67
+		yMin = y1;
68
+		yMax = y2;
69
+	} else {
70
+		yMin = y2;
71
+		yMax = y1;
72
+	}
73
+	for (depth = depthMin; depth <= depthMax; depth++) {
74
+		// now draw a 2d rectangle, z = depth
75
+		for (x = xMin; x <= xMax; x++) {
76
+			for (y = yMin; y <= yMax; y++) {
77
+				if (value) {
78
+					buffSetPixel(buffer, x, y, depth);
79
+				} else {
80
+					buffClearPixel(buffer, x, y, depth);
81
+				}
82
+			}
83
+		}
84
+	}
85
+}
86
+
87
+void buffFree(uint8_t *buffer) {
88
+	free(buffer);
89
+}

+ 28
- 0
CubeFirmware/header/buffhelp.h Näytä tiedosto

@@ -0,0 +1,28 @@
1
+/*
2
+ * buffhelp.h
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+uint8_t *buffNew(void);
24
+void buffSetPixel(uint8_t *buffer, uint8_t x, uint8_t y, uint8_t z);
25
+void buffClearPixel(uint8_t *buffer, uint8_t x, uint8_t y, uint8_t z);
26
+void buffFillRect(uint8_t *buffer, uint8_t x1, uint8_t y1, uint8_t z1,
27
+					uint8_t x2, uint8_t y2, uint8_t z2, uint8_t value);
28
+void buffFree(uint8_t *buffer);

+ 24
- 0
CubeFirmware/header/visualizer.h Näytä tiedosto

@@ -0,0 +1,24 @@
1
+/*
2
+ * visualizer.h
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+void simpleVisualization(uint8_t *data);
24
+void wave3DVisualization(uint8_t *data);

+ 2
- 111
CubeFirmware/main.c Näytä tiedosto

@@ -44,6 +44,7 @@
44 44
 #include "memLayer.h"
45 45
 #include "twi.h"
46 46
 #include "strings.h"
47
+#include "visualizer.h"
47 48
 
48 49
 #define NOERROR 0
49 50
 // Audio does not answer
@@ -63,9 +64,6 @@ void sendAudioData(void);
63 64
 void recieveAnimations(void);
64 65
 void transmitAnimations(void);
65 66
 uint8_t audioModeSelected(void);
66
-void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf);
67
-void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
68
-void visualizeAudioData(uint8_t *audioData, uint8_t *imageData);
69 67
 #ifdef DEBUG
70 68
 void printErrors(uint8_t e);
71 69
 uint8_t selfTest(void);
@@ -205,16 +203,7 @@ int main(void) {
205 203
 			if (isFinished()) {
206 204
 				audioData = getAudioData(); // Not malloc'ed => Don't free
207 205
 				if (audioData != NULL) {
208
-					imageData = (uint8_t *)malloc(64);
209
-					if (imageData == NULL) {
210
-#ifdef DEBUG
211
-						serialWriteString(getString(24));
212
-#endif
213
-						while(1); // Ran out of heap => Watchdog Reset
214
-					}
215
-					visualizeAudioData(audioData, imageData);
216
-					setImage(imageData);
217
-					free(imageData);
206
+					simpleVisualization(audioData);
218 207
 				}
219 208
 			}
220 209
 		} else {
@@ -724,101 +713,3 @@ uint8_t audioModeSelected(void) {
724 713
 	}
725 714
 	return lastButtonState;
726 715
 }
727
-
728
-void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
729
-	uint8_t i = 0;
730
-	for (; i < height; i++) {
731
-		setPixelBuffer(x, i, z, buf);
732
-	}
733
-}
734
-
735
-void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
736
-	buf[(8 * z) + (7 - y)] |= (1 << x);
737
-}
738
-
739
-void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {
740
-	uint8_t i;
741
-	for (i = 0; i < 64; i++) {
742
-		imageData[i] = 0;
743
-	}
744
-
745
-	// 8 LEDs, Max Val 255:
746
-	// 256 / 8 = 32 => Divide by 31 (FACTOR) to get num of leds to light
747
-	// 255 / FACTOR = 8,...
748
-	// 127 / FACTOR = 4,...
749
-
750
-	#define FACTOR 31
751
-
752
-	// Could not figure out a way to represent this easily in a loop
753
-	// without using a shitload of 'if's...
754
-	setRow(0, 0, (audioData[0] / FACTOR), imageData);
755
-	setRow(0, 1, (audioData[0] / FACTOR), imageData);
756
-	setRow(1, 0, (audioData[0] / FACTOR), imageData);
757
-
758
-	setRow(0, 2, (audioData[1] / FACTOR), imageData);
759
-	setRow(0, 3, (audioData[1] / FACTOR), imageData);
760
-	setRow(1, 1, (audioData[1] / FACTOR), imageData);
761
-	setRow(1, 2, (audioData[1] / FACTOR), imageData);
762
-	setRow(2, 0, (audioData[1] / FACTOR), imageData);
763
-	setRow(2, 1, (audioData[1] / FACTOR), imageData);
764
-
765
-	setRow(0, 4, (audioData[2] / FACTOR), imageData);
766
-	setRow(0, 5, (audioData[2] / FACTOR), imageData);
767
-	setRow(1, 3, (audioData[2] / FACTOR), imageData);
768
-	setRow(1, 4, (audioData[2] / FACTOR), imageData);
769
-	setRow(2, 2, (audioData[2] / FACTOR), imageData);
770
-	setRow(2, 3, (audioData[2] / FACTOR), imageData);
771
-	setRow(3, 0, (audioData[2] / FACTOR), imageData);
772
-	setRow(3, 1, (audioData[2] / FACTOR), imageData);
773
-	setRow(3, 2, (audioData[2] / FACTOR), imageData);
774
-	setRow(4, 0, (audioData[2] / FACTOR), imageData);
775
-	setRow(4, 1, (audioData[2] / FACTOR), imageData);
776
-
777
-	setRow(0, 6, (audioData[3] / FACTOR), imageData);
778
-	setRow(0, 7, (audioData[3] / FACTOR), imageData);
779
-	setRow(1, 5, (audioData[3] / FACTOR), imageData);
780
-	setRow(1, 6, (audioData[3] / FACTOR), imageData);
781
-	setRow(2, 4, (audioData[3] / FACTOR), imageData);
782
-	setRow(2, 5, (audioData[3] / FACTOR), imageData);
783
-	setRow(3, 3, (audioData[3] / FACTOR), imageData);
784
-	setRow(3, 4, (audioData[3] / FACTOR), imageData);
785
-	setRow(4, 2, (audioData[3] / FACTOR), imageData);
786
-	setRow(4, 3, (audioData[3] / FACTOR), imageData);
787
-	setRow(5, 0, (audioData[3] / FACTOR), imageData);
788
-	setRow(5, 1, (audioData[3] / FACTOR), imageData);
789
-	setRow(5, 2, (audioData[3] / FACTOR), imageData);
790
-	setRow(6, 0, (audioData[3] / FACTOR), imageData);
791
-	setRow(6, 1, (audioData[3] / FACTOR), imageData);
792
-
793
-	setRow(1, 7, (audioData[4] / FACTOR), imageData);
794
-	setRow(2, 6, (audioData[4] / FACTOR), imageData);
795
-	setRow(2, 7, (audioData[4] / FACTOR), imageData);
796
-	setRow(3, 5, (audioData[4] / FACTOR), imageData);
797
-	setRow(3, 6, (audioData[4] / FACTOR), imageData);
798
-	setRow(4, 4, (audioData[4] / FACTOR), imageData);
799
-	setRow(4, 5, (audioData[4] / FACTOR), imageData);
800
-	setRow(5, 3, (audioData[4] / FACTOR), imageData);
801
-	setRow(5, 4, (audioData[4] / FACTOR), imageData);
802
-	setRow(6, 2, (audioData[4] / FACTOR), imageData);
803
-	setRow(6, 3, (audioData[4] / FACTOR), imageData);
804
-	setRow(7, 0, (audioData[4] / FACTOR), imageData);
805
-	setRow(7, 1, (audioData[4] / FACTOR), imageData);
806
-
807
-	setRow(3, 7, (audioData[5] / FACTOR), imageData);
808
-	setRow(4, 6, (audioData[5] / FACTOR), imageData);
809
-	setRow(4, 7, (audioData[5] / FACTOR), imageData);
810
-	setRow(5, 5, (audioData[5] / FACTOR), imageData);
811
-	setRow(5, 6, (audioData[5] / FACTOR), imageData);
812
-	setRow(6, 4, (audioData[5] / FACTOR), imageData);
813
-	setRow(6, 5, (audioData[5] / FACTOR), imageData);
814
-	setRow(7, 2, (audioData[5] / FACTOR), imageData);
815
-	setRow(7, 3, (audioData[5] / FACTOR), imageData);
816
-	setRow(7, 4, (audioData[5] / FACTOR), imageData);
817
-
818
-	setRow(5, 7, (audioData[6] / FACTOR), imageData);
819
-	setRow(6, 6, (audioData[6] / FACTOR), imageData);
820
-	setRow(6, 7, (audioData[6] / FACTOR), imageData);
821
-	setRow(7, 5, (audioData[6] / FACTOR), imageData);
822
-	setRow(7, 6, (audioData[6] / FACTOR), imageData);
823
-	setRow(7, 7, (audioData[6] / FACTOR), imageData);
824
-}

+ 2
- 0
CubeFirmware/makefile Näytä tiedosto

@@ -45,6 +45,8 @@ SRC += audio.c
45 45
 SRC += time.c
46 46
 SRC += memLayer.c
47 47
 SRC += strings.c
48
+SRC += buffhelp.c
49
+SRC += visualizer.c
48 50
 
49 51
 # List Assembler source files here.
50 52
 # Make them always end in a capital .S.  Files ending in a lowercase .s

+ 47
- 0
CubeFirmware/visualizer.c Näytä tiedosto

@@ -0,0 +1,47 @@
1
+/*
2
+ * visualizer.c
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+#include <avr/io.h>
24
+#include <stdint.h>
25
+
26
+#include <visualizer.h>
27
+#include <cube.h>
28
+#include <buffhelp.h>
29
+
30
+void simpleVisualization(uint8_t *data) {
31
+	uint8_t *buff;
32
+
33
+	buff = buffNew();
34
+	buffFillRect(buff, 0, data[0] / 31, 0, 0, 0, 7, 1);
35
+	buffFillRect(buff, 1, data[1] / 31, 0, 1, 0, 7, 1);
36
+	buffFillRect(buff, 2, data[2] / 31, 0, 2, 0, 7, 1);
37
+	buffFillRect(buff, 3, data[3] / 31, 0, 3, 0, 7, 1);
38
+	buffFillRect(buff, 4, data[4] / 31, 0, 4, 0, 7, 1);
39
+	buffFillRect(buff, 5, data[5] / 31, 0, 5, 0, 7, 1);
40
+	buffFillRect(buff, 6, data[6] / 31, 0, 6, 0, 7, 1);
41
+	setImage(buff);
42
+	buffFree(buff);
43
+}
44
+
45
+void wave3DVisualization(uint8_t *data) {
46
+
47
+}

Loading…
Peruuta
Tallenna