Skip to content

Commit 34857d7

Browse files
committed
Work on audio patterns
1 parent 5f99e3c commit 34857d7

File tree

2 files changed

+145
-12
lines changed

2 files changed

+145
-12
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
boolean MSGEQ7read() {
2+
return fft_available;
3+
}
4+
5+
6+
#define MSGEQ7_OUT_MAX 255
7+
8+
int MSGEQ7get(int band, int channel) {
9+
int value = map((fftData[band] * 100), 0, 100, 0, MSGEQ7_OUT_MAX);
10+
// Serial.printf("Band: %u = %u\n", band, value);
11+
return value;
12+
}
13+
14+
int barWidth = (kMatrixWidth / 8) / 2;
15+
int blockWidth = barWidth * 8;
16+
17+
void drawPixel(int x, int y, CRGB color) {
18+
leds[XY(x, y)] = color;
19+
}
20+
21+
22+
// Funky plank -----------------------------------------------------------------------------------
23+
24+
void FunkyPlank() {
25+
26+
bool newReading = MSGEQ7read();
27+
28+
// Led strip output
29+
if (newReading) {
30+
31+
// display values of left channel on DMD
32+
for (int band = 0; band < 8; band++ )
33+
{
34+
int hue = MSGEQ7get(band, 0);
35+
int v = map(MSGEQ7get(band, 0), 0, MSGEQ7_OUT_MAX, 10, 255);
36+
for (int b = 0; b < barWidth; b++) {
37+
int xpos = blockWidth - (barWidth * band) - b;
38+
drawPixel(xpos, 0, CHSV(hue, 255, v));
39+
// Serial.printf("band: %u, hue: %u v: %u\n", band, hue, v);
40+
// drawPixel((offset + band + 1), 0, CHSV(hue, 255, 255));
41+
}
42+
}
43+
44+
// display values of left channel on DMD
45+
for (int band = 0; band < 8; band++ )
46+
{
47+
int hue = MSGEQ7get(band, 1);
48+
int v = map(MSGEQ7get(band, 1), 0, MSGEQ7_OUT_MAX, 10, 255);
49+
for (int b = 0; b < barWidth; b++) {
50+
int xpos = blockWidth + 1 + (barWidth * band) + b;
51+
drawPixel(xpos, 0, CHSV(hue, 255, v));
52+
}
53+
}
54+
55+
FastLED.show();
56+
moveUp();
57+
58+
}
59+
}
60+
61+
void moveUp() {
62+
// Update the display:
63+
for (int i = (kMatrixHeight - 1); i >= 0; i--) {
64+
for (int j = (kMatrixWidth - 1); j >= 0; j--) {
65+
int src = XY(j, (i - 1));
66+
int dst = XY(j, i);
67+
leds[dst] = leds[src];
68+
}
69+
}
70+
}
71+
72+
73+
// DJ Light -----------------------------------------------------------------------------------
74+
75+
76+
void DJLight() {
77+
78+
bool newReading = MSGEQ7read();
79+
80+
// int offset = 8;
81+
82+
int mid = NUM_AUDIO_LEDS / 2;
83+
84+
// Led strip output
85+
if (newReading) {
86+
87+
int bands[8];
88+
for (int band = 0; band < 8; band++ )
89+
{
90+
bands[band] = MSGEQ7get(band, 1);
91+
}
92+
93+
94+
// leds[mid] = CRGB(bands[6], bands[5] / 8, bands[1] / 2);
95+
// leds[mid].fadeToBlackBy(bands[3] / 12);
96+
97+
98+
ledsAudio[mid] = CRGB(bands[5]/2, bands[2]/2, bands[0]/2);
99+
ledsAudio[mid].fadeToBlackBy((map(bands[1], 0, MSGEQ7_OUT_MAX, 255, 10)));
100+
101+
Serial.printf("RGB: %u %u %u\n", bands[5]/2, bands[2]/2, bands[0]/2);
102+
103+
104+
//move to the left
105+
for (int i = NUM_AUDIO_LEDS - 1; i > mid; i--) {
106+
ledsAudio[i] = ledsAudio[i - 1];
107+
}
108+
// move to the right
109+
for (int i = 0; i < mid; i++) {
110+
ledsAudio[i] = ledsAudio[i + 1];
111+
}
112+
113+
EVERY_N_MILLISECONDS(300) {
114+
// TODO: map to fade
115+
for (int i = 0; i < NUM_AUDIO_LEDS; i++) {
116+
ledsAudio[i].fadeToBlackBy(10);
117+
}
118+
}
119+
showSegments();
120+
}
121+
}

Deevstock/DeevstockDMX/soundmems.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
#ifndef SOUNDMEMS_H
22
#define SOUNDMEMS_H
33

4-
// all these libraries are required for the Teensy Audio Library
5-
#include <Audio.h>
6-
#include <Wire.h>
7-
#include <SPI.h>
8-
#include <SD.h>
9-
#include <SerialFlash.h>
10-
11-
AudioInputI2S audioInput;
12-
AudioAnalyzeFFT256 fft;
13-
AudioControlSGTL5000 audioShield;
4+
AudioInputI2S audioInput; // audio shield: mic or line-in
5+
AudioAnalyzeFFT256 fft;
146
AudioConnection patchCord1(audioInput, 0, fft, 0);
7+
AudioControlSGTL5000 audioShield;
8+
9+
10+
boolean fft_available;
11+
float fftData[8];
1512

16-
void soundmems() { // Here's where we capture sound. It provides an average, a current sample as well as a peak trigger.
17-
if (fft.available()) { // I tried some fancier math, but never came up with anything that really worked all that well. Must . . work. . harder.
13+
14+
void soundmems() {
15+
fft_available = fft.available();
16+
if (fft_available) {
17+
18+
fftData[0] = fft.read(2, 3);
19+
fftData[1] = fft.read(4, 6);
20+
fftData[2] = fft.read(7, 10);
21+
fftData[3] = fft.read(11, 19);
22+
fftData[4] = fft.read(20, 32);
23+
fftData[5] = fft.read(33, 52);
24+
fftData[6] = fft.read(53, 82);
25+
fftData[7] = fft.read(83, 127);
26+
27+
// Here's where we capture sound. It provides an average, a current sample as well as a peak trigger.
28+
// I tried some fancier math, but never came up with anything that really worked all that well. Must . . work. . harder.
29+
1830
// Local definitions
1931
#define sensitivity 100 // Define maximum cutoff of potentiometer for cutting off sounds.
2032
#define NSAMPLES 64 // Creating an array of lots of samples for decent averaging.

0 commit comments

Comments
 (0)