Преглед изворни кода

Logarithmic scale visualizer implemented.

Thomas Buck пре 12 година
родитељ
комит
6c59b90794
2 измењених фајлова са 1055 додато и 1004 уклоњено
  1. 1009
    997
      CubeFirmware/main.hex
  2. 46
    7
      CubeFirmware/visualizer.c

+ 1009
- 997
CubeFirmware/main.hex
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 46
- 7
CubeFirmware/visualizer.c Прегледај датотеку

@@ -35,11 +35,14 @@
35 35
 void simpleVisualization(uint8_t *data);
36 36
 void fullDepthVisualization(uint8_t *data);
37 37
 void horribleWave(uint8_t *audioData);
38
+void simpleLog(uint8_t *data);
39
+void fullDepthLog(uint8_t *data);
38 40
 
39
-#define NUMOFVISUALIZATIONS 3
41
+#define NUMOFVISUALIZATIONS 5
40 42
 
41 43
 void (*visualizations[NUMOFVISUALIZATIONS])(uint8_t *data) = { &simpleVisualization,
42
-													&fullDepthVisualization, &horribleWave };
44
+													&fullDepthVisualization, &horribleWave,
45
+													&simpleLog, &fullDepthLog };
43 46
 
44 47
 uint8_t numberOfVisualizations(void) {
45 48
 	return NUMOFVISUALIZATIONS;
@@ -50,10 +53,19 @@ void runVisualization(uint8_t *data, uint8_t id) {
50 53
 		visualizations[id](data);
51 54
 }
52 55
 
53
-void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z) {
54
-	uint8_t i, h, max;
56
+uint8_t logScale[8] = { 2, 4, 8, 16, 31, 63, 125, 250 };
57
+// --> ca. (1 << (led + 1));
58
+
59
+void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z, uint8_t log) {
60
+	uint8_t i, h = 0, max;
55 61
 	for(i = 0; i < 7; i++) {
56
-		max = data[i] / FACTOR;
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
+		}
57 69
 		for (h = 0; h < max; h++) {
58 70
 			if (i == 0) {
59 71
 				buffSetPixel(buff, i, (h * 10 / 15), z);
@@ -63,13 +75,40 @@ void simpleVUMeter(uint8_t *data, uint8_t *buff, uint8_t z) {
63 75
 	}
64 76
 }
65 77
 
78
+void simpleLog(uint8_t *data) {
79
+	uint8_t *buff;
80
+
81
+	buff = buffNew();
82
+	buffClearAllPixels(buff);
83
+
84
+	simpleVUMeter(data, buff, 7, 1);
85
+
86
+	setImage(buff);
87
+	buffFree(buff);
88
+}
89
+
66 90
 void simpleVisualization(uint8_t *data) {
67 91
 	uint8_t *buff;
68 92
 	buff = buffNew();
69 93
 
70 94
 	buffClearAllPixels(buff);
71 95
 
72
-	simpleVUMeter(data, buff, 7);
96
+	simpleVUMeter(data, buff, 7, 0);
97
+
98
+	setImage(buff);
99
+	buffFree(buff);
100
+}
101
+
102
+void fullDepthLog(uint8_t *data) {
103
+	uint8_t *buff;
104
+	uint8_t i;
105
+	buff = buffNew();
106
+
107
+	buffClearAllPixels(buff);
108
+
109
+	for (i = 0; i < 8; i++) {
110
+		simpleVUMeter(data, buff, i, 1);
111
+	}
73 112
 
74 113
 	setImage(buff);
75 114
 	buffFree(buff);
@@ -83,7 +122,7 @@ void fullDepthVisualization(uint8_t *data) {
83 122
 	buffClearAllPixels(buff);
84 123
 
85 124
 	for (i = 0; i < 8; i++) {
86
-		simpleVUMeter(data, buff, i);
125
+		simpleVUMeter(data, buff, i, 0);
87 126
 	}
88 127
 
89 128
 	setImage(buff);

Loading…
Откажи
Сачувај