Browse Source

Improved Visualizer.

Thomas Buck 12 years ago
parent
commit
a03216caee
3 changed files with 976 additions and 948 deletions
  1. 928
    922
      CubeFirmware/main.hex
  2. 44
    18
      CubeFirmware/visualizer.c
  3. 4
    8
      lookUp.c

+ 928
- 922
CubeFirmware/main.hex
File diff suppressed because it is too large
View File


+ 44
- 18
CubeFirmware/visualizer.c View File

@@ -31,7 +31,12 @@
31 31
 					// 256 / 8 = 32 => Divide by 31 (FACTOR) to get num of leds to light
32 32
 					// 255 / FACTOR = 8,...
33 33
 					// 127 / FACTOR = 4,...
34
+ #define THRESHOLD (FACTOR * 10 / 17)
34 35
 
36
+uint8_t maxVal(uint8_t data, uint8_t log);
37
+void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
38
+uint8_t average(uint8_t *data);
39
+void filterData(uint8_t *data);
35 40
 void simpleVisualization(uint8_t *data);
36 41
 void fullDepthVisualization(uint8_t *data);
37 42
 void horribleWave(uint8_t *audioData);
@@ -39,33 +44,56 @@ void simpleLog(uint8_t *data);
39 44
 void fullDepthLog(uint8_t *data);
40 45
 
41 46
 #define NUMOFVISUALIZATIONS 5
42
-
43 47
 void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
44 48
 													&fullDepthVisualization, &horribleWave,
45 49
 													&simpleLog, &fullDepthLog };
50
+uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 }; // --> ca. (1 << (led + 1));
46 51
 
47 52
 uint8_t numberOfVisualizations(void) {
48 53
 	return NUMOFVISUALIZATIONS;
49 54
 }
50 55
 
51 56
 void runVisualization(uint8_t *data, uint8_t id) {
52
-	if (id < NUMOFVISUALIZATIONS)
57
+	if (id < NUMOFVISUALIZATIONS) {
58
+		filterData(data);
53 59
 		visualizations[id](data);
60
+	}
54 61
 }
55 62
 
56
-uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 };
57
-// --> ca. (1 << (led + 1));
63
+uint8_t maxVal(uint8_t data, uint8_t log) {
64
+	uint8_t max = 0;
65
+	if (log) {
66
+		while ((max <= 7) && (data > logScale[max])) // Some bitshifting would do it...
67
+			max++; // But this is more fine grained
68
+	} else {
69
+		max = data / FACTOR;
70
+	}
71
+	return max;
72
+}
73
+
74
+uint8_t average(uint8_t *data) {
75
+	uint16_t sum = 0;
76
+	uint8_t i;
77
+	for (i = 0; i < 7; i++) {
78
+		sum += data[i];
79
+	}
80
+	sum /= 7;
81
+	return (uint8_t)sum;
82
+}
83
+
84
+void filterData(uint8_t *data) {
85
+	uint8_t i;
86
+	if (average(data) < THRESHOLD) {
87
+		for (i = 0; i < 7; i++) {
88
+			data[i] = 0;
89
+		}
90
+	}
91
+}
58 92
 
59 93
 void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z, uint8_t log) {
60 94
 	uint8_t i, h = 0, max;
61 95
 	for(i = 0; i < 7; i++) {
62
-		if (log) {
63
-			while ((h <= 7) && (data[i] > logScale[h])) // Some bitshifting would do it...
64
-				h++; // But this is more fine grained
65
-			max = h;
66
-		} else {
67
-			max = data[i] / FACTOR;
68
-		}
96
+		max = maxVal(data[i], log);
69 97
 		for (h = 0; h < max; h++) {
70 98
 			if (i == 0) {
71 99
 				buffSetPixel(buff, i, (h * 10 / 15), z);
@@ -81,6 +109,7 @@ void simpleLog(uint8_t *data) {
81 109
 	buff = buffNew();
82 110
 	buffClearAllPixels(buff);
83 111
 
112
+	setRow(0, 0, maxVal(average(data), 1), buff); // Show average
84 113
 	simpleVUMeter(data, buff, 7, 1);
85 114
 
86 115
 	setImage(buff);
@@ -93,6 +122,7 @@ void simpleVisualization(uint8_t *data) {
93 122
 
94 123
 	buffClearAllPixels(buff);
95 124
 
125
+	setRow(0, 0, maxVal(average(data), 0), buff); // Show average
96 126
 	simpleVUMeter(data, buff, 7, 0);
97 127
 
98 128
 	setImage(buff);
@@ -129,14 +159,10 @@ void fullDepthVisualization(uint8_t *data) {
129 159
 	buffFree(buff);
130 160
 }
131 161
 
132
-void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
133
-	buf[(8 * (7 - z)) + (7 - y)] |= (1 << x); // z is inverted for beauty reasons
134
-}
135
-
136 162
 void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
137
-	uint8_t i = 0;
138
-	for (; i < height; i++) {
139
-		setPixelBuffer(x, i, z, buf);
163
+	uint8_t i;
164
+	for (i = 0; i < height; i++) {
165
+		buffSetPixel(buf, x, i, z);
140 166
 	}
141 167
 }
142 168
 

+ 4
- 8
lookUp.c View File

@@ -30,17 +30,12 @@ int flipAdjacent(int d) {
30 30
 	return converted;
31 31
 }
32 32
 
33
-void main() {
33
+int main() {
34 34
 	int byte;
35
-	int converted;
36 35
 
37
-	printf("penis = {");
38
-	
36
+	printf("uint8_t lookUp[256] = {");
39 37
 	for (byte = 0; byte < 256; byte++) {
40
-		converted = flip(byte);
41
-		converted = flipAdjacent(converted);
42
-
43
-		printf(" %d", converted);
38
+		printf(" %d", flipAdjacent(flip(byte));
44 39
 		if (((byte % 10) == 0) && (byte > 0)) {
45 40
 			printf(",\n");
46 41
 		} else if (byte < 255) {
@@ -48,4 +43,5 @@ void main() {
48 43
 		}
49 44
 	}
50 45
 	printf(" }\n");
46
+	return 0;
51 47
 }

Loading…
Cancel
Save